Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Improve peer connection handling #590

Closed

Conversation

peterargue
Copy link

@peterargue peterargue commented Oct 11, 2022

Currently, the bitswap network only adds peers to its client/server peer lists that connected after the network has started. This means the network must be started before enabling the libp2p listeners, otherwise some peers may connect too early and never be added to the network.

To address this, this PR updates the bitswap network's Start() method to first, listen for new peer connection events, and then iterate through all peers and add any that support the bitswap protocols. The issue and solution were originally described by @Stebalien in ipfs/boxo#83.

@welcome
Copy link

welcome bot commented Oct 11, 2022

Thank you for submitting this PR!
A maintainer will be here shortly to review it.
We are super grateful, but we are also overloaded! Help us by making sure that:

  • The context for this PR is clear, with relevant discussion, decisions
    and stakeholders linked/mentioned.

  • Your contribution itself is clear (code comments, self-review for the
    rest) and in its best form. Follow the code contribution
    guidelines

    if they apply.

Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment.
Next steps:

  • A maintainer will triage and assign priority to this PR, commenting on
    any missing things and potentially assigning a reviewer for high
    priority items.

  • The PR gets reviews, discussed and approvals as needed.

  • The PR is merged by maintainers when it has been approved and comments addressed.

We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution.
We are very grateful for your contribution!

@peterargue
Copy link
Author

peterargue commented Oct 13, 2022

Looks like different tests failed in each of the suites. All tests pass locally.

I'm happy to fix/add tests if you're ok with the changes.

Copy link
Contributor

@Jorropo Jorropo left a comment

Choose a reason for hiding this comment

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

Sorry for the delay.
Overall it seems correct, I don't see a test for this (I guess the test would be start node 1 and 2 but don't connect them, start a request on node 1 then connect 2 to 1 and see if the request complete in less than X timeout).

Comment on lines +403 to +417
if peu, ok := evt.(event.EvtPeerProtocolsUpdated); ok {
if bsnet.hasBitswapProtocol(peu.Added) {
log.Debugf("connecting to peer with updated protocol list: %s", peu.Peer)
bsnet.connectEvtMgr.Connected(peu.Peer)
continue
}

if bsnet.hasBitswapProtocol(peu.Removed) && !bsnet.peerSupportsBitswap(peu.Peer) {
log.Debugf("disconnecting from peer with updated protocol list: %s", peu.Peer)
bsnet.connectEvtMgr.Disconnected(peu.Peer)
}
continue
}

if peic, ok := evt.(event.EvtPeerIdentificationCompleted); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use a type switch

@Jorropo
Copy link
Contributor

Jorropo commented Jan 27, 2023

This repository has been moved to https://github.com/ipfs/go-libipfs. There is not an easy way to transfer PRs, so if you would like to continue with this PR then please re-open it in the new repository and link to this PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants