-
Notifications
You must be signed in to change notification settings - Fork 143
change network connect way #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
e0516bd to
0e82bd8
Compare
|
|
||
| func (al *KnownAddressList) RandGetAddresses(nbrAddrs []NodeAddr) []NodeAddr { | ||
| var keys []uint64 | ||
| for k := range al.List { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- missing lock here.
- maybe it is better to directly copy out the address instead of the key to avoid unnecessary existence check in the latter code.
| ka.srcAddr.ID = na.ID | ||
| } | ||
|
|
||
| func (ka *KnownAddress) NetAddress() NodeAddr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use NodeAddr directly or type KnownAddress NodeAddr to avoid redundant code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This structure will add other members in next version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
1. When receive address message save the addresses in address list. 2. If the connection is less than MaxOutboundCnt, select addresses from address list and connect them. 3. When receive getaddr request, randomly select some address and send addr response. At most send 8 address. Signed-off-by: Jin Qing <1091147665@qq.com>
If the connection is less than MaxOutboundCnt, the node will pick peers from address list and connect them. So we don't need reconnect now. Signed-off-by: Jin Qing <1091147665@qq.com>
If the connection more than max connect peers, disconnect one node. Signed-off-by: Jin Qing <1091147665@qq.com>
If address list less than 1000 send getaddr request Signed-off-by: Jin Qing <1091147665@qq.com>
| func (ka *KnownAddress) updateLastDisconnect() { | ||
| // set last disconnect time to now | ||
| ka.lastattempt = time.Now() | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the upper two function signatures have opposite function body.
Judge whether the peer is bad before connect it. If it is bad won't connect it. Signed-off-by: Jin Qing <1091147665@qq.com>
If receive getaddr request, randomly select some address and send addr response. At most send 8 address.
When receive addr message, save the addresses in address list