quic

package
v0.0.0-...-f274180 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HandshakeIdleTimeout = 5 * time.Second
	MaxIdleTimeout       = 5 * time.Second
	MaxIdlePingPeriod    = 1 * time.Second

	// MaxIncomingStreams is 2^60, which is the maximum supported value by Quic-Go
	MaxIncomingStreams = 1 << 60
)
View Source
const (
	MaxDatagramFrameSize = 1350
)

Variables

View Source
var (
	// DataStreamProtocolSignature is a custom protocol signature for data stream
	DataStreamProtocolSignature = ProtocolSignature{0x0A, 0x36, 0xCD, 0x12, 0xA1, 0x3E}

	// RPCStreamProtocolSignature is a custom protocol signature for RPC stream
	RPCStreamProtocolSignature = ProtocolSignature{0x52, 0xBB, 0x82, 0x5C, 0xDB, 0x65}
)

Functions

func GenerateTLSConfig

func GenerateTLSConfig() *tls.Config

GenerateTLSConfig sets up a bare-bones TLS config for a QUIC server

func SuffixSessionID

func SuffixSessionID(sessionID uuid.UUID, b []byte) ([]byte, error)

SuffixSessionID appends the session ID at the end of the payload. Suffix is more performant than prefix because the payload slice might already have enough capacity to append the session ID at the end

func SuffixType

func SuffixType(b []byte, datagramType DatagramV2Type) ([]byte, error)

Types

type BaseDatagramMuxer

type BaseDatagramMuxer interface {
	// SendToSession suffix the session ID to the payload so the other end of the QUIC connection can demultiplex the
	// payload from multiple datagram sessions.
	SendToSession(session *packet.Session) error
	// ServeReceive starts a loop to receive datagrams from the QUIC connection
	ServeReceive(ctx context.Context) error
}

type ConnectRequest

type ConnectRequest struct {
	Dest     string         `capnp:"dest"`
	Type     ConnectionType `capnp:"type"`
	Metadata []Metadata     `capnp:"metadata"`
}

ConnectRequest is the representation of metadata sent at the start of a QUIC application handshake.

func (*ConnectRequest) MetadataMap

func (r *ConnectRequest) MetadataMap() map[string]string

MetadataMap returns a map format of []Metadata.

type ConnectResponse

type ConnectResponse struct {
	Error    string     `capnp:"error"`
	Metadata []Metadata `capnp:"metadata"`
}

ConnectResponse is a representation of metadata sent as a response to a QUIC application handshake.

type ConnectionType

type ConnectionType uint16

ConnectionType indicates the type of underlying connection proxied within the QUIC stream.

const (
	ConnectionTypeHTTP ConnectionType = iota
	ConnectionTypeWebsocket
	ConnectionTypeTCP
)

func (ConnectionType) String

func (c ConnectionType) String() string

type DatagramMuxer

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

func NewDatagramMuxer

func NewDatagramMuxer(quicSession quic.Connection, log *zerolog.Logger, demuxChan chan<- *packet.Session) *DatagramMuxer

func (*DatagramMuxer) SendToSession

func (dm *DatagramMuxer) SendToSession(session *packet.Session) error

func (*DatagramMuxer) ServeReceive

func (dm *DatagramMuxer) ServeReceive(ctx context.Context) error

type DatagramMuxerV2

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

func NewDatagramMuxerV2

func NewDatagramMuxerV2(
	quicSession quic.Connection,
	log *zerolog.Logger,
	sessionDemuxChan chan<- *packet.Session,
) *DatagramMuxerV2

func (*DatagramMuxerV2) ReceivePacket

func (dm *DatagramMuxerV2) ReceivePacket(ctx context.Context) (pk Packet, err error)

func (*DatagramMuxerV2) SendPacket

func (dm *DatagramMuxerV2) SendPacket(pk Packet) error

SendPacket sends a packet with datagram version in the suffix. If ctx is a TracedContext, it adds the tracing context between payload and datagram version. The other end of the QUIC connection can demultiplex by parsing the payload as IP and look at the source and destination.

func (*DatagramMuxerV2) SendToSession

func (dm *DatagramMuxerV2) SendToSession(session *packet.Session) error

SendToSession suffix the session ID and datagram version to the payload so the other end of the QUIC connection can demultiplex the payload from multiple datagram sessions

func (*DatagramMuxerV2) ServeReceive

func (dm *DatagramMuxerV2) ServeReceive(ctx context.Context) error

Demux reads datagrams from the QUIC connection and demuxes depending on whether it's a session or packet

type DatagramV2Type

type DatagramV2Type byte
const (
	// UDP payload
	DatagramTypeUDP DatagramV2Type = iota
	// Full IP packet
	DatagramTypeIP
	// DatagramTypeIP + tracing ID
	DatagramTypeIPWithTrace
	// Tracing spans in protobuf format
	DatagramTypeTracingSpan
)

type Metadata

type Metadata struct {
	Key string `capnp:"key"`
	Val string `capnp:"val"`
}

Metadata is a representation of key value based data sent via RequestMeta.

type Packet

type Packet interface {
	Type() DatagramV2Type
	Payload() []byte
	Metadata() []byte
}

type ProtocolSignature

type ProtocolSignature [6]byte

ProtocolSignature defines the first 6 bytes of the stream, which is used to distinguish the type of stream. It ensures whoever performs a handshake does not write data before writing the metadata.

func DetermineProtocol

func DetermineProtocol(stream io.Reader) (ProtocolSignature, error)

type RPCClientStream

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

RPCClientStream is a stream to call methods of SessionManager

func NewRPCClientStream

func NewRPCClientStream(ctx context.Context, stream io.ReadWriteCloser, rpcUnregisterUDPSessionDeadline time.Duration, logger *zerolog.Logger) (*RPCClientStream, error)

func (*RPCClientStream) Close

func (rcs *RPCClientStream) Close()

func (*RPCClientStream) RegisterUdpSession

func (rcs *RPCClientStream) RegisterUdpSession(ctx context.Context, sessionID uuid.UUID, dstIP net.IP, dstPort uint16, closeIdleAfterHint time.Duration, traceContext string) (*tunnelpogs.RegisterUdpSessionResponse, error)

func (*RPCClientStream) UnregisterUdpSession

func (rcs *RPCClientStream) UnregisterUdpSession(ctx context.Context, sessionID uuid.UUID, message string) error

func (*RPCClientStream) UpdateConfiguration

func (rcs *RPCClientStream) UpdateConfiguration(ctx context.Context, version int32, config []byte) (*tunnelpogs.UpdateConfigurationResponse, error)

type RPCServerStream

type RPCServerStream struct {
	io.ReadWriteCloser
}

RPCServerStream is a stream to serve RPCs. It is closed when the RPC client is done

func NewRPCServerStream

func NewRPCServerStream(stream io.ReadWriteCloser, protocol ProtocolSignature) (*RPCServerStream, error)

func (*RPCServerStream) Serve

func (s *RPCServerStream) Serve(sessionManager tunnelpogs.SessionManager, configManager tunnelpogs.ConfigurationManager, logger *zerolog.Logger) error

type RawPacket

type RawPacket packet.RawPacket

func (RawPacket) Metadata

func (rw RawPacket) Metadata() []byte

func (RawPacket) Payload

func (rw RawPacket) Payload() []byte

func (RawPacket) Type

func (rw RawPacket) Type() DatagramV2Type

type RequestClientStream

type RequestClientStream struct {
	io.ReadWriteCloser
}

func (*RequestClientStream) ReadConnectResponseData

func (rcs *RequestClientStream) ReadConnectResponseData() (*ConnectResponse, error)

ReadConnectResponseData reads the response to a RequestMeta in a stream.

func (*RequestClientStream) WriteConnectRequestData

func (rcs *RequestClientStream) WriteConnectRequestData(dest string, connectionType ConnectionType, metadata ...Metadata) error

WriteConnectRequestData writes requestMeta to a stream.

type RequestServerStream

type RequestServerStream struct {
	io.ReadWriteCloser
}

RequestServerStream is a stream to serve requests

func NewRequestServerStream

func NewRequestServerStream(stream io.ReadWriteCloser, signature ProtocolSignature) (*RequestServerStream, error)

func (*RequestServerStream) ReadConnectRequestData

func (rss *RequestServerStream) ReadConnectRequestData() (*ConnectRequest, error)

ReadConnectRequestData reads the handshake data from a QUIC stream.

func (*RequestServerStream) WriteConnectResponseData

func (rss *RequestServerStream) WriteConnectResponseData(respErr error, metadata ...Metadata) error

WriteConnectResponseData writes response to a QUIC stream.

type SafeStreamCloser

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

func NewSafeStreamCloser

func NewSafeStreamCloser(stream quic.Stream, writeTimeout time.Duration, log *zerolog.Logger) *SafeStreamCloser

func (*SafeStreamCloser) Close

func (s *SafeStreamCloser) Close() error

func (*SafeStreamCloser) CloseWrite

func (s *SafeStreamCloser) CloseWrite() error

func (*SafeStreamCloser) Read

func (s *SafeStreamCloser) Read(p []byte) (n int, err error)

func (*SafeStreamCloser) SetDeadline

func (s *SafeStreamCloser) SetDeadline(deadline time.Time) error

func (*SafeStreamCloser) Write

func (s *SafeStreamCloser) Write(p []byte) (n int, err error)

type TracedPacket

type TracedPacket struct {
	Packet          packet.RawPacket
	TracingIdentity []byte
}

func (*TracedPacket) Metadata

func (tp *TracedPacket) Metadata() []byte

func (*TracedPacket) Payload

func (tp *TracedPacket) Payload() []byte

func (*TracedPacket) Type

func (tp *TracedPacket) Type() DatagramV2Type

type TracingSpanPacket

type TracingSpanPacket struct {
	Spans           []byte
	TracingIdentity []byte
}

func (*TracingSpanPacket) Metadata

func (tsp *TracingSpanPacket) Metadata() []byte

func (*TracingSpanPacket) Payload

func (tsp *TracingSpanPacket) Payload() []byte

func (*TracingSpanPacket) Type

func (tsp *TracingSpanPacket) Type() DatagramV2Type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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