libp2p / go-libp2p-examples

Example libp2p applications
MIT License
339 stars 145 forks source link

Error protocol not supported #87

Open thevzurd opened 4 years ago

thevzurd commented 4 years ago

I was trying out the examples and it panics at the following line with the error protocol not supported. stream, err := node.NewStream(ctx, peer.ID, protocol.ID("/plaintext/2.0.0"))

I tried the one mentioned in the example "/chat/1.0.0" as well. Where do I define this ?

joelcho commented 3 years ago

The host sets the handler for a protocol, and then can new a stream to this host

main.go#L104

h.SetStreamHandler("/echo/1.0.0", func(s network.Stream) {
    if err := doEcho(s); err != nil {
        log.Println(err)
        _ = s.Reset()
    } else {
        _ = s.Close()
    }
})

main.go#L150

basicHost.NewStream(context.Background(), peerid, "/echo/1.0.0")