Skip to content

Conversation

@superJinQing
Copy link
Contributor

  1. change getaddr request handle.
    If receive getaddr request, randomly select some address and send addr response. At most send 8 address.
  2. change addr response handle
    When receive addr message, save the addresses in address list
  3. If the connection is less than MaxOutboundCnt, select addresses from address list and connect them.
  4. Disable reconnect function
  5. If the connection more than max connect peers, disconnect one node.

@superJinQing superJinQing force-pushed the rand branch 3 times, most recently from e0516bd to 0e82bd8 Compare September 19, 2017 08:58

func (al *KnownAddressList) RandGetAddresses(nbrAddrs []NodeAddr) []NodeAddr {
var keys []uint64
for k := range al.List {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. missing lock here.
  2. 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 {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor

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()
}
Copy link
Contributor

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>
Honglei-Cong pushed a commit to Honglei-Cong/DNA that referenced this pull request Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants