liteclient

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 28 Imported by: 23

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoActiveConnections = errors.New("no active connections")
	ErrADNLReqTimeout      = errors.New("adnl request timeout")
)
View Source
var (
	ErrNoConnections = errors.New("no connections established")
)
View Source
var ErrStopped = errors.New("connection pool is closed")
View Source
var Logger = log.Println

Functions

This section is empty.

Types

type ADNLRequest added in v1.6.0

type ADNLRequest struct {
	QueryID  []byte
	Data     any
	RespChan chan *ADNLResponse
}

type ADNLResponse added in v1.6.0

type ADNLResponse struct {
	Data tl.Serializable
}

type ConfigBlock added in v1.8.0

type ConfigBlock struct {
	Workchain int32  `json:"workchain"`
	Shard     int64  `json:"shard"`
	SeqNo     uint32 `json:"seqno"`
	RootHash  []byte `json:"root_hash"`
	FileHash  []byte `json:"file_hash"`
}

type ConnectionPool added in v1.0.0

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

func NewConnectionPool added in v1.0.0

func NewConnectionPool() *ConnectionPool

NewConnectionPool - ordinary pool to query liteserver

func NewConnectionPoolWithAuth added in v1.6.0

func NewConnectionPoolWithAuth(key ed25519.PrivateKey) *ConnectionPool

NewConnectionPoolWithAuth - will do TCP authorization after connection, can be used to communicate with storage-daemon

func (*ConnectionPool) AddConnection added in v1.0.0

func (c *ConnectionPool) AddConnection(ctx context.Context, addr, serverKey string, clientKey ...ed25519.PrivateKey) error

func (*ConnectionPool) AddConnectionsFromConfig added in v1.0.0

func (c *ConnectionPool) AddConnectionsFromConfig(ctx context.Context, config *GlobalConfig) error

func (*ConnectionPool) AddConnectionsFromConfigFile added in v1.8.0

func (c *ConnectionPool) AddConnectionsFromConfigFile(configPath string) error

func (*ConnectionPool) AddConnectionsFromConfigUrl added in v1.0.0

func (c *ConnectionPool) AddConnectionsFromConfigUrl(ctx context.Context, configUrl string) error

func (*ConnectionPool) DefaultReconnect added in v1.0.0

func (c *ConnectionPool) DefaultReconnect(waitBeforeReconnect time.Duration, maxTries int) OnDisconnectCallback

func (*ConnectionPool) QueryADNL added in v1.6.0

func (c *ConnectionPool) QueryADNL(ctx context.Context, request tl.Serializable, result tl.Serializable) error

QueryADNL - sends ADNL request to peer

func (*ConnectionPool) QueryLiteserver added in v1.6.0

func (c *ConnectionPool) QueryLiteserver(ctx context.Context, request tl.Serializable, result tl.Serializable) error

QueryLiteserver - sends request to liteserver

func (*ConnectionPool) SetOnDisconnect added in v1.0.0

func (c *ConnectionPool) SetOnDisconnect(cb OnDisconnectCallback)

func (*ConnectionPool) StickyContext added in v1.0.0

func (c *ConnectionPool) StickyContext(ctx context.Context) context.Context

StickyContext - bounds all requests with this context to the same lite-server node, if possible. This is useful when we are doing some requests which depends on each other.

For example: we requested MasterchainInfo from node A, and we are trying to request account with this block info from node B but node B don't have yet information about this block, so it can return error. If we use StickyContext, all requests where its passed will be routed to same node.

In case if sticky node goes down, default balancer will be used as fallback

func (*ConnectionPool) StickyContextNextNode added in v1.8.0

func (c *ConnectionPool) StickyContextNextNode(ctx context.Context) (context.Context, error)

func (*ConnectionPool) StickyContextWithNodeID added in v1.8.0

func (c *ConnectionPool) StickyContextWithNodeID(ctx context.Context, nodeId uint32) context.Context

func (*ConnectionPool) StickyNodeID added in v1.5.0

func (c *ConnectionPool) StickyNodeID(ctx context.Context) uint32

func (*ConnectionPool) Stop added in v1.8.0

func (c *ConnectionPool) Stop()

type DHTAddress added in v1.0.0

type DHTAddress struct {
	Type string `json:"@type"`
	IP   int    `json:"ip"`
	Port int    `json:"port"`
}

type DHTAddressList added in v1.0.0

type DHTAddressList struct {
	Type       string       `json:"@type"`
	Addrs      []DHTAddress `json:"addrs"`
	Version    int          `json:"version"`
	ReinitDate int          `json:"reinit_date"`
	Priority   int          `json:"priority"`
	ExpireAt   int          `json:"expire_at"`
}

type DHTConfig added in v1.0.0

type DHTConfig struct {
	Type        string   `json:"@type"`
	K           int      `json:"k"`
	A           int      `json:"a"`
	StaticNodes DHTNodes `json:"static_nodes"`
}

type DHTNode added in v1.0.0

type DHTNode struct {
	Type      string         `json:"@type"`
	ID        ServerID       `json:"id"`
	AddrList  DHTAddressList `json:"addr_list"`
	Version   int            `json:"version"`
	Signature string         `json:"signature"`
}

type DHTNodes added in v1.0.0

type DHTNodes struct {
	Type  string    `json:"@type"`
	Nodes []DHTNode `json:"nodes"`
}

type GlobalConfig added in v1.0.0

type GlobalConfig struct {
	Type        string             `json:"@type"`
	DHT         DHTConfig          `json:"dht"`
	Liteservers []LiteserverConfig `json:"liteservers"`
	Validator   ValidatorConfig    `json:"validator"`
}

func GetConfigFromFile added in v1.8.0

func GetConfigFromFile(filepath string) (*GlobalConfig, error)

func GetConfigFromUrl added in v1.0.0

func GetConfigFromUrl(ctx context.Context, url string) (*GlobalConfig, error)

type LiteServerQuery

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

type LiteserverConfig added in v1.0.0

type LiteserverConfig struct {
	IP   int64    `json:"ip"`
	Port int      `json:"port"`
	ID   ServerID `json:"id"`
}

type NetworkErr added in v1.6.2

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

func (NetworkErr) Is added in v1.6.2

func (e NetworkErr) Is(err error) bool

func (NetworkErr) Unwrap added in v1.6.2

func (e NetworkErr) Unwrap() error

type OnDisconnectCallback added in v0.2.0

type OnDisconnectCallback func(addr, key string)

type Server added in v1.9.0

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

func NewServer added in v1.9.0

func NewServer(keys []ed25519.PrivateKey) *Server

func (*Server) Close added in v1.9.0

func (s *Server) Close() error

func (*Server) Listen added in v1.9.0

func (s *Server) Listen(addr string) error

func (*Server) SetConnectionHook added in v1.9.0

func (s *Server) SetConnectionHook(hook func(client *ServerClient) error)

func (*Server) SetDisconnectHook added in v1.9.0

func (s *Server) SetDisconnectHook(hook func(client *ServerClient))

func (*Server) SetMessageHandler added in v1.9.0

func (s *Server) SetMessageHandler(handler func(ctx context.Context, client *ServerClient, msg tl.Serializable) error)

type ServerClient added in v1.9.0

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

func (*ServerClient) Close added in v1.9.0

func (s *ServerClient) Close()

func (*ServerClient) IP added in v1.9.0

func (s *ServerClient) IP() string

func (*ServerClient) Port added in v1.9.0

func (s *ServerClient) Port() uint16

func (*ServerClient) Send added in v1.9.0

func (s *ServerClient) Send(msg tl.Serializable) error

func (*ServerClient) ServerKey added in v1.9.0

func (s *ServerClient) ServerKey() ed25519.PublicKey

type ServerID added in v1.0.0

type ServerID struct {
	Type string `json:"@type"`
	Key  string `json:"key"`
}

type TCPAuthenticate added in v1.6.0

type TCPAuthenticate struct {
	Nonce []byte `tl:"bytes"`
}

type TCPAuthenticationComplete added in v1.6.0

type TCPAuthenticationComplete struct {
	PublicKey any    `tl:"struct boxed [pub.ed25519]"`
	Signature []byte `tl:"bytes"`
}

type TCPAuthenticationNonce added in v1.6.0

type TCPAuthenticationNonce struct {
	Nonce []byte `tl:"bytes"`
}

type TCPPing

type TCPPing struct {
	RandomID int64 `tl:"long"`
}

type TCPPong

type TCPPong struct {
	RandomID int64 `tl:"long"`
}

type ValidatorConfig added in v1.0.0

type ValidatorConfig struct {
	Type      string        `json:"@type"`
	ZeroState ConfigBlock   `json:"zero_state"`
	InitBlock ConfigBlock   `json:"init_block"`
	Hardforks []ConfigBlock `json:"hardforks"`
}

Jump to

Keyboard shortcuts

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