@cryptotaxi247 / kubo / commits / 313f3c83c

muxer construction

Juan Batiz-Benet committed Sep 18, 2014 at 20:57 UTC 313f3c83c8c93e1ddcc4e94e9896acdb44c944b1
3 files changed +22 -23
net/mux/mux.go
+8
@@ -34,6 +34,14 @@ type Muxer struct {
34 *msg.Pipe
35 }
36
37 +// NewMuxer constructs a muxer given a protocol map.
38 +func NewMuxer(mp ProtocolMap) *Muxer {
39 + return &Muxer{
40 + Protocols: mp,
41 + Pipe: msg.NewPipe(10),
42 + }
43 +}
44 +
45 // GetPipe implements the Protocol interface
46 func (m *Muxer) GetPipe() *msg.Pipe {
47 return m.Pipe
net/mux/mux_test.go
+13 -22
@@ -6,10 +6,10 @@ import (
6 "testing"
7 "time"
8
9 + mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
10 msg "github.com/jbenet/go-ipfs/net/message"
11 peer "github.com/jbenet/go-ipfs/peer"
12 u "github.com/jbenet/go-ipfs/util"
12 - mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
13
14 context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
15 )
@@ -60,13 +60,10 @@ func TestSimpleMuxer(t *testing.T) {
60 p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
61 pid1 := ProtocolID_Test
62 pid2 := ProtocolID_Routing
63 - mux1 := &Muxer{
64 - Pipe: msg.NewPipe(10),
65 - Protocols: ProtocolMap{
66 - pid1: p1,
67 - pid2: p2,
68 - },
69 - }
63 + mux1 := NewMuxer(ProtocolMap{
64 + pid1: p1,
65 + pid2: p2,
66 + })
67 peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
68 // peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
69
@@ -114,13 +111,10 @@ func TestSimultMuxer(t *testing.T) {
111 p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
112 pid1 := ProtocolID_Test
113 pid2 := ProtocolID_Identify
117 - mux1 := &Muxer{
118 - Pipe: msg.NewPipe(10),
119 - Protocols: ProtocolMap{
120 - pid1: p1,
121 - pid2: p2,
122 - },
123 - }
114 + mux1 := NewMuxer(ProtocolMap{
115 + pid1: p1,
116 + pid2: p2,
117 + })
118 peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
119 // peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
120
@@ -224,13 +218,10 @@ func TestStopping(t *testing.T) {
218 p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
219 pid1 := ProtocolID_Test
220 pid2 := ProtocolID_Identify
227 - mux1 := &Muxer{
228 - Pipe: msg.NewPipe(10),
229 - Protocols: ProtocolMap{
230 - pid1: p1,
231 - pid2: p2,
232 - },
233 - }
221 + mux1 := NewMuxer(ProtocolMap{
222 + pid1: p1,
223 + pid2: p2,
224 + })
225 peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
226 // peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
227
net/net.go
+1 -1
@@ -36,7 +36,7 @@ func NewIpfsNetwork(ctx context.Context, local *peer.Peer,
36
37 in := &IpfsNetwork{
38 local: local,
39 - muxer: &mux.Muxer{Protocols: *pmap},
39 + muxer: mux.NewMuxer(*pmap),
40 ctx: ctx,
41 cancel: cancel,
42 }