Skip to content

Commit bbb18fd

Browse files
committed
If address list less than 1000 send getaddr req
If address list less than 1000 send getaddr request Signed-off-by: Jin Qing <1091147665@qq.com>
1 parent 513e30f commit bbb18fd

4 files changed

Lines changed: 20 additions & 2 deletions

File tree

net/message/verack.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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))

net/node/infoUpdate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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)

net/node/knowaddrlist.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
1016
type 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+
3649
func (al *KnownAddressList) AddressExisted(uid uint64) bool {
3750
_, ok := al.List[uid]
3851
return ok

net/protocol/protocol.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ type Noder interface {
148148
GetDefaultMaxPeers() uint
149149
GetMaxOutboundCnt() uint
150150
GetGetAddrMax() uint
151+
NeedMoreAddresses() bool
151152
}
152153

153154
func (msg *NodeAddr) Deserialization(p []byte) error {

0 commit comments

Comments
 (0)