Unverified Commit 8bdf9d0d authored by Steven Allen's avatar Steven Allen Committed by GitHub
Browse files

Merge pull request #299 from libp2p/feat/refactor

refactor for transport changes
parents 4b33a800 a612c7dd
...@@ -9,10 +9,8 @@ import ( ...@@ -9,10 +9,8 @@ import (
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
goprocess "github.com/jbenet/goprocess" goprocess "github.com/jbenet/goprocess"
circuit "github.com/libp2p/go-libp2p-circuit" goprocessctx "github.com/jbenet/goprocess/context"
ifconnmgr "github.com/libp2p/go-libp2p-interface-connmgr" ifconnmgr "github.com/libp2p/go-libp2p-interface-connmgr"
metrics "github.com/libp2p/go-libp2p-metrics"
mstream "github.com/libp2p/go-libp2p-metrics/stream"
inet "github.com/libp2p/go-libp2p-net" inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore" pstore "github.com/libp2p/go-libp2p-peerstore"
...@@ -67,8 +65,6 @@ type BasicHost struct { ...@@ -67,8 +65,6 @@ type BasicHost struct {
negtimeout time.Duration negtimeout time.Duration
proc goprocess.Process proc goprocess.Process
bwc metrics.Reporter
} }
// HostOpts holds options that can be passed to NewHost in order to // HostOpts holds options that can be passed to NewHost in order to
...@@ -97,25 +93,14 @@ type HostOpts struct { ...@@ -97,25 +93,14 @@ type HostOpts struct {
// NATManager takes care of setting NAT port mappings, and discovering external addresses. // NATManager takes care of setting NAT port mappings, and discovering external addresses.
// If omitted, this will simply be disabled. // If omitted, this will simply be disabled.
NATManager NATManager NATManager func(inet.Network) NATManager
// BandwidthReporter is used for collecting aggregate metrics of the
// bandwidth used by various protocols.
BandwidthReporter metrics.Reporter
// ConnManager is a libp2p connection manager // ConnManager is a libp2p connection manager
ConnManager ifconnmgr.ConnManager ConnManager ifconnmgr.ConnManager
// Relay indicates whether the host should use circuit relay transport
EnableRelay bool
// RelayOpts are options for the relay transport; only meaningful when Relay=true
RelayOpts []circuit.RelayOpt
} }
// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network. // NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost, error) { func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost, error) {
ctx, cancel := context.WithCancel(ctx)
h := &BasicHost{ h := &BasicHost{
network: net, network: net,
mux: msmux.NewMultistreamMuxer(), mux: msmux.NewMultistreamMuxer(),
...@@ -124,11 +109,10 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost, ...@@ -124,11 +109,10 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
maResolver: madns.DefaultResolver, maResolver: madns.DefaultResolver,
} }
h.proc = goprocess.WithTeardown(func() error { h.proc = goprocessctx.WithContextAndTeardown(ctx, func() error {
if h.natmgr != nil { if h.natmgr != nil {
h.natmgr.Close() h.natmgr.Close()
} }
cancel()
return h.Network().Close() return h.Network().Close()
}) })
...@@ -152,18 +136,13 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost, ...@@ -152,18 +136,13 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
} }
if opts.NATManager != nil { if opts.NATManager != nil {
h.natmgr = opts.NATManager h.natmgr = opts.NATManager(net)
} }
if opts.MultiaddrResolver != nil { if opts.MultiaddrResolver != nil {
h.maResolver = opts.MultiaddrResolver h.maResolver = opts.MultiaddrResolver
} }
if opts.BandwidthReporter != nil {
h.bwc = opts.BandwidthReporter
h.ids.Reporter = opts.BandwidthReporter
}
if opts.ConnManager == nil { if opts.ConnManager == nil {
h.cmgr = &ifconnmgr.NullConnMgr{} h.cmgr = &ifconnmgr.NullConnMgr{}
} else { } else {
...@@ -173,20 +152,16 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost, ...@@ -173,20 +152,16 @@ func NewHost(ctx context.Context, net inet.Network, opts *HostOpts) (*BasicHost,
net.SetConnHandler(h.newConnHandler) net.SetConnHandler(h.newConnHandler)
net.SetStreamHandler(h.newStreamHandler) net.SetStreamHandler(h.newStreamHandler)
if opts.EnableRelay {
err := circuit.AddRelayTransport(ctx, h, opts.RelayOpts...)
if err != nil {
h.Close()
return nil, err
}
}
return h, nil return h, nil
} }
// New constructs and sets up a new *BasicHost with given Network and options. // New constructs and sets up a new *BasicHost with given Network and options.
// Three options can be passed: NATPortMap, AddrsFactory, and metrics.Reporter. // The following options can be passed:
// * NATPortMap
// * AddrsFactory
// * ifconnmgr.ConnManager
// * madns.Resolver
//
// This function is deprecated in favor of NewHost and HostOpts. // This function is deprecated in favor of NewHost and HostOpts.
func New(net inet.Network, opts ...interface{}) *BasicHost { func New(net inet.Network, opts ...interface{}) *BasicHost {
hostopts := &HostOpts{} hostopts := &HostOpts{}
...@@ -196,10 +171,8 @@ func New(net inet.Network, opts ...interface{}) *BasicHost { ...@@ -196,10 +171,8 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
case Option: case Option:
switch o { switch o {
case NATPortMap: case NATPortMap:
hostopts.NATManager = newNatManager(net) hostopts.NATManager = NewNATManager
} }
case metrics.Reporter:
hostopts.BandwidthReporter = o
case AddrsFactory: case AddrsFactory:
hostopts.AddrsFactory = AddrsFactory(o) hostopts.AddrsFactory = AddrsFactory(o)
case ifconnmgr.ConnManager: case ifconnmgr.ConnManager:
...@@ -270,10 +243,6 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) { ...@@ -270,10 +243,6 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
} }
s.SetProtocol(protocol.ID(protoID)) s.SetProtocol(protocol.ID(protoID))
if h.bwc != nil {
s = mstream.WrapStream(s, h.bwc)
}
log.Debugf("protocol negotiation took %s", took) log.Debugf("protocol negotiation took %s", took)
go handle(protoID, s) go handle(protoID, s)
...@@ -366,10 +335,6 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I ...@@ -366,10 +335,6 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
s.SetProtocol(selpid) s.SetProtocol(selpid)
h.Peerstore().AddProtocols(p, selected) h.Peerstore().AddProtocols(p, selected)
if h.bwc != nil {
s = mstream.WrapStream(s, h.bwc)
}
return s, nil return s, nil
} }
...@@ -403,10 +368,6 @@ func (h *BasicHost) newStream(ctx context.Context, p peer.ID, pid protocol.ID) ( ...@@ -403,10 +368,6 @@ func (h *BasicHost) newStream(ctx context.Context, p peer.ID, pid protocol.ID) (
s.SetProtocol(pid) s.SetProtocol(pid)
if h.bwc != nil {
s = mstream.WrapStream(s, h.bwc)
}
lzcon := msmux.NewMSSelect(s, string(pid)) lzcon := msmux.NewMSSelect(s, string(pid))
return &streamWrapper{ return &streamWrapper{
Stream: s, Stream: s,
...@@ -536,11 +497,6 @@ func (h *BasicHost) Close() error { ...@@ -536,11 +497,6 @@ func (h *BasicHost) Close() error {
return h.proc.Close() return h.proc.Close()
} }
// GetBandwidthReporter exposes the Host's bandiwth metrics reporter
func (h *BasicHost) GetBandwidthReporter() metrics.Reporter {
return h.bwc
}
type streamWrapper struct { type streamWrapper struct {
inet.Stream inet.Stream
rw io.ReadWriter rw io.ReadWriter
......
...@@ -8,11 +8,13 @@ import ( ...@@ -8,11 +8,13 @@ import (
"testing" "testing"
"time" "time"
testutil "github.com/libp2p/go-testutil"
host "github.com/libp2p/go-libp2p-host" host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net" inet "github.com/libp2p/go-libp2p-net"
testutil "github.com/libp2p/go-libp2p-netutil"
pstore "github.com/libp2p/go-libp2p-peerstore" pstore "github.com/libp2p/go-libp2p-peerstore"
protocol "github.com/libp2p/go-libp2p-protocol" protocol "github.com/libp2p/go-libp2p-protocol"
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
ma "github.com/multiformats/go-multiaddr" ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns" madns "github.com/multiformats/go-multiaddr-dns"
) )
...@@ -20,8 +22,8 @@ import ( ...@@ -20,8 +22,8 @@ import (
func TestHostSimple(t *testing.T) { func TestHostSimple(t *testing.T) {
ctx := context.Background() ctx := context.Background()
h1 := New(testutil.GenSwarmNetwork(t, ctx)) h1 := New(swarmt.GenSwarm(t, ctx))
h2 := New(testutil.GenSwarmNetwork(t, ctx)) h2 := New(swarmt.GenSwarm(t, ctx))
defer h1.Close() defer h1.Close()
defer h2.Close() defer h2.Close()
...@@ -74,7 +76,7 @@ func TestHostAddrsFactory(t *testing.T) { ...@@ -74,7 +76,7 @@ func TestHostAddrsFactory(t *testing.T) {
} }
ctx := context.Background() ctx := context.Background()
h := New(testutil.GenSwarmNetwork(t, ctx), AddrsFactory(addrsFactory)) h := New(swarmt.GenSwarm(t, ctx), AddrsFactory(addrsFactory))
defer h.Close() defer h.Close()
addrs := h.Addrs() addrs := h.Addrs()
...@@ -87,8 +89,8 @@ func TestHostAddrsFactory(t *testing.T) { ...@@ -87,8 +89,8 @@ func TestHostAddrsFactory(t *testing.T) {
} }
func getHostPair(ctx context.Context, t *testing.T) (host.Host, host.Host) { func getHostPair(ctx context.Context, t *testing.T) (host.Host, host.Host) {
h1 := New(testutil.GenSwarmNetwork(t, ctx)) h1 := New(swarmt.GenSwarm(t, ctx))
h2 := New(testutil.GenSwarmNetwork(t, ctx)) h2 := New(swarmt.GenSwarm(t, ctx))
h2pi := h2.Peerstore().PeerInfo(h2.ID()) h2pi := h2.Peerstore().PeerInfo(h2.ID())
if err := h1.Connect(ctx, h2pi); err != nil { if err := h1.Connect(ctx, h2pi); err != nil {
...@@ -193,8 +195,8 @@ func TestHostProtoPreknowledge(t *testing.T) { ...@@ -193,8 +195,8 @@ func TestHostProtoPreknowledge(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
h1 := New(testutil.GenSwarmNetwork(t, ctx)) h1 := New(swarmt.GenSwarm(t, ctx))
h2 := New(testutil.GenSwarmNetwork(t, ctx)) h2 := New(swarmt.GenSwarm(t, ctx))
conn := make(chan protocol.ID) conn := make(chan protocol.ID)
handler := func(s inet.Stream) { handler := func(s inet.Stream) {
...@@ -358,7 +360,7 @@ func TestAddrResolution(t *testing.T) { ...@@ -358,7 +360,7 @@ func TestAddrResolution(t *testing.T) {
} }
resolver := &madns.Resolver{Backend: backend} resolver := &madns.Resolver{Backend: backend}
h := New(testutil.GenSwarmNetwork(t, ctx), resolver) h := New(swarmt.GenSwarm(t, ctx), resolver)
defer h.Close() defer h.Close()
pi, err := pstore.InfoFromP2pAddr(p2paddr1) pi, err := pstore.InfoFromP2pAddr(p2paddr1)
......
...@@ -118,12 +118,12 @@ func (c *conn) NewStream() (inet.Stream, error) { ...@@ -118,12 +118,12 @@ func (c *conn) NewStream() (inet.Stream, error) {
return s, nil return s, nil
} }
func (c *conn) GetStreams() ([]inet.Stream, error) { func (c *conn) GetStreams() []inet.Stream {
var out []inet.Stream var out []inet.Stream
for e := c.streams.Front(); e != nil; e = e.Next() { for e := c.streams.Front(); e != nil; e = e.Next() {
out = append(out, e.Value.(*stream)) out = append(out, e.Value.(*stream))
} }
return out, nil return out
} }
// LocalMultiaddr is the Multiaddr on this side // LocalMultiaddr is the Multiaddr on this side
......
...@@ -13,8 +13,6 @@ import ( ...@@ -13,8 +13,6 @@ import (
ic "github.com/libp2p/go-libp2p-crypto" ic "github.com/libp2p/go-libp2p-crypto"
host "github.com/libp2p/go-libp2p-host" host "github.com/libp2p/go-libp2p-host"
lgbl "github.com/libp2p/go-libp2p-loggables" lgbl "github.com/libp2p/go-libp2p-loggables"
metrics "github.com/libp2p/go-libp2p-metrics"
mstream "github.com/libp2p/go-libp2p-metrics/stream"
inet "github.com/libp2p/go-libp2p-net" inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore" pstore "github.com/libp2p/go-libp2p-peerstore"
...@@ -44,7 +42,6 @@ var ClientVersion = "go-libp2p/3.3.4" ...@@ -44,7 +42,6 @@ var ClientVersion = "go-libp2p/3.3.4"
type IDService struct { type IDService struct {
Host host.Host Host host.Host
Reporter metrics.Reporter
// connections undergoing identification // connections undergoing identification
// for wait purposes // for wait purposes
currid map[inet.Conn]chan struct{} currid map[inet.Conn]chan struct{}
...@@ -64,7 +61,7 @@ func NewIDService(h host.Host) *IDService { ...@@ -64,7 +61,7 @@ func NewIDService(h host.Host) *IDService {
Host: h, Host: h,
currid: make(map[inet.Conn]chan struct{}), currid: make(map[inet.Conn]chan struct{}),
} }
h.SetStreamHandler(ID, s.RequestHandler) h.SetStreamHandler(ID, s.requestHandler)
h.Network().Notify((*netNotifiee)(s)) h.Network().Notify((*netNotifiee)(s))
return s return s
} }
...@@ -95,21 +92,17 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { ...@@ -95,21 +92,17 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
c.Close() c.Close()
return return
} }
defer s.Close() defer inet.FullClose(s)
s.SetProtocol(ID) s.SetProtocol(ID)
if ids.Reporter != nil {
s = mstream.WrapStream(s, ids.Reporter)
}
// ok give the response to our handler. // ok give the response to our handler.
if err := msmux.SelectProtoOrFail(ID, s); err != nil { if err := msmux.SelectProtoOrFail(ID, s); err != nil {
log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer(), logging.Metadata{"error": err}) log.Event(context.TODO(), "IdentifyOpenFailed", c.RemotePeer(), logging.Metadata{"error": err})
return return
} }
ids.ResponseHandler(s) ids.responseHandler(s)
ids.currmu.Lock() ids.currmu.Lock()
_, found := ids.currid[c] _, found := ids.currid[c]
...@@ -122,14 +115,10 @@ func (ids *IDService) IdentifyConn(c inet.Conn) { ...@@ -122,14 +115,10 @@ func (ids *IDService) IdentifyConn(c inet.Conn) {
} }
} }
func (ids *IDService) RequestHandler(s inet.Stream) { func (ids *IDService) requestHandler(s inet.Stream) {
defer s.Close() defer inet.FullClose(s)
c := s.Conn() c := s.Conn()
if ids.Reporter != nil {
s = mstream.WrapStream(s, ids.Reporter)
}
w := ggio.NewDelimitedWriter(s) w := ggio.NewDelimitedWriter(s)
mes := pb.Identify{} mes := pb.Identify{}
ids.populateMessage(&mes, s.Conn()) ids.populateMessage(&mes, s.Conn())
...@@ -139,8 +128,7 @@ func (ids *IDService) RequestHandler(s inet.Stream) { ...@@ -139,8 +128,7 @@ func (ids *IDService) RequestHandler(s inet.Stream) {
c.RemotePeer(), c.RemoteMultiaddr()) c.RemotePeer(), c.RemoteMultiaddr())
} }
func (ids *IDService) ResponseHandler(s inet.Stream) { func (ids *IDService) responseHandler(s inet.Stream) {
defer s.Close()
c := s.Conn() c := s.Conn()
r := ggio.NewDelimitedReader(s, 2048) r := ggio.NewDelimitedReader(s, 2048)
......
...@@ -6,9 +6,9 @@ import ( ...@@ -6,9 +6,9 @@ import (
"time" "time"
ic "github.com/libp2p/go-libp2p-crypto" ic "github.com/libp2p/go-libp2p-crypto"
testutil "github.com/libp2p/go-libp2p-netutil"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore" pstore "github.com/libp2p/go-libp2p-peerstore"
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
identify "github.com/libp2p/go-libp2p/p2p/protocol/identify" identify "github.com/libp2p/go-libp2p/p2p/protocol/identify"
blhost "github.com/libp2p/go-libp2p-blankhost" blhost "github.com/libp2p/go-libp2p-blankhost"
...@@ -20,8 +20,8 @@ func subtestIDService(t *testing.T) { ...@@ -20,8 +20,8 @@ func subtestIDService(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
h1 := blhost.NewBlankHost(testutil.GenSwarmNetwork(t, ctx)) h1 := blhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h2 := blhost.NewBlankHost(testutil.GenSwarmNetwork(t, ctx)) h2 := blhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
h1p := h1.ID() h1p := h1.ID()
h2p := h2.ID() h2p := h2.ID()
...@@ -65,7 +65,7 @@ func subtestIDService(t *testing.T) { ...@@ -65,7 +65,7 @@ func subtestIDService(t *testing.T) {
ids2.IdentifyConn(c[0]) ids2.IdentifyConn(c[0])
addrs := h1.Peerstore().Addrs(h1p) addrs := h1.Peerstore().Addrs(h1p)
addrs = append(addrs, c[0].RemoteMultiaddr(), forgetMe) addrs = append(addrs, forgetMe)
// and the protocol versions. // and the protocol versions.
t.Log("test peer2 has peer1 addrs correctly") t.Log("test peer2 has peer1 addrs correctly")
......
...@@ -5,17 +5,17 @@ import ( ...@@ -5,17 +5,17 @@ import (
"testing" "testing"
"time" "time"
netutil "github.com/libp2p/go-libp2p-netutil"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore" pstore "github.com/libp2p/go-libp2p-peerstore"
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
bhost "github.com/libp2p/go-libp2p/p2p/host/basic" bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
) )
func TestPing(t *testing.T) { func TestPing(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
h1 := bhost.New(netutil.GenSwarmNetwork(t, ctx)) h1 := bhost.New(swarmt.GenSwarm(t, ctx))
h2 := bhost.New(netutil.GenSwarmNetwork(t, ctx)) h2 := bhost.New(swarmt.GenSwarm(t, ctx))
err := h1.Connect(ctx, pstore.PeerInfo{ err := h1.Connect(ctx, pstore.PeerInfo{
ID: h2.ID(), ID: h2.ID(),
......
...@@ -13,9 +13,9 @@ import ( ...@@ -13,9 +13,9 @@ import (
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
host "github.com/libp2p/go-libp2p-host" host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net" inet "github.com/libp2p/go-libp2p-net"
testutil "github.com/libp2p/go-libp2p-netutil"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
protocol "github.com/libp2p/go-libp2p-protocol" protocol "github.com/libp2p/go-libp2p-protocol"
swarmt "github.com/libp2p/go-libp2p-swarm/testing"
) )
var log = logging.Logger("backpressure") var log = logging.Logger("backpressure")
...@@ -137,8 +137,8 @@ a problem. ...@@ -137,8 +137,8 @@ a problem.
// ok that's enough setup. let's do it! // ok that's enough setup. let's do it!
ctx := context.Background() ctx := context.Background()
h1 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h1 := bhost.New(swarmt.GenSwarm(t, ctx))
h2 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h2 := bhost.New(swarmt.GenSwarm(t, ctx))
// setup receiver handler // setup receiver handler
h1.SetStreamHandler(protocol.TestingID, receiver) h1.SetStreamHandler(protocol.TestingID, receiver)
...@@ -274,8 +274,8 @@ func TestStBackpressureStreamWrite(t *testing.T) { ...@@ -274,8 +274,8 @@ func TestStBackpressureStreamWrite(t *testing.T) {
// setup the networks // setup the networks
ctx := context.Background() ctx := context.Background()
h1 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h1 := bhost.New(swarmt.GenSwarm(t, ctx))
h2 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h2 := bhost.New(swarmt.GenSwarm(t, ctx))
// setup sender handler on 1 // setup sender handler on 1
h1.SetStreamHandler(protocol.TestingID, sender) h1.SetStreamHandler(protocol.TestingID, sender)
......
...@@ -14,17 +14,10 @@ import ( ...@@ -14,17 +14,10 @@ import (
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
host "github.com/libp2p/go-libp2p-host" host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net" inet "github.com/libp2p/go-libp2p-net"
testutil "github.com/libp2p/go-libp2p-netutil"
protocol "github.com/libp2p/go-libp2p-protocol" protocol "github.com/libp2p/go-libp2p-protocol"
swarm "github.com/libp2p/go-libp2p-swarm" swarmt "github.com/libp2p/go-libp2p-swarm/testing"
ps "github.com/libp2p/go-peerstream"
) )
func init() {
// change the garbage collect timeout for testing.
ps.GarbageCollectTimeout = 10 * time.Millisecond
}
var log = logging.Logger("reconnect") var log = logging.Logger("reconnect")
func EchoStreamHandler(stream inet.Stream) { func EchoStreamHandler(stream inet.Stream) {
...@@ -109,8 +102,8 @@ func newSender() (chan sendChans, func(s inet.Stream)) { ...@@ -109,8 +102,8 @@ func newSender() (chan sendChans, func(s inet.Stream)) {
// TestReconnect tests whether hosts are able to disconnect and reconnect. // TestReconnect tests whether hosts are able to disconnect and reconnect.
func TestReconnect2(t *testing.T) { func TestReconnect2(t *testing.T) {
ctx := context.Background() ctx := context.Background()
h1 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h1 := bhost.New(swarmt.GenSwarm(t, ctx))
h2 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h2 := bhost.New(swarmt.GenSwarm(t, ctx))
hosts := []host.Host{h1, h2} hosts := []host.Host{h1, h2}
h1.SetStreamHandler(protocol.TestingID, EchoStreamHandler) h1.SetStreamHandler(protocol.TestingID, EchoStreamHandler)
...@@ -129,11 +122,11 @@ func TestReconnect2(t *testing.T) { ...@@ -129,11 +122,11 @@ func TestReconnect2(t *testing.T) {
// TestReconnect tests whether hosts are able to disconnect and reconnect. // TestReconnect tests whether hosts are able to disconnect and reconnect.
func TestReconnect5(t *testing.T) { func TestReconnect5(t *testing.T) {
ctx := context.Background() ctx := context.Background()
h1 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h1 := bhost.New(swarmt.GenSwarm(t, ctx))
h2 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h2 := bhost.New(swarmt.GenSwarm(t, ctx))
h3 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h3 := bhost.New(swarmt.GenSwarm(t, ctx))
h4 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h4 := bhost.New(swarmt.GenSwarm(t, ctx))
h5 := bhost.New(testutil.GenSwarmNetwork(t, ctx)) h5 := bhost.New(swarmt.GenSwarm(t, ctx))
hosts := []host.Host{h1, h2, h3, h4, h5} hosts := []host.Host{h1, h2, h3, h4, h5}
h1.SetStreamHandler(protocol.TestingID, EchoStreamHandler) h1.SetStreamHandler(protocol.TestingID, EchoStreamHandler)
...@@ -219,13 +212,11 @@ func SubtestConnSendDisc(t *testing.T, hosts []host.Host) { ...@@ -219,13 +212,11 @@ func SubtestConnSendDisc(t *testing.T, hosts []host.Host) {
// close connection // close connection
cs := h1.Network().Conns() cs := h1.Network().Conns()
for _, c := range cs { for _, c := range cs {
sc := c.(*swarm.Conn) if c.LocalPeer() > c.RemotePeer() {
if sc.LocalPeer() > sc.RemotePeer() { continue
continue // only close it on one side.
} }
log.Debugf("closing: %s", c)
log.Debugf("closing: %s", sc.RawConn()) c.Close()
sc.Close()
} }
} }
......
...@@ -18,21 +18,11 @@ ...@@ -18,21 +18,11 @@
"name": "mdns", "name": "mdns",
"version": "0.1.1" "version": "0.1.1"
}, },
{
"hash": "QmWBug6eBS7AxRdCDVuSY5CnSit7cS2XnPFYJWqWDumhCG",
"name": "go-msgio",
"version": "0.0.3"
},
{ {
"hash": "QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx", "hash": "QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx",
"name": "go-ipfs-util", "name": "go-ipfs-util",
"version": "1.2.7" "version": "1.2.7"
}, },
{
"hash": "QmUusaX99BZoELh7dmPgirqRQ1FAmMnmnBn3oiqDFGBUSc",
"name": "go-keyspace",
"version": "1.0.0"
},
{ {
"hash": "QmbXRda5H2K3MSQyWWxTMtd8DWuguEBUCe6hpxfXVpFUGj", "hash": "QmbXRda5H2K3MSQyWWxTMtd8DWuguEBUCe6hpxfXVpFUGj",
"name": "go-multistream", "name": "go-multistream",
...@@ -54,24 +44,9 @@ ...@@ -54,24 +44,9 @@
"version": "1.4.1" "version": "1.4.1"
}, },
{ {
"hash": "QmRK2LxanhK2gZq6k6R7vk5ZoYZk8ULSSTB7FzDsMUX6CB", "hash": "QmcGXGdw9BWDysPJQHxJinjGHha3eEg4vzFETre4woNwcX",
"name": "go-multiaddr-net", "name": "go-multiaddr-net",
"version": "1.5.7" "version": "1.6.0"
},
{
"hash": "QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua",
"name": "go-multihash",
"version": "1.0.7"
},
{
"hash": "QmSMZwvs3n4GBikZ7hKzT17c3bk65FmyZo2JqtJ16swqCv",
"name": "multiaddr-filter",
"version": "1.0.2"
},
{
"hash": "QmaPHkZLbQQbvcyavn8q1GFHg6o6yeceyHFSJ3Pjf3p3TQ",
"name": "go-crypto",
"version": "0.0.0"
}, },
{ {
"hash": "QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV", "hash": "QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV",
...@@ -83,38 +58,6 @@ ...@@ -83,38 +58,6 @@
"name": "go-multiaddr", "name": "go-multiaddr",
"version": "1.2.6" "version": "1.2.6"
}, },
{
"hash": "QmYvsG72GsfLgUeSojXArjnU6L4Wmwk7wuAxtNLuyXcc1T",
"name": "randbo",
"version": "0.0.0"
},
{
"hash": "QmeQW4ayVqi7Jjay1SrP2wYydsH9KwSrzQBnqyC25gPFnG",
"name": "go-notifier",
"version": "1.0.0"
},
{
"hash": "QmWHgLqrghM9zw77nF6gdvT9ExQ2RB9pLxkd8sDHZf1rWb",
"name": "go-temp-err-catcher",
"version": "0.0.0"
},
{
"hash": "QmVXXxPsnDY16szK4gPy1oz4qKd8HHshemX1miZR2frtJo",
"name": "go-peerstream",
"version": "2.1.5"
},
{
"author": "whyrusleeping",
"hash": "QmTy17Jm1foTnvUS9JXRhLbRQ3XuC64jPTjUfpB4mHz2QM",
"name": "mafmt",
"version": "1.2.5"
},
{
"author": "whyrusleeping",
"hash": "QmTd4Jgb4nbJq5uR55KJgGLyHWmM3dovS21D1HcwRneSLu",
"name": "gorocheck",
"version": "0.0.0"
},
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmPDZJxtWGfcwLPazJxD4h3v3aDs43V7UNAVs3Jz1Wo7o4", "hash": "QmPDZJxtWGfcwLPazJxD4h3v3aDs43V7UNAVs3Jz1Wo7o4",
...@@ -123,33 +66,33 @@ ...@@ -123,33 +66,33 @@
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmP47neqyP4NR9CKbjVogZ8U9Gybxfcfsa8HtPSPSxwiA8", "hash": "QmQS7P1VV4JuqbXEEaPQZ5ERHDQuGp8qk26Gfdg9ZtP1Eb",
"name": "go-libp2p-secio", "name": "go-libp2p-secio",
"version": "1.2.7" "version": "2.0.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmdeiKhUy1TVGBaKxt7y1QmBDLBdisSrLJ1x58Eoj4PXUh", "hash": "QmZb7hAgQEhW9dBbzBudU39gCeD4zbe6xafD52LUuF4cUN",
"name": "go-libp2p-peerstore", "name": "go-libp2p-peerstore",
"version": "1.4.17" "version": "1.4.18"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmPUHzTLPZFYqv8WqcBTuMFYTgeom4uHHEaxzk7bd5GYZB", "hash": "QmYnjSGtvn7LhrxCvwrU9uDWxKyg28uBYeXvgzTDDDzVy4",
"name": "go-libp2p-transport", "name": "go-libp2p-transport",
"version": "2.2.14" "version": "3.0.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmdxKHpkZCTV3C7xdE1iJdPfFm5LVvMPvirdFmKu1TimzY", "hash": "QmU7NiV3ZRJoNk8XZEKazs4AW7XQT1rQCrhh8cmhSjZgrC",
"name": "go-tcp-transport", "name": "go-tcp-transport",
"version": "1.2.9" "version": "2.0.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "Qmf2UAmRwDG4TvnkQpHZWPAzw7rpCYVhxmRXmYxXr5LD1g", "hash": "QmYF6XMumtqvXtZfQKrCokXEdFvfy2i7tbpvSRzRrHyY8c",
"name": "go-maddr-filter", "name": "go-maddr-filter",
"version": "1.1.6" "version": "1.1.7"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
...@@ -157,12 +100,6 @@ ...@@ -157,12 +100,6 @@
"name": "go-libp2p-protocol", "name": "go-libp2p-protocol",
"version": "1.0.0" "version": "1.0.0"
}, },
{
"author": "whyrusleeping",
"hash": "QmTGSre9j1otFgsr1opCUQDXTPSM6BTZnMWwPeA5nYJM7w",
"name": "go-addr-util",
"version": "1.2.7"
},
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmUJzxQQ2kzwQubsMqBTr1NGDpLfh7pGA2E1oaJULcKDPq", "hash": "QmUJzxQQ2kzwQubsMqBTr1NGDpLfh7pGA2E1oaJULcKDPq",
...@@ -171,57 +108,45 @@ ...@@ -171,57 +108,45 @@
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmYSQpi68jBLVUx62u543RVvnjjaQQDDxyopWWG31kiUkG", "hash": "QmYj8wdn5sZEHX2XMDWGBvcXJNdzVbaVpHmXvhHBVZepen",
"name": "go-libp2p-conn",
"version": "1.7.7"
},
{
"author": "whyrusleeping",
"hash": "QmXoz9o2PT3tEzf7hicegwex5UgVP54n3k82K7jrWFyN86",
"name": "go-libp2p-net", "name": "go-libp2p-net",
"version": "2.0.7" "version": "3.0.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmVvu4bS5QLfS19ePkp5Wgzn2ZUma5oXTT9BgDFyQLxUZF", "hash": "QmNnaGds3p4hfTqSH4KURKh8pBRcisAWYbNDEGeMZ7c3Hv",
"name": "go-libp2p-metrics", "name": "go-libp2p-metrics",
"version": "2.0.6" "version": "2.1.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmYDNqBAMWVMHKndYR35Sd8PfEVWBiDmpHYkuRJTunJDeJ", "hash": "QmdHyfNVTZ5VtUx4Xz23z8wtnioSrFQ28XSfpVkdhQBkGA",
"name": "go-libp2p-interface-conn",
"version": "0.4.13"
},
{
"author": "whyrusleeping",
"hash": "QmaSfSMvc1VPZ8JbMponFs4WHvF9FgEruF56opm5E1RgQA",
"name": "go-libp2p-host", "name": "go-libp2p-host",
"version": "2.1.8" "version": "3.0.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmRpKdg1xs4Yyrn9yrVYRBp7AQqyRxMLpD6Jgp1eZAGqEr", "hash": "QmPzT3rJnSP8VFP1kw7Ly7HP8AprKNZtwLHXHnxfVSbWT3",
"name": "go-libp2p-swarm", "name": "go-libp2p-swarm",
"version": "2.1.9" "version": "3.0.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmXtFH52dAPCq5i4iYjr1g8xVFVJD3fwKWWyNHjVB4sHRp", "hash": "QmQF7htcTXeVqdTg4fKPGU59PeeTpsFgn9UquiixwbTPG1",
"name": "go-libp2p-nat", "name": "go-libp2p-nat",
"version": "0.0.8" "version": "0.8.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "Qma2UuHusnaFV24DgeZ5hyrM9uc4UdyVaZbtn2FQsPRhES", "hash": "Qmb3r9qUR7PnkyUKztmXp8sQhzXZHGmRg7fR5zsB1ebWMj",
"name": "go-libp2p-netutil", "name": "go-libp2p-netutil",
"version": "0.3.13" "version": "0.4.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
"hash": "QmYEmPwCBe7ZUFfuymozopHTuF3JXejvJPDAjwtyQCrsDi", "hash": "QmQ6ASb73YCy77TLfxzKnzQFUyFKMQzDhmjwjaQp6rxK34",
"name": "go-libp2p-blankhost", "name": "go-libp2p-blankhost",
"version": "0.2.8" "version": "0.3.0"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
...@@ -255,9 +180,9 @@ ...@@ -255,9 +180,9 @@
}, },
{ {
"author": "vyzo", "author": "vyzo",
"hash": "QmR5sXZi68rm9m2E3KiXj6hE5m3GeLaDjbLPUeV6W3MLR8", "hash": "QmNXLcLAcfo8yp59FxFQJNa7pDbUUw97QN9GwefWWFK4hk",
"name": "go-libp2p-circuit", "name": "go-libp2p-circuit",
"version": "2.0.14" "version": "2.1.0"
}, },
{ {
"author": "lgierth", "author": "lgierth",
...@@ -267,9 +192,9 @@ ...@@ -267,9 +192,9 @@
}, },
{ {
"author": "why", "author": "why",
"hash": "QmfQNieWBPwmnUjXWPZbjJPzhNwFFabTb5RQ79dyVWGujQ", "hash": "QmWCWsDQnnQ9Mo9V3GK8TSR91662FdFxjjqPX8YbHC8Ltz",
"name": "go-libp2p-interface-connmgr", "name": "go-libp2p-interface-connmgr",
"version": "0.0.8" "version": "0.0.7"
}, },
{ {
"author": "whyrusleeping", "author": "whyrusleeping",
...@@ -288,6 +213,42 @@ ...@@ -288,6 +213,42 @@
"hash": "QmcBWojPoNh4qm7zvv4qiepvCnnc7ALS9qcp7TNwwxT1gT", "hash": "QmcBWojPoNh4qm7zvv4qiepvCnnc7ALS9qcp7TNwwxT1gT",
"name": "go.uuid", "name": "go.uuid",
"version": "1.1.0" "version": "1.1.0"
},
{
"author": "whyrusleeping",
"hash": "QmTeRSFgnXRCh13sxsZkLTVCc1diUbZiT5mkGUgkR1J1on",
"name": "go-ws-transport",
"version": "2.0.0"
},
{
"author": "stebalien",
"hash": "QmRYk8zWrXSkXsE16vM8yxByqM6eVvnXzDXKGvHFJJubVc",
"name": "go-conn-security-multistream",
"version": "0.1.0"
},
{
"author": "Stebalien",
"hash": "QmSieFUauuYnroStqmRAEgu9BMXDNY5LbtNgzXcFitBKXQ",
"name": "go-conn-security",
"version": "0.1.1"
},
{
"author": "libp2p",
"hash": "QmW7Ump7YyBMr712Ta3iEVh3ZYcfVvJaPryfbCnyE826b4",
"name": "go-libp2p-interface-pnet",
"version": "3.0.0"
},
{
"author": "whyrusleeping",
"hash": "QmY9JXR3FupnYAYJWK9aMr9bCpqWKcToQ1tz8DVGTrHpHw",
"name": "go-stream-muxer",
"version": "3.0.0"
},
{
"author": "steb",
"hash": "Qmf3ejfGWR8Bd3wKFBvwYGFMJ9TeKJwYJUc2WchXjMxzg7",
"name": "go-libp2p-transport-upgrader",
"version": "0.1.0"
} }
], ],
"gxVersion": "0.4.0", "gxVersion": "0.4.0",
...@@ -295,6 +256,6 @@ ...@@ -295,6 +256,6 @@
"license": "MIT", "license": "MIT",
"name": "go-libp2p", "name": "go-libp2p",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"", "releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "5.0.21" "version": "6.0.0"
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment