mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2024-12-26 23:30:27 +08:00
e4c76cf7cd
* add resource manager interfaces * add scope accessors to streams and conns * add ResourceManager accessor to the Network interface * allow initially unattached streams. * introduce service scopes, canonicalize ownership interface through setters * make system scope explicit * make memory stat an int64 * make the system scope a generic resource scope, introduce the DMZ * fix typo Co-authored-by: Marten Seemann <martenseemann@gmail.com> * fix typo Co-authored-by: Marten Seemann <martenseemann@gmail.com> * rename DMZ to transient scope, remove OpenConnection from PeerScope * remove ncopy param from GrowBuffer * remove protocols from OpenStream The stream is unnegotiated state until the actual protocol has been determined. * document nil receiver contract, fix protocol scope protocol accessor method * remove nil receiver contract requirement * flesh out stat struct * turn resource manager scope accessors into viewers * interface refiniments 1. Introduce transactions in all scopes 2. Limit the view of stream/connection scope for users, to avoid the Done footgun 3. Move OpenStream to the resource manager * add Buffer interface * fix typo Co-authored-by: Marten Seemann <martenseemann@gmail.com> * fix typo Co-authored-by: Marten Seemann <martenseemann@gmail.com> * fix typo Co-authored-by: Marten Seemann <martenseemann@gmail.com> * rename user scopes to plain names, management scopes as such * rename BeginTxn to BeginTransaction * RIP Buffers * make ErrResourceLimitExceeded a temporary error; move rcmgr errors with the other errors. * unexport TemporaryError * null resource manager stub * unexport the null stubs, make entry point a variable * don't rely on typed nils but instead use actual null object instances So that we don't confuse the hell out of everyone! * add Scope to the CapableConn interface * rename ConnectionScope to ConnScope for consistency * fix typo * rename ConnectionManagementScope to ConnManagementScope * add the ConnManagementScope to Upgrader.Upgrade * fix argument name * godocs for ResourceManager * introduce MemoryStatus indicator in ReserveMemory * use uint8 for MemoryStatus Co-authored-by: Marten Seemann <martenseemann@gmail.com> * rework reservation interface to pass priority instead of returning memory status so that we don't have to undo reservations if there is too much pressure. * improve comment * fix typo * export the NullScope * Stream.SetProtocol can return an error It needs to attach the protocol to the protocol scope, which may fail. * merge the mux package into network * pass the PeerScope to Multiplexer.NetConn * Update network/rcmgr.go Co-authored-by: raulk <raul@protocol.ai> * Update network/rcmgr.go Co-authored-by: raulk <raul@protocol.ai> * Update network/rcmgr.go Co-authored-by: raulk <raul@protocol.ai> * Update network/rcmgr.go Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com> * remove reference to deprecated mux.MuxedConn * rename transaction to span * indicate bytes in ReserveMemory * break ResourceManager View methods into Viewer interface. * add experimental interface warning Co-authored-by: Marten Seemann <martenseemann@gmail.com> Co-authored-by: raulk <raul@protocol.ai> Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>
76 lines
2.0 KiB
Go
76 lines
2.0 KiB
Go
package network
|
|
|
|
import (
|
|
"context"
|
|
"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
|
|
ConnStat
|
|
ConnScoper
|
|
|
|
// ID returns an identifier that uniquely identifies this Conn within this
|
|
// host, during this run. Connection IDs may repeat across restarts.
|
|
ID() string
|
|
|
|
// NewStream constructs a new Stream over this conn.
|
|
NewStream(context.Context) (Stream, error)
|
|
|
|
// 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
|
|
}
|
|
|
|
// ConnStat is an interface mixin for connection types that provide connection statistics.
|
|
type ConnStat interface {
|
|
// Stat stores metadata pertaining to this conn.
|
|
Stat() ConnStats
|
|
}
|
|
|
|
// 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
|
|
}
|