go-libp2p-examples | Example libp2p applications
kandi X-RAY | go-libp2p-examples Summary
kandi X-RAY | go-libp2p-examples Summary
In this folder, you can find a variety of examples to help you get started in using go-libp2p. Every example as a specific purpose and some of each incorporate a full tutorial that you can follow through, helping you expand your knowledge about libp2p and p2p networks in general.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of go-libp2p-examples
go-libp2p-examples Key Features
go-libp2p-examples Examples and Code Snippets
Community Discussions
Trending Discussions on go-libp2p-examples
QUESTION
I am following this tutorial:
https://github.com/libp2p/go-libp2p-examples/tree/master/chat-with-mdns
In a short form, it:
- configures a p2p host
- sets a default handler function for incoming connections (3. not necessary)
- and opens a stream to the connecting peers:
stream, err := host.NewStream(ctx, peer.ID, protocol.ID(cfg.ProtocolID))
Afterwards, there is a buffer stream/read-write variable created:
rw := bufio.NewReadWriter(bufio.NewReader(stream), bufio.NewWriter(stream))
Now this stream is used to send and receive data between the peers. This is done using two goroutine functions that have rw as an input:
go writeData(rw)
go readData(rw)
My problems are:
I want to send data to my peers and need feedback from them: e.g. in rw there is a question and they need to answer yes/no. How can I transfer back this answer and process it (enable some interaction)?
The data I want to send in rw is not always the same. Sometimes it's a string containing only a name, sometimes it's a string containing a whole block etc. How can I distinguish?
I thought about those solutions. But I am new to golang, so maybe you have a better one:
do I need a new stream for every different content:
stream, err := host.NewStream(ctx, peer.ID, protocol.ID(cfg.ProtocolID))
do I need to open more buffered rw varibales for every different content:
rw := bufio.NewReadWriter(bufio.NewReader(stream), bufio.NewWriter(stream))
are there any other solutions?
Thank you for any help to solve this!!
...ANSWER
Answered 2019-Mar-25 at 16:42This is what readData
does from your tuto:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install go-libp2p-examples
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page