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

refactor: update network to use async libp2p #206

Merged
merged 29 commits into from
Jan 28, 2020
Merged

Conversation

jacobheun
Copy link
Contributor

@jacobheun jacobheun commented Dec 12, 2019

Migrating to async libp2p.

Note: This is currently using the prerelease

@jacobheun jacobheun force-pushed the refactor/libp2p-async branch from 00ff648 to c8593bb Compare December 14, 2019 17:19
@jacobheun jacobheun changed the title [WIP] refactor: update network to use async libp2p refactor: update network to use async libp2p Dec 15, 2019
@jacobheun
Copy link
Contributor Author

This is still pending the release of libp2p 0.27, but should otherwise be good to review. I refactored some things that were related to the libp2p change, but tried to avoid touching too much. I wouldn't mind helping do some more refactoring as a followup PR (after the new year).

@jacobheun jacobheun requested a review from dirkmc December 15, 2019 18:10
package.json Outdated
"just-debounce-it": "^1.1.0",
"moving-average": "^1.0.0",
"multicodec": "~0.5.0",
"multihashing-async": "^0.8.0",
"protons": "^1.0.1",
"pull-length-prefixed": "^1.3.1",
"pull-stream": "^3.6.9",
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this and callbackify?

src/network.js Outdated
}
})
}
Copy link
Member

Choose a reason for hiding this comment

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

try/catch around this pipeline? I think the remote can send a stream reset message that will throw.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch, added.

this._log('sendMessage to %s', stringId, msg)

const { conn, protocol } = await this._dialPeer(peer)
const { stream, protocol } = await this._dialPeer(peer)
Copy link
Member

Choose a reason for hiding this comment

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

Does this need a try/catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't need one because sendMessage already throws. There are catches in both places sendMessage is used.

src/network.js Outdated
const message = await Message.deserialize(data.slice())
this.bitswap._receiveMessage(connection.remotePeer, message)
} catch (err) {
this.bitswap._receiveError(err)
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to continue receiving or return?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be the same as the existing code it should end iteration, you're right. I added a break to exit iteration to keep it consistent with the existing functionality.

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

Awesome! Thanks @jacobheun, and congrats on the libp2p changes, it makes the calling code so much nicer. Thanks for refactoring some of the gnarlier code in here, I'd love to have further refactors where you can see improvements in future.

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

Lets get this merged and released! 🥳

@dirkmc
Copy link
Contributor

dirkmc commented Jan 23, 2020

@jacobheun please let me know when libp2p is released and I will update the dependency and merge

@jacobheun
Copy link
Contributor Author

@dirkmc will do, we just have two outstanding docs PRs, libp2p/js-libp2p#514 and libp2p/js-libp2p#508. Once those are merged I will do an RC and follow up shortly after that with a release (potentially tomorrow, pending reviews).

@dirkmc
Copy link
Contributor

dirkmc commented Jan 23, 2020

Cool thank you, no rush ❤️

@jacobheun jacobheun marked this pull request as ready for review January 28, 2020 12:56
@jacobheun jacobheun force-pushed the refactor/libp2p-async branch from 3af509a to 51209da Compare January 28, 2020 12:59
@jacobheun jacobheun requested a review from dirkmc January 28, 2020 13:29
@jacobheun
Copy link
Contributor Author

@dirkmc I've updated libp2p, this should be all set.

Copy link
Contributor

@dirkmc dirkmc left a comment

Choose a reason for hiding this comment

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

💥

@dirkmc dirkmc merged commit 57cd476 into master Jan 28, 2020
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.

3 participants