adnl

package
v1.9.7 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 27 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Dial = func(addr string, timeout time.Duration) (net.Conn, error) {
	return net.DialTimeout("udp", addr, timeout)
}

Dial - can be changed to websockets for example, this way can be used from browser if compiled to wasm

View Source
var ErrTooShortData = errors.New("too short data")
View Source
var Logger = log.Println
View Source
var RawListener = func(addr string) (net.PacketConn, error) {
	return net.ListenPacket("udp", addr)
}
View Source
var ToKeyID = tl.Hash

Deprecated: use tl.Hash

Functions

func BuildSharedCipher

func BuildSharedCipher(key []byte, checksum []byte) (cipher.Stream, error)

func NewCipherCtr

func NewCipherCtr(key, iv []byte) (cipher.Stream, error)

func SharedKey

func SharedKey(ourKey ed25519.PrivateKey, serverKey ed25519.PublicKey) ([]byte, error)

SharedKey - Generate encryption key based on our and server key, ECDH algorithm

Types

type ADNL

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

func Connect

func Connect(ctx context.Context, addr string, peerKey ed25519.PublicKey, ourKey ed25519.PrivateKey) (_ *ADNL, err error)

Connect - connect to ADNL UDP Peer Deprecated: Connect is DEPRECATED use Gateway

func (*ADNL) Answer

func (a *ADNL) Answer(ctx context.Context, queryID []byte, result tl.Serializable) error

func (*ADNL) Close

func (a *ADNL) Close()

func (*ADNL) GetAddressList

func (a *ADNL) GetAddressList() address.List

func (*ADNL) GetDisconnectHandler added in v1.9.3

func (a *ADNL) GetDisconnectHandler() func(addr string, key ed25519.PublicKey)

func (*ADNL) GetID added in v1.5.1

func (a *ADNL) GetID() []byte

func (*ADNL) GetQueryHandler added in v1.7.0

func (a *ADNL) GetQueryHandler() func(msg *MessageQuery) error

func (*ADNL) Query

func (a *ADNL) Query(ctx context.Context, req, result tl.Serializable) error

func (*ADNL) RemoteAddr

func (a *ADNL) RemoteAddr() string

func (*ADNL) SendCustomMessage

func (a *ADNL) SendCustomMessage(ctx context.Context, req tl.Serializable) error

func (*ADNL) SetAddresses

func (a *ADNL) SetAddresses(list address.List)

func (*ADNL) SetChannelReadyHandler

func (a *ADNL) SetChannelReadyHandler(handler func(ch *Channel))

func (*ADNL) SetCustomMessageHandler

func (a *ADNL) SetCustomMessageHandler(handler func(msg *MessageCustom) error)

func (*ADNL) SetDisconnectHandler

func (a *ADNL) SetDisconnectHandler(handler func(addr string, key ed25519.PublicKey))

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

func (c *Channel) SendCustomMessage(ctx context.Context, req tl.Serializable) error

type CustomMessageHandler

type CustomMessageHandler func(msg *MessageCustom) error

type DisconnectHandler

type DisconnectHandler func(addr string, key ed25519.PublicKey)

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 (*Gateway) Close added in v1.6.0

func (g *Gateway) Close() error

func (*Gateway) GetAddressList added in v1.6.0

func (g *Gateway) GetAddressList() address.List

func (*Gateway) GetID added in v1.8.0

func (g *Gateway) GetID() []byte

func (*Gateway) RegisterClient added in v1.6.0

func (g *Gateway) RegisterClient(addr string, key ed25519.PublicKey) (Peer, error)

func (*Gateway) SetConnectionHandler added in v1.6.0

func (g *Gateway) SetConnectionHandler(handler func(client Peer) error)

func (*Gateway) SetExternalIP added in v1.6.0

func (g *Gateway) SetExternalIP(ip net.IP)

func (*Gateway) StartClient added in v1.6.0

func (g *Gateway) StartClient() (err error)

func (*Gateway) StartServer added in v1.6.0

func (g *Gateway) StartServer(listenAddr string) (err error)

type MessageAnswer

type MessageAnswer struct {
	ID   []byte `tl:"int256"`
	Data any    `tl:"bytes struct boxed"`
}

type MessageConfirmChannel

type MessageConfirmChannel struct {
	Key     []byte `tl:"int256"`
	PeerKey []byte `tl:"int256"`
	Date    int32  `tl:"int"`
}

type MessageCreateChannel

type MessageCreateChannel struct {
	Key  []byte `tl:"int256"`
	Date int32  `tl:"int"`
}

type MessageCustom

type MessageCustom struct {
	Data any `tl:"bytes struct boxed"`
}

type MessageNop

type MessageNop struct{}

type MessagePart

type MessagePart struct {
	Hash      []byte `tl:"int256"`
	TotalSize int32  `tl:"int"`
	Offset    int32  `tl:"int"`
	Data      []byte `tl:"bytes"`
}

type MessagePing

type MessagePing struct {
	Value int64 `tl:"long"`
}

type MessagePong

type MessagePong struct {
	Value int64 `tl:"long"`
}

type MessageQuery

type MessageQuery struct {
	ID   []byte `tl:"int256"`
	Data any    `tl:"bytes struct boxed"`
}

type MessageReinit

type MessageReinit struct {
	Date int32 `tl:"int"`
}

type PacketContent

type PacketContent struct {
	Rand1                       []byte
	From                        *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
}

func (*PacketContent) Serialize

func (p *PacketContent) Serialize() ([]byte, error)

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
	Query(ctx context.Context, req, result tl.Serializable) error
	Answer(ctx context.Context, queryID []byte, result tl.Serializable) error
	GetQueryHandler() func(msg *MessageQuery) error
	RemoteAddr() string
	GetID() []byte
	Close()
}

type PrivateKeyAES

type PrivateKeyAES struct {
	Key []byte `tl:"int256"`
}

type PublicKeyAES

type PublicKeyAES struct {
	Key []byte `tl:"int256"`
}

type PublicKeyED25519

type PublicKeyED25519 struct {
	Key ed25519.PublicKey `tl:"int256"`
}

type PublicKeyOverlay

type PublicKeyOverlay struct {
	Key []byte `tl:"bytes"`
}

type PublicKeyUnEnc

type PublicKeyUnEnc struct {
	Key []byte `tl:"bytes"`
}

type QueryHandler

type QueryHandler func(msg *MessageQuery) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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