tunnel

Tunnel proxy package in Go

  • 所有者: koding/tunnel
  • 平台:
  • 许可证: BSD 3-Clause "New" or "Revised" License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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

主要指标

概览
名称与所有者koding/tunnel
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证BSD 3-Clause "New" or "Revised" License
所有者活动
创建于2015-05-28 07:26:42
推送于2023-10-20 13:43:58
最后一次提交2017-06-01 12:54:43
发布数0
用户参与
星数332
关注者数19
派生数72
提交数139
已启用问题?
问题数13
打开的问题数7
拉请求数30
打开的拉请求数0
关闭的拉请求数9
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?