File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,7 +69,9 @@ func (msg verACK) Handle(node Noder) error {
6969 // Fixme, there is a race condition here,
7070 // but it doesn't matter to access the invalid
7171 // node which will trigger a warning
72- node .ReqNeighborList ()
72+ if node .LocalNode ().NeedMoreAddresses () {
73+ node .ReqNeighborList ()
74+ }
7375 addr := node .GetAddr ()
7476 port := node .GetPort ()
7577 nodeAddr := addr + ":" + strconv .Itoa (int (port ))
Original file line number Diff line number Diff line change @@ -136,7 +136,9 @@ func (node *node) ConnectSeeds() {
136136 node .nbrNodes .Unlock ()
137137 if found {
138138 if n .GetState () == ESTABLISH {
139- n .ReqNeighborList ()
139+ if node .LocalNode ().NeedMoreAddresses () {
140+ n .ReqNeighborList ()
141+ }
140142 }
141143 } else { //not found
142144 go node .Connect (nodeAddr )
Original file line number Diff line number Diff line change @@ -7,6 +7,12 @@ import (
77 "sync"
88)
99
10+ const (
11+ // needAddressThreshold is the number of addresses under which the
12+ // address manager will claim to need more addresses.
13+ needAddressThreshold = 1000
14+ )
15+
1016type KnownAddress struct {
1117 srcAddr NodeAddr
1218}
@@ -33,6 +39,13 @@ func (ka *KnownAddress) GetID() uint64 {
3339 return ka .srcAddr .ID
3440}
3541
42+ func (al * KnownAddressList ) NeedMoreAddresses () bool {
43+ al .Lock ()
44+ defer al .Unlock ()
45+
46+ return al .addrCount < needAddressThreshold
47+ }
48+
3649func (al * KnownAddressList ) AddressExisted (uid uint64 ) bool {
3750 _ , ok := al .List [uid ]
3851 return ok
Original file line number Diff line number Diff line change @@ -148,6 +148,7 @@ type Noder interface {
148148 GetDefaultMaxPeers () uint
149149 GetMaxOutboundCnt () uint
150150 GetGetAddrMax () uint
151+ NeedMoreAddresses () bool
151152}
152153
153154func (msg * NodeAddr ) Deserialization (p []byte ) error {
You can’t perform that action at this time.
0 commit comments