link

package
v0.43.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMountedStreamContext = errors.New("no mounted stream context")

ErrNoMountedStreamContext is returned if there was no MountedStreamContext.

Functions

func WithMountedStreamContext added in v0.20.2

func WithMountedStreamContext(ctx context.Context, msc MountedStreamContext) context.Context

WithMountedStreamContext attaches a MountedStreamContext to a Context.

Types

type EstablishLinkWithPeer

type EstablishLinkWithPeer interface {
	// Directive indicates EstablishLinkWithPeer is a directive.
	directive.Directive

	// EstablishLinkSourcePeerId returns the source peer ID.
	// Can be empty to allow any.
	EstablishLinkSourcePeerId() peer.ID
	// EstablishLinkTargetPeerId returns the target peer ID.
	// Cannot be empty.
	EstablishLinkTargetPeerId() peer.ID
}

EstablishLinkWithPeer is a directive to establish a link with a peer.

Value: Link

func NewEstablishLinkWithPeer

func NewEstablishLinkWithPeer(srcPeer, destPeer peer.ID) EstablishLinkWithPeer

NewEstablishLinkWithPeer constructs a new EstablishLinkWithPeer directive.

type EstablishLinkWithPeerValue added in v0.14.1

type EstablishLinkWithPeerValue = MountedLink

EstablishLinkWithPeerValue is the type emitted when resolving EstablishLinkWithPeer.

func EstablishLinkWithPeerEx added in v0.14.1

func EstablishLinkWithPeerEx(
	ctx context.Context,
	b bus.Bus,
	localPeerID, remotePeerID peer.ID,
	returnIfIdle bool,
) (EstablishLinkWithPeerValue, func(), error)

EstablishLinkWithPeerEx executes a EstablishLinkWithPeer directive. Returns a release function. if returnIfIdle: returns nil, nil, nil if not found (idle directive)

type HandleMountedStream

type HandleMountedStream interface {
	// Directive indicates HandleMountedStream is a directive.
	directive.Directive

	// HandleMountedStreamProtocolID returns the protocol ID we are requesting a
	// handler for. Cannot be empty.
	HandleMountedStreamProtocolID() protocol.ID
	// HandleMountedStreamLocalPeerID returns the local peer ID we are
	// requesting a handler for. Cannot be empty.
	HandleMountedStreamLocalPeerID() peer.ID
	// HandleMountedStreamRemotePeerID returns the remote peer ID we are
	// requesting a handler for. Cannot be empty.
	HandleMountedStreamRemotePeerID() peer.ID
}

HandleMountedStream is a directive to return a mounted stream handler for a protocol ID.

Value is of type link.MountedStreamHandler.

func NewHandleMountedStream

func NewHandleMountedStream(
	protocolID protocol.ID,
	localPeerID, remotePeerID peer.ID,
) HandleMountedStream

NewHandleMountedStream constructs a new HandleMountedStream directive.

type HandleMountedStreamValue

type HandleMountedStreamValue = MountedStreamHandler

HandleMountedStreamValue is the value type for HandleMountedStream.

type Link interface {
	// GetUUID returns the host-unique ID.
	// This should be repeatable between re-constructions of the same link.
	GetUUID() uint64
	// GetTransportUUID returns the unique ID of the transport.
	GetTransportUUID() uint64
	// OpenStream opens a stream on the link, with the given parameters.
	OpenStream(opts stream.OpenOpts) (stream.Stream, error)
	// AcceptStream accepts a stream from the link.
	// Terminates when the link closes.
	AcceptStream() (stream.Stream, stream.OpenOpts, error)
	// GetRemotePeer returns the identity of the remote peer.
	GetRemotePeer() peer.ID
	// GetLocalPeer returns the identity of the local peer.
	GetLocalPeer() peer.ID
	// GetRemoteTransportUUID returns the reported remote transport UUID.
	// This should be negotiated in the handshake.
	GetRemoteTransportUUID() uint64
	// Close closes the link.
	// Any blocked ReadFrom or WriteTo operations will be unblocked and return errors.
	// The link should call the HandleLinkLost callback exactly once.
	// Close may be called many times.
	Close() error
}

Link represents a one-hop connection between two peers.

type MountedLink interface {
	// GetLinkUUID returns the host-unique link ID.
	// This should be repeatable between re-constructions of the same link.
	GetLinkUUID() uint64

	// GetTransportUUID returns the unique ID of the transport.
	GetTransportUUID() uint64
	// GetRemoteTransportUUID returns the reported remote transport UUID.
	// This should be negotiated in the handshake.
	GetRemoteTransportUUID() uint64

	// GetLocalPeer returns the identity of the local peer.
	GetLocalPeer() peer.ID
	// GetRemotePeer returns the identity of the remote peer.
	GetRemotePeer() peer.ID

	// OpenMountedStream opens a stream on the link, with the given parameters.
	OpenMountedStream(
		ctx context.Context,
		protocolID protocol.ID,
		opts stream.OpenOpts,
	) (MountedStream, error)
}

MountedLink is a Link managed by the transport controller.

type MountedStream

type MountedStream interface {
	// GetStream returns the underlying stream object.
	GetStream() stream.Stream
	// GetProtocolID returns the protocol ID of the stream.
	GetProtocolID() protocol.ID
	// GetOpenOpts returns the options used to open the stream.
	GetOpenOpts() stream.OpenOpts
	// GetPeerID returns the peer ID for the other end of the stream.
	GetPeerID() peer.ID
	// GetLink returns the associated link carrying the stream.
	GetLink() MountedLink
}

MountedStream is a stream attached to a Link. This is produced and managed by the link controller. A mounted stream is produced after the initial stream negotiation is completed.

func OpenStreamWithPeerEx

func OpenStreamWithPeerEx(
	ctx context.Context,
	b bus.Bus,
	protocolID protocol.ID,
	localPeerID, remotePeerID peer.ID,
	transportID uint64,
	openOpts stream.OpenOpts,
) (MountedStream, func(), error)

OpenStreamWithPeerEx executes a OpenStreamWithPeer directive. Returns a release function for the reference to the link used for the stream.

type MountedStreamContext added in v0.20.2

type MountedStreamContext = MountedStream

MountedStreamContext is the value attached to a Context containing information about the current mounted stream.

func GetMountedStreamContext added in v0.20.2

func GetMountedStreamContext(ctx context.Context) MountedStreamContext

GetMountedStreamContext returns the MountedStreamContext from the Context or nil if unset.

func MustGetMountedStreamContext added in v0.35.1

func MustGetMountedStreamContext(ctx context.Context) (MountedStreamContext, error)

MustGetMountedStreamContext returns the MountedStreamContext from the Context or an error if unset.

type MountedStreamHandler

type MountedStreamHandler interface {
	// HandleMountedStream handles an incoming mounted stream.
	//
	// This function should return as soon as possible, and start
	// additional goroutines to manage the lifecycle of the stream.
	//
	// The context will be canceled when the Link closes.
	// The context will /not/ be canceled when ms closes.
	// Any returned error indicates the stream should be closed.
	HandleMountedStream(ctx context.Context, ms MountedStream) error
}

MountedStreamHandler handles an incoming mounted stream.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL