tunnel

package module
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2023 License: Apache-2.0 Imports: 16 Imported by: 3

README

NKN Tunnel

GitHub license Go Report Card Build Status PRs Welcome

nkn

Tunnel any TCP applications through NKN client or Tuna. A few advantages:

  • Network agnostic: Neither sender nor receiver needs to have public IP address or port forwarding. NKN tunnel only establish outbound (websocket) connections, so Internet access is all they need on both side.
  • Top level security: All data are end to end authenticated and encrypted. No one else in the world except sender and receiver can see or modify the content of the data. The same public key is used for both routing and encryption, eliminating the possibility of man in the middle attack.
  • Decent performance: By aggregating multiple overlay paths concurrently, one can get ~100ms end to end latency and 10+mbps end to end throughput between international devices using the default NKN client mode, or much lower latency and higher throughput using Tuna mode.
  • Everything is open source and decentralized. The default NKN client mode is free (If you are curious, node relay traffic for clients for free to earn mining rewards in NKN blockchain), while Tuna mode requires listener to pay NKN token directly to Tuna service providers.

A diagram of the default NKN client mode:

                                 A - ... - X
                               /             \
Alice <--> TCP <--> NKN client - B - ... - Y - NKN client <--> TCP <--> Bob
                               \             /
                                 C - ... - Z

A diagram of the Tuna mode:

                                      A
                                    /   \
Alice <--> TCP <--> NKN Tuna client - B - NKN Tuna client <--> TCP <--> Bob
                                    \   /
                                      C

Build

go build -o nkn-tunnel bin/main.go

Basic Usage

"Server" side:

./nkn-tunnel -to 127.0.0.1:8080 -s <seed>

and you will see an output like Listening at xxx where xxx is the server listening address.

"Client" side:

./nkn-tunnel -from 127.0.0.1:8081 -to <server-listening-address>

Now any TCP connection to client port 8081 will be forwarded to server port 8080.

Tuna Mode

Add -tuna on both side of the tunnel to use Tuna mode, which has much better performance but requires listener to pay NKN token directly to Tuna service providers.

Turn on UDP under Tuna Mode

When using Tuna mode, add -udp to turn on UDP communication on both side to support UDP communication.

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

This section is empty.

Variables

View Source
var (
	ErrUDPNotSupported = errors.New("UDP is only supported in tuna mode")
)

Functions

This section is empty.

Types

type Config added in v0.2.1

type Config struct {
	NumSubClients     int
	OriginalClient    bool
	AcceptAddrs       *nkngomobile.StringArray
	ClientConfig      *nkn.ClientConfig
	WalletConfig      *nkn.WalletConfig
	DialConfig        *nkn.DialConfig
	TunaSessionConfig *ts.Config
	UDP               bool
	UDPIdleTime       int32 // Seconds. Time to purge idle udp connections, 0 is for no purge.
	Verbose           bool
	TunaNode          *types.Node
}

func DefaultConfig added in v0.2.1

func DefaultConfig() *Config

func MergedConfig added in v0.2.1

func MergedConfig(conf *Config) (*Config, error)

type Tunnel

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

Tunnel is the tunnel client struct.

func NewTunnel

func NewTunnel(account *nkn.Account, identifier, from, to string, tuna bool, config *Config, mc *nkn.MultiClient) (*Tunnel, error)

NewTunnel creates a Tunnel client with given options.

func NewTunnels added in v0.3.5

func NewTunnels(account *nkn.Account, identifier string, from, to []string, tuna bool, config *Config, mc *nkn.MultiClient) ([]*Tunnel, error)

NewTunnels creates Tunnel clients with given options. If argument `mc` is nil, then a new MultiClient will be created based on `account` and `identifier`.

func (*Tunnel) Addr added in v0.3.0

func (t *Tunnel) Addr() net.Addr

Addr returns the tunnel NKN address.

func (*Tunnel) Close added in v0.2.1

func (t *Tunnel) Close() error

Close will close the tunnel.

func (*Tunnel) FromAddr added in v0.2.1

func (t *Tunnel) FromAddr() string

FromAddr returns the tunnel listening address.

func (*Tunnel) IsClosed added in v0.2.1

func (t *Tunnel) IsClosed() bool

IsClosed returns whether the tunnel is closed.

func (*Tunnel) MultiClient added in v0.3.1

func (t *Tunnel) MultiClient() *nkn.MultiClient

MultiClient returns the NKN multiclient that tunnel creates and uses.

func (*Tunnel) SetAcceptAddrs added in v0.2.1

func (t *Tunnel) SetAcceptAddrs(addrsRe *nkngomobile.StringArray) error

SetAcceptAddrs updates the accept address regex for incoming sessions. Tunnel will accept sessions from address that matches any of the given regular expressions. If addrsRe is nil, any address will be accepted. Each function call will overwrite previous accept addresses.

func (*Tunnel) Start

func (t *Tunnel) Start() error

Start starts the tunnel and will return on error.

func (*Tunnel) ToAddr added in v0.2.1

func (t *Tunnel) ToAddr() string

ToAddr returns the tunnel dialing address.

func (*Tunnel) TunaPubAddrs added in v0.3.0

func (t *Tunnel) TunaPubAddrs() *ts.PubAddrs

TunaPubAddrs returns the public node info of tuna listeners. Returns nil if there is no tuna listener.

func (*Tunnel) TunaSessionClient added in v0.3.1

func (t *Tunnel) TunaSessionClient() *ts.TunaSessionClient

TunaSessionClient returns the tuna session client that tunnel creates and uses. It is not nil only if tunnel is created with tuna == true.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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