Documentation ¶
Index ¶
- Constants
- Variables
- func Close(conn io.Closer)
- func ConnIDToPort(data []byte) uint16
- func CreateRawMetadata(serviceID byte, serviceTCP []uint32, serviceUDP []uint32, ip string, ...) []byte
- func GetFavoriteSeedRPCServer(path, filenamePrefix string, timeout int32, ...) ([]string, error)
- func GetFavoriteSeedRPCServerContext(ctx context.Context, path, filenamePrefix string, timeout int32, ...) ([]string, error)
- func LoadOrCreateAccount(walletFile, passwordFile string) (*vault.Account, error)
- func LoadPassword(path string) (string, error)
- func ParseEncryptionAlgo(encryptionAlgoStr string) (pb.EncryptionAlgo, error)
- func ParsePrice(priceStr string) (common.Fixed64, common.Fixed64, error)
- func PortToConnID(port uint16) []byte
- func ReadMetadata(metadataString string) (*pb.ServiceMetadata, error)
- func ReadVarBytes(reader io.Reader, maxMsgSize uint32) ([]byte, error)
- func StartReverse(config *EntryConfiguration, wallet *nkn.Wallet) error
- func UpdateMetadata(serviceName string, serviceID byte, serviceTCP []uint32, serviceUDP []uint32, ...)
- func WriteVarBytes(writer io.Writer, b []byte) error
- type Common
- func (c *Common) CreateServerConn(force bool) error
- func (c *Common) GetConnected() bool
- func (c *Common) GetMetadata() *pb.ServiceMetadata
- func (c *Common) GetNumActiveSessions() int
- func (c *Common) GetPaymentReceiver() string
- func (c *Common) GetPrice() (common.Fixed64, common.Fixed64)
- func (c *Common) GetRemoteNknAddress() string
- func (c *Common) GetServerTCPConn(force bool) (net.Conn, error)
- func (c *Common) GetServerUDPConn(force bool) (UDPConn, error)
- func (c *Common) GetServerUDPReadChan(force bool) (chan []byte, error)
- func (c *Common) GetServerUDPWriteChan(force bool) (chan []byte, error)
- func (c *Common) GetSessionsWaitGroup() *sync.WaitGroup
- func (c *Common) GetTCPConn() net.Conn
- func (c *Common) GetTopPerformanceNodes(measureBandwidth bool, n int) (types.Nodes, error)
- func (c *Common) GetTopPerformanceNodesContext(ctx context.Context, measureBandwidth bool, n int) (types.Nodes, error)
- func (c *Common) GetUDPConn() *EncryptUDPConn
- func (c *Common) SetConnected(connected bool)
- func (c *Common) SetLinger(t time.Duration)
- func (c *Common) SetMetadata(metadata *pb.ServiceMetadata)
- func (c *Common) SetPaymentReceiver(paymentReceiver string) error
- func (c *Common) SetRemoteNknAddress(nknAddr string)
- func (c *Common) SetRemoteNode(node *types.Node)
- func (c *Common) SetServerTCPConn(conn net.Conn)
- func (c *Common) SetServerUDPConn(conn *EncryptUDPConn)
- func (c *Common) SetServerUDPReadChan(udpReadChan chan []byte)
- func (c *Common) SetServerUDPWriteChan(udpWriteChan chan []byte)
- func (c *Common) UpdateServerConn(remotePublicKey []byte) error
- func (c *Common) WaitSessions()
- type EncryptUDPConn
- func (ec *EncryptUDPConn) AddCodec(addr *net.UDPAddr, encryptKey *[32]byte, encryptionAlgo pb.EncryptionAlgo, ...) error
- func (ec *EncryptUDPConn) Close() error
- func (ec *EncryptUDPConn) IsClosed() bool
- func (ec *EncryptUDPConn) LocalAddr() net.Addr
- func (ec *EncryptUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)
- func (ec *EncryptUDPConn) ReadFromUDPEncrypted(b []byte) (n int, addr *net.UDPAddr, encrypted bool, err error)
- func (ec *EncryptUDPConn) RemoteAddr() net.Addr
- func (ec *EncryptUDPConn) RemoteUDPAddr() *net.UDPAddr
- func (ec *EncryptUDPConn) SetDeadline(t time.Time) error
- func (ec *EncryptUDPConn) SetReadBuffer(size int) error
- func (ec *EncryptUDPConn) SetReadDeadline(t time.Time) error
- func (ec *EncryptUDPConn) SetWriteBuffer(size int) error
- func (ec *EncryptUDPConn) SetWriteDeadline(t time.Time) error
- func (ec *EncryptUDPConn) WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error)
- func (ec *EncryptUDPConn) WriteMsgUDPEncrypted(b, oob []byte, addr *net.UDPAddr) (n, oobn int, encrypted bool, err error)
- type EntryConfiguration
- type ExitConfiguration
- type ExitServiceInfo
- type OnConnect
- type OnConnectFunc
- type Service
- type ServiceInfo
- type TunaEntry
- type TunaExit
- func (te *TunaExit) Close()
- func (te *TunaExit) CloseUDPConn()
- func (te *TunaExit) GetReverseIP() net.IP
- func (te *TunaExit) GetReverseTCPPorts() []uint32
- func (te *TunaExit) GetReverseUDPPorts() []uint32
- func (te *TunaExit) IsClosed() bool
- func (te *TunaExit) Start() error
- func (te *TunaExit) StartReverse(shouldReconnect bool) error
- type UDPConn
Constants ¶
const ( DefaultSubscriptionPrefix = "tuna_v1." DefaultReverseServiceName = "reverse" )
const ( PrefixLen = 4 DefaultUDPBufferSize = 8192 MaxUDPBufferSize = 65527 )
const (
TrafficUnit = 1024 * 1024
)
Variables ¶
var (
ErrClosed = errors.New("closed")
)
Functions ¶
func ConnIDToPort ¶
func CreateRawMetadata ¶
func GetFavoriteSeedRPCServer ¶
func GetFavoriteSeedRPCServer(path, filenamePrefix string, timeout int32, dialContext func(ctx context.Context, network, addr string) (net.Conn, error)) ([]string, error)
GetFavoriteSeedRPCServer wraps GetFavoriteSeedRPCServerContext with background context.
func GetFavoriteSeedRPCServerContext ¶
func GetFavoriteSeedRPCServerContext(ctx context.Context, path, filenamePrefix string, timeout int32, dialContext func(ctx context.Context, network, addr string) (net.Conn, error)) ([]string, error)
GetFavoriteSeedRPCServerContext returns an array of node rpc address from favorite node file. Timeout is in unit of millisecond.
func LoadOrCreateAccount ¶
func LoadPassword ¶
func ParseEncryptionAlgo ¶
func ParseEncryptionAlgo(encryptionAlgoStr string) (pb.EncryptionAlgo, error)
func PortToConnID ¶
func ReadMetadata ¶
func ReadMetadata(metadataString string) (*pb.ServiceMetadata, error)
func StartReverse ¶
func StartReverse(config *EntryConfiguration, wallet *nkn.Wallet) error
func UpdateMetadata ¶
func UpdateMetadata( serviceName string, serviceID byte, serviceTCP []uint32, serviceUDP []uint32, ip string, tcpPort uint32, udpPort uint32, price string, beneficiaryAddr string, subscriptionPrefix string, subscriptionDuration uint32, subscriptionFee string, subscriptionReplaceTxPool bool, client *nkn.MultiClient, closeChan chan struct{}, )
Types ¶
type Common ¶
type Common struct { Service *Service ServiceInfo *ServiceInfo Wallet *nkn.Wallet Client *nkn.MultiClient DialTimeout int32 SubscriptionPrefix string Reverse bool ReverseMetadata *pb.ServiceMetadata OnConnect *OnConnect IsServer bool GeoDBPath string DownloadGeoDB bool GetSubscribersBatchSize int MeasureBandwidth bool MeasureBandwidthTimeout time.Duration MeasureBandwidthWorkersTimeout time.Duration MeasurementBytesDownLink int32 MeasureStoragePath string MaxPoolSize int32 TcpDialContext func(ctx context.Context, network, addr string) (net.Conn, error) HttpDialContext func(ctx context.Context, network, addr string) (net.Conn, error) WsDialContext func(ctx context.Context, network, addr string) (net.Conn, error) sync.RWMutex // contains filtered or unexported fields }
func NewCommon ¶
func NewCommon( service *Service, serviceInfo *ServiceInfo, wallet *nkn.Wallet, client *nkn.MultiClient, seedRPCServerAddr []string, dialTimeout int32, subscriptionPrefix string, reverse, isServer bool, geoDBPath string, downloadGeoDB bool, getSubscribersBatchSize int32, measureBandwidth bool, measureBandwidthTimeout int32, measureBandwidthWorkersTimeout int32, measurementBytes int32, measureStoragePath string, maxPoolSize int32, tcpDialContext func(ctx context.Context, network, addr string) (net.Conn, error), httpDialContext func(ctx context.Context, network, addr string) (net.Conn, error), wsDialContext func(ctx context.Context, network, addr string) (net.Conn, error), sortMeasuredNodes func(types.Nodes), reverseMetadata *pb.ServiceMetadata, minBalance string, ) (*Common, error)
func (*Common) CreateServerConn ¶
func (*Common) GetConnected ¶
func (*Common) GetMetadata ¶
func (c *Common) GetMetadata() *pb.ServiceMetadata
func (*Common) GetNumActiveSessions ¶
func (*Common) GetPaymentReceiver ¶
func (*Common) GetRemoteNknAddress ¶
func (*Common) GetServerUDPReadChan ¶
func (*Common) GetServerUDPWriteChan ¶
func (*Common) GetSessionsWaitGroup ¶
func (*Common) GetTCPConn ¶
func (*Common) GetTopPerformanceNodes ¶
func (*Common) GetTopPerformanceNodesContext ¶
func (*Common) GetUDPConn ¶
func (c *Common) GetUDPConn() *EncryptUDPConn
func (*Common) SetConnected ¶
func (*Common) SetLinger ¶
SetLinger sets the behavior of Close when there is at least one active session. t = 0 (default): close all conn when tuna close. t < 0: tuna Close() call will block and wait for all sessions to close before closing tuna. t > 0: tuna Close() call will block and wait for up to timeout all sessions to close before closing tuna.
func (*Common) SetMetadata ¶
func (c *Common) SetMetadata(metadata *pb.ServiceMetadata)
func (*Common) SetPaymentReceiver ¶
func (*Common) SetRemoteNknAddress ¶
func (*Common) SetRemoteNode ¶
func (*Common) SetServerTCPConn ¶
func (*Common) SetServerUDPConn ¶
func (c *Common) SetServerUDPConn(conn *EncryptUDPConn)
func (*Common) SetServerUDPReadChan ¶
func (*Common) SetServerUDPWriteChan ¶
func (*Common) UpdateServerConn ¶
func (*Common) WaitSessions ¶
func (c *Common) WaitSessions()
WaitSessions waits for sessions wait group, or until linger times out.
type EncryptUDPConn ¶
type EncryptUDPConn struct {
// contains filtered or unexported fields
}
func NewEncryptUDPConn ¶
func NewEncryptUDPConn(conn *net.UDPConn) *EncryptUDPConn
func (*EncryptUDPConn) AddCodec ¶
func (ec *EncryptUDPConn) AddCodec(addr *net.UDPAddr, encryptKey *[32]byte, encryptionAlgo pb.EncryptionAlgo, initiator bool) error
func (*EncryptUDPConn) Close ¶
func (ec *EncryptUDPConn) Close() error
func (*EncryptUDPConn) IsClosed ¶
func (ec *EncryptUDPConn) IsClosed() bool
func (*EncryptUDPConn) LocalAddr ¶
func (ec *EncryptUDPConn) LocalAddr() net.Addr
func (*EncryptUDPConn) ReadFromUDP ¶
func (*EncryptUDPConn) ReadFromUDPEncrypted ¶
func (*EncryptUDPConn) RemoteAddr ¶
func (ec *EncryptUDPConn) RemoteAddr() net.Addr
func (*EncryptUDPConn) RemoteUDPAddr ¶
func (ec *EncryptUDPConn) RemoteUDPAddr() *net.UDPAddr
func (*EncryptUDPConn) SetDeadline ¶
func (ec *EncryptUDPConn) SetDeadline(t time.Time) error
func (*EncryptUDPConn) SetReadBuffer ¶
func (ec *EncryptUDPConn) SetReadBuffer(size int) error
func (*EncryptUDPConn) SetReadDeadline ¶
func (ec *EncryptUDPConn) SetReadDeadline(t time.Time) error
func (*EncryptUDPConn) SetWriteBuffer ¶
func (ec *EncryptUDPConn) SetWriteBuffer(size int) error
func (*EncryptUDPConn) SetWriteDeadline ¶
func (ec *EncryptUDPConn) SetWriteDeadline(t time.Time) error
func (*EncryptUDPConn) WriteMsgUDP ¶
func (*EncryptUDPConn) WriteMsgUDPEncrypted ¶
type EntryConfiguration ¶
type EntryConfiguration struct { SeedRPCServerAddr []string `json:"seedRPCServerAddr"` Services map[string]ServiceInfo `json:"services"` DialTimeout int32 `json:"dialTimeout"` UDPTimeout int32 `json:"udpTimeout"` NanoPayFee string `json:"nanoPayFee"` MinNanoPayFee string `json:"minNanoPayFee"` NanoPayFeeRatio float64 `json:"nanoPayFeeRatio"` SubscriptionPrefix string `json:"subscriptionPrefix"` Reverse bool `json:"reverse"` ReverseBeneficiaryAddr string `json:"reverseBeneficiaryAddr"` ReverseTCP int32 `json:"reverseTCP"` ReverseUDP int32 `json:"reverseUDP"` ReverseServiceListenIP string `json:"reverseServiceListenIP"` ReversePrice string `json:"reversePrice"` ReverseClaimInterval int32 `json:"reverseClaimInterval"` ReverseMinFlushAmount string `json:"reverseMinFlushAmount"` ReverseServiceName string `json:"reverseServiceName"` ReverseSubscriptionPrefix string `json:"reverseSubscriptionPrefix"` ReverseSubscriptionDuration int32 `json:"reverseSubscriptionDuration"` ReverseSubscriptionFee string `json:"reverseSubscriptionFee"` ReverseSubscriptionReplaceTxPool bool `json:"reverseSubscriptionReplaceTxPool"` GeoDBPath string `json:"geoDBPath"` DownloadGeoDB bool `json:"downloadGeoDB"` GetSubscribersBatchSize int32 `json:"getSubscribersBatchSize"` MeasureBandwidth bool `json:"measureBandwidth"` MeasureBandwidthTimeout int32 `json:"measureBandwidthTimeout"` MeasureBandwidthWorkersTimeout int32 `json:"measureBandwidthWorkersTimeout"` MeasurementBytesDownLink int32 `json:"measurementBytesDownLink"` MeasureStoragePath string `json:"measureStoragePath"` MaxMeasureWorkerPoolSize int32 `json:"maxMeasureWorkerPoolSize"` SortMeasuredNodes func(types.Nodes) `json:"-"` TcpDialContext func(ctx context.Context, network, addr string) (net.Conn, error) `json:"-"` HttpDialContext func(ctx context.Context, network, addr string) (net.Conn, error) `json:"-"` WsDialContext func(ctx context.Context, network, addr string) (net.Conn, error) `json:"-"` MinBalance string `json:"minBalance"` }
func DefaultEntryConfig ¶
func DefaultEntryConfig() *EntryConfiguration
func MergedEntryConfig ¶
func MergedEntryConfig(conf *EntryConfiguration) (*EntryConfiguration, error)
type ExitConfiguration ¶
type ExitConfiguration struct { SeedRPCServerAddr []string `json:"seedRPCServerAddr"` BeneficiaryAddr string `json:"beneficiaryAddr"` ListenTCP int32 `json:"listenTCP"` ListenUDP int32 `json:"listenUDP"` DialTimeout int32 `json:"dialTimeout"` UDPTimeout int32 `json:"udpTimeout"` SubscriptionPrefix string `json:"subscriptionPrefix"` SubscriptionDuration int32 `json:"subscriptionDuration"` SubscriptionFee string `json:"subscriptionFee"` SubscriptionReplaceTxPool bool `json:"subscriptionReplaceTxPool"` ClaimInterval int32 `json:"claimInterval"` MinFlushAmount string `json:"minFlushAmount"` Services map[string]ExitServiceInfo `json:"services"` Reverse bool `json:"reverse"` ReverseRandomPorts bool `json:"reverseRandomPorts"` ReverseMaxPrice string `json:"reverseMaxPrice"` ReverseNanoPayFee string `json:"reverseNanopayfee"` MinReverseNanoPayFee string `json:"minReverseNanoPayFee"` ReverseNanoPayFeeRatio float64 `json:"reverseNanopayfeeRatio"` ReverseServiceName string `json:"reverseServiceName"` ReverseSubscriptionPrefix string `json:"reverseSubscriptionPrefix"` ReverseEncryption string `json:"reverseEncryption"` GeoDBPath string `json:"geoDBPath"` DownloadGeoDB bool `json:"downloadGeoDB"` GetSubscribersBatchSize int32 `json:"getSubscribersBatchSize"` ReverseIPFilter geo.IPFilter `json:"reverseIPFilter"` ReverseNknFilter filter.NknFilter `json:"reverseNknFilter"` MeasureBandwidth bool `json:"measureBandwidth"` MeasureBandwidthTimeout int32 `json:"measureBandwidthTimeout"` MeasureBandwidthWorkersTimeout int32 `json:"measureBandwidthWorkersTimeout"` MeasurementBytesDownLink int32 `json:"measurementBytesDownLink"` MeasureStoragePath string `json:"measureStoragePath"` MaxMeasureWorkerPoolSize int32 `json:"maxMeasureWorkerPoolSize"` SortMeasuredNodes func(types.Nodes) `json:"-"` TcpDialContext func(ctx context.Context, network, addr string) (net.Conn, error) `json:"-"` HttpDialContext func(ctx context.Context, network, addr string) (net.Conn, error) `json:"-"` WsDialContext func(ctx context.Context, network, addr string) (net.Conn, error) `json:"-"` ReverseMinBalance string `json:"reverseMinBalance"` }
func DefaultExitConfig ¶
func DefaultExitConfig() *ExitConfiguration
func MergedExitConfig ¶
func MergedExitConfig(conf *ExitConfiguration) (*ExitConfiguration, error)
type ExitServiceInfo ¶
type OnConnect ¶
type OnConnect struct { C chan struct{} Callback OnConnectFunc // contains filtered or unexported fields }
OnConnect is a wrapper type for gomobile compatibility.
func NewOnConnect ¶
func NewOnConnect(size int, cb OnConnectFunc) *OnConnect
NewOnConnect creates an OnConnect channel with a channel size and callback function.
type OnConnectFunc ¶
type OnConnectFunc interface{ OnConnect() }
OnConnectFunc is a wrapper type for gomobile compatibility.
type ServiceInfo ¶
type TunaEntry ¶
type TunaEntry struct { *Common // contains filtered or unexported fields }
func NewTunaEntry ¶
func NewTunaEntry(service Service, serviceInfo ServiceInfo, wallet *nkn.Wallet, client *nkn.MultiClient, config *EntryConfiguration) (*TunaEntry, error)
func (*TunaEntry) StartReverse ¶
type TunaExit ¶
type TunaExit struct { *Common OnConnect *OnConnect // override Common.OnConnect // contains filtered or unexported fields }
func NewTunaExit ¶
func NewTunaExit(services []Service, wallet *nkn.Wallet, client *nkn.MultiClient, config *ExitConfiguration) (*TunaExit, error)
func (*TunaExit) CloseUDPConn ¶
func (te *TunaExit) CloseUDPConn()