Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultSessionConfig() *ncp.Config
- func GetFreePort(port int) (int, error)
- type Config
- type Conn
- type PubAddr
- type PubAddrs
- type Request
- type TunaSessionClient
- func (c *TunaSessionClient) Accept() (net.Conn, error)
- func (c *TunaSessionClient) AcceptSession() (*ncp.Session, error)
- func (c *TunaSessionClient) Addr() net.Addr
- func (c *TunaSessionClient) Address() string
- func (c *TunaSessionClient) Close() error
- func (c *TunaSessionClient) CloseOneConn(sess *ncp.Session, connId string)
- func (c *TunaSessionClient) Dial(remoteAddr string) (net.Conn, error)
- func (c *TunaSessionClient) DialSession(remoteAddr string) (*ncp.Session, error)
- func (c *TunaSessionClient) DialUDP(remoteAddr string) (*UdpSession, error)
- func (c *TunaSessionClient) DialUDPWithConfig(remoteAddr string, config *nkn.DialConfig) (*UdpSession, error)
- func (c *TunaSessionClient) DialWithConfig(remoteAddr string, config *nkn.DialConfig) (*ncp.Session, error)
- func (c *TunaSessionClient) GetPubAddrs() *PubAddrs
- func (c *TunaSessionClient) IsClosed() bool
- func (c *TunaSessionClient) IsSessClosed(sessKey string) bool
- func (c *TunaSessionClient) Listen(addrsRe *nkngomobile.StringArray) error
- func (c *TunaSessionClient) ListenUDP() (*UdpSession, error)
- func (c *TunaSessionClient) OnConnect() chan struct{}
- func (c *TunaSessionClient) RotateAll() error
- func (c *TunaSessionClient) RotateOne(i int) error
- func (c *TunaSessionClient) SetConfig(conf *Config) error
- func (c *TunaSessionClient) SetTunaNode(node *types.Node)
- type UdpSession
- func (us *UdpSession) Close() (err error)
- func (us *UdpSession) CloseTcp(i int)
- func (us *UdpSession) DialUpSession(listenerNknAddr string, sessionID []byte, config *nkn.DialConfig) (err error)
- func (us *UdpSession) GetEstablishedUDPConn() (*tuna.EncryptUDPConn, error)
- func (us *UdpSession) GetUDPConn() *tuna.EncryptUDPConn
- func (us *UdpSession) IsClosed() bool
- func (us *UdpSession) LocalAddr() net.Addr
- func (us *UdpSession) Read(b []byte) (int, error)
- func (us *UdpSession) ReadFrom(b []byte) (n int, addr net.Addr, err error)
- func (us *UdpSession) RemoteAddr() net.Addr
- func (us *UdpSession) SetDeadline(t time.Time) error
- func (us *UdpSession) SetReadBuffer(size int) error
- func (us *UdpSession) SetReadDeadline(t time.Time) error
- func (us *UdpSession) SetWriteBuffer(size int) error
- func (us *UdpSession) SetWriteDeadline(t time.Time) error
- func (us *UdpSession) Write(b []byte) (int, error)
- func (us *UdpSession) WriteTo(b []byte, addr net.Addr) (n int, err error)
Constants ¶
const ( DefaultSessionAllowAddr = nkn.DefaultSessionAllowAddr SessionIDSize = nkn.SessionIDSize )
const (
ActionGetPubAddr = "getPubAddr"
)
Variables ¶
var ( ErrClosed = errors.New("tuna session is closed") ErrNoPubAddr = errors.New("no public address avalaible") ErrRemoteAddrRejected = errors.New("remote address is rejected") ErrWrongMsgFormat = errors.New("wrong message format") ErrWrongAddr = errors.New("wrong address") ErrOnlyDailer = errors.New("this function only for dialer") ErrNilConn = errors.New("conn is nil") )
Functions ¶
func DefaultSessionConfig ¶
func GetFreePort ¶ added in v0.2.6
Types ¶
type Config ¶
type Config struct {
NumTunaListeners int
TunaDialTimeout int // in millisecond
TunaMaxPrice string
TunaNanoPayFee string
TunaMinNanoPayFee string
TunaNanoPayFeeRatio float64
TunaServiceName string
TunaSubscriptionPrefix string
TunaIPFilter *geo.IPFilter
TunaNknFilter *filter.NknFilter
TunaDownloadGeoDB bool
TunaGeoDBPath string
TunaMeasureBandwidth bool
TunaMeasureStoragePath string
TunaMeasurementBytesDownLink int32
TunaMinBalance string
SessionConfig *ncp.Config
ReconnectRetries int // negative value: unlimited retries, 0: no reconnect, positive value: limit retries.
ReconnectInterval int // millisecond
UDPRecvBufferSize int // UDP user data receive buffer size, bytes
MaxUdpDatagramBuffered int // Maximum udp datagrams can be buffered. It works with UDPRecvBufferSize together go decide if a datagram is buffered.
Verbose bool
}
func DefaultConfig ¶
func DefaultConfig() *Config
func MergedConfig ¶
type PubAddr ¶
type TunaSessionClient ¶
func NewTunaSessionClient ¶
func NewTunaSessionClient(clientAccount *nkn.Account, m *nkn.MultiClient, wallet *nkn.Wallet, config *Config) (*TunaSessionClient, error)
func (*TunaSessionClient) AcceptSession ¶
func (c *TunaSessionClient) AcceptSession() (*ncp.Session, error)
func (*TunaSessionClient) Addr ¶
func (c *TunaSessionClient) Addr() net.Addr
func (*TunaSessionClient) Address ¶
func (c *TunaSessionClient) Address() string
func (*TunaSessionClient) Close ¶
func (c *TunaSessionClient) Close() error
func (*TunaSessionClient) CloseOneConn ¶ added in v0.2.6
func (c *TunaSessionClient) CloseOneConn(sess *ncp.Session, connId string)
func (*TunaSessionClient) Dial ¶
func (c *TunaSessionClient) Dial(remoteAddr string) (net.Conn, error)
func (*TunaSessionClient) DialSession ¶
func (c *TunaSessionClient) DialSession(remoteAddr string) (*ncp.Session, error)
func (*TunaSessionClient) DialUDP ¶ added in v0.2.6
func (c *TunaSessionClient) DialUDP(remoteAddr string) (*UdpSession, error)
func (*TunaSessionClient) DialUDPWithConfig ¶ added in v0.2.6
func (c *TunaSessionClient) DialUDPWithConfig(remoteAddr string, config *nkn.DialConfig) (*UdpSession, error)
func (*TunaSessionClient) DialWithConfig ¶
func (c *TunaSessionClient) DialWithConfig(remoteAddr string, config *nkn.DialConfig) (*ncp.Session, error)
func (*TunaSessionClient) GetPubAddrs ¶ added in v0.1.9
func (c *TunaSessionClient) GetPubAddrs() *PubAddrs
func (*TunaSessionClient) IsClosed ¶
func (c *TunaSessionClient) IsClosed() bool
func (*TunaSessionClient) IsSessClosed ¶ added in v0.2.6
func (c *TunaSessionClient) IsSessClosed(sessKey string) bool
func (*TunaSessionClient) Listen ¶
func (c *TunaSessionClient) Listen(addrsRe *nkngomobile.StringArray) error
func (*TunaSessionClient) ListenUDP ¶ added in v0.2.6
func (c *TunaSessionClient) ListenUDP() (*UdpSession, error)
Start UDP server listening. Because UDP is connectionless, we use TCP to track the connection status. So we need to start a TCP server first, and then start a UDP server. Meanwhile, Tuna session server hase two modes: TCP only, or TCP + UDP.
func (*TunaSessionClient) OnConnect ¶ added in v0.2.6
func (c *TunaSessionClient) OnConnect() chan struct{}
OnConnect returns a channel that will be closed when at least one tuna exit is connected after Listen() is first called.
func (*TunaSessionClient) RotateAll ¶ added in v0.2.1
func (c *TunaSessionClient) RotateAll() error
RotateAll create and replace all tuna exit. New connections accepted will use new tuna exit, existing connections will not be affected.
func (*TunaSessionClient) RotateOne ¶ added in v0.2.1
func (c *TunaSessionClient) RotateOne(i int) error
RotateOne create a new tuna exit and replace the i-th one. New connections accepted will use new tuna exit, existing connections will not be affected.
func (*TunaSessionClient) SetConfig ¶ added in v0.2.1
func (c *TunaSessionClient) SetConfig(conf *Config) error
SetConfig will set any non-empty value in conf to tuna session config.
func (*TunaSessionClient) SetTunaNode ¶ added in v0.2.6
func (c *TunaSessionClient) SetTunaNode(node *types.Node)
type UdpSession ¶ added in v0.2.6
UDP session, it is a UDP listener or dialer endpoint for reading and writing udp data. After tuna session set up UDP connection, it return UpdSession to applications. Applications use this end point to read and write data. If there is a node break down between UDP listener and dialer, udp session will reconenct automatically without interrupting application usage.
func (*UdpSession) Close ¶ added in v0.2.6
func (us *UdpSession) Close() (err error)
The endpoint close session actively.
func (*UdpSession) DialUpSession ¶ added in v0.2.6
func (us *UdpSession) DialUpSession(listenerNknAddr string, sessionID []byte, config *nkn.DialConfig) (err error)
func (*UdpSession) GetEstablishedUDPConn ¶ added in v0.2.6
func (us *UdpSession) GetEstablishedUDPConn() (*tuna.EncryptUDPConn, error)
func (*UdpSession) GetUDPConn ¶ added in v0.2.6
func (us *UdpSession) GetUDPConn() *tuna.EncryptUDPConn
func (*UdpSession) IsClosed ¶ added in v0.2.6
func (us *UdpSession) IsClosed() bool
func (*UdpSession) LocalAddr ¶ added in v0.2.6
func (us *UdpSession) LocalAddr() net.Addr
func (*UdpSession) ReadFrom ¶ added in v0.2.6
ReadFrom, implement of standard library function: net.UDPConn.ReadFrom
func (*UdpSession) RemoteAddr ¶ added in v0.2.6
func (us *UdpSession) RemoteAddr() net.Addr
func (*UdpSession) SetDeadline ¶ added in v0.2.6
func (us *UdpSession) SetDeadline(t time.Time) error
func (*UdpSession) SetReadBuffer ¶ added in v0.2.6
func (us *UdpSession) SetReadBuffer(size int) error
func (*UdpSession) SetReadDeadline ¶ added in v0.2.6
func (us *UdpSession) SetReadDeadline(t time.Time) error
func (*UdpSession) SetWriteBuffer ¶ added in v0.2.6
func (us *UdpSession) SetWriteBuffer(size int) error
func (*UdpSession) SetWriteDeadline ¶ added in v0.2.6
func (us *UdpSession) SetWriteDeadline(t time.Time) error