mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-25 23:21:54 +08:00
muxer construction
This commit is contained in:

committed by
Brian Tiger Chow

parent
700b6ab99f
commit
313f3c83c8
@ -34,6 +34,14 @@ type Muxer struct {
|
|||||||
*msg.Pipe
|
*msg.Pipe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewMuxer constructs a muxer given a protocol map.
|
||||||
|
func NewMuxer(mp ProtocolMap) *Muxer {
|
||||||
|
return &Muxer{
|
||||||
|
Protocols: mp,
|
||||||
|
Pipe: msg.NewPipe(10),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetPipe implements the Protocol interface
|
// GetPipe implements the Protocol interface
|
||||||
func (m *Muxer) GetPipe() *msg.Pipe {
|
func (m *Muxer) GetPipe() *msg.Pipe {
|
||||||
return m.Pipe
|
return m.Pipe
|
||||||
|
@ -6,10 +6,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||||
msg "github.com/jbenet/go-ipfs/net/message"
|
msg "github.com/jbenet/go-ipfs/net/message"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
|
||||||
|
|
||||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||||
)
|
)
|
||||||
@ -60,13 +60,10 @@ func TestSimpleMuxer(t *testing.T) {
|
|||||||
p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
|
p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
|
||||||
pid1 := ProtocolID_Test
|
pid1 := ProtocolID_Test
|
||||||
pid2 := ProtocolID_Routing
|
pid2 := ProtocolID_Routing
|
||||||
mux1 := &Muxer{
|
mux1 := NewMuxer(ProtocolMap{
|
||||||
Pipe: msg.NewPipe(10),
|
|
||||||
Protocols: ProtocolMap{
|
|
||||||
pid1: p1,
|
pid1: p1,
|
||||||
pid2: p2,
|
pid2: p2,
|
||||||
},
|
})
|
||||||
}
|
|
||||||
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
|
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
|
||||||
// peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
|
// peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
|
||||||
|
|
||||||
@ -114,13 +111,10 @@ func TestSimultMuxer(t *testing.T) {
|
|||||||
p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
|
p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
|
||||||
pid1 := ProtocolID_Test
|
pid1 := ProtocolID_Test
|
||||||
pid2 := ProtocolID_Identify
|
pid2 := ProtocolID_Identify
|
||||||
mux1 := &Muxer{
|
mux1 := NewMuxer(ProtocolMap{
|
||||||
Pipe: msg.NewPipe(10),
|
|
||||||
Protocols: ProtocolMap{
|
|
||||||
pid1: p1,
|
pid1: p1,
|
||||||
pid2: p2,
|
pid2: p2,
|
||||||
},
|
})
|
||||||
}
|
|
||||||
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
|
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
|
||||||
// peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
|
// peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
|
||||||
|
|
||||||
@ -224,13 +218,10 @@ func TestStopping(t *testing.T) {
|
|||||||
p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
|
p2 := &TestProtocol{Pipe: msg.NewPipe(10)}
|
||||||
pid1 := ProtocolID_Test
|
pid1 := ProtocolID_Test
|
||||||
pid2 := ProtocolID_Identify
|
pid2 := ProtocolID_Identify
|
||||||
mux1 := &Muxer{
|
mux1 := NewMuxer(ProtocolMap{
|
||||||
Pipe: msg.NewPipe(10),
|
|
||||||
Protocols: ProtocolMap{
|
|
||||||
pid1: p1,
|
pid1: p1,
|
||||||
pid2: p2,
|
pid2: p2,
|
||||||
},
|
})
|
||||||
}
|
|
||||||
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
|
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
|
||||||
// peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
|
// peer2 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275bbbbbb")
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ func NewIpfsNetwork(ctx context.Context, local *peer.Peer,
|
|||||||
|
|
||||||
in := &IpfsNetwork{
|
in := &IpfsNetwork{
|
||||||
local: local,
|
local: local,
|
||||||
muxer: &mux.Muxer{Protocols: *pmap},
|
muxer: mux.NewMuxer(*pmap),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user