forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport.go
47 lines (39 loc) · 1.58 KB
/
transport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package p2p
import (
"net"
"github.com/cosmos/gogoproto/proto"
na "github.com/cometbft/cometbft/p2p/netaddr"
)
// peerConfig is used to bundle data we need to fully setup a Peer with an
// MConn, provided by the caller of Accept and Dial (currently the Switch). This
// a temporary measure until reactor setup is less dynamic and we introduce the
// concept of PeerBehaviour to communicate about significant Peer lifecycle
// events.
// TODO(xla): Refactor out with more static Reactor setup and PeerBehaviour.
type peerConfig struct {
streamDescs []StreamDescriptor
onPeerError func(Peer, any)
outbound bool
// isPersistent allows you to set a function, which, given socket address
// (for outbound peers) OR self-reported address (for inbound peers), tells
// if the peer is persistent or not.
isPersistent func(*na.NetAddr) bool
reactorsByCh map[byte]Reactor
msgTypeByChID map[byte]proto.Message
metrics *Metrics
}
// Transport emits and connects to Peers. The implementation of Peer is left to
// the transport. Each transport is also responsible to filter establishing
// peers specific to its domain.
type Transport interface {
// NetAddr returns the network address of the local node.
NetAddr() na.NetAddr
// Accept waits for and returns the next connection to the local node.
Accept() (net.Conn, *na.NetAddr, error)
// Dial dials the given address and returns a connection.
Dial(addr na.NetAddr) (net.Conn, error)
// Cleanup any resources associated with the given connection.
//
// Must be run when the peer is dropped for any reason.
Cleanup(conn net.Conn) error
}