Categorygithub.com/programmare-labs/tunnel
modulepackage
0.0.2
Repository: https://github.com/programmare-labs/tunnel.git
Documentation: pkg.go.dev

# README

Tunnel GoDoc Go Report Card Build Status

Tunnel is a server/client package that enables to proxy public connections to your local machine over a tunnel connection from the local machine to the public server. What this means is, you can share your localhost even if it doesn't have a Public IP or if it's not reachable from outside.

It uses the excellent yamux package to multiplex connections between server and client.

The project is under active development, please vendor it if you want to use it.

Usage

The tunnel package consists of two parts. The server and the client.

Server is the public facing part. It's type that satisfies the http.Handler. So it's easily pluggable into existing servers.

Let assume that you setup your DNS service so all *.example.com domains route to your server at the public IP 203.0.113.0. Let us first create the server part:

package main

import (
	"net/http"

	"github.com/koding/tunnel"
)

func main() {
	cfg := &tunnel.ServerConfig{}
	server, _ := tunnel.NewServer(cfg)
	server.AddHost("sub.example.com", "1234")
	http.ListenAndServe(":80", server)
}

Once you create the server, you just plug it into your server. The only detail here is to map a virtualhost to a secret token. The secret token is the only part that needs to be known for the client side.

Let us now create the client side part:

package main

import "github.com/koding/tunnel"

func main() {
	cfg := &tunnel.ClientConfig{
		Identifier: "1234",
		ServerAddr: "203.0.113.0:80",
	}

	client, err := tunnel.NewClient(cfg)
	if err != nil {
		panic(err)
	}

	client.Start()
}

The Start() method is by default blocking. As you see you, we just passed the server address and the secret token.

Now whenever someone hit sub.example.com, the request will be proxied to the machine where client is running and hit the local server running 127.0.0.1:80 (assuming there is one). If someone hits sub.example.com:3000 (assume your server is running at this port), it'll be routed to 127.0.0.1:3000

That's it.

There are many options that can be changed, such as a static local address for your client. Have alook at the documentation

Protocol

The server/client protocol is written in the spec.md file. Please have a look for more detail.

License

The BSD 3-Clause License - see LICENSE for more details

# Packages

Package proto defines tunnel client server communication protocol.
No description provided by the author

# Functions

Join copies data between local and remote connections.
NewClient creates a new tunnel that is established between the serverAddr and localAddr.
NewServer creates a new Server.
Proxy returns a ProxyFunc that uses custom function if provided, otherwise falls back to DefaultProxyFuncs.

# Constants

keep it always last.
ClientState enumeration.
ClientState enumeration.
ClientState enumeration.
ClientState enumeration.
ClientState enumeration.

# Variables

DefaultProxy is a ProxyFunc that uses DefaultProxyFuncs.
DefaultProxyFuncs holds global default proxy functions for all transport protocols.
ErrRedialAborted is emitted on ClientClosed event, when backoff policy used by a client decided no more reconnection attempts must be made.

# Structs

Client is responsible for creating a control connection to a tunnel server, creating new tunnels and proxy them to tunnel server.
ClientConfig defines the configuration for the Client.
ClientStateChange represents single client state transition.
HTTPProxy forwards HTTP traffic.
ProxyFuncs is a collection of ProxyFunc.
Server is responsible for proxying public connections to the client over a tunnel connection.
ServerConfig defines the configuration for the Server.
TCPProxy forwards TCP streams.

# Interfaces

Backoff defines behavior of staggering reconnection retries.

# Type aliases

ClientState represents client connection state to tunnel server.
ProxyFunc is responsible for forwarding a remote connection to local server and writing the response back.