adnl

package
v0.0.0-...-bcde84c Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: AGPL-3.0 Imports: 27 Imported by: 0

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)
}

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

func ToKeyID

func ToKeyID(key any) ([]byte, error)

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) GetID

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

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

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

func NewGateway

func NewGateway(key ed25519.PrivateKey) *Gateway

func (*Gateway) Close

func (g *Gateway) Close() error

func (*Gateway) GetAddressList

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

func (*Gateway) RegisterClient

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

func (*Gateway) SetConnectionHandler

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

func (*Gateway) SetExternalIP

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

func (*Gateway) StartClient

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

func (*Gateway) StartServer

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

type Peer interface {
	SetCustomMessageHandler(handler func(msg *MessageCustom) error)
	SetQueryHandler(handler func(msg *MessageQuery) error)
	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
	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