Skip to content
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

change network connect way #410

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

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 <[email protected]>
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 <[email protected]>
If the connection more than max connect peers,
disconnect one node.

Signed-off-by: Jin Qing <[email protected]>
If address list less than 1000 send getaddr request

Signed-off-by: Jin Qing <[email protected]>
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 <[email protected]>
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