Skip to content

Commit

Permalink
Merge pull request #1462 from ipfs/fix/zero-rtt
Browse files Browse the repository at this point in the history
allow multistream to have zero rtt stream opening
  • Loading branch information
jbenet committed Jul 13, 2015
2 parents 95df5a1 + ade2879 commit 0b76942
Show file tree
Hide file tree
Showing 6 changed files with 274 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.

124 changes: 124 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.NewMSSelect(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 0b76942

Please sign in to comment.