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

Support sending files #69

Closed
youngjoon-lee opened this issue May 6, 2023 · 9 comments · Fixed by #76
Closed

Support sending files #69

youngjoon-lee opened this issue May 6, 2023 · 9 comments · Fixed by #76

Comments

@youngjoon-lee
Copy link
Contributor

youngjoon-lee commented May 6, 2023

Hi all,

Thank you for making this repo. It’s super helpful to understand how to configure nodes for each programming languages and to see the current state of libp2p connectivity.

If I’m allowed, I would like to try to implement the file-sharing feature using the request-response protocol. The file-sharing example is already presented in the rust-libp2p repo, but it would be meaningful to implement it in this repo using multiple programming languages.

I’m thinking about the following scenario.

  • Browser A clicks a send-file button next to the message textbox. Then, a file browser is opened. The user selects a file. The browser holds the file in memory and provide the file using Kademlia (start-providing). Plus, Browser A publishes a special message FileAd(name) via gossipsub.
  • Other browser peers, which receive the FileAd(name) message, execute the Kademlia get-provider operation. After getting the provider information, it sends a file request to Browser A by its relay address. Until the file is delivered, web UI just shows a temporary message box: Receiving a file.
  • Finally, Browser A sends a file response back to the file requester. Then, the web UI of the file requester displays a clickable file name in the message box, so that the user can download the file to their local.

I’m not sure if this scenario will work, but I think it’s worth trying, if I can have a chance to do it.

@p-shahi
Copy link
Member

p-shahi commented May 11, 2023

@youngjoon-lee That would awesome, and a very useful feature for a chat app such as this. If you would like to do this, please feel free to! I had some idea about this myself about perhaps integrating with https://github.com/ipfs/helia as a backend for storing files

@youngjoon-lee
Copy link
Contributor Author

@youngjoon-lee That would awesome, and a very useful feature for a chat app such as this. If you would like to do this, please feel free to! I had some idea about this myself about perhaps integrating with https://github.com/ipfs/helia as a backend for storing files

Thank you! I'll share a draft PR with you soon!

@mxinden
Copy link
Member

mxinden commented May 12, 2023

Browser A clicks a send-file button next to the message textbox. Then, a file browser is opened. The user selects a file. The browser holds the file in memory and provide the file using Kademlia (start-providing). Plus, Browser A publishes a special message FileAd(name) via gossipsub.

For the sake of simplicity, given that you are already planning to publish to a gossipsub topic, you might as well include the nodes addresses in the announcement, thus alleviating the need for Kademlia and its Provider system.

@youngjoon-lee
Copy link
Contributor Author

For the sake of simplicity, given that you are already planning to publish to a gossipsub topic, you might as well include the nodes addresses in the announcement, thus alleviating the need for Kademlia and its Provider system.

Thank you! That’s definitely more efficient. 👍

I have a short question. It seems that the request-response protocol is implemented only in rust-libp2p, not in js-libp2p and go-libp2p. Is the request-response not a part of the official libp2p spec? or is it a deprecated spec? If so, I need to consider using IPFS as @p-shahi suggested above, but I’m not sure if it’s okay to use IPFS in this repo, considering the coverage/purpose of this universal-connectivity topic

@p-shahi
Copy link
Member

p-shahi commented May 12, 2023

@youngjoon-lee request/response or libp2p + HTTP is an active area of development right now. There is a spec being written: libp2p/specs#508 and some draft PRs in go-libp2p right now. In js-libp2p we have this prototype: https://github.com/MarcoPolo/js-libp2p-fetch
Adding this is a high priority for the team atm, so please stay tuned!

Wrt integrating with Helia in this repo: You're right, the goal of this project is to showcase different libp2p transports/connectivity capabilities all in one application. We'll be creating a tutorial that shows how to build it etc: #67

I think adding a Helia integration would be cool, but maybe in a forked repo?
One of our goals after finishing up this app was to create a guide on fetching a CID with Helia using the libp2p peers.
Depending on how your organize the new integration in the codebase, I think there's a case for the fork to be merged in here too

@BigLep
Copy link

BigLep commented May 12, 2023

As far as an example that uses IPFS in a browser to share files, I'm just passing on that there is https://github.com/ipfs-shipyard/ipfs-share-files and there is an issue (ipfs-shipyard/ipfs-share-files#136 ) to move it to Helia. I'm just passing that on as an FYI.

@thomaseizinger
Copy link
Contributor

For the sake of simplicity, given that you are already planning to publish to a gossipsub topic, you might as well include the nodes addresses in the announcement, thus alleviating the need for Kademlia and its Provider system.

Thank you! That’s definitely more efficient. 👍

I have a short question. It seems that the request-response protocol is implemented only in rust-libp2p, not in js-libp2p and go-libp2p.

The request-response module is just an abstraction to send a request and receive a response on a stream. You can do this in all other languages too! Just use the same codec.

For example, soon, there will be out-of-the-box JSON and CBOR support: libp2p/rust-libp2p#3952

The only convention that you need to follow in other languages is to close the stream after writing (both for requests and responses).

@p-shahi
Copy link
Member

p-shahi commented May 31, 2023

@youngjoon-lee Btw if you're interested in working on this, I think this would be a good project for HackFS our upcoming hackathon: https://ethglobal.com/events/hackfs2023
Would love it you join (registration ends 11:59pm ET)

@youngjoon-lee
Copy link
Contributor Author

@youngjoon-lee Btw if you're interested in working on this, I think this would be a good project for HackFS our upcoming hackathon: https://ethglobal.com/events/hackfs2023
Would love it you join (registration ends 11:59pm ET)

Thank you! I will

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 a pull request may close this issue.

5 participants