-
Notifications
You must be signed in to change notification settings - Fork 3
Question about new streams #9
Comments
for streams to work, you need to specify a protocol that the other peer has a handler for. an empty protocol handler wont work. (i mean, unless the other side has a protocol handler for the empty string) |
yea assuming i also did
will there be any headers or extra information passed between the two hosts when the stream is created? or will nothing be written until i call |
im asking because there's this comment in host.go
but for some reason I still get extra stuff written to new streams, messages that look like:
and I'm not sure if my code is unexpectedly writing something or if I'm not understanding the NewStream correctly. |
thats multistream youre seeing. try using a protocol that isnt named |
seems like a bug to me... @jbenet thoughts? |
with the protocol as protocol.TestingID i get similar messages: � /ipfs/identify /ipfs/identify /ipfs/identify [ i was just wondering if it was possible to have no extra stuff between hosts to make testing easier, and if not, will the headers for the same protocol always be the same length? |
@Heems could you show me some example code where youre seeing this? |
I print the messages before the s.Writer.Write()s in the transport function of mock_stream. Before the 'ping' messages are printed, I get some of the |
That looks like a bug to me... it seems like all of the data for the connection is coming in over the stream you have. Its like there isnt a stream muxer involved.. |
agree with @whyrusleeping's assessment. @Heems can you make a running example? i.e make a small program like: package main
import (
stuff
)
func main() {
... what you pasted above + anything else needed
} that way i can help debug |
package main
import (
"fmt"
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
"io"
inet "github.com/ipfs/go-ipfs/p2p/net"
protocol "github.com/ipfs/go-ipfs/p2p/protocol"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
func main() {
mn, err := mocknet.FullMeshConnected(context.Background(), 2)
if err != nil {
panic(err)
}
messages := 10
handler := func(s inet.Stream) {
b := make([]byte, 4)
for i := 0; i < messages; i++ {
if _, err := io.ReadFull(s, b); err != nil {
panic(err)
}
fmt.Println(string(b))
}
s.Close()
}
hosts := mn.Hosts()
hosts[1].SetStreamHandler(protocol.TestingID, handler)
s, err := hosts[0].NewStream(protocol.TestingID, hosts[1].ID())
if err != nil {
panic(err)
}
data := []byte("ping")
for i := 0; i < messages; i++ {
if _, err := s.Write(data); err != nil {
panic(err)
}
}
} And this is my |
Could you guys quickly explain how new streams are handled? If I have an empty ("") protocol ID like here:
s, err := host0.NewStream("", host1.ID())
will there be any messages sent between hosts other than what I write to their streams?
The text was updated successfully, but these errors were encountered: