From 8ca20a2d615752670385292fece99a73fc5ccac5 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Fri, 13 Sep 2019 19:14:17 +0530 Subject: [PATCH] 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