Skip to content

Commit

Permalink
allow multistream to have zero rtt stream opening
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <[email protected]>
  • Loading branch information
whyrusleeping committed Jul 15, 2015
1 parent e6dd70a commit b5b27f1
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

129 changes: 129 additions & 0 deletions Godeps/_workspace/src/github.com/whyrusleeping/go-multistream/lazy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,11 @@ func (h *BasicHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {

logStream := mstream.WrapStream(s, pid, h.bwc)

if err := msmux.SelectProtoOrFail(string(pid), logStream); err != nil {
logStream.Close()
return nil, err
}

return logStream, nil
lzcon := msmux.NewLazyHandshakeConn(logStream, string(pid))
return &streamWrapper{
Stream: logStream,
rw: lzcon,
}, nil
}

// Connect ensures there is a connection between this host and the peer with
Expand Down Expand Up @@ -254,3 +253,16 @@ func (h *BasicHost) Close() error {
func (h *BasicHost) GetBandwidthReporter() metrics.Reporter {
return h.bwc
}

type streamWrapper struct {
inet.Stream
rw io.ReadWriter
}

func (s *streamWrapper) Read(b []byte) (int, error) {
return s.rw.Read(b)
}

func (s *streamWrapper) Write(b []byte) (int, error) {
return s.rw.Write(b)
}
6 changes: 6 additions & 0 deletions p2p/test/backpressure/backpressure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ func TestStBackpressureStreamWrite(t *testing.T) {
}
}

// trigger lazy connection handshaking
_, err = s.Read(nil)
if err != nil {
t.Fatal(err)
}

// 500ms rounds of lockstep write + drain
roundsStart := time.Now()
roundsTotal := 0
Expand Down

0 comments on commit b5b27f1

Please sign in to comment.