updated Update function
Juan Batiz-Benet committed
Sep 16, 2014 at 06:40 UTC
0773e584fd09fef858ccbf0d93521ac22d367e02
1 file changed
+12
-11
routing/dht/dht.go
+12
-11
@@ -302,24 +302,25 @@ func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
302
return dht.datastore.Put(ds.NewKey(string(key)), value)
303
}
304
305
-// Update TODO(chas) Document this function
305
+// Update signals to all routingTables to Update their last-seen status
306
+// on the given peer.
307
func (dht *IpfsDHT) Update(p *peer.Peer) {
308
+ removedCount := 0
309
for _, route := range dht.routingTables {
310
removed := route.Update(p)
311
// Only close the connection if no tables refer to this peer
312
if removed != nil {
311
- found := false
312
- for _, r := range dht.routingTables {
313
- if r.Find(removed.ID) != nil {
314
- found = true
315
- break
316
- }
317
- }
318
- if !found {
319
- dht.network.CloseConnection(removed)
320
- }
313
+ removedCount++
314
}
315
}
316
+
317
+ // Only close the connection if no tables refer to this peer
318
+ // if removedCount == len(dht.routingTables) {
319
+ // dht.network.ClosePeer(p)
320
+ // }
321
+ // ACTUALLY, no, let's not just close the connection. it may be connected
322
+ // due to other things. it seems that we just need connection timeouts
323
+ // after some deadline of inactivity.
324
}
325
326
// Find looks for a peer with a given ID connected to this dht and returns the peer and the table it was found in.