-
Notifications
You must be signed in to change notification settings - Fork 443
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
Formalising the API #64
Conversation
Finished polishing and documenting the libp2p API. Feel welcome to post comments and review. Now:
|
|
||
`callback` is a function with the following `function (err) {}` signature, where `err` is an Error in case stopping the node fails. | ||
|
||
#### `libp2p.dial(peer [, protocol, callback])` |
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.
I would like to split this into dial
and connect
.
dial(peer, protocol, callback)
all args required does what this does currentlyconnect(peer, callback)
only ensures a connection is made to the peer, does not return a conn in the callback
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.
Interesting, I'm thinking about it, not 100% convinced yet, but I can definitely see the potential of having a 'more clean way' for people to migrate from that swarm.connect that go-ipfs kind of standardised.
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.
On a second though, I like to keep it simple in libp2p land.
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.
Why does this make it simpler? It's just overloading a single method with even more functionality
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.
Simpler as in "start fresh" and not have to take in a legacy 'connect'. I kind of like your idea, just not convinced about the dial and connect keyword: is it intuitive for users?
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.
Maybe, on the other hand as long as dial creates a connection if it's missing I am not sure this is actually needed currently. Lets leave it as is for now, need to work through more code until am sure
|
||
#### `libp2p.findProviders` | ||
|
||
#### `libp2p.record.put` |
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.
I think these should be called dht.put
and dht.get
as they allow you to put arbitrary values not only records
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.
go-ipfs only allows (at least per js-ipfs-api tests) to put/get records, provider or IPNS.
It might make sense to just expose it as dht, so that we have a clean upgrade path for when we have the routing and record interfaces well established.
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.
Not sure why that is, the underlying method do not have this restriction: https://github.com/libp2p/go-libp2p-kad-dht/blob/master/routing.go#L35
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.
@dignifiedquire because there is no current value for IPFS in having people using the DHT as a generic key-value store.
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.
That being said, don't feel the need to shoehorn this API methods as you develop the DHT, they aren't solidified yet.
src/index.js
Outdated
pingByMultiaddr (maddr, callback) { | ||
assert(this.isOnline, OFFLINE_ERROR_MESSAGE) | ||
callback(new Error('not implemented yet')) | ||
isOn () { |
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.
Hmm why isOn
and isOnline
both?
src/index.js
Outdated
pingByPeerInfo (peerInfo, callback) { | ||
assert(this.isOnline, OFFLINE_ERROR_MESSAGE) | ||
ping (peer, callback) { | ||
assert(this.isOn, OFFLINE_ERROR_MESSAGE) |
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.
isOn
is a method
src/index.js
Outdated
|
||
this.peerBook.removeByB58String(peer.id.toB58String()) | ||
this.swarm.hangUp(peer, callback) | ||
this.peerBook.removeByB58String(peerInfo.id.toB58String()) |
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 is not good, just because we hang up does not mean we want to forget about the peer details
try { | ||
p = this.peerBook.getByB58String(peerIdB58Str) | ||
} catch (err) { | ||
// TODO this is where PeerRouting comes into place |
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.
Actually it doesn't. As far as I understand additions to the peerbook are made directly from e.g. the dht while peers are discovered. If you want to dial a peerid you do not know you make a manual request on the libp2p level to the peer routing mechanism to get multiaddrs. The automatic check should happen at the ipfs level.
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.
Here, what would happen would be something like a this.findPeers, to see if we can find the Peer we are looking for. If we then retrieve it from the PeerBook, that is ok.
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.
But we already do a lookup in the peerbook, we can not start a dht query here, as this method gets called by the dht to dial, so it could get stuck in a loop
hangUpById (id, callback) { | ||
// TODO | ||
callback(new Error('not implemented yet')) | ||
this.peerBook.removeByB58String(peerInfo.id.toB58String()) |
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.
@diasdavid THIS IS GOING TO BREAK THINGS when we have a dht :(
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.
Yeah, and we actually don't need it. Note that this was here before.
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.
I was trying to remember why this was added here and I just figured out. pre-dht era, I treated the PeerBook as our source of truth for peers we are connected, and so: https://github.com/ipfs/js-ipfs/blob/master/src/core/components/swarm.js#L12-L47 relies on that.
We could do a match with swarm.muxedConns, but a better solution is to actually have a little bit more state on the PeerInfo object I believe. Same goes for the address that gets picked, so that when we do log out the peers we are connected, we only print the addr we are actually using (like go-ipfs does).
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.
Maybe we should separate these two like go does, so that we have one storage for all details about peers we have ever seen and one storage where we just store the currently connected peers with the address they are connected with.
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.
swarm.muxedConns is kind of that place where "just store the currently connected peers with the address they are connected with.".
I feel it is more reasonable to keep all that state in just one place.
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.
sounds good, lets keep the discussion in #68
restructure and add spdy to browser tests
## [6.0.1](libp2p/js-libp2p-peer-store@v6.0.0...v6.0.1) (2023-02-28) ### Trivial Changes * replace err-code with CodeError ([libp2p#53](libp2p/js-libp2p-peer-store#53)) ([e6b87d7](libp2p/js-libp2p-peer-store@e6b87d7)), closes [js-libp2p#1269](libp2p#1269) * Update .github/workflows/semantic-pull-request.yml [skip ci] ([1139dc4](libp2p/js-libp2p-peer-store@1139dc4)) ### Documentation * Update API link ([libp2p#65](libp2p/js-libp2p-peer-store#65)) ([1b75110](libp2p/js-libp2p-peer-store@1b75110)), closes [libp2p#64](libp2p/js-libp2p-peer-store#64)
* deps(dev): bump aegir from 38.1.8 to 39.0.10 Bumps [aegir](https://github.com/ipfs/aegir) from 38.1.8 to 39.0.10. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](ipfs/aegir@v38.1.8...v39.0.10) --- updated-dependencies: - dependency-name: aegir dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore: fix linting --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: achingbrain <alex@achingbrain.net>
## [5.0.4](libp2p/js-libp2p-peer-record@v5.0.3...v5.0.4) (2023-06-15) ### Trivial Changes * Update .github/workflows/semantic-pull-request.yml [skip ci] ([10f3201](libp2p/js-libp2p-peer-record@10f3201)) * Update .github/workflows/stale.yml [skip ci] ([0bd8e9d](libp2p/js-libp2p-peer-record@0bd8e9d)) ### Dependencies * **dev:** bump aegir from 38.1.8 to 39.0.10 ([libp2p#64](libp2p/js-libp2p-peer-record#64)) ([ba3ac38](libp2p/js-libp2p-peer-record@ba3ac38))
No description provided.