|
42 | 42 | baseLogger = logger.Desugar() |
43 | 43 | ) |
44 | 44 |
|
45 | | -// BaseConnMgrScore is the base of the score set on the connection manager "kbucket" tag. |
46 | | -// It is added with the common prefix length between two peer IDs. |
47 | | -const BaseConnMgrScore = 5 |
| 45 | +const ( |
| 46 | + // BaseConnMgrScore is the base of the score set on the connection |
| 47 | + // manager "kbucket" tag. It is added with the common prefix length |
| 48 | + // between two peer IDs. |
| 49 | + baseConnMgrScore = 5 |
| 50 | + |
| 51 | + // UsefulConnMgrScore is given to peers that are among the first peers |
| 52 | + // to respond to a query. |
| 53 | + // |
| 54 | + // This score is given to peers the first time they're useful and lasts |
| 55 | + // until we disconnect from the peer. |
| 56 | + usefulConnMgrScore = 20 |
| 57 | + |
| 58 | + // UsefulConnMgrProtectedBuckets is the number of buckets where useful |
| 59 | + // peers are _protected_, instead of just given the useful score. |
| 60 | + usefulConnMgrProtectedBuckets = 2 |
| 61 | +) |
48 | 62 |
|
49 | 63 | type mode int |
50 | 64 |
|
@@ -347,8 +361,14 @@ func makeRoutingTable(dht *IpfsDHT, cfg config, maxLastSuccessfulOutboundThresho |
347 | 361 | cmgr := dht.host.ConnManager() |
348 | 362 |
|
349 | 363 | rt.PeerAdded = func(p peer.ID) { |
| 364 | + // We tag our closest peers with higher and higher scores so we |
| 365 | + // stay connected to our nearest neighbors. |
| 366 | + // |
| 367 | + // We _also_ (elsewhere) protect useful peers in the furthest |
| 368 | + // buckets (our "core" routing nodes) and give high scores to |
| 369 | + // all other useful peers. |
350 | 370 | commonPrefixLen := kb.CommonPrefixLen(dht.selfKey, kb.ConvertPeerID(p)) |
351 | | - cmgr.TagPeer(p, kbucketTag, BaseConnMgrScore+commonPrefixLen) |
| 371 | + cmgr.TagPeer(p, kbucketTag, baseConnMgrScore+commonPrefixLen) |
352 | 372 | } |
353 | 373 | rt.PeerRemoved = func(p peer.ID) { |
354 | 374 | cmgr.Unprotect(p, dhtUsefulTag) |
|
0 commit comments