transport_quic

package
v0.37.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const Alpn = "bifrost"

Alpn is set to ensure quic does not talk to non-bifrost peers

Variables

View Source
var (
	// ErrDialUnimplemented is returned if dialing the peer is unimplemented.
	ErrDialUnimplemented = errors.New("dial peer not implemented")
	// ErrRemoteUnspecified is returned if the remote addr is unspecified.
	ErrRemoteUnspecified = errors.New("peer id and/or remote addr must be specified")
)

Functions

func BuildIncomingTlsConf

func BuildIncomingTlsConf(identity *p2ptls.Identity, rpeer peer.ID) *tls.Config

BuildIncomingTlsConf builds the tls config for incoming conns.

rpeer can be empty to indicate accepting any remote peer

func BuildQuicConfig

func BuildQuicConfig(le *logrus.Entry, opts *Opts) *quic.Config

BuildQuicConfig constructs the quic config.

func CheckAlreadyConnected

func CheckAlreadyConnected(t *Transport, addr string, peerID peer.ID) (bool, error)

CheckAlreadyConnected checks if a address and peer id is already connected.

func DetermineSessionIdentity

func DetermineSessionIdentity(sess quic.Connection) (peer.ID, crypto.PubKey, error)

DetermineSessionIdentity determines the identity from the session cert chain.

func DialSession

func DialSession(
	ctx context.Context,
	le *logrus.Entry,
	opts *Opts,
	pconn net.PacketConn,
	identity *p2ptls.Identity,
	addr net.Addr,
	rpeer peer.ID,
) (quic.Connection, crypto.PubKey, error)

DialSession dials a remote addr on a packet conn to create a session.

Negotiates a TLS session. Specify a empty peer ID to allow any. Dial indicates this is the originator of the conn.

func DialSessionViaTransport added in v0.16.3

func DialSessionViaTransport(
	ctx context.Context,
	le *logrus.Entry,
	opts *Opts,
	tpt *quic.Transport,
	identity *p2ptls.Identity,
	addr net.Addr,
	rpeer peer.ID,
) (quic.Connection, crypto.PubKey, error)

DialSessionViaTransport dials a remote addr on a quic transport to create a session.

Negotiates a TLS session. Specify a empty peer ID to allow any. Dial indicates this is the originator of the conn.

func ListenSession

func ListenSession(
	ctx context.Context,
	le *logrus.Entry,
	opts *Opts,
	pconn net.PacketConn,
	identity *p2ptls.Identity,
	rpeer peer.ID,
) (quic.Connection, error)

ListenSession listens for a single incoming session on a PacketConn.

Negotiates a TLS session. Specify a empty peer ID to allow any. Dial indicates this is the originator of the conn.

func NewLinkUUID

func NewLinkUUID(localAddr, remoteAddr net.Addr, peerID peer.ID) uint64

NewLinkUUID builds the UUID for a link

func NewTransportUUID

func NewTransportUUID(localAddr string, peerID peer.ID) uint64

NewTransportUUID builds the UUID for a transport with a local address and peer id

Types

type DialFunc

type DialFunc func(ctx context.Context, addr string) (quic.Connection, net.Addr, error)

DialFunc is a function to dial a peer with a string address. The function should parse the addr to a net.Addr.

type Dialer

type Dialer struct {
	// contains filtered or unexported fields
}

Dialer represents a ongoing attempt to dial an address

func NewDialer

func NewDialer(
	rctx context.Context,
	t *Transport,
	peerID peer.ID,
	addr string,
) (*Dialer, error)

NewDialer constructs a new dialer.

func (*Dialer) Execute

func (d *Dialer) Execute()

Execute executes the dialer, yielding a Link.

type Link struct {
	// contains filtered or unexported fields
}

Link represents a Quic-based connection/link.

func NewLink(
	ctx context.Context,
	le *logrus.Entry,
	opts *Opts,
	localTransportUUID uint64,
	localPeerID peer.ID,
	localAddr net.Addr,
	sess quic.Connection,
	closed func(),
) (*Link, error)

NewLink builds a new link.

func (*Link) AcceptStream

func (l *Link) AcceptStream() (stream.Stream, stream.OpenOpts, error)

AcceptStream accepts a stream from the link.

func (*Link) Close

func (l *Link) Close() error

Close closes the connection.

func (*Link) GetContext

func (l *Link) GetContext() context.Context

GetContext returns a context that is canceled when the Link is closed.

func (*Link) GetLocalPeer

func (l *Link) GetLocalPeer() peer.ID

GetLocalPeer returns the identity of the local peer.

func (*Link) GetRemotePeer

func (l *Link) GetRemotePeer() peer.ID

GetRemotePeer returns the identity of the remote peer if encrypted.

func (*Link) GetRemotePeerPubKey

func (l *Link) GetRemotePeerPubKey() crypto.PublicKey

GetRemotePeerPubKey returns the remote peer public key

func (*Link) GetRemoteTransportUUID

func (l *Link) GetRemoteTransportUUID() uint64

GetRemoteTransportUUID returns the unique ID of the remote transport. Reported by the remote peer. May be zero or unknown value.

func (*Link) GetTransportUUID

func (l *Link) GetTransportUUID() uint64

GetTransportUUID returns the unique ID of the transport.

func (*Link) GetUUID

func (l *Link) GetUUID() uint64

GetUUID returns the link unique id.

func (*Link) LocalAddr

func (l *Link) LocalAddr() net.Addr

LocalAddr returns the local address.

func (*Link) OpenStream

func (l *Link) OpenStream(opts stream.OpenOpts) (stream.Stream, error)

OpenStream opens a stream on the link, with the given parameters.

func (*Link) RemoteAddr

func (l *Link) RemoteAddr() net.Addr

RemoteAddr returns the remote address.

type Opts

type Opts struct {

	// MaxIdleTimeoutDur is the duration of idle after which conn is closed.
	//
	// Defaults to 10s.
	MaxIdleTimeoutDur string `protobuf:"bytes,1,opt,name=max_idle_timeout_dur,json=maxIdleTimeoutDur,proto3" json:"maxIdleTimeoutDur,omitempty"`
	// MaxIncomingStreams is the maximum number of concurrent bidirectional
	// streams that a peer is allowed to open.
	//
	// If unset or negative, defaults to 100000.
	MaxIncomingStreams int32 `protobuf:"varint,2,opt,name=max_incoming_streams,json=maxIncomingStreams,proto3" json:"maxIncomingStreams,omitempty"`
	// DisableKeepAlive disables the keep alive packets.
	DisableKeepAlive bool `protobuf:"varint,3,opt,name=disable_keep_alive,json=disableKeepAlive,proto3" json:"disableKeepAlive,omitempty"`
	// KeepAliveDur is the duration between keep-alive pings.
	//
	// If disable_keep_alive is set, this value is ignored.
	// If unset, sets keep-alive to half of MaxIdleTimeout.
	KeepAliveDur string `protobuf:"bytes,7,opt,name=keep_alive_dur,json=keepAliveDur,proto3" json:"keepAliveDur,omitempty"`
	// DisableDatagrams disables the unreliable datagrams feature.
	// Both peers must support it for it to be enabled, regardless of this flag.
	DisableDatagrams bool `protobuf:"varint,4,opt,name=disable_datagrams,json=disableDatagrams,proto3" json:"disableDatagrams,omitempty"`
	// DisablePathMtuDiscovery disables sending packets to discover max packet size.
	DisablePathMtuDiscovery bool `` /* 132-byte string literal not displayed */
	// Verbose indicates to use verbose logging.
	// Note: this is VERY verbose, logs every packet sent.
	Verbose bool `protobuf:"varint,6,opt,name=verbose,proto3" json:"verbose,omitempty"`
	// contains filtered or unexported fields
}

func (*Opts) CloneMessageVT added in v0.15.6

func (m *Opts) CloneMessageVT() protobuf_go_lite.CloneMessage

func (*Opts) CloneVT added in v0.8.3

func (m *Opts) CloneVT() *Opts

func (*Opts) EqualMessageVT added in v0.15.6

func (this *Opts) EqualMessageVT(thatMsg any) bool

func (*Opts) EqualVT added in v0.3.0

func (this *Opts) EqualVT(that *Opts) bool

func (*Opts) GetDisableDatagrams

func (x *Opts) GetDisableDatagrams() bool

func (*Opts) GetDisableKeepAlive

func (x *Opts) GetDisableKeepAlive() bool

func (*Opts) GetDisablePathMtuDiscovery

func (x *Opts) GetDisablePathMtuDiscovery() bool

func (*Opts) GetKeepAliveDur added in v0.4.0

func (x *Opts) GetKeepAliveDur() string

func (*Opts) GetMaxIdleTimeoutDur

func (x *Opts) GetMaxIdleTimeoutDur() string

func (*Opts) GetMaxIncomingStreams

func (x *Opts) GetMaxIncomingStreams() int32

func (*Opts) GetVerbose

func (x *Opts) GetVerbose() bool

func (*Opts) MarshalJSON added in v0.29.0

func (x *Opts) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Opts to JSON.

func (*Opts) MarshalProtoJSON added in v0.29.0

func (x *Opts) MarshalProtoJSON(s *json.MarshalState)

MarshalProtoJSON marshals the Opts message to JSON.

func (*Opts) MarshalProtoText added in v0.29.2

func (x *Opts) MarshalProtoText() string

func (*Opts) MarshalToSizedBufferVT added in v0.2.0

func (m *Opts) MarshalToSizedBufferVT(dAtA []byte) (int, error)

func (*Opts) MarshalToVT added in v0.2.0

func (m *Opts) MarshalToVT(dAtA []byte) (int, error)

func (*Opts) MarshalVT added in v0.2.0

func (m *Opts) MarshalVT() (dAtA []byte, err error)

func (*Opts) ProtoMessage

func (*Opts) ProtoMessage()

func (*Opts) Reset

func (x *Opts) Reset()

func (*Opts) SizeVT added in v0.2.0

func (m *Opts) SizeVT() (n int)

func (*Opts) String

func (x *Opts) String() string

func (*Opts) UnmarshalJSON added in v0.29.0

func (x *Opts) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the Opts from JSON.

func (*Opts) UnmarshalProtoJSON added in v0.29.0

func (x *Opts) UnmarshalProtoJSON(s *json.UnmarshalState)

UnmarshalProtoJSON unmarshals the Opts message from JSON.

func (*Opts) UnmarshalVT added in v0.2.0

func (m *Opts) UnmarshalVT(dAtA []byte) error

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport implements a bifrost transport with a Quic-based packet conn. Transport UUIDs are deterministic and based on the LocalAddr() of the pconn.

func NewTransport

func NewTransport(
	ctx context.Context,
	le *logrus.Entry,
	uuid uint64,
	laddr net.Addr,
	privKey crypto.PrivKey,
	tc transport.TransportHandler,
	opts *Opts,
	dialFn DialFunc,
) (*Transport, error)

NewTransport constructs a new quic-backed based transport.

func (*Transport) CancelDialer

func (t *Transport) CancelDialer(as string)

CancelDialer cancels the dialer to a given address.

func (*Transport) Close

func (t *Transport) Close() error

Close closes the transport, returning any errors closing.

func (*Transport) DialPeer

func (t *Transport) DialPeer(ctx context.Context, peerID peer.ID, as string) (link.Link, bool, error)

DialPeer dials a peer given an address. The yielded link should be emitted to the transport handler. DialPeer should return nil if the link was established. DialPeer will then not be called again for the same peer ID and address tuple until the yielded link is lost.

func (*Transport) Execute

func (t *Transport) Execute(ctx context.Context) error

Execute executes the transport as configured, returning any fatal error.

func (*Transport) GetIdentity

func (t *Transport) GetIdentity() *p2ptls.Identity

GetIdentity returns the p2ptls identity.

func (*Transport) GetPeerID

func (t *Transport) GetPeerID() peer.ID

GetPeerID returns the peer ID.

func (*Transport) GetUUID

func (t *Transport) GetUUID() uint64

GetUUID returns a host-unique ID for this transport.

func (*Transport) HandleConn

func (t *Transport) HandleConn(ctx context.Context, dial bool, pc net.PacketConn, raddr net.Addr, peerID peer.ID) (*Link, error)

HandleConn handles an incoming or outgoing packet connection.

dial indicates if this is the originator (outgoing) conn or not ctx is used for the negotiation phase only if peerID is empty, allows any peer ID on the remote end raddr can be nil if peerID is NOT empty

func (*Transport) HandleSession

func (t *Transport) HandleSession(ctx context.Context, sess quic.Connection) (*Link, error)

HandleSession handles a new Quic session, creating & registering a link.

func (*Transport) LocalAddr

func (t *Transport) LocalAddr() net.Addr

LocalAddr returns the local address.

func (*Transport) LookupLinkWithAddr

func (t *Transport) LookupLinkWithAddr(as string) (*Link, bool)

LookupLinkWithAddr returns any link with the given remote addr.

func (*Transport) LookupLinkWithPeer

func (t *Transport) LookupLinkWithPeer(p peer.ID) (*Link, bool)

LookupLinkWithPeer returns any link with the given remote peer.

Jump to

Keyboard shortcuts

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