Documentation ¶
Index ¶
- Constants
- Variables
- func BuildIncomingTlsConf(identity *p2ptls.Identity, rpeer peer.ID) *tls.Config
- func BuildQuicConfig(le *logrus.Entry, opts *Opts) *quic.Config
- func CheckAlreadyConnected(t *Transport, addr string, peerID peer.ID) (bool, error)
- func DetermineSessionIdentity(sess quic.Connection) (peer.ID, crypto.PubKey, error)
- func DialSession(ctx context.Context, le *logrus.Entry, opts *Opts, pconn net.PacketConn, ...) (quic.Connection, crypto.PubKey, error)
- func DialSessionViaTransport(ctx context.Context, le *logrus.Entry, opts *Opts, tpt *quic.Transport, ...) (quic.Connection, crypto.PubKey, error)
- func ListenSession(ctx context.Context, le *logrus.Entry, opts *Opts, pconn net.PacketConn, ...) (quic.Connection, error)
- func NewLinkUUID(localAddr, remoteAddr net.Addr, peerID peer.ID) uint64
- func NewTransportUUID(localAddr string, peerID peer.ID) uint64
- type DialFunc
- type Dialer
- type Link
- func (l *Link) AcceptStream() (stream.Stream, stream.OpenOpts, error)
- func (l *Link) Close() error
- func (l *Link) GetContext() context.Context
- func (l *Link) GetLocalPeer() peer.ID
- func (l *Link) GetRemotePeer() peer.ID
- func (l *Link) GetRemotePeerPubKey() crypto.PublicKey
- func (l *Link) GetRemoteTransportUUID() uint64
- func (l *Link) GetTransportUUID() uint64
- func (l *Link) GetUUID() uint64
- func (l *Link) LocalAddr() net.Addr
- func (l *Link) OpenStream(opts stream.OpenOpts) (stream.Stream, error)
- func (l *Link) RemoteAddr() net.Addr
- type Opts
- func (m *Opts) CloneMessageVT() proto.Message
- func (m *Opts) CloneVT() *Opts
- func (*Opts) Descriptor() ([]byte, []int)deprecated
- func (this *Opts) EqualMessageVT(thatMsg proto.Message) bool
- func (this *Opts) EqualVT(that *Opts) bool
- func (x *Opts) GetDisableDatagrams() bool
- func (x *Opts) GetDisableKeepAlive() bool
- func (x *Opts) GetDisablePathMtuDiscovery() bool
- func (x *Opts) GetKeepAliveDur() string
- func (x *Opts) GetMaxIdleTimeoutDur() string
- func (x *Opts) GetMaxIncomingStreams() int32
- func (x *Opts) GetVerbose() bool
- func (m *Opts) MarshalToSizedBufferVT(dAtA []byte) (int, error)
- func (m *Opts) MarshalToVT(dAtA []byte) (int, error)
- func (m *Opts) MarshalVT() (dAtA []byte, err error)
- func (*Opts) ProtoMessage()
- func (x *Opts) ProtoReflect() protoreflect.Message
- func (x *Opts) Reset()
- func (m *Opts) SizeVT() (n int)
- func (x *Opts) String() string
- func (m *Opts) UnmarshalVT(dAtA []byte) error
- type Transport
- func (t *Transport) CancelDialer(as string)
- func (t *Transport) Close() error
- func (t *Transport) DialPeer(ctx context.Context, peerID peer.ID, as string) (bool, error)
- func (t *Transport) Execute(ctx context.Context) error
- func (t *Transport) GetIdentity() *p2ptls.Identity
- func (t *Transport) GetPeerID() peer.ID
- func (t *Transport) GetUUID() uint64
- func (t *Transport) HandleConn(ctx context.Context, dial bool, pc net.PacketConn, raddr net.Addr, ...) (*Link, error)
- func (t *Transport) HandleSession(ctx context.Context, sess quic.Connection) (*Link, error)
- func (t *Transport) LocalAddr() net.Addr
- func (t *Transport) LookupLinkWithAddr(as string) (*Link, bool)
- func (t *Transport) LookupLinkWithPeer(p peer.ID) (*Link, bool)
Constants ¶
const Alpn = "bifrost"
Alpn is set to ensure quic does not talk to non-bifrost peers
Variables ¶
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") )
var ( ErrInvalidLength = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflow = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroup = fmt.Errorf("proto: unexpected end of group") )
var File_github_com_aperturerobotics_bifrost_transport_common_quic_quic_proto protoreflect.FileDescriptor
Functions ¶
func BuildIncomingTlsConf ¶
BuildIncomingTlsConf builds the tls config for incoming conns.
rpeer can be empty to indicate accepting any remote peer
func BuildQuicConfig ¶
BuildQuicConfig constructs the quic config.
func CheckAlreadyConnected ¶
CheckAlreadyConnected checks if a address and peer id is already connected.
func DetermineSessionIdentity ¶
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 ¶
NewLinkUUID builds the UUID for a link
Types ¶
type DialFunc ¶
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
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link represents a Quic-based connection/link.
func NewLink ¶
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 ¶
AcceptStream accepts a stream from the link.
func (*Link) GetContext ¶
GetContext returns a context that is canceled when the Link is closed.
func (*Link) GetLocalPeer ¶
GetLocalPeer returns the identity of the local peer.
func (*Link) GetRemotePeer ¶
GetRemotePeer returns the identity of the remote peer if encrypted.
func (*Link) GetRemotePeerPubKey ¶
GetRemotePeerPubKey returns the remote peer public key
func (*Link) GetRemoteTransportUUID ¶
GetRemoteTransportUUID returns the unique ID of the remote transport. Reported by the remote peer. May be zero or unreliable value.
func (*Link) GetTransportUUID ¶
GetTransportUUID returns the unique ID of the transport.
func (*Link) OpenStream ¶
OpenStream opens a stream on the link, with the given parameters.
func (*Link) RemoteAddr ¶
RemoteAddr returns the remote address.
type Opts ¶
type Opts struct { // MaxIdleTimeoutDur is the duration of idle after which conn is closed. // // If unset, uses a default value of 30 seconds. MaxIdleTimeoutDur string `protobuf:"bytes,1,opt,name=max_idle_timeout_dur,json=maxIdleTimeoutDur,proto3" json:"max_idle_timeout_dur,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:"max_incoming_streams,omitempty"` // DisableKeepAlive disables the keep alive packets. DisableKeepAlive bool `protobuf:"varint,3,opt,name=disable_keep_alive,json=disableKeepAlive,proto3" json:"disable_keep_alive,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:"keep_alive_dur,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:"disable_datagrams,omitempty"` // DisablePathMtuDiscovery disables sending packets to discover max packet size. DisablePathMtuDiscovery bool `` /* 135-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 (*Opts) Descriptor
deprecated
func (*Opts) EqualMessageVT ¶ added in v0.15.6
func (*Opts) GetDisableDatagrams ¶
func (*Opts) GetDisableKeepAlive ¶
func (*Opts) GetDisablePathMtuDiscovery ¶
func (*Opts) GetKeepAliveDur ¶ added in v0.4.0
func (*Opts) GetMaxIdleTimeoutDur ¶
func (*Opts) GetMaxIncomingStreams ¶
func (*Opts) GetVerbose ¶
func (*Opts) MarshalToSizedBufferVT ¶ added in v0.2.0
func (*Opts) ProtoMessage ¶
func (*Opts) ProtoMessage()
func (*Opts) ProtoReflect ¶ added in v0.2.0
func (x *Opts) ProtoReflect() protoreflect.Message
func (*Opts) UnmarshalVT ¶ added in v0.2.0
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 ¶
CancelDialer cancels the dialer to a given address.
func (*Transport) DialPeer ¶
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 ¶
Execute executes the transport as configured, returning any fatal error.
func (*Transport) GetIdentity ¶
GetIdentity returns the p2ptls identity.
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 ¶
HandleSession handles a new Quic session, creating & registering a link.
func (*Transport) LookupLinkWithAddr ¶
LookupLinkWithAddr returns any link with the given remote addr.