exit

package module
v0.0.0-...-a8d65f3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

README

Build

Simply run:

go build bin/main.go

How to use

Edit config.json with your data:

{
  "ListenTCP": 30004,
  "ListenUDP": 30005,
  "Reverse": false,
  "ReverseRandomPorts": false,
  "DialTimeout": 30,
  "UDPTimeout": 60,
  "Seed": "",
  "SubscriptionPrefix": "tuna+1.",
  "SubscriptionDuration": 60,
  "SubscriptionFee": "0",
  "ClaimInterval": 60,
  "Services": {
    "httpproxy": {
      "address": "127.0.0.1",
      "price": "0.001"
    },
    "moonlight": {
      "address": "127.0.0.1",
      "price": "0.001"
    }
  }
}

ListenTCP TCP port to listen for connections
ListenUDP UDP port to listen for connections
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)
DialTimeout timeout for connections to services
UDPTimeout timeout for UDP connections
Seed your seed
SubscriptionPrefix prefix appended to topics for subscription
SubscriptionDuration duration for subscription in blocks
SubscriptionFee fee used for subscription
ClaimInterval payment claim interval for connections
Services services you want to provide

Run like this:

./bin/main

Then users can connect to your services over NKN through their tuna client

Specifying service ports programmatically

In case you're running services with dynamic ports it may be inconvenient to specify port in the services.json before each launch.
Instead you can run TUNA's exit programmatically, launch your service and then provide it's port to TUNA.

...
// read/prepare config
// init wallet sdk
// launch your service
port := ... // port of the newly launched service
...
serviceName := "proxy"
services := []Service{{
    Name: serviceName,
    TCP:  []int{port},
}}
exit := NewTunaExit(config, services, wallet) // can be used only once-per-service
exit.StartReverse(serviceName)

select {} // prevent TUNA from exiting

Getting dynamic ports

When some of the ports of the service is specified as 0, then entry will use random ports for them, here's how you can check which ports it's actually using:

exit.OnEntryConnected(func() {
    ip := exit.GetReverseIP()
    tcpPorts := exit.GetReverseTCPPorts()
    udpPorts := exit.GetReverseUDPPorts()
})

Returned ports will correspond to local ports specified in the same order.
This information will only be available after connection with the reverse entry has been made.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	ListenTCP            int                    `json:"ListenTCP"`
	ListenUDP            int                    `json:"ListenUDP"`
	Reverse              bool                   `json:"Reverse"`
	ReverseRandomPorts   bool                   `json:"ReverseRandomPorts"`
	ReverseMaxPrice      string                 `json:"ReverseMaxPrice"`
	DialTimeout          uint16                 `json:"DialTimeout"`
	UDPTimeout           uint16                 `json:"UDPTimeout"`
	Seed                 string                 `json:"Seed"`
	SubscriptionPrefix   string                 `json:"SubscriptionPrefix"`
	SubscriptionDuration uint32                 `json:"SubscriptionDuration"`
	SubscriptionFee      string                 `json:"SubscriptionFee"`
	ClaimInterval        uint32                 `json:"ClaimInterval"`
	Services             map[string]ServiceInfo `json:"Services"`
}

type Service

type Service struct {
	Name string `json:"name"`
	TCP  []int  `json:"tcp"`
	UDP  []int  `json:"udp"`
}

type ServiceInfo

type ServiceInfo struct {
	Address string `json:"address"`
	Price   string `json:"price"`
}

type TunaExit

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

func NewTunaExit

func NewTunaExit(config Configuration, services []Service, wallet *WalletSDK) *TunaExit

func (*TunaExit) GetReverseIP

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

func (*TunaExit) GetReverseTCPPorts

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

func (*TunaExit) GetReverseUDPPorts

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

func (*TunaExit) OnEntryConnected

func (te *TunaExit) OnEntryConnected(callback func())

func (*TunaExit) Start

func (te *TunaExit) Start()

func (*TunaExit) StartReverse

func (te *TunaExit) StartReverse(serviceName string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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