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

Add more examples of getting and putting records in the IPFS DHT #2263

Closed
pawelradtke-sage opened this issue Oct 3, 2021 · 7 comments · Fixed by #4567
Closed

Add more examples of getting and putting records in the IPFS DHT #2263

pawelradtke-sage opened this issue Oct 3, 2021 · 7 comments · Fixed by #4567
Assignees
Labels
difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted

Comments

@pawelradtke-sage
Copy link

pawelradtke-sage commented Oct 3, 2021

Hi,

The ipfs-kad.rs only demonstrates one operation (find closest peers) on the IPFS DHT. I think it would be useful to go a bit further and demonstrate how to read/write PK or IPNS records.

I'm willing to contribute an example file similar to these in the ./examples folder, but I myself need to be shown how perform these operations first.

@pawelradtke-sage pawelradtke-sage changed the title Can't put records to IPFS DHT Add more examples of getting and putting records in the IPFS DHT Oct 5, 2021
@mxinden mxinden added difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted labels Nov 10, 2021
@mxinden
Copy link
Member

mxinden commented Nov 10, 2021

With #2309 merged, do you want to take a shot at this one @pawelradtke-sage?

@pradt2
Copy link
Contributor

pradt2 commented Nov 12, 2021

I had a brief look at go-libp2p-kad-dht yesterday, and there they have some IPFS DHT-specific primitives like PK/IPNS record validators, IPNS structs, IPLD Nodes, some factory methods, utils for signing and signature verification, etc. This makes high-level interactions with the DHT very easy.

None of these primitives exist in rust-libp2p (or I haven't found them). This means that an example of putting an IPNS record into the DHT would not only need to show how to call kademlia::PutValue, but also how to build the record from scratch (and it's a bit of a lengthy process). This doesn't sit right with me. I think it would make more sense to have these primities available in our codebase, so that we can offer an easy to use, high level API similar to that of go-libp2p-kad-dht. This would make the primitives readily reusable, and would make the example a lot less cluttered.

Specifically, we would need (almost) all of go-ipns (IPNS struct, Create method for IPNS records, Validate method for IPNS records), a little bit of go-libp2p-record (Validate method for PublicKeyRecords) and some of go-ipld-prime (Node struct and methods are used to create CBOR data used for signing and validation of IPNS records).

I understand that not everyone might be interested in these primitives, but this can be easily solved by hiding them behind a feature flag.

I am happy to give this a try, but I first wanted to ask if you agree that this is the right way to go. I may need some guidance in terms of where to place this new code, and how to make other crates (optionally) dependent on it. Right now I'm thinking we could either add more top-level crates (i.e. rust-ipns, rust-ipld-prime, etc.) and make rust-libp2p-kad optionally dependent on them, or we could just put it all in rust-libp2p-kad and add an optional feature there.

Let me know what you think @mxinden

BTW fyi, @pawelradtke-sage is my work account, I forgot to switch accounts before opening this issue. Apologies for any confusion.

@mxinden
Copy link
Member

mxinden commented Nov 13, 2021

Thus far the Rust libp2p-kad implementation is a low level layer enabling other projects, e.g. https://github.com/rs-ipfs/rust-ipfs/ to build on top of it.

Instead of including IPNS, IPLD etc. to libp2p-kad, how about improving the interfaces of libp2p-kad to enable these higher layers to easily operate on top of libp2p-kad?

In my eyes that would (1) enable a clean layer distinction and (2) does not increase the already very large maintenance surface of rust-libp2p.

@thomaseizinger
Copy link
Contributor

With #3509, all the examples are separate binary crates. Thus, they can have their own dependencies. We could thus add whatever dependencies we need, for example https://github.com/ipld/libipld to demonstrate how to interact with the IPFS network.

@pradt2
Copy link
Contributor

pradt2 commented Sep 12, 2023

Nice, I think I should be able to do it next week, or the week after.

@thomaseizinger
Copy link
Contributor

thomaseizinger commented Sep 12, 2023

Nice, I think I should be able to do it next week, or the week after.

Great! Let me say this upfront though: Depending on how many dependencies we need, this might still have to be something that lives outside the repository. I'd suggest that you open a draft PR fairly early on so we can evaluate, whether or not such an example is something that we are able to maintain :)

Hope that makes sense!

@pradt2
Copy link
Contributor

pradt2 commented Sep 27, 2023

I've just opened a PR for this: #4566

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants