tuna

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 42 Imported by: 8

README

TUNA 🐟

TUNA software is a decentralized, peer-to-peer networking software that enables users to share their unused network bandwidth with others. It is designed to create a more efficient and decentralized internet by allowing users to earn rewards for sharing their resources. The TUNA software is integrated with NKN blockchain technology, which allows for secure and transparent transactions between users. Based services through NKN. Node will receive payment for tunneled traffic directly from user

Build

Simply run make will do the work. The output binary name will be tuna.

Get Started

Either entry mode or exit mode will need a service definition file services.json. You can start by using services.json.example as template. The service file defines what services to use or provide, which ports a service uses, and various configurations like encryption.

How to use

Forward mode

If you want to use a forward proxy, whether it's an HTTP proxy or a SOCKS5 proxy, you can configure it by modifying the services.json file from services.json.example and starting the TUNA entry. By modifying this file, you can specify the type of proxy you want to use (i.e. HTTP or SOCKS5), as well as the port listening on your local machine.

For example, the following configuration can be used to start TUNA entry client(forward mode) The TUNA entry client automatically searches for TUNA entry servers that provide httpproxy services in the network, and selects the node with the best speed for connection, then listens on the local port 30080. It provides TCP proxy services. With this functionality, the client can automatically find the best available proxy server based on network conditions and provide optimal performance for the user.

Here is an example of services.json

[
  {
    "name": "httpproxy",
    "tcp": [
      30080
    ],
    "encryption": "aes-gcm"
  }
]

Then you can start your entry client

You will need a config file config.entry.json. You can start by using config.entry.json.example as template. You can just run the command below

cp config.entry.json.example config.entry.json

Start tuna in entry mode:

./tuna entry

Then you can start using configured services as if they're on your local machine (e.g. 127.0.0.1:30080 for HTTP proxy).

Reverse mode

TUNA reverse mode is a reverse proxy. Exit is the internal service that need to be exposed to public Internet. Entry is the service provider that provides public IP address.

For example, if you have a web server running on a local network, and you want to access it from the internet, you can start TUNA exit to connect TUNA entry server. This way, when someone accesses the TUNA entry server with the IP address and port that is configured, TUNA will forward the request to the TUNA exit, then it will forward to the local web server.

Reverse mode is a powerful feature that allows users to access devices and services that are not directly accessible from the internet, it can be useful for remote access to local resources, testing, and troubleshooting.

Here is an example of services.json for reverse clients which TUNA exit need

[
  {
    "name": "httpproxy",
    "tcp": [
      30081
    ],
    "encryption": "xsalsa20-poly1305"
  }
]

You will need a config file config.exit.json. You can start by using config.exit.json.example as template.

Set reverse to true in config.exit.json and start tuna in exit mode. Then your service will be exposed to public network by reverse entry. Your node does not need to have public IP address or open port at all.

If you want to use specific port on reverse entry, you need to set reverseRandomPorts == true in config.exit.json, otherwise, you will be assigned to a random port.

If the client side does not set the TCP and UDP ports, then the TUNA server will automatically allocate random ports.

Start tuna in exit mode:

./tuna exit

How to become a TUNA service provider and earn NKN from it

There are two ways for users to earn NKN by providing services using TUNA.

Entry Mode

The first way is to use the reverse mode of the entry to provide reverse proxy services

./tuna -b=[YOUR_BENEFICIARY_ADDR] entry --reverse

Set reverse to true in config.entry.json and start tuna in entry mode. Then users can use your node as reverse proxy and pay you NKN based on bandwidth consumption.

Or you can set reverseBeneficiaryAddr in config.entry.json

You can also change the default listening port by setting reverseTCP & reverseUDP in entry config file.

Remember to set your price of your services by setting reversePrice default value is 0.0002 NKN per MB.

Exit Mode

The second way to earn revenue using TUNA is by using the forward mode of the exit to provide forward proxy services

Here is an example of services.json

[
  {
    "name": "httpproxy",
    "tcp": [
      30080
    ],
    "encryption": "xsalsa20-poly1305"
  },
  {
    "name": "socksproxy",
    "tcp": [
      30489
    ],
    "udp": [
      30489
    ],
    "encryption": "xsalsa20-poly1305"
  }
]

Then you can start your exit server by ./tuna -b=[YOUR_BENEFICIARY_ADDR] exit

Don't forget to deploy your proxy services at port 30080 & 30489.

You can change the port as long as you ensure that the listening port is consistent with services.json

Then users can connect to your services through their tuna entry and pay you NKN based on bandwidth consumption.

Config
Entry mode config config.entry.json:
  • services services you want to use
  • dialTimeout timeout for NKN node connection
  • udpTimeout timeout for UDP connections
  • nanoPayFee fee used for nano pay transaction
  • reverse should be used to provide reverse tunnel for those who don't have public IP
  • reverseBeneficiaryAddr Beneficiary address (NKN wallet address to receive rewards)
  • reverseTCP TCP port to listen for connections
  • reverseUDP UDP port to listen for connections
  • reversePrice price for reverse connections
  • reverseClaimInterval payment claim interval for reverse connections
  • reverseSubscriptionDuration duration for subscription in blocks
  • reverseSubscriptionFee fee used for subscription
Exit mode config config.exit.json:
  • beneficiaryAddr beneficiary address (NKN wallet address to receive rewards)
  • listenTCP TCP port to listen for connections
  • listenUDP UDP port to listen for connections
  • dialTimeout timeout for connections to services
  • udpTimeout timeout for UDP connections
  • claimInterval payment claim interval for connections
  • subscriptionDuration duration for subscription in blocks
  • subscriptionFee fee used for subscription
  • services services you want to provide
  • reverse should be used if you don't have public IP and want to use another server for accepting clients
  • reverseRandomPorts meaning reverse entry can use random ports instead of specified ones (useful when service has dynamic ports)
  • reverseMaxPrice max accepted price for reverse service, unit is NKN per MB traffic
  • reverseNanoPayFee nanoPay transaction fee for reverse service
  • reverseIPFilter reverse service IP address filter
encryption

TUNA supports AES and Salsa20 encryption algorithms, you can refer to the JSON configuration example above.

Service filter

Users can configure several settings for the services offered by TUNA, such as setting a maximum price for the service, creating IP whitelists and blacklists, creating a whitelist and blacklist of service provider public keys and specifying the geographical location of the server. Remember using same service name in services.json and config.exit(or entry).json when you set those settings You can check geo.IPFilter and filter.NknFilter for more details.

Use TUNA as library

Most of them times you just need to run tuna entry/exit as a separate program together with the services, but you can also use tuna as a library. See tests/util.go for entry/exit & forward/reverse examples.

Compiling to iOS/Android native library

This library is designed to work with gomobile and run natively on iOS/Android without any modification. You can use gomobile bind to compile it to Objective-C framework for iOS:

gomobile bind -target=ios -ldflags "-s -w" github.com/nknorg/tuna github.com/nknorg/nkn-sdk-go github.com/nknorg/nkngomobile

and Java AAR for Android:

gomobile bind -target=android -ldflags "-s -w" github.com/nknorg/tuna github.com/nknorg/nkn-sdk-go github.com/nknorg/nkngomobile

More likely you might want to write a simple wrapper uses tuna and compile it using gomobile.

It's recommended to use the latest version of gomobile that supports go modules.

Contributing

Can I submit a bug, suggestion or feature request?

Yes. Please open an issue for that.

Can I contribute patches?

Yes, we appreciate your help! To make contributions, please fork the repo, push your changes to the forked repo with signed-off commits, and open a pull request here.

Please sign off your commit. This means adding a line "Signed-off-by: Name " at the end of each commit, indicating that you wrote the code and have the right to pass it on as an open source patch. This can be done automatically by adding -s when committing:

git commit -s

Community

Documentation

Index

Constants

View Source
const (
	DefaultSubscriptionPrefix = "tuna_v1."
	DefaultReverseServiceName = "reverse"
)
View Source
const (
	PrefixLen            = 4
	DefaultUDPBufferSize = 8192
	MaxUDPBufferSize     = 65527
)
View Source
const (
	TrafficUnit = 1024 * 1024
)

Variables

View Source
var (
	ErrClosed = errors.New("closed")
)

Functions

func Close

func Close(conn io.Closer)

func ConnIDToPort

func ConnIDToPort(data []byte) uint16

func CreateRawMetadata

func CreateRawMetadata(
	serviceID byte,
	serviceTCP []uint32,
	serviceUDP []uint32,
	ip string,
	tcpPort uint32,
	udpPort uint32,
	price string,
	beneficiaryAddr string,
) []byte

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 LoadOrCreateAccount(walletFile, passwordFile string) (*vault.Account, error)

func LoadPassword

func LoadPassword(path string) (string, error)

func ParseEncryptionAlgo

func ParseEncryptionAlgo(encryptionAlgoStr string) (pb.EncryptionAlgo, error)

func ParsePrice

func ParsePrice(priceStr string) (common.Fixed64, common.Fixed64, error)

func PortToConnID

func PortToConnID(port uint16) []byte

func ReadMetadata

func ReadMetadata(metadataString string) (*pb.ServiceMetadata, error)

func ReadVarBytes

func ReadVarBytes(reader io.Reader, maxMsgSize uint32) ([]byte, 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{},
)

func WriteVarBytes

func WriteVarBytes(writer io.Writer, b []byte) error

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 (c *Common) CreateServerConn(force bool) error

func (*Common) GetConnected

func (c *Common) GetConnected() bool

func (*Common) GetMetadata

func (c *Common) GetMetadata() *pb.ServiceMetadata

func (*Common) GetNumActiveSessions

func (c *Common) GetNumActiveSessions() int

func (*Common) GetPaymentReceiver

func (c *Common) GetPaymentReceiver() string

func (*Common) GetPrice

func (c *Common) GetPrice() (common.Fixed64, common.Fixed64)

func (*Common) GetRemoteNknAddress

func (c *Common) GetRemoteNknAddress() string

func (*Common) GetServerTCPConn

func (c *Common) GetServerTCPConn(force bool) (net.Conn, error)

func (*Common) GetServerUDPConn

func (c *Common) GetServerUDPConn(force bool) (UDPConn, error)

func (*Common) GetServerUDPReadChan

func (c *Common) GetServerUDPReadChan(force bool) (chan []byte, error)

func (*Common) GetServerUDPWriteChan

func (c *Common) GetServerUDPWriteChan(force bool) (chan []byte, error)

func (*Common) GetSessionsWaitGroup

func (c *Common) GetSessionsWaitGroup() *sync.WaitGroup

func (*Common) GetTCPConn

func (c *Common) GetTCPConn() net.Conn

func (*Common) GetTopPerformanceNodes

func (c *Common) GetTopPerformanceNodes(measureBandwidth bool, n int) (types.Nodes, error)

func (*Common) GetTopPerformanceNodesContext

func (c *Common) GetTopPerformanceNodesContext(ctx context.Context, measureBandwidth bool, n int) (types.Nodes, error)

func (*Common) GetUDPConn

func (c *Common) GetUDPConn() *EncryptUDPConn

func (*Common) SetConnected

func (c *Common) SetConnected(connected bool)

func (*Common) SetLinger

func (c *Common) SetLinger(t time.Duration)

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 (c *Common) SetPaymentReceiver(paymentReceiver string) error

func (*Common) SetRemoteNknAddress

func (c *Common) SetRemoteNknAddress(nknAddr string)

func (*Common) SetRemoteNode

func (c *Common) SetRemoteNode(node *types.Node)

func (*Common) SetServerTCPConn

func (c *Common) SetServerTCPConn(conn net.Conn)

func (*Common) SetServerUDPConn

func (c *Common) SetServerUDPConn(conn *EncryptUDPConn)

func (*Common) SetServerUDPReadChan

func (c *Common) SetServerUDPReadChan(udpReadChan chan []byte)

func (*Common) SetServerUDPWriteChan

func (c *Common) SetServerUDPWriteChan(udpWriteChan chan []byte)

func (*Common) UpdateServerConn

func (c *Common) UpdateServerConn(remotePublicKey []byte) error

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 (ec *EncryptUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)

func (*EncryptUDPConn) ReadFromUDPEncrypted

func (ec *EncryptUDPConn) ReadFromUDPEncrypted(b []byte) (n int, addr *net.UDPAddr, encrypted bool, err error)

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 (ec *EncryptUDPConn) WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error)

func (*EncryptUDPConn) WriteMsgUDPEncrypted

func (ec *EncryptUDPConn) WriteMsgUDPEncrypted(b, oob []byte, addr *net.UDPAddr) (n, oobn int, encrypted bool, err error)

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 ExitServiceInfo struct {
	Address string `json:"address"`
	Price   string `json:"price"`
}

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.

func (*OnConnect) Next

func (c *OnConnect) Next()

Next waits and returns the next element from the channel.

type OnConnectFunc

type OnConnectFunc interface{ OnConnect() }

OnConnectFunc is a wrapper type for gomobile compatibility.

type Service

type Service struct {
	Name          string   `json:"name"`
	TCP           []uint32 `json:"tcp"`
	UDP           []uint32 `json:"udp"`
	UDPBufferSize int      `json:"udpBufferSize"`
	Encryption    string   `json:"encryption"`
}

type ServiceInfo

type ServiceInfo struct {
	MaxPrice  string            `json:"maxPrice"`
	ListenIP  string            `json:"listenIP"`
	IPFilter  *geo.IPFilter     `json:"ipFilter"`
	NknFilter *filter.NknFilter `json:"nknFilter"`
}

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

func (te *TunaEntry) Close()

func (*TunaEntry) IsClosed

func (te *TunaEntry) IsClosed() bool

func (*TunaEntry) Start

func (te *TunaEntry) Start(shouldReconnect bool) error

func (*TunaEntry) StartReverse

func (te *TunaEntry) StartReverse(stream *smux.Stream, connMetadata *pb.ConnectionMetadata) error

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

func (te *TunaExit) Close()

func (*TunaExit) CloseUDPConn

func (te *TunaExit) CloseUDPConn()

func (*TunaExit) GetReverseIP

func (te *TunaExit) GetReverseIP() net.IP

func (*TunaExit) GetReverseTCPPorts

func (te *TunaExit) GetReverseTCPPorts() []uint32

func (*TunaExit) GetReverseUDPPorts

func (te *TunaExit) GetReverseUDPPorts() []uint32

func (*TunaExit) IsClosed

func (te *TunaExit) IsClosed() bool

func (*TunaExit) Start

func (te *TunaExit) Start() error

func (*TunaExit) StartReverse

func (te *TunaExit) StartReverse(shouldReconnect bool) error

type UDPConn

type UDPConn interface {
	WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error)
	ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error)

	Close() error

	LocalAddr() net.Addr
	RemoteAddr() net.Addr

	SetWriteBuffer(bytes int) error
	SetReadBuffer(bytes int) error
}

Directories

Path Synopsis
exit module

Jump to

Keyboard shortcuts

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