From 8ca20a2d615752670385292fece99a73fc5ccac5 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Fri, 13 Sep 2019 19:14:17 +0530 Subject: [PATCH 1/7] enable network to emit events on a bus --- network/events.go | 15 +++++++++++++++ network/network.go | 6 ++++++ 2 files changed, 21 insertions(+) create mode 100644 network/events.go diff --git a/network/events.go b/network/events.go new file mode 100644 index 0000000..cbcc1a0 --- /dev/null +++ b/network/events.go @@ -0,0 +1,15 @@ +package network + +// EvtPeerConnectionStateChange should be emitted when we connect/disconnect from a peer +type EvtPeerConnectionStateChange struct { + Network Network + Connection Conn + NewState Connectedness +} + +// EvtStreamStateChange is emitted when we open/close a stream with a peer +type EvtStreamStateChange struct { + Network Network + Stream Stream + NewState Connectedness +} diff --git a/network/network.go b/network/network.go index 467109c..f8e458d 100644 --- a/network/network.go +++ b/network/network.go @@ -10,6 +10,7 @@ import ( "io" "github.com/jbenet/goprocess" + "github.com/libp2p/go-libp2p-core/event" "github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peerstore" @@ -100,6 +101,11 @@ type Network interface { // Process returns the network's Process Process() goprocess.Process + + // EventBus returns the network's Event Bus + // we can subscribe to this bus to listen for connection/disconnection of peers, + // opening/closing of streams etc etc + EventBus() event.Bus } // Dialer represents a service that can dial out to peers From 3e988ff158e2cacaee209dab71549d3732765694 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Fri, 28 Feb 2020 16:06:03 +0530 Subject: [PATCH 2/7] changes as per review --- event/network.go | 21 +++++++++++++++++++++ network/events.go | 15 --------------- network/network.go | 6 ------ 3 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 event/network.go delete mode 100644 network/events.go diff --git a/event/network.go b/event/network.go new file mode 100644 index 0000000..e7428e3 --- /dev/null +++ b/event/network.go @@ -0,0 +1,21 @@ +package event + +import "github.com/libp2p/go-libp2p-core/network" + +// EvtPeerConnectionStateChange should be emitted when we connect to a peer or disconnect +// from a peer. It contains the network interface for the connection, +// the connection handle & the new state of the connection. +type EvtPeerConnectionStateChange struct { + Network network.Network + Connection network.Conn + NewState network.Connectedness +} + +// EvtStreamStateChange should be emitted when we open a new stream with a peer or close an existing stream. +// It contains the network interface for the connection, the stream handle & +// the new state of the stream. +type EvtStreamStateChange struct { + Network network.Network + Stream network.Stream + NewState network.Connectedness +} diff --git a/network/events.go b/network/events.go deleted file mode 100644 index cbcc1a0..0000000 --- a/network/events.go +++ /dev/null @@ -1,15 +0,0 @@ -package network - -// EvtPeerConnectionStateChange should be emitted when we connect/disconnect from a peer -type EvtPeerConnectionStateChange struct { - Network Network - Connection Conn - NewState Connectedness -} - -// EvtStreamStateChange is emitted when we open/close a stream with a peer -type EvtStreamStateChange struct { - Network Network - Stream Stream - NewState Connectedness -} diff --git a/network/network.go b/network/network.go index f8e458d..467109c 100644 --- a/network/network.go +++ b/network/network.go @@ -10,7 +10,6 @@ import ( "io" "github.com/jbenet/goprocess" - "github.com/libp2p/go-libp2p-core/event" "github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peerstore" @@ -101,11 +100,6 @@ type Network interface { // Process returns the network's Process Process() goprocess.Process - - // EventBus returns the network's Event Bus - // we can subscribe to this bus to listen for connection/disconnection of peers, - // opening/closing of streams etc etc - EventBus() event.Bus } // Dialer represents a service that can dial out to peers From f4b25da8e4ddd865979fcb7d4ec201e2f4772fd3 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Fri, 28 Feb 2020 16:18:42 +0530 Subject: [PATCH 3/7] remove network from the events --- event/network.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/event/network.go b/event/network.go index e7428e3..8fcc1ea 100644 --- a/event/network.go +++ b/event/network.go @@ -6,7 +6,6 @@ import "github.com/libp2p/go-libp2p-core/network" // from a peer. It contains the network interface for the connection, // the connection handle & the new state of the connection. type EvtPeerConnectionStateChange struct { - Network network.Network Connection network.Conn NewState network.Connectedness } @@ -15,7 +14,6 @@ type EvtPeerConnectionStateChange struct { // It contains the network interface for the connection, the stream handle & // the new state of the stream. type EvtStreamStateChange struct { - Network network.Network Stream network.Stream NewState network.Connectedness } From 8721a124d26eba3db55d8497b42ecaa399ec7d6d Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Sat, 29 Feb 2020 11:46:17 +0530 Subject: [PATCH 4/7] peer connectedness event --- event/network.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/event/network.go b/event/network.go index 8fcc1ea..c03c8d9 100644 --- a/event/network.go +++ b/event/network.go @@ -2,18 +2,13 @@ package event import "github.com/libp2p/go-libp2p-core/network" -// EvtPeerConnectionStateChange should be emitted when we connect to a peer or disconnect -// from a peer. It contains the network interface for the connection, -// the connection handle & the new state of the connection. -type EvtPeerConnectionStateChange struct { +// EvtPeerStateChange should be emitted when we form our first connection with a peer or drop our last +// connection with the peer. Essentially, it is emitted in two cases: +// a) We go from having no connection with a peer to having a connection with a peer. +// b) We go from having a connection/s with a peer to having no connection with the peer. +// It contains the network interface for the connection, the connection handle for the first/last connection and +// the new connection state. +type EvtPeerStateChange struct { Connection network.Conn NewState network.Connectedness } - -// EvtStreamStateChange should be emitted when we open a new stream with a peer or close an existing stream. -// It contains the network interface for the connection, the stream handle & -// the new state of the stream. -type EvtStreamStateChange struct { - Stream network.Stream - NewState network.Connectedness -} From 3ff44e37701006c7d6ffea08cfc6020037a93859 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Tue, 3 Mar 2020 13:53:03 +0530 Subject: [PATCH 5/7] docs change --- event/network.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/event/network.go b/event/network.go index c03c8d9..1a8af30 100644 --- a/event/network.go +++ b/event/network.go @@ -2,12 +2,11 @@ package event import "github.com/libp2p/go-libp2p-core/network" -// EvtPeerStateChange should be emitted when we form our first connection with a peer or drop our last +// EvtPeerStateChange should be emitted everytime we form a connection with a peer or drop our last // connection with the peer. Essentially, it is emitted in two cases: -// a) We go from having no connection with a peer to having a connection with a peer. +// a) We form a/any connection with a peer. // b) We go from having a connection/s with a peer to having no connection with the peer. -// It contains the network interface for the connection, the connection handle for the first/last connection and -// the new connection state. +// It contains the connection handle and the new connection state. type EvtPeerStateChange struct { Connection network.Conn NewState network.Connectedness From 22092abdbb863caba65673af5929f8f51445ac23 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Fri, 6 Mar 2020 15:58:32 +0530 Subject: [PATCH 6/7] changes as per review --- event/network.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/event/network.go b/event/network.go index 1a8af30..8786fcf 100644 --- a/event/network.go +++ b/event/network.go @@ -1,13 +1,16 @@ package event -import "github.com/libp2p/go-libp2p-core/network" +import ( + "github.com/libp2p/go-libp2p-core/network" + "github.com/libp2p/go-libp2p-core/peer" +) -// EvtPeerStateChange should be emitted everytime we form a connection with a peer or drop our last +// EvtPeerConnectednessChange should be emitted every time we form a connection with a peer or drop our last // connection with the peer. Essentially, it is emitted in two cases: // a) We form a/any connection with a peer. // b) We go from having a connection/s with a peer to having no connection with the peer. -// It contains the connection handle and the new connection state. -type EvtPeerStateChange struct { - Connection network.Conn - NewState network.Connectedness +// It contains the Id of the remote peer and the new connectedness state. +type EvtPeerConnectednessChange struct { + RemotePeerId peer.ID + Connectedness network.Connectedness } From 493f2b140f27339cb83f26e91b772ba3aa23b6ee Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Fri, 6 Mar 2020 16:08:03 +0530 Subject: [PATCH 7/7] changes as per raul's review --- event/network.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/event/network.go b/event/network.go index 8786fcf..05b435d 100644 --- a/event/network.go +++ b/event/network.go @@ -5,12 +5,12 @@ import ( "github.com/libp2p/go-libp2p-core/peer" ) -// EvtPeerConnectednessChange should be emitted every time we form a connection with a peer or drop our last +// EvtPeerConnectednessChanged should be emitted every time we form a connection with a peer or drop our last // connection with the peer. Essentially, it is emitted in two cases: // a) We form a/any connection with a peer. // b) We go from having a connection/s with a peer to having no connection with the peer. // It contains the Id of the remote peer and the new connectedness state. -type EvtPeerConnectednessChange struct { - RemotePeerId peer.ID +type EvtPeerConnectednessChanged struct { + Peer peer.ID Connectedness network.Connectedness }