Skip to content

Commit 0b76942

Browse files
committed
Merge pull request #1462 from ipfs/fix/zero-rtt
allow multistream to have zero rtt stream opening
2 parents 95df5a1 + ade2879 commit 0b76942

File tree

6 files changed

+274
-18
lines changed

6 files changed

+274
-18
lines changed

Godeps/Godeps.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/whyrusleeping/go-multistream/lazy.go

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/whyrusleeping/go-multistream/multistream.go

+19-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Godeps/_workspace/src/github.com/whyrusleeping/go-multistream/multistream_test.go

+106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

p2p/host/basic/basic_host.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,11 @@ func (h *BasicHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {
170170

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

173-
if err := msmux.SelectProtoOrFail(string(pid), logStream); err != nil {
174-
logStream.Close()
175-
return nil, err
176-
}
177-
178-
return logStream, nil
173+
lzcon := msmux.NewMSSelect(logStream, string(pid))
174+
return &streamWrapper{
175+
Stream: logStream,
176+
rw: lzcon,
177+
}, nil
179178
}
180179

181180
// Connect ensures there is a connection between this host and the peer with
@@ -254,3 +253,16 @@ func (h *BasicHost) Close() error {
254253
func (h *BasicHost) GetBandwidthReporter() metrics.Reporter {
255254
return h.bwc
256255
}
256+
257+
type streamWrapper struct {
258+
inet.Stream
259+
rw io.ReadWriter
260+
}
261+
262+
func (s *streamWrapper) Read(b []byte) (int, error) {
263+
return s.rw.Read(b)
264+
}
265+
266+
func (s *streamWrapper) Write(b []byte) (int, error) {
267+
return s.rw.Write(b)
268+
}

p2p/test/backpressure/backpressure_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ func TestStBackpressureStreamWrite(t *testing.T) {
299299
}
300300
}
301301

302+
// trigger lazy connection handshaking
303+
_, err = s.Read(nil)
304+
if err != nil {
305+
t.Fatal(err)
306+
}
307+
302308
// 500ms rounds of lockstep write + drain
303309
roundsStart := time.Now()
304310
roundsTotal := 0

0 commit comments

Comments
 (0)