network.go 2 KB
Newer Older
Aarsh Shah's avatar
Aarsh Shah committed
1 2
package event

Aarsh Shah's avatar
Aarsh Shah committed
3
import (
tavit ohanian's avatar
tavit ohanian committed
4 5
	"gitlab.dms3.io/p2p/go-p2p-core/network"
	"gitlab.dms3.io/p2p/go-p2p-core/peer"
Aarsh Shah's avatar
Aarsh Shah committed
6
)
Aarsh Shah's avatar
Aarsh Shah committed
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
// EvtPeerConnectednessChanged should be emitted every time the "connectedness" to a
// given peer changes. Specifically, this event is emitted in the following
// cases:
//
// * Connectedness = Connected: Every time we transition from having no
//   connections to a peer to having at least one connection to the peer.
// * Connectedness = NotConnected: Every time we transition from having at least
//   one connection to a peer to having no connections to the peer.
//
// Additional connectedness states may be added in the future. This list should
// not be considered exhaustive.
//
// Take note:
//
//  * It's possible to have _multiple_ connections to a given peer.
tavit ohanian's avatar
tavit ohanian committed
23
//  * Both p2p and networks are asynchronous.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
//
// This means that all of the following situations are possible:
//
// A connection is cut and is re-established:
//
//   * Peer A observes a transition from Connected -> NotConnected -> Connected
//   * Peer B observes a transition from Connected -> NotConnected -> Connected
//
// Explanation: Both peers observe the connection die. This is the "nice" case.
//
// A connection is cut and is re-established.
//
//   * Peer A observes a transition from Connected -> NotConnected -> Connected.
//   * Peer B observes no transition.
//
// Explanation: Peer A re-establishes the dead connection. Peer B observes the
// new connection form before it observes the old connection die.
//
// A connection is cut:
//
//   * Peer A observes no transition.
//   * Peer B observes no transition.
//
// Explanation: There were two connections and one was cut. This connection
// might have been in active use but neither peer will observe a change in
// "connectedness". Peers should always make sure to re-try network requests.
Aarsh Shah's avatar
Aarsh Shah committed
50
type EvtPeerConnectednessChanged struct {
51 52 53
	// Peer is the remote peer who's connectedness has changed.
	Peer peer.ID
	// Connectedness is the new connectedness state.
Aarsh Shah's avatar
Aarsh Shah committed
54
	Connectedness network.Connectedness
Aarsh Shah's avatar
Aarsh Shah committed
55
}