2019-05-23 01:31:11 +08:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2020-12-19 10:36:59 +08:00
|
|
|
"context"
|
2019-05-23 01:31:11 +08:00
|
|
|
"io"
|
|
|
|
|
|
|
|
ic "github.com/libp2p/go-libp2p-core/crypto"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Conn is a connection to a remote peer. It multiplexes streams.
|
|
|
|
// Usually there is no need to use a Conn directly, but it may
|
|
|
|
// be useful to get information about the peer on the other side:
|
|
|
|
// stream.Conn().RemotePeer()
|
|
|
|
type Conn interface {
|
|
|
|
io.Closer
|
|
|
|
|
|
|
|
ConnSecurity
|
|
|
|
ConnMultiaddrs
|
2021-02-04 19:27:23 +08:00
|
|
|
ConnStat
|
2022-01-17 15:15:05 +08:00
|
|
|
ConnScoper
|
2019-05-23 01:31:11 +08:00
|
|
|
|
2020-06-05 19:24:56 +08:00
|
|
|
// ID returns an identifier that uniquely identifies this Conn within this
|
|
|
|
// host, during this run. Connection IDs may repeat across restarts.
|
|
|
|
ID() string
|
|
|
|
|
2019-05-23 01:31:11 +08:00
|
|
|
// NewStream constructs a new Stream over this conn.
|
2020-12-19 10:36:59 +08:00
|
|
|
NewStream(context.Context) (Stream, error)
|
2019-05-23 01:31:11 +08:00
|
|
|
|
|
|
|
// GetStreams returns all open streams over this conn.
|
|
|
|
GetStreams() []Stream
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnSecurity is the interface that one can mix into a connection interface to
|
|
|
|
// give it the security methods.
|
|
|
|
type ConnSecurity interface {
|
|
|
|
// LocalPeer returns our peer ID
|
|
|
|
LocalPeer() peer.ID
|
|
|
|
|
|
|
|
// LocalPrivateKey returns our private key
|
|
|
|
LocalPrivateKey() ic.PrivKey
|
|
|
|
|
|
|
|
// RemotePeer returns the peer ID of the remote peer.
|
|
|
|
RemotePeer() peer.ID
|
|
|
|
|
|
|
|
// RemotePublicKey returns the public key of the remote peer.
|
|
|
|
RemotePublicKey() ic.PubKey
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnMultiaddrs is an interface mixin for connection types that provide multiaddr
|
|
|
|
// addresses for the endpoints.
|
|
|
|
type ConnMultiaddrs interface {
|
|
|
|
// LocalMultiaddr returns the local Multiaddr associated
|
|
|
|
// with this connection
|
|
|
|
LocalMultiaddr() ma.Multiaddr
|
|
|
|
|
|
|
|
// RemoteMultiaddr returns the remote Multiaddr associated
|
|
|
|
// with this connection
|
|
|
|
RemoteMultiaddr() ma.Multiaddr
|
|
|
|
}
|
2021-02-04 19:27:23 +08:00
|
|
|
|
2021-02-17 17:21:51 +08:00
|
|
|
// ConnStat is an interface mixin for connection types that provide connection statistics.
|
2021-02-04 19:27:23 +08:00
|
|
|
type ConnStat interface {
|
|
|
|
// Stat stores metadata pertaining to this conn.
|
2021-12-12 18:58:02 +08:00
|
|
|
Stat() ConnStats
|
2021-02-04 19:27:23 +08:00
|
|
|
}
|
2022-01-17 15:15:05 +08:00
|
|
|
|
|
|
|
// ConnScoper is the interface that one can mix into a connection interface to give it a resource
|
|
|
|
// management scope
|
|
|
|
type ConnScoper interface {
|
|
|
|
// Scope returns the user view of this connection's resource scope
|
|
|
|
Scope() ConnScope
|
|
|
|
}
|