From cea1fe131f4596b74931df2721d59149db633a1e Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 4 Oct 2016 13:50:34 -0700 Subject: [PATCH] extract net interface and metrics --- examples/hosts/main.go | 4 +- p2p/host/basic/basic_host.go | 11 +- p2p/host/basic/basic_host_test.go | 2 +- p2p/host/basic/natmgr.go | 5 +- p2p/host/host.go | 4 +- p2p/host/routed/routed.go | 8 +- p2p/metrics/bw_stats.go | 89 ------------ p2p/metrics/conn/conn.go | 39 ----- p2p/metrics/interface.go | 19 --- p2p/metrics/stream/metered.go | 52 ------- p2p/metrics/stream/metered_test.go | 78 ---------- p2p/net/interface.go | 159 --------------------- p2p/net/mock/interface.go | 2 +- p2p/net/mock/mock_conn.go | 2 +- p2p/net/mock/mock_link.go | 2 +- p2p/net/mock/mock_net.go | 2 +- p2p/net/mock/mock_notif_test.go | 2 +- p2p/net/mock/mock_peernet.go | 5 +- p2p/net/mock/mock_printer.go | 2 +- p2p/net/mock/mock_stream.go | 2 +- p2p/net/mock/mock_test.go | 2 +- p2p/net/swarm/swarm.go | 7 +- p2p/net/swarm/swarm_addr_test.go | 3 +- p2p/net/swarm/swarm_conn.go | 2 +- p2p/net/swarm/swarm_listen.go | 5 +- p2p/net/swarm/swarm_net.go | 7 +- p2p/net/swarm/swarm_net_test.go | 4 +- p2p/net/swarm/swarm_notif_test.go | 2 +- p2p/net/swarm/swarm_stream.go | 2 +- p2p/net/swarm/swarm_test.go | 5 +- p2p/protocol/identify/id.go | 16 +-- p2p/protocol/ping/ping.go | 2 +- p2p/protocol/relay/relay.go | 9 +- p2p/protocol/relay/relay_test.go | 2 +- p2p/test/backpressure/backpressure_test.go | 2 +- p2p/test/reconnects/reconnect_test.go | 2 +- p2p/test/util/util.go | 4 +- package.json | 12 ++ 38 files changed, 75 insertions(+), 502 deletions(-) delete mode 100644 p2p/metrics/bw_stats.go delete mode 100644 p2p/metrics/conn/conn.go delete mode 100644 p2p/metrics/interface.go delete mode 100644 p2p/metrics/stream/metered.go delete mode 100644 p2p/metrics/stream/metered_test.go delete mode 100644 p2p/net/interface.go diff --git a/examples/hosts/main.go b/examples/hosts/main.go index e73191b4e..0732e34ca 100644 --- a/examples/hosts/main.go +++ b/examples/hosts/main.go @@ -8,10 +8,10 @@ import ( "log" "strings" + inet "github.com/libp2p/go-libp2p-net" + net "github.com/libp2p/go-libp2p-net" host "github.com/libp2p/go-libp2p/p2p/host" bhost "github.com/libp2p/go-libp2p/p2p/host/basic" - inet "github.com/libp2p/go-libp2p/p2p/net" - net "github.com/libp2p/go-libp2p/p2p/net" swarm "github.com/libp2p/go-libp2p/p2p/net/swarm" peer "github.com/ipfs/go-libp2p-peer" diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 170677c83..50dd403be 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -5,17 +5,18 @@ import ( "io" "time" + identify "github.com/libp2p/go-libp2p/p2p/protocol/identify" + relay "github.com/libp2p/go-libp2p/p2p/protocol/relay" + peer "github.com/ipfs/go-libp2p-peer" pstore "github.com/ipfs/go-libp2p-peerstore" logging "github.com/ipfs/go-log" ma "github.com/jbenet/go-multiaddr" goprocess "github.com/jbenet/goprocess" + metrics "github.com/libp2p/go-libp2p-metrics" + mstream "github.com/libp2p/go-libp2p-metrics/stream" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - mstream "github.com/libp2p/go-libp2p/p2p/metrics/stream" - inet "github.com/libp2p/go-libp2p/p2p/net" - identify "github.com/libp2p/go-libp2p/p2p/protocol/identify" - relay "github.com/libp2p/go-libp2p/p2p/protocol/relay" msmux "github.com/whyrusleeping/go-multistream" ) diff --git a/p2p/host/basic/basic_host_test.go b/p2p/host/basic/basic_host_test.go index 00a9d20f1..a562139da 100644 --- a/p2p/host/basic/basic_host_test.go +++ b/p2p/host/basic/basic_host_test.go @@ -7,9 +7,9 @@ import ( "testing" "time" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" host "github.com/libp2p/go-libp2p/p2p/host" - inet "github.com/libp2p/go-libp2p/p2p/net" testutil "github.com/libp2p/go-libp2p/p2p/test/util" ) diff --git a/p2p/host/basic/natmgr.go b/p2p/host/basic/natmgr.go index 6e8ccb7d2..8f375b906 100644 --- a/p2p/host/basic/natmgr.go +++ b/p2p/host/basic/natmgr.go @@ -4,11 +4,12 @@ import ( "context" "sync" + inat "github.com/libp2p/go-libp2p/p2p/nat" + lgbl "github.com/ipfs/go-libp2p-loggables" ma "github.com/jbenet/go-multiaddr" goprocess "github.com/jbenet/goprocess" - inat "github.com/libp2p/go-libp2p/p2p/nat" - inet "github.com/libp2p/go-libp2p/p2p/net" + inet "github.com/libp2p/go-libp2p-net" ) // natManager takes care of adding + removing port mappings to the nat. diff --git a/p2p/host/host.go b/p2p/host/host.go index 4fee58049..89d2db874 100644 --- a/p2p/host/host.go +++ b/p2p/host/host.go @@ -7,9 +7,9 @@ import ( pstore "github.com/ipfs/go-libp2p-peerstore" logging "github.com/ipfs/go-log" ma "github.com/jbenet/go-multiaddr" + metrics "github.com/libp2p/go-libp2p-metrics" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - inet "github.com/libp2p/go-libp2p/p2p/net" msmux "github.com/whyrusleeping/go-multistream" ) diff --git a/p2p/host/routed/routed.go b/p2p/host/routed/routed.go index 7737a592a..13552149c 100644 --- a/p2p/host/routed/routed.go +++ b/p2p/host/routed/routed.go @@ -5,16 +5,16 @@ import ( "fmt" "time" + host "github.com/libp2p/go-libp2p/p2p/host" + lgbl "github.com/ipfs/go-libp2p-loggables" peer "github.com/ipfs/go-libp2p-peer" pstore "github.com/ipfs/go-libp2p-peerstore" logging "github.com/ipfs/go-log" ma "github.com/jbenet/go-multiaddr" + metrics "github.com/libp2p/go-libp2p-metrics" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" - host "github.com/libp2p/go-libp2p/p2p/host" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - inet "github.com/libp2p/go-libp2p/p2p/net" - msmux "github.com/whyrusleeping/go-multistream" ) diff --git a/p2p/metrics/bw_stats.go b/p2p/metrics/bw_stats.go deleted file mode 100644 index e34ec1c51..000000000 --- a/p2p/metrics/bw_stats.go +++ /dev/null @@ -1,89 +0,0 @@ -package metrics - -import ( - gm "github.com/whyrusleeping/go-metrics" - "sync" - - peer "github.com/ipfs/go-libp2p-peer" - protocol "github.com/libp2p/go-libp2p-protocol" -) - -type Stats struct { - TotalIn int64 - TotalOut int64 - RateIn float64 - RateOut float64 -} - -type BandwidthCounter struct { - lock sync.Mutex - totalIn gm.Meter - totalOut gm.Meter - reg gm.Registry -} - -func NewBandwidthCounter() *BandwidthCounter { - reg := gm.NewRegistry() - return &BandwidthCounter{ - totalIn: gm.GetOrRegisterMeter("totalIn", reg), - totalOut: gm.GetOrRegisterMeter("totalOut", reg), - reg: reg, - } -} - -func (bwc *BandwidthCounter) LogSentMessage(size int64) { - bwc.totalOut.Mark(size) -} - -func (bwc *BandwidthCounter) LogRecvMessage(size int64) { - bwc.totalIn.Mark(size) -} - -func (bwc *BandwidthCounter) LogSentMessageStream(size int64, proto protocol.ID, p peer.ID) { - meter := gm.GetOrRegisterMeter("/peer/out/"+string(p), bwc.reg) - meter.Mark(size) - - pmeter := gm.GetOrRegisterMeter("/proto/out/"+string(proto), bwc.reg) - pmeter.Mark(size) -} - -func (bwc *BandwidthCounter) LogRecvMessageStream(size int64, proto protocol.ID, p peer.ID) { - meter := gm.GetOrRegisterMeter("/peer/in/"+string(p), bwc.reg) - meter.Mark(size) - - pmeter := gm.GetOrRegisterMeter("/proto/in/"+string(proto), bwc.reg) - pmeter.Mark(size) -} - -func (bwc *BandwidthCounter) GetBandwidthForPeer(p peer.ID) (out Stats) { - inMeter := gm.GetOrRegisterMeter("/peer/in/"+string(p), bwc.reg).Snapshot() - outMeter := gm.GetOrRegisterMeter("/peer/out/"+string(p), bwc.reg).Snapshot() - - return Stats{ - TotalIn: inMeter.Count(), - TotalOut: outMeter.Count(), - RateIn: inMeter.RateFine(), - RateOut: outMeter.RateFine(), - } -} - -func (bwc *BandwidthCounter) GetBandwidthForProtocol(proto protocol.ID) (out Stats) { - inMeter := gm.GetOrRegisterMeter(string("/proto/in/"+proto), bwc.reg).Snapshot() - outMeter := gm.GetOrRegisterMeter(string("/proto/out/"+proto), bwc.reg).Snapshot() - - return Stats{ - TotalIn: inMeter.Count(), - TotalOut: outMeter.Count(), - RateIn: inMeter.RateFine(), - RateOut: outMeter.RateFine(), - } -} - -func (bwc *BandwidthCounter) GetBandwidthTotals() (out Stats) { - return Stats{ - TotalIn: bwc.totalIn.Count(), - TotalOut: bwc.totalOut.Count(), - RateIn: bwc.totalIn.RateFine(), - RateOut: bwc.totalOut.RateFine(), - } -} diff --git a/p2p/metrics/conn/conn.go b/p2p/metrics/conn/conn.go deleted file mode 100644 index f7e6ae293..000000000 --- a/p2p/metrics/conn/conn.go +++ /dev/null @@ -1,39 +0,0 @@ -package meterconn - -import ( - transport "github.com/libp2p/go-libp2p-transport" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" -) - -type MeteredConn struct { - mesRecv metrics.MeterCallback - mesSent metrics.MeterCallback - - transport.Conn -} - -func WrapConn(bwc metrics.Reporter, c transport.Conn) transport.Conn { - return newMeteredConn(c, bwc.LogRecvMessage, bwc.LogSentMessage) -} - -func newMeteredConn(base transport.Conn, rcb metrics.MeterCallback, scb metrics.MeterCallback) transport.Conn { - return &MeteredConn{ - Conn: base, - mesRecv: rcb, - mesSent: scb, - } -} - -func (mc *MeteredConn) Read(b []byte) (int, error) { - n, err := mc.Conn.Read(b) - - mc.mesRecv(int64(n)) - return n, err -} - -func (mc *MeteredConn) Write(b []byte) (int, error) { - n, err := mc.Conn.Write(b) - - mc.mesSent(int64(n)) - return n, err -} diff --git a/p2p/metrics/interface.go b/p2p/metrics/interface.go deleted file mode 100644 index 814e94fcf..000000000 --- a/p2p/metrics/interface.go +++ /dev/null @@ -1,19 +0,0 @@ -package metrics - -import ( - peer "github.com/ipfs/go-libp2p-peer" - protocol "github.com/libp2p/go-libp2p-protocol" -) - -type StreamMeterCallback func(int64, protocol.ID, peer.ID) -type MeterCallback func(int64) - -type Reporter interface { - LogSentMessage(int64) - LogRecvMessage(int64) - LogSentMessageStream(int64, protocol.ID, peer.ID) - LogRecvMessageStream(int64, protocol.ID, peer.ID) - GetBandwidthForPeer(peer.ID) Stats - GetBandwidthForProtocol(protocol.ID) Stats - GetBandwidthTotals() Stats -} diff --git a/p2p/metrics/stream/metered.go b/p2p/metrics/stream/metered.go deleted file mode 100644 index 3eddfd4db..000000000 --- a/p2p/metrics/stream/metered.go +++ /dev/null @@ -1,52 +0,0 @@ -package meterstream - -import ( - peer "github.com/ipfs/go-libp2p-peer" - protocol "github.com/libp2p/go-libp2p-protocol" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - inet "github.com/libp2p/go-libp2p/p2p/net" -) - -type meteredStream struct { - // keys for accessing metrics data - protoKey protocol.ID - peerKey peer.ID - - inet.Stream - - // callbacks for reporting bandwidth usage - mesSent metrics.StreamMeterCallback - mesRecv metrics.StreamMeterCallback -} - -func newMeteredStream(base inet.Stream, p peer.ID, recvCB, sentCB metrics.StreamMeterCallback) inet.Stream { - return &meteredStream{ - Stream: base, - mesSent: sentCB, - mesRecv: recvCB, - protoKey: base.Protocol(), - peerKey: p, - } -} - -func WrapStream(base inet.Stream, bwc metrics.Reporter) inet.Stream { - return newMeteredStream(base, base.Conn().RemotePeer(), bwc.LogRecvMessageStream, bwc.LogSentMessageStream) -} - -func (s *meteredStream) Read(b []byte) (int, error) { - n, err := s.Stream.Read(b) - - // Log bytes read - s.mesRecv(int64(n), s.protoKey, s.peerKey) - - return n, err -} - -func (s *meteredStream) Write(b []byte) (int, error) { - n, err := s.Stream.Write(b) - - // Log bytes written - s.mesSent(int64(n), s.protoKey, s.peerKey) - - return n, err -} diff --git a/p2p/metrics/stream/metered_test.go b/p2p/metrics/stream/metered_test.go deleted file mode 100644 index 9c1d12147..000000000 --- a/p2p/metrics/stream/metered_test.go +++ /dev/null @@ -1,78 +0,0 @@ -package meterstream - -import ( - "io" - "io/ioutil" - "testing" - - randbo "github.com/dustin/randbo" - peer "github.com/ipfs/go-libp2p-peer" - protocol "github.com/libp2p/go-libp2p-protocol" - inet "github.com/libp2p/go-libp2p/p2p/net" -) - -type FakeStream struct { - ReadBuf io.Reader - inet.Stream -} - -func (fs *FakeStream) Read(b []byte) (int, error) { - return fs.ReadBuf.Read(b) -} - -func (fs *FakeStream) Write(b []byte) (int, error) { - return len(b), nil -} - -func (fs *FakeStream) Protocol() protocol.ID { - return "TEST" -} - -func TestCallbacksWork(t *testing.T) { - fake := new(FakeStream) - - var sent int64 - var recv int64 - - sentCB := func(n int64, proto protocol.ID, p peer.ID) { - sent += n - } - - recvCB := func(n int64, proto protocol.ID, p peer.ID) { - recv += n - } - - ms := newMeteredStream(fake, peer.ID("PEER"), recvCB, sentCB) - - toWrite := int64(100000) - toRead := int64(100000) - - fake.ReadBuf = io.LimitReader(randbo.New(), toRead) - writeData := io.LimitReader(randbo.New(), toWrite) - - n, err := io.Copy(ms, writeData) - if err != nil { - t.Fatal(err) - } - - if n != toWrite { - t.Fatal("incorrect write amount") - } - - if toWrite != sent { - t.Fatal("incorrectly reported writes", toWrite, sent) - } - - n, err = io.Copy(ioutil.Discard, ms) - if err != nil { - t.Fatal(err) - } - - if n != toRead { - t.Fatal("incorrect read amount") - } - - if toRead != recv { - t.Fatal("incorrectly reported reads") - } -} diff --git a/p2p/net/interface.go b/p2p/net/interface.go deleted file mode 100644 index 1b296356d..000000000 --- a/p2p/net/interface.go +++ /dev/null @@ -1,159 +0,0 @@ -package net - -import ( - "context" - "io" - - peer "github.com/ipfs/go-libp2p-peer" - pstore "github.com/ipfs/go-libp2p-peerstore" - ma "github.com/jbenet/go-multiaddr" - "github.com/jbenet/goprocess" - conn "github.com/libp2p/go-libp2p-conn" - protocol "github.com/libp2p/go-libp2p-protocol" -) - -// MessageSizeMax is a soft (recommended) maximum for network messages. -// One can write more, as the interface is a stream. But it is useful -// to bunch it up into multiple read/writes when the whole message is -// a single, large serialized object. -const MessageSizeMax = 2 << 22 // 4MB - -// Stream represents a bidirectional channel between two agents in -// the IPFS network. "agent" is as granular as desired, potentially -// being a "request -> reply" pair, or whole protocols. -// Streams are backed by SPDY streams underneath the hood. -type Stream interface { - io.Reader - io.Writer - io.Closer - - Protocol() protocol.ID - SetProtocol(protocol.ID) - - // Conn returns the connection this stream is part of. - Conn() Conn -} - -// StreamHandler is the type of function used to listen for -// streams opened by the remote side. -type StreamHandler func(Stream) - -// Conn is a connection to a remote peer. It multiplexes streams. -// Usually there is no need to use a Conn directly, but it may -// be useful to get information about the peer on the other side: -// stream.Conn().RemotePeer() -type Conn interface { - conn.PeerConn - - // NewStream constructs a new Stream over this conn. - NewStream() (Stream, error) -} - -// ConnHandler is the type of function used to listen for -// connections opened by the remote side. -type ConnHandler func(Conn) - -// Network is the interface used to connect to the outside world. -// It dials and listens for connections. it uses a Swarm to pool -// connnections (see swarm pkg, and peerstream.Swarm). Connections -// are encrypted with a TLS-like protocol. -type Network interface { - Dialer - io.Closer - - // SetStreamHandler sets the handler for new streams opened by the - // remote side. This operation is threadsafe. - SetStreamHandler(StreamHandler) - - // SetConnHandler sets the handler for new connections opened by the - // remote side. This operation is threadsafe. - SetConnHandler(ConnHandler) - - // NewStream returns a new stream to given peer p. - // If there is no connection to p, attempts to create one. - NewStream(context.Context, peer.ID) (Stream, error) - - // Listen tells the network to start listening on given multiaddrs. - Listen(...ma.Multiaddr) error - - // ListenAddresses returns a list of addresses at which this network listens. - ListenAddresses() []ma.Multiaddr - - // InterfaceListenAddresses returns a list of addresses at which this network - // listens. It expands "any interface" addresses (/ip4/0.0.0.0, /ip6/::) to - // use the known local interfaces. - InterfaceListenAddresses() ([]ma.Multiaddr, error) - - // Process returns the network's Process - Process() goprocess.Process -} - -// Dialer represents a service that can dial out to peers -// (this is usually just a Network, but other services may not need the whole -// stack, and thus it becomes easier to mock) -type Dialer interface { - - // Peerstore returns the internal peerstore - // This is useful to tell the dialer about a new address for a peer. - // Or use one of the public keys found out over the network. - Peerstore() pstore.Peerstore - - // LocalPeer returns the local peer associated with this network - LocalPeer() peer.ID - - // DialPeer establishes a connection to a given peer - DialPeer(context.Context, peer.ID) (Conn, error) - - // ClosePeer closes the connection to a given peer - ClosePeer(peer.ID) error - - // Connectedness returns a state signaling connection capabilities - Connectedness(peer.ID) Connectedness - - // Peers returns the peers connected - Peers() []peer.ID - - // Conns returns the connections in this Netowrk - Conns() []Conn - - // ConnsToPeer returns the connections in this Netowrk for given peer. - ConnsToPeer(p peer.ID) []Conn - - // Notify/StopNotify register and unregister a notifiee for signals - Notify(Notifiee) - StopNotify(Notifiee) -} - -// Connectedness signals the capacity for a connection with a given node. -// It is used to signal to services and other peers whether a node is reachable. -type Connectedness int - -const ( - // NotConnected means no connection to peer, and no extra information (default) - NotConnected Connectedness = iota - - // Connected means has an open, live connection to peer - Connected - - // CanConnect means recently connected to peer, terminated gracefully - CanConnect - - // CannotConnect means recently attempted connecting but failed to connect. - // (should signal "made effort, failed") - CannotConnect -) - -// Notifiee is an interface for an object wishing to receive -// notifications from a Network. -type Notifiee interface { - Listen(Network, ma.Multiaddr) // called when network starts listening on an addr - ListenClose(Network, ma.Multiaddr) // called when network starts listening on an addr - Connected(Network, Conn) // called when a connection opened - Disconnected(Network, Conn) // called when a connection closed - OpenedStream(Network, Stream) // called when a stream opened - ClosedStream(Network, Stream) // called when a stream closed - - // TODO - // PeerConnected(Network, peer.ID) // called when a peer connected - // PeerDisconnected(Network, peer.ID) // called when a peer disconnected -} diff --git a/p2p/net/mock/interface.go b/p2p/net/mock/interface.go index d6384c4e2..c6018a2b6 100644 --- a/p2p/net/mock/interface.go +++ b/p2p/net/mock/interface.go @@ -11,12 +11,12 @@ import ( "time" host "github.com/libp2p/go-libp2p/p2p/host" - inet "github.com/libp2p/go-libp2p/p2p/net" ic "github.com/ipfs/go-libp2p-crypto" peer "github.com/ipfs/go-libp2p-peer" pstore "github.com/ipfs/go-libp2p-peerstore" ma "github.com/jbenet/go-multiaddr" + inet "github.com/libp2p/go-libp2p-net" ) type Mocknet interface { diff --git a/p2p/net/mock/mock_conn.go b/p2p/net/mock/mock_conn.go index e9b723190..55488b34a 100644 --- a/p2p/net/mock/mock_conn.go +++ b/p2p/net/mock/mock_conn.go @@ -8,7 +8,7 @@ import ( peer "github.com/ipfs/go-libp2p-peer" ma "github.com/jbenet/go-multiaddr" process "github.com/jbenet/goprocess" - inet "github.com/libp2p/go-libp2p/p2p/net" + inet "github.com/libp2p/go-libp2p-net" ) // conn represents one side's perspective of a diff --git a/p2p/net/mock/mock_link.go b/p2p/net/mock/mock_link.go index 30379dac6..9beeada4d 100644 --- a/p2p/net/mock/mock_link.go +++ b/p2p/net/mock/mock_link.go @@ -7,7 +7,7 @@ import ( "time" peer "github.com/ipfs/go-libp2p-peer" - inet "github.com/libp2p/go-libp2p/p2p/net" + inet "github.com/libp2p/go-libp2p-net" ) // link implements mocknet.Link diff --git a/p2p/net/mock/mock_net.go b/p2p/net/mock/mock_net.go index 53cb971a9..f15b00a89 100644 --- a/p2p/net/mock/mock_net.go +++ b/p2p/net/mock/mock_net.go @@ -8,7 +8,6 @@ import ( host "github.com/libp2p/go-libp2p/p2p/host" bhost "github.com/libp2p/go-libp2p/p2p/host/basic" - inet "github.com/libp2p/go-libp2p/p2p/net" p2putil "github.com/libp2p/go-libp2p/p2p/test/util" ic "github.com/ipfs/go-libp2p-crypto" @@ -17,6 +16,7 @@ import ( ma "github.com/jbenet/go-multiaddr" "github.com/jbenet/goprocess" goprocessctx "github.com/jbenet/goprocess/context" + inet "github.com/libp2p/go-libp2p-net" testutil "github.com/libp2p/go-testutil" ) diff --git a/p2p/net/mock/mock_notif_test.go b/p2p/net/mock/mock_notif_test.go index a9cb4ea73..88b347fc4 100644 --- a/p2p/net/mock/mock_notif_test.go +++ b/p2p/net/mock/mock_notif_test.go @@ -7,7 +7,7 @@ import ( peer "github.com/ipfs/go-libp2p-peer" ma "github.com/jbenet/go-multiaddr" - inet "github.com/libp2p/go-libp2p/p2p/net" + inet "github.com/libp2p/go-libp2p-net" ) func TestNotifications(t *testing.T) { diff --git a/p2p/net/mock/mock_peernet.go b/p2p/net/mock/mock_peernet.go index 9f0786cf7..5a5b61041 100644 --- a/p2p/net/mock/mock_peernet.go +++ b/p2p/net/mock/mock_peernet.go @@ -1,18 +1,17 @@ package mocknet import ( + "context" "fmt" "math/rand" "sync" - inet "github.com/libp2p/go-libp2p/p2p/net" - - "context" peer "github.com/ipfs/go-libp2p-peer" pstore "github.com/ipfs/go-libp2p-peerstore" ma "github.com/jbenet/go-multiaddr" "github.com/jbenet/goprocess" goprocessctx "github.com/jbenet/goprocess/context" + inet "github.com/libp2p/go-libp2p-net" ) // peernet implements inet.Network diff --git a/p2p/net/mock/mock_printer.go b/p2p/net/mock/mock_printer.go index 977328385..0465922d8 100644 --- a/p2p/net/mock/mock_printer.go +++ b/p2p/net/mock/mock_printer.go @@ -5,7 +5,7 @@ import ( "io" peer "github.com/ipfs/go-libp2p-peer" - inet "github.com/libp2p/go-libp2p/p2p/net" + inet "github.com/libp2p/go-libp2p-net" ) // separate object so our interfaces are separate :) diff --git a/p2p/net/mock/mock_stream.go b/p2p/net/mock/mock_stream.go index 4aa623a6f..bcdff3bd0 100644 --- a/p2p/net/mock/mock_stream.go +++ b/p2p/net/mock/mock_stream.go @@ -6,8 +6,8 @@ import ( "time" process "github.com/jbenet/goprocess" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" - inet "github.com/libp2p/go-libp2p/p2p/net" ) // stream implements inet.Stream diff --git a/p2p/net/mock/mock_test.go b/p2p/net/mock/mock_test.go index cef3a789a..e6e28eeda 100644 --- a/p2p/net/mock/mock_test.go +++ b/p2p/net/mock/mock_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - inet "github.com/libp2p/go-libp2p/p2p/net" + inet "github.com/libp2p/go-libp2p-net" peer "github.com/ipfs/go-libp2p-peer" detectrace "github.com/jbenet/go-detect-race" diff --git a/p2p/net/swarm/swarm.go b/p2p/net/swarm/swarm.go index 9107d7160..77c7daff0 100644 --- a/p2p/net/swarm/swarm.go +++ b/p2p/net/swarm/swarm.go @@ -11,10 +11,6 @@ import ( "sync" "time" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - mconn "github.com/libp2p/go-libp2p/p2p/metrics/conn" - inet "github.com/libp2p/go-libp2p/p2p/net" - ci "github.com/ipfs/go-libp2p-crypto" peer "github.com/ipfs/go-libp2p-peer" pstore "github.com/ipfs/go-libp2p-peerstore" @@ -26,6 +22,9 @@ import ( goprocessctx "github.com/jbenet/goprocess/context" addrutil "github.com/libp2p/go-addr-util" conn "github.com/libp2p/go-libp2p-conn" + metrics "github.com/libp2p/go-libp2p-metrics" + mconn "github.com/libp2p/go-libp2p-metrics/conn" + inet "github.com/libp2p/go-libp2p-net" transport "github.com/libp2p/go-libp2p-transport" filter "github.com/libp2p/go-maddr-filter" tcpt "github.com/libp2p/go-tcp-transport" diff --git a/p2p/net/swarm/swarm_addr_test.go b/p2p/net/swarm/swarm_addr_test.go index bd48d4f60..5d2225405 100644 --- a/p2p/net/swarm/swarm_addr_test.go +++ b/p2p/net/swarm/swarm_addr_test.go @@ -4,11 +4,10 @@ import ( "context" "testing" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - pstore "github.com/ipfs/go-libp2p-peerstore" ma "github.com/jbenet/go-multiaddr" addrutil "github.com/libp2p/go-addr-util" + metrics "github.com/libp2p/go-libp2p-metrics" testutil "github.com/libp2p/go-testutil" ) diff --git a/p2p/net/swarm/swarm_conn.go b/p2p/net/swarm/swarm_conn.go index 30ef800ed..42fc8905d 100644 --- a/p2p/net/swarm/swarm_conn.go +++ b/p2p/net/swarm/swarm_conn.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - inet "github.com/libp2p/go-libp2p/p2p/net" + inet "github.com/libp2p/go-libp2p-net" ic "github.com/ipfs/go-libp2p-crypto" peer "github.com/ipfs/go-libp2p-peer" diff --git a/p2p/net/swarm/swarm_listen.go b/p2p/net/swarm/swarm_listen.go index 702ef54b7..0c9d85973 100644 --- a/p2p/net/swarm/swarm_listen.go +++ b/p2p/net/swarm/swarm_listen.go @@ -4,14 +4,13 @@ import ( "context" "fmt" - inet "github.com/libp2p/go-libp2p/p2p/net" - lgbl "github.com/ipfs/go-libp2p-loggables" ma "github.com/jbenet/go-multiaddr" ps "github.com/jbenet/go-peerstream" conn "github.com/libp2p/go-libp2p-conn" + mconn "github.com/libp2p/go-libp2p-metrics/conn" + inet "github.com/libp2p/go-libp2p-net" transport "github.com/libp2p/go-libp2p-transport" - mconn "github.com/libp2p/go-libp2p/p2p/metrics/conn" ) func (s *Swarm) AddListenAddr(a ma.Multiaddr) error { diff --git a/p2p/net/swarm/swarm_net.go b/p2p/net/swarm/swarm_net.go index d9e83d5fd..86755cf8b 100644 --- a/p2p/net/swarm/swarm_net.go +++ b/p2p/net/swarm/swarm_net.go @@ -1,16 +1,15 @@ package swarm import ( + "context" "fmt" peer "github.com/ipfs/go-libp2p-peer" pstore "github.com/ipfs/go-libp2p-peerstore" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - inet "github.com/libp2p/go-libp2p/p2p/net" - - "context" ma "github.com/jbenet/go-multiaddr" "github.com/jbenet/goprocess" + metrics "github.com/libp2p/go-libp2p-metrics" + inet "github.com/libp2p/go-libp2p-net" ) // Network implements the inet.Network interface. diff --git a/p2p/net/swarm/swarm_net_test.go b/p2p/net/swarm/swarm_net_test.go index 205b841a1..ebf3bb82a 100644 --- a/p2p/net/swarm/swarm_net_test.go +++ b/p2p/net/swarm/swarm_net_test.go @@ -5,9 +5,9 @@ import ( "testing" "time" - inet "github.com/libp2p/go-libp2p/p2p/net" - testutil "github.com/libp2p/go-libp2p/p2p/test/util" "context" + inet "github.com/libp2p/go-libp2p-net" + testutil "github.com/libp2p/go-libp2p/p2p/test/util" ) // TestConnectednessCorrect starts a few networks, connects a few diff --git a/p2p/net/swarm/swarm_notif_test.go b/p2p/net/swarm/swarm_notif_test.go index 2bc663e0a..9e914b821 100644 --- a/p2p/net/swarm/swarm_notif_test.go +++ b/p2p/net/swarm/swarm_notif_test.go @@ -7,7 +7,7 @@ import ( "context" peer "github.com/ipfs/go-libp2p-peer" ma "github.com/jbenet/go-multiaddr" - inet "github.com/libp2p/go-libp2p/p2p/net" + inet "github.com/libp2p/go-libp2p-net" ) func streamsSame(a, b inet.Stream) bool { diff --git a/p2p/net/swarm/swarm_stream.go b/p2p/net/swarm/swarm_stream.go index 51c846001..ef3ab3c8f 100644 --- a/p2p/net/swarm/swarm_stream.go +++ b/p2p/net/swarm/swarm_stream.go @@ -1,8 +1,8 @@ package swarm import ( + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" - inet "github.com/libp2p/go-libp2p/p2p/net" ps "github.com/jbenet/go-peerstream" ) diff --git a/p2p/net/swarm/swarm_test.go b/p2p/net/swarm/swarm_test.go index e7099812d..f0ed560cf 100644 --- a/p2p/net/swarm/swarm_test.go +++ b/p2p/net/swarm/swarm_test.go @@ -10,12 +10,11 @@ import ( "testing" "time" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - inet "github.com/libp2p/go-libp2p/p2p/net" - peer "github.com/ipfs/go-libp2p-peer" pstore "github.com/ipfs/go-libp2p-peerstore" ma "github.com/jbenet/go-multiaddr" + metrics "github.com/libp2p/go-libp2p-metrics" + inet "github.com/libp2p/go-libp2p-net" testutil "github.com/libp2p/go-testutil" ) diff --git a/p2p/protocol/identify/id.go b/p2p/protocol/identify/id.go index 161b6a129..15042f593 100644 --- a/p2p/protocol/identify/id.go +++ b/p2p/protocol/identify/id.go @@ -5,20 +5,20 @@ import ( "strings" "sync" + host "github.com/libp2p/go-libp2p/p2p/host" + pb "github.com/libp2p/go-libp2p/p2p/protocol/identify/pb" + semver "github.com/coreos/go-semver/semver" ggio "github.com/gogo/protobuf/io" ic "github.com/ipfs/go-libp2p-crypto" + lgbl "github.com/ipfs/go-libp2p-loggables" peer "github.com/ipfs/go-libp2p-peer" pstore "github.com/ipfs/go-libp2p-peerstore" - ma "github.com/jbenet/go-multiaddr" - host "github.com/libp2p/go-libp2p/p2p/host" - mstream "github.com/libp2p/go-libp2p/p2p/metrics/stream" - inet "github.com/libp2p/go-libp2p/p2p/net" - pb "github.com/libp2p/go-libp2p/p2p/protocol/identify/pb" - msmux "github.com/whyrusleeping/go-multistream" - - lgbl "github.com/ipfs/go-libp2p-loggables" logging "github.com/ipfs/go-log" + ma "github.com/jbenet/go-multiaddr" + mstream "github.com/libp2p/go-libp2p-metrics/stream" + inet "github.com/libp2p/go-libp2p-net" + msmux "github.com/whyrusleeping/go-multistream" ) var log = logging.Logger("net/identify") diff --git a/p2p/protocol/ping/ping.go b/p2p/protocol/ping/ping.go index 9ce056d12..2c9982e4d 100644 --- a/p2p/protocol/ping/ping.go +++ b/p2p/protocol/ping/ping.go @@ -10,8 +10,8 @@ import ( u "github.com/ipfs/go-ipfs-util" peer "github.com/ipfs/go-libp2p-peer" logging "github.com/ipfs/go-log" + inet "github.com/libp2p/go-libp2p-net" host "github.com/libp2p/go-libp2p/p2p/host" - inet "github.com/libp2p/go-libp2p/p2p/net" ) var log = logging.Logger("ping") diff --git a/p2p/protocol/relay/relay.go b/p2p/protocol/relay/relay.go index c485d700f..85006b2a5 100644 --- a/p2p/protocol/relay/relay.go +++ b/p2p/protocol/relay/relay.go @@ -1,20 +1,21 @@ package relay import ( + "context" "fmt" "io" "time" - "context" + host "github.com/libp2p/go-libp2p/p2p/host" + peer "github.com/ipfs/go-libp2p-peer" logging "github.com/ipfs/go-log" mh "github.com/jbenet/go-multihash" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" - host "github.com/libp2p/go-libp2p/p2p/host" - inet "github.com/libp2p/go-libp2p/p2p/net" ) -var log = logging.Logger("github.com/libp2p/go-libp2p/p2p/protocol/relay") +var log = logging.Logger("protocol/relay") // ID is the protocol.ID of the Relay Service. const ID protocol.ID = "/ipfs/relay/line/0.1.0" diff --git a/p2p/protocol/relay/relay_test.go b/p2p/protocol/relay/relay_test.go index d541876c3..fbc1fc104 100644 --- a/p2p/protocol/relay/relay_test.go +++ b/p2p/protocol/relay/relay_test.go @@ -6,8 +6,8 @@ import ( "context" logging "github.com/ipfs/go-log" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" - inet "github.com/libp2p/go-libp2p/p2p/net" relay "github.com/libp2p/go-libp2p/p2p/protocol/relay" testutil "github.com/libp2p/go-libp2p/p2p/test/util" msmux "github.com/whyrusleeping/go-multistream" diff --git a/p2p/test/backpressure/backpressure_test.go b/p2p/test/backpressure/backpressure_test.go index 6b6af8238..25cda403b 100644 --- a/p2p/test/backpressure/backpressure_test.go +++ b/p2p/test/backpressure/backpressure_test.go @@ -10,9 +10,9 @@ import ( u "github.com/ipfs/go-ipfs-util" peer "github.com/ipfs/go-libp2p-peer" logging "github.com/ipfs/go-log" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" host "github.com/libp2p/go-libp2p/p2p/host" - inet "github.com/libp2p/go-libp2p/p2p/net" testutil "github.com/libp2p/go-libp2p/p2p/test/util" ) diff --git a/p2p/test/reconnects/reconnect_test.go b/p2p/test/reconnects/reconnect_test.go index 017c80d04..7675c4d7a 100644 --- a/p2p/test/reconnects/reconnect_test.go +++ b/p2p/test/reconnects/reconnect_test.go @@ -11,9 +11,9 @@ import ( u "github.com/ipfs/go-ipfs-util" logging "github.com/ipfs/go-log" ps "github.com/jbenet/go-peerstream" + inet "github.com/libp2p/go-libp2p-net" protocol "github.com/libp2p/go-libp2p-protocol" host "github.com/libp2p/go-libp2p/p2p/host" - inet "github.com/libp2p/go-libp2p/p2p/net" swarm "github.com/libp2p/go-libp2p/p2p/net/swarm" testutil "github.com/libp2p/go-libp2p/p2p/test/util" ) diff --git a/p2p/test/util/util.go b/p2p/test/util/util.go index 917b2e2f1..1104de0b9 100644 --- a/p2p/test/util/util.go +++ b/p2p/test/util/util.go @@ -5,12 +5,12 @@ import ( "testing" bhost "github.com/libp2p/go-libp2p/p2p/host/basic" - metrics "github.com/libp2p/go-libp2p/p2p/metrics" - inet "github.com/libp2p/go-libp2p/p2p/net" swarm "github.com/libp2p/go-libp2p/p2p/net/swarm" pstore "github.com/ipfs/go-libp2p-peerstore" ma "github.com/jbenet/go-multiaddr" + metrics "github.com/libp2p/go-libp2p-metrics" + inet "github.com/libp2p/go-libp2p-net" tu "github.com/libp2p/go-testutil" ) diff --git a/package.json b/package.json index b76b3d6ea..dd2522760 100644 --- a/package.json +++ b/package.json @@ -218,6 +218,18 @@ "hash": "QmTaW4q1AbqMkpfDLUYzW18nW62GsrnFvtVcvR1pnaURm6", "name": "go-libp2p-conn", "version": "1.0.0" + }, + { + "author": "whyrusleeping", + "hash": "QmSctCnUNkE7c7C2LGRGYrdmU9SDH3MtbAeueN7Jq1NN2q", + "name": "go-libp2p-net", + "version": "1.0.0" + }, + { + "author": "whyrusleeping", + "hash": "QmS38TTyj47fP5NVNznxpw4KpFYSU9zHkCEfmuBSkHzb6d", + "name": "go-libp2p-metrics", + "version": "1.0.0" } ], "gxVersion": "0.4.0",