Commit f34b0b2
tracker: make memory-store announce a uniform random peer sample
The previous ordered-scan-with-wraparound selection biased toward the
low end of the peer-id key space: because ETS ordered_set keys are
sorted (where Go maps iterate randomly) and real peer ids cluster, a
random start key usually landed past every entry, so announces kept
returning the same lowest-keyed peers instead of a varied subset. This
starves high-keyed peers and diverges from chihaya's randomized map
iteration. Replace it with an explicit uniform random sample over the
swarm's keys of the requested kind. The Redis store already matches
chihaya by taking the HKEYS-order prefix and is unchanged. Adds a
regression test with clustered peer ids.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DqKy7xpT2kp7ZATjLKsdhT1 parent 85fd39f commit f34b0b2
2 files changed
Lines changed: 48 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
| 132 | + | |
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
136 | | - | |
| 136 | + | |
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| |||
365 | 365 | | |
366 | 366 | | |
367 | 367 | | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
392 | 374 | | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
397 | 378 | | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
405 | 382 | | |
406 | 383 | | |
407 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
408 | 388 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
87 | 116 | | |
0 commit comments