enable network to emit events on a bus

This commit is contained in:
Aarsh Shah 2019-09-13 19:14:17 +05:30
parent bcf3ad5c24
commit 8ca20a2d61
2 changed files with 21 additions and 0 deletions

15
network/events.go Normal file
View File

@ -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
}

View File

@ -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