Documentation
¶
Overview ¶
Package quic implements the TON QUIC transport: RFC 7250 raw-public-key (Ed25519/ADNL) mutual authentication over QUIC v1, with the quic.message/quic.query/quic.answer framing used by the reference C++ node.
It is built on github.com/xssnick/quic-go-ton — a fork of quic-go bundled with an RFC 7250-patched crypto/tls — so the whole stack stays pure Go.
Index ¶
- Constants
- Variables
- type Answer
- type Client
- type ConnectionHandler
- type Gateway
- func (g *Gateway) Close() error
- func (g *Gateway) Dial(ctx context.Context, local, peer ed25519.PublicKey, addr string) (*Peer, error)
- func (g *Gateway) DialDefault(ctx context.Context, peer ed25519.PublicKey, addr string) (*Peer, error)
- func (g *Gateway) ID() []byte
- func (g *Gateway) Identities() []ed25519.PublicKey
- func (g *Gateway) Peer(local, peer ed25519.PublicKey) *Peer
- func (g *Gateway) PublicKey() ed25519.PublicKey
- func (g *Gateway) Serve(pc net.PacketConn) error
- func (g *Gateway) SetConnectionHandler(handler ConnectionHandler)
- type Handler
- type Identity
- type Message
- type Peer
- func (p *Peer) Close() error
- func (p *Peer) LocalID() []byte
- func (p *Peer) PeerID() []byte
- func (p *Peer) PeerKey() ed25519.PublicKey
- func (p *Peer) Query(ctx context.Context, payload []byte, maxAnswer int64) ([]byte, error)
- func (p *Peer) RemoteAddr() string
- func (p *Peer) SendMessage(ctx context.Context, payload []byte) error
- func (p *Peer) SetDisconnectHandler(handler PeerDisconnectHandler)
- func (p *Peer) SetMessageHandler(handler PeerMessageHandler)
- func (p *Peer) SetQueryHandler(handler PeerQueryHandler)
- type PeerDisconnectHandler
- type PeerMessageHandler
- type PeerQueryHandler
- type Query
- type Server
Constants ¶
const ALPN = "ton"
ALPN is the application protocol negotiated for TON QUIC.
const DefaultMaxObjectSize = 4 << 20
DefaultMaxObjectSize caps how many bytes a single stream object may carry. The value follows the C++ node's initial local bidi stream receive window.
Variables ¶
var ErrNoQueryHandler = errors.New("quic: peer query handler is not set")
ErrNoQueryHandler is returned when a peer receives quic.query but has no handler.
var ErrPeerClosed = errors.New("quic: peer is closed")
ErrPeerClosed is returned when a peer has no live QUIC connection.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an outbound TON QUIC connection to a single peer.
func Dial ¶
func Dial(ctx context.Context, addr string, localKey ed25519.PrivateKey, expectedPeer ed25519.PublicKey) (*Client, error)
Dial establishes a TON QUIC connection to addr ("host:port"), authenticating with localKey and requiring the server to present expectedPeer's raw public key. The context bounds the handshake.
func (*Client) PeerKey ¶
PeerKey returns a copy of the authenticated Ed25519 public key of the remote endpoint.
type ConnectionHandler ¶
ConnectionHandler is called once when a Gateway sees a new (local, peer) path.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway manages TON QUIC peers keyed by (local ADNL id, peer ADNL id).
func NewGateway ¶
func NewGateway(keys ...ed25519.PrivateKey) (*Gateway, error)
NewGateway builds a Gateway hosting the given local Ed25519 identities.
func (*Gateway) Dial ¶
func (g *Gateway) Dial(ctx context.Context, local, peer ed25519.PublicKey, addr string) (*Peer, error)
Dial establishes or reuses a peer path from local to peer.
func (*Gateway) DialDefault ¶
func (g *Gateway) DialDefault(ctx context.Context, peer ed25519.PublicKey, addr string) (*Peer, error)
DialDefault establishes or reuses a peer path from the default local identity.
func (*Gateway) Identities ¶
Identities returns the local Ed25519 public keys hosted by the Gateway.
func (*Gateway) Serve ¶
func (g *Gateway) Serve(pc net.PacketConn) error
Serve listens on pc and accepts inbound TON QUIC connections.
func (*Gateway) SetConnectionHandler ¶
func (g *Gateway) SetConnectionHandler(handler ConnectionHandler)
SetConnectionHandler sets the handler called for newly discovered paths.
type Handler ¶
type Handler struct {
// OnQuery handles a quic.query and returns the answer payload. Required.
OnQuery func(ctx context.Context, from ed25519.PublicKey, payload []byte) ([]byte, error)
// OnMessage handles a fire-and-forget quic.message. Optional.
OnMessage func(ctx context.Context, from ed25519.PublicKey, payload []byte)
// contains filtered or unexported fields
}
Handler processes inbound stream objects for a Server.
type Identity ¶
type Identity struct {
// contains filtered or unexported fields
}
Identity is a local ADNL identity backed by an Ed25519 private key.
func NewIdentity ¶
func NewIdentity(key ed25519.PrivateKey) (Identity, error)
NewIdentity builds an Identity from an Ed25519 private key.
type Message ¶
type Message struct {
Data []byte `tl:"bytes"`
}
Message is a TL quic.message object.
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer is a managed TON QUIC path between one local id and one peer id.
func (*Peer) RemoteAddr ¶
RemoteAddr returns the last known remote QUIC address.
func (*Peer) SendMessage ¶
SendMessage sends a fire-and-forget quic.message on the path.
func (*Peer) SetDisconnectHandler ¶
func (p *Peer) SetDisconnectHandler(handler PeerDisconnectHandler)
SetDisconnectHandler sets the handler called when the path is closed.
func (*Peer) SetMessageHandler ¶
func (p *Peer) SetMessageHandler(handler PeerMessageHandler)
SetMessageHandler sets the handler for inbound quic.message streams.
func (*Peer) SetQueryHandler ¶
func (p *Peer) SetQueryHandler(handler PeerQueryHandler)
SetQueryHandler sets the handler for inbound quic.query streams.
type PeerDisconnectHandler ¶
type PeerDisconnectHandler func(peer *Peer)
PeerDisconnectHandler is called after the path loses all live connections or is closed.
type PeerMessageHandler ¶
PeerMessageHandler handles inbound quic.message streams for a Peer.
type PeerQueryHandler ¶
PeerQueryHandler handles inbound quic.query streams for a Peer.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server accepts TON QUIC connections on a net.PacketConn and dispatches inbound query/message streams to a Handler.
func NewServer ¶
func NewServer(handler Handler, keys ...ed25519.PrivateKey) (*Server, error)
NewServer builds a Server hosting the given Ed25519 identities. The first key is the default identity used when a client sends no SNI; additional keys are reachable by their ADNL-id SNI.