update multistream naming of lazyconn
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Jul 10, 2015 at 15:28 UTC
e431f35a0c7f0ccca7d810c14f1ef36381e12a43
4 files changed
+22
-27
Godeps/Godeps.json
+1
-1
@@ -344,7 +344,7 @@
344
},
345
{
346
"ImportPath": "github.com/whyrusleeping/go-multistream",
347
- "Rev": "30c7a81b6c568654147bf6e106870c5d64ccebc8"
347
+ "Rev": "31bb014803a6eba2261bda5593e42c016a5f33bb"
348
},
349
{
350
"ImportPath": "github.com/whyrusleeping/multiaddr-filter",
Godeps/_workspace/src/github.com/whyrusleeping/go-multistream/lazy.go
+16
-21
@@ -6,7 +6,16 @@ import (
6
"sync"
7
)
8
9
-func NewLazyHandshakeConn(c io.ReadWriteCloser, proto string) io.ReadWriteCloser {
9
+type Multistream interface {
10
+ io.ReadWriteCloser
11
+ Protocol() string
12
+}
13
+
14
+func NewMSSelect(c io.ReadWriteCloser, proto string) Multistream {
15
+ return NewMultistream(NewMultistream(c, ProtocolID), proto)
16
+}
17
+
18
+func NewMultistream(c io.ReadWriteCloser, proto string) Multistream {
19
return &lazyConn{
20
proto: proto,
21
con: c,
@@ -30,6 +39,10 @@ type lazyConn struct {
39
con io.ReadWriteCloser
40
}
41
42
+func (l *lazyConn) Protocol() string {
43
+ return l.proto
44
+}
45
+
46
func (l *lazyConn) Read(b []byte) (int, error) {
47
if !l.rhandshake {
48
go l.writeHandshake()
@@ -58,20 +71,8 @@ func (l *lazyConn) readHandshake() error {
71
}
72
l.rhsync = true
73
61
- // read multistream version
62
- tok, err := ReadNextToken(l.con)
63
- if err != nil {
64
- l.rerr = err
65
- return err
66
- }
67
-
68
- if tok != ProtocolID {
69
- l.rerr = fmt.Errorf("multistream protocol mismatch ( %s != %s )", tok, ProtocolID)
70
- return l.rerr
71
- }
72
-
74
// read protocol
74
- tok, err = ReadNextToken(l.con)
75
+ tok, err := ReadNextToken(l.con)
76
if err != nil {
77
l.rerr = err
78
return err
@@ -95,13 +96,7 @@ func (l *lazyConn) writeHandshake() error {
96
97
l.whsync = true
98
98
- err := delimWrite(l.con, []byte(ProtocolID))
99
- if err != nil {
100
- l.werr = err
101
- return err
102
- }
103
-
104
- err = delimWrite(l.con, []byte(l.proto))
99
+ err := delimWrite(l.con, []byte(l.proto))
100
if err != nil {
101
l.werr = err
102
return err
Godeps/_workspace/src/github.com/whyrusleeping/go-multistream/multistream_test.go
+4
-4
@@ -126,8 +126,8 @@ func TestLazyConns(t *testing.T) {
126
mux.AddHandler("/b", nil)
127
mux.AddHandler("/c", nil)
128
129
- la := NewLazyHandshakeConn(a, "/c")
130
- lb := NewLazyHandshakeConn(b, "/c")
129
+ la := NewMSSelect(a, "/c")
130
+ lb := NewMSSelect(b, "/c")
131
132
verifyPipe(t, la, lb)
133
}
@@ -159,7 +159,7 @@ func TestLazyAndMux(t *testing.T) {
159
close(done)
160
}()
161
162
- lb := NewLazyHandshakeConn(b, "/c")
162
+ lb := NewMSSelect(b, "/c")
163
164
// do a write to push the handshake through
165
_, err := lb.Write([]byte("hello"))
@@ -202,7 +202,7 @@ func TestLazyAndMuxWrite(t *testing.T) {
202
close(done)
203
}()
204
205
- lb := NewLazyHandshakeConn(b, "/c")
205
+ lb := NewMSSelect(b, "/c")
206
207
// do a write to push the handshake through
208
msg := make([]byte, 5)
p2p/host/basic/basic_host.go
+1
-1
@@ -170,7 +170,7 @@ func (h *BasicHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {
170
171
logStream := mstream.WrapStream(s, pid, h.bwc)
172
173
- lzcon := msmux.NewLazyHandshakeConn(logStream, string(pid))
173
+ lzcon := msmux.NewMSSelect(logStream, string(pid))
174
return &streamWrapper{
175
Stream: logStream,
176
rw: lzcon,