Documentation
¶
Index ¶
- Constants
- Variables
- type ADNL
- func (a *ADNL) Answer(ctx context.Context, queryID []byte, result tl.Serializable) error
- func (a *ADNL) Close()
- func (a *ADNL) GetAddressList() address.List
- func (a *ADNL) GetCloserCtx() context.Context
- func (a *ADNL) GetDisconnectHandler() func(addr string, key ed25519.PublicKey)
- func (a *ADNL) GetID() []byte
- func (a *ADNL) GetPubKey() ed25519.PublicKey
- func (a *ADNL) GetQueryHandler() func(msg *MessageQuery) error
- func (a *ADNL) Ping(ctx context.Context) (time.Duration, error)
- func (a *ADNL) Query(ctx context.Context, req, result tl.Serializable) error
- func (a *ADNL) Reinit()
- func (a *ADNL) RemoteAddr() string
- func (a *ADNL) SendCustomMessage(_ context.Context, req tl.Serializable) error
- func (a *ADNL) SendNop(_ context.Context) error
- func (a *ADNL) SetAddresses(list address.List)
- func (a *ADNL) SetChannelReadyHandler(handler func(ch *Channel))
- func (a *ADNL) SetCustomMessageHandler(handler func(msg *MessageCustom) error)
- func (a *ADNL) SetDisconnectHandler(handler func(addr string, key ed25519.PublicKey))
- func (a *ADNL) SetQueryHandler(handler func(msg *MessageQuery) error)
- func (a *ADNL) Stats() PeerStats
- type Channel
- type CustomMessageHandler
- type DisconnectHandler
- type Gateway
- func (g *Gateway) Close() error
- func (g *Gateway) GetActivePeers() []Peer
- func (g *Gateway) GetAddressList() address.List
- func (g *Gateway) GetID() []byte
- func (g *Gateway) GetPublicKey() ed25519.PublicKey
- func (g *Gateway) RegisterClient(addr string, key ed25519.PublicKey) (Peer, error)
- func (g *Gateway) SetAddressList(addresses []address.Address)
- func (g *Gateway) SetConnectionHandler(handler func(client Peer) error)
- func (g *Gateway) StartClient(listenThreads ...int) (err error)
- func (g *Gateway) StartServer(listenAddr string, listenThreads ...int) (err error)
- type MessageAnswer
- type MessageConfirmChannel
- type MessageCreateChannel
- type MessageCustom
- type MessageNop
- type MessagePart
- type MessagePing
- type MessagePong
- type MessageQuery
- type MessageReinit
- type MultiNetManager
- func (m *MultiNetManager) Close()
- func (m *MultiNetManager) CloseConnection(gate *Gateway)
- func (m *MultiNetManager) Free(p *UDPPacket)
- func (m *MultiNetManager) GetReaderChan(gate *Gateway) <-chan *UDPPacket
- func (m *MultiNetManager) InitConnection(gate *Gateway, addr string) error
- func (m *MultiNetManager) WritePacket(gate *Gateway, p []byte, addr net.Addr) (n int, err error)
- type NetManager
- type Node
- type PacketContent
- type PacketWriter
- type Peer
- type PeerChannelState
- type PeerChannelStats
- type PeerInboundStats
- type PeerOutboundStats
- type PeerReinitializationStats
- type PeerSequenceStats
- type PeerStats
- type QueryHandler
- type SingleNetManager
- func (s *SingleNetManager) Close()
- func (s *SingleNetManager) CloseConnection(gate *Gateway)
- func (s *SingleNetManager) Free(p *UDPPacket)
- func (s *SingleNetManager) GetReaderChan(gate *Gateway) <-chan *UDPPacket
- func (s *SingleNetManager) InitConnection(gate *Gateway, addr string) error
- func (s *SingleNetManager) WritePacket(gate *Gateway, p []byte, addr net.Addr) (n int, err error)
- type SyncConn
- func (s *SyncConn) Close() error
- func (s *SyncConn) LocalAddr() net.Addr
- func (s *SyncConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (s *SyncConn) SetDeadline(t time.Time) error
- func (s *SyncConn) SetReadDeadline(t time.Time) error
- func (s *SyncConn) SetWriteDeadline(t time.Time) error
- func (s *SyncConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type UDPPacket
Constants ¶
View Source
const BasePayloadMTU = 1024
View Source
const HugePacketMaxSz = 1024*8 + 128
View Source
const MaxMTU = 1500 - 40 - 8 // max is for ipv6 over ethernet
Variables ¶
View Source
var DefaultListener = func(addr string) (net.PacketConn, error) { lp, err := net.ListenPacket("udp", addr) if err != nil { return nil, err } if conn, ok := lp.(*net.UDPConn); ok { if err := conn.SetReadBuffer(DefaultUDPBufferSize); err != nil { if Logger != nil { Logger("[ADNL] failed to set read buffer:", err) } } if err := conn.SetWriteBuffer(DefaultUDPBufferSize); err != nil { if Logger != nil { Logger("[ADNL] failed to set write buffer:", err) } } } return NewSyncConn(lp, PacketsBufferSize), nil }
View Source
var DefaultMaxPendingPeers = 8192
View Source
var DefaultPendingPeerTTL = 30 * time.Second
View Source
var DefaultUDPBufferSize = 32 << 20
View Source
var ErrPacketBiggerThanMTU = fmt.Errorf("packet bigger than MTU")
View Source
var ErrPeerConnClosed = errors.New("peer connection was closed")
View Source
var ErrTooShortData = errors.New("too short data")
View Source
var Logger func(v ...any)
View Source
var PacketsBufferSize = 128 * 1024
Functions ¶
This section is empty.
Types ¶
type ADNL ¶
type ADNL struct {
// contains filtered or unexported fields
}
func (*ADNL) GetAddressList ¶
func (*ADNL) GetCloserCtx ¶ added in v1.11.0
func (*ADNL) GetDisconnectHandler ¶ added in v1.9.3
func (*ADNL) GetQueryHandler ¶ added in v1.7.0
func (a *ADNL) GetQueryHandler() func(msg *MessageQuery) error
func (*ADNL) RemoteAddr ¶
func (*ADNL) SendCustomMessage ¶
func (*ADNL) SetAddresses ¶
func (*ADNL) SetChannelReadyHandler ¶
func (*ADNL) SetCustomMessageHandler ¶
func (a *ADNL) SetCustomMessageHandler(handler func(msg *MessageCustom) error)
func (*ADNL) SetDisconnectHandler ¶
func (*ADNL) SetQueryHandler ¶
func (a *ADNL) SetQueryHandler(handler func(msg *MessageQuery) error)
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
func (*Channel) SendCustomMessage ¶
type CustomMessageHandler ¶
type CustomMessageHandler func(msg *MessageCustom) error
type DisconnectHandler ¶
type Gateway ¶ added in v1.6.0
type Gateway struct {
// contains filtered or unexported fields
}
func NewGateway ¶ added in v1.6.0
func NewGateway(key ed25519.PrivateKey) *Gateway
func NewGatewayWithNetManager ¶ added in v1.12.0
func NewGatewayWithNetManager(key ed25519.PrivateKey, reader NetManager) *Gateway
func (*Gateway) GetActivePeers ¶ added in v1.11.1
func (*Gateway) GetAddressList ¶ added in v1.6.0
func (*Gateway) GetPublicKey ¶ added in v1.17.0
func (*Gateway) RegisterClient ¶ added in v1.6.0
func (*Gateway) SetAddressList ¶ added in v1.12.0
func (*Gateway) SetConnectionHandler ¶ added in v1.6.0
func (*Gateway) StartClient ¶ added in v1.6.0
type MessageAnswer ¶
func (*MessageAnswer) Parse ¶ added in v1.18.0
func (m *MessageAnswer) Parse(data []byte) ([]byte, error)
func (*MessageAnswer) ParseNoCopy ¶ added in v1.18.0
func (m *MessageAnswer) ParseNoCopy(data []byte) ([]byte, error)
type MessageConfirmChannel ¶
type MessageCreateChannel ¶
type MessageCustom ¶
type MessageCustom struct {
Data any `tl:"bytes struct boxed"`
}
func (*MessageCustom) Parse ¶ added in v1.18.0
func (m *MessageCustom) Parse(data []byte) ([]byte, error)
func (*MessageCustom) ParseNoCopy ¶ added in v1.18.0
func (m *MessageCustom) ParseNoCopy(data []byte) ([]byte, error)
type MessageNop ¶
type MessageNop struct{}
type MessagePart ¶
type MessagePing ¶
type MessagePing struct {
Value int64 `tl:"long"`
}
type MessagePong ¶
type MessagePong struct {
Value int64 `tl:"long"`
}
type MessageQuery ¶
func (*MessageQuery) Parse ¶ added in v1.18.0
func (m *MessageQuery) Parse(data []byte) ([]byte, error)
func (*MessageQuery) ParseNoCopy ¶ added in v1.18.0
func (m *MessageQuery) ParseNoCopy(data []byte) ([]byte, error)
type MessageReinit ¶
type MessageReinit struct {
Date int32 `tl:"int"`
}
type MultiNetManager ¶ added in v1.12.0
type MultiNetManager struct {
// contains filtered or unexported fields
}
func NewMultiNetReader ¶ added in v1.12.0
func NewMultiNetReader(conn net.PacketConn) *MultiNetManager
func (*MultiNetManager) Close ¶ added in v1.13.0
func (m *MultiNetManager) Close()
func (*MultiNetManager) CloseConnection ¶ added in v1.12.0
func (m *MultiNetManager) CloseConnection(gate *Gateway)
func (*MultiNetManager) Free ¶ added in v1.12.0
func (m *MultiNetManager) Free(p *UDPPacket)
func (*MultiNetManager) GetReaderChan ¶ added in v1.12.0
func (m *MultiNetManager) GetReaderChan(gate *Gateway) <-chan *UDPPacket
func (*MultiNetManager) InitConnection ¶ added in v1.12.0
func (m *MultiNetManager) InitConnection(gate *Gateway, addr string) error
func (*MultiNetManager) WritePacket ¶ added in v1.12.0
type NetManager ¶ added in v1.12.0
type Node ¶ added in v1.17.0
type Node struct {
ID any `tl:"struct boxed [pub.ed25519,pub.aes]"`
AddrList *address.List `tl:"struct"`
Version int32 `tl:"int"`
Signature []byte `tl:"bytes"`
}
func (*Node) CheckSignature ¶ added in v1.17.0
type PacketContent ¶
type PacketContent struct {
Rand1 []byte
From *keys.PublicKeyED25519
FromIDShort []byte
Messages []any
Address *address.List
PriorityAddress *address.List
Seqno *int64
ConfirmSeqno *int64
RecvAddrListVersion *int32
RecvPriorityAddrListVersion *int32
ReinitDate *int32
DstReinitDate *int32
Signature []byte
Rand2 []byte
// contains filtered or unexported fields
}
func (*PacketContent) ConfirmSeqnoValue ¶ added in v1.17.0
func (p *PacketContent) ConfirmSeqnoValue() int64
func (*PacketContent) DstReinitDateValue ¶ added in v1.17.0
func (p *PacketContent) DstReinitDateValue() int32
func (*PacketContent) ReinitDateValue ¶ added in v1.17.0
func (p *PacketContent) ReinitDateValue() int32
func (*PacketContent) SeqnoValue ¶ added in v1.17.0
func (p *PacketContent) SeqnoValue() int64
type PacketWriter ¶ added in v1.11.0
type Peer ¶ added in v1.6.0
type Peer interface {
SetCustomMessageHandler(handler func(msg *MessageCustom) error)
SetQueryHandler(handler func(msg *MessageQuery) error)
GetDisconnectHandler() func(addr string, key ed25519.PublicKey)
SetDisconnectHandler(handler func(addr string, key ed25519.PublicKey))
SendCustomMessage(ctx context.Context, req tl.Serializable) error
SendNop(ctx context.Context) error
Query(ctx context.Context, req, result tl.Serializable) error
Answer(ctx context.Context, queryID []byte, result tl.Serializable) error
Ping(ctx context.Context) (time.Duration, error)
GetQueryHandler() func(msg *MessageQuery) error
GetCloserCtx() context.Context
SetAddresses(addresses address.List)
RemoteAddr() string
GetID() []byte
GetPubKey() ed25519.PublicKey
Stats() PeerStats
Reinit()
Close()
}
type PeerChannelState ¶ added in v1.18.0
type PeerChannelState uint8
PeerChannelState is the current channel negotiation state.
const ( PeerChannelStateUnknown PeerChannelState = iota PeerChannelStateNone PeerChannelStatePending PeerChannelStateReady )
type PeerChannelStats ¶ added in v1.18.0
type PeerChannelStats struct {
State PeerChannelState
}
PeerChannelStats describes the encrypted ADNL channel state.
type PeerInboundStats ¶ added in v1.18.0
type PeerInboundStats struct {
Packets uint64
Bytes uint64
ProcessingErrors uint64
LastPacketAt time.Time
LastErrorAt time.Time
}
PeerInboundStats describes authenticated ADNL datagrams attributed to the peer.
type PeerOutboundStats ¶ added in v1.18.0
type PeerOutboundStats struct {
Packets uint64
Bytes uint64
WriteErrors uint64
LastPacketAt time.Time
LastErrorAt time.Time
}
PeerOutboundStats describes ADNL datagrams accepted by the packet writer.
type PeerReinitializationStats ¶ added in v1.18.0
type PeerReinitializationStats struct {
LocalEpoch int32
PeerEpoch int32
PeerEvents uint64
RootRecoveryAttempts uint64
LastPeerEventAt time.Time
LastRootRecoveryAt time.Time
}
PeerReinitializationStats contains current protocol epochs and cumulative recovery events.
type PeerSequenceStats ¶ added in v1.18.0
type PeerSequenceStats struct {
// LocalSeqno is the highest locally allocated ADNL sequence number.
LocalSeqno int64
// PeerSeqno is the highest ADNL sequence number received from the peer.
PeerSeqno int64
// ConfirmedByPeerSeqno is the highest local sequence number reported by the peer.
ConfirmedByPeerSeqno int64
}
PeerSequenceStats contains the current ADNL sequence and confirmation state.
type PeerStats ¶ added in v1.18.0
type PeerStats struct {
CapturedAt time.Time
CreatedAt time.Time
Closed bool
Channel PeerChannelStats
Inbound PeerInboundStats
Outbound PeerOutboundStats
Sequences PeerSequenceStats
Reinitialization PeerReinitializationStats
}
PeerStats is a point-in-time snapshot of an ADNL peer state. Counters are cumulative for the lifetime of the peer and are not reset by Reinit.
type QueryHandler ¶
type QueryHandler func(msg *MessageQuery) error
type SingleNetManager ¶ added in v1.12.0
type SingleNetManager struct {
// contains filtered or unexported fields
}
func NewSingleNetReader ¶ added in v1.12.0
func NewSingleNetReader(connector func(addr string) (net.PacketConn, error)) *SingleNetManager
func (*SingleNetManager) Close ¶ added in v1.13.0
func (s *SingleNetManager) Close()
func (*SingleNetManager) CloseConnection ¶ added in v1.12.0
func (s *SingleNetManager) CloseConnection(gate *Gateway)
func (*SingleNetManager) Free ¶ added in v1.12.0
func (s *SingleNetManager) Free(p *UDPPacket)
func (*SingleNetManager) GetReaderChan ¶ added in v1.12.0
func (s *SingleNetManager) GetReaderChan(gate *Gateway) <-chan *UDPPacket
func (*SingleNetManager) InitConnection ¶ added in v1.12.0
func (s *SingleNetManager) InitConnection(gate *Gateway, addr string) error
func (*SingleNetManager) WritePacket ¶ added in v1.12.0
type SyncConn ¶ added in v1.11.0
type SyncConn struct {
// contains filtered or unexported fields
}
func NewSyncConn ¶ added in v1.11.0
func NewSyncConn(conn net.PacketConn, packetsBufSz int) *SyncConn
func (*SyncConn) SetReadDeadline ¶ added in v1.11.0
func (*SyncConn) SetWriteDeadline ¶ added in v1.11.0
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
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.
|
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. |
Click to show internal directories.
Click to hide internal directories.