@@ -63,6 +63,18 @@ func NewRTHostList() *RTHostList {
63
63
return r
64
64
}
65
65
66
+ // Copies an RTHost and computes the Distance of rh.Host to newref. If
67
+ // newref is "", the old distance is used
68
+ func (rh * RTHost ) Copy (newref string ) (rhc * RTHost ) {
69
+ rhc = new (RTHost )
70
+ rhc .Host = rh .Host
71
+ if newref == "" {
72
+ newref = rh .Host .Id
73
+ }
74
+ rhc .Distance = XOR (newref , rhc .Host .Id )
75
+ return
76
+ }
77
+
66
78
func (l * RTHostList ) Push (h * RTHost ) { l .v .Push (h ) }
67
79
68
80
func (l * RTHostList ) Len () int {
@@ -348,7 +360,7 @@ func (rt *BRoutingTable) GetClosest(t string, n uint) *RTHostList {
348
360
return <- r
349
361
}
350
362
351
- // TODO: wtf behaviour? gets the closests n nodes to us close to t????
363
+
352
364
// not goroutine safe. for internal use!
353
365
func (rt * BRoutingTable ) getClosest (t string , n uint ) * RTHostList {
354
366
//rt.logger.Logf("looking for %x dist %v<br>\n", t, XOR(rt.id, t))
@@ -369,7 +381,7 @@ func (rt *BRoutingTable) getClosest(t string, n uint) *RTHostList {
369
381
var rn uint = 0
370
382
371
383
for _ , el := range buckets [bucketno ].hosts {
372
- hl .Push (el )
384
+ hl .Push (el . Copy ( t ) )
373
385
rn ++
374
386
}
375
387
@@ -389,14 +401,14 @@ func (rt *BRoutingTable) getClosest(t string, n uint) *RTHostList {
389
401
390
402
if cangoup {
391
403
for _ , el := range buckets [bucketno + delta ].hosts {
392
- hl .Push (el )
404
+ hl .Push (el . Copy ( t ) )
393
405
rn ++
394
406
}
395
407
}
396
408
397
409
if cangodown {
398
410
for _ , el := range buckets [bucketno - delta ].hosts {
399
- hl .Push (el )
411
+ hl .Push (el . Copy ( t ) )
400
412
rn ++
401
413
}
402
414
}
0 commit comments