Git Product home page Git Product logo

t's Introduction

What is t?

Another weekend project.

In short, this is like ngrok, or like so many other tunneling softwares out there. But I got bored, so here we are.

WARNING: NO TESTS, NO LUBE, WORKS FOR ME, USE AT YOUR OWN RISK

Configuration

See example.config.yaml for reference. You will need to generate your own CA and peer certificates. However, client/gateway TLS will be issued via Let's Encrypt, so there will be no need for configurations on the client side.

How It Works

t uses Hashicorp's:

  • memberlist for peer discovery, state synchronization (updating the peer graph), and failure detection.

t also uses the following for multiplexing:

t supports these protocols for creating logical streams between peers and clients, and clients can be connected to any one of the peers, and the gateway on any of the peers will route the HTTPS request to the client's forwarding port.

Because of the architecture, peers and clients can be connected to each other with different protocols. This allows for complex networking environments where some peers are not able to communicate via QUIC because of buggy cloud firewall configuration, while other peers are able to communicate via QUIC.

The peers have to be publicly accessible on the Internet (they are the gateway, after all).

Architecture

t architecture

How to Use (Simple)

  1. First you need a publicly accessible host. You can run one for $5 a month or cheaper from your favorite cloud/vps providers;
  2. Configure RFC2136 settings. This is for completing the dns-01 challenge for Let's Encrypt as we will be requesting for wildcard certificate;
  3. Configure the rest of config.yaml, then run the server -config config.yaml with your favorite manager (e.g. Systemd);
  4. Run t-client-${GOOS}-${GOARCH} tunnel -where tunnel.example.com -forward http://127.0.0.1:3000, and you should see a FQDN hostname ready to be used to tunnel HTTPS request to your apps running locally.

How to Use (Advanced)

NAME:
   client - t tunnel client for amd64 on linux

USAGE:
   client [global options] command [command options]

VERSION:
   dev

DESCRIPTION:
   like ngrok, but ambitious

COMMANDS:
   tunnel   Create a new tunnel to an application of your choosing
   connect  Proxy TCP connection through the tunnel via stdin/stdout
   forward  Listen for connections locally and forward them via the tunnel

GLOBAL OPTIONS:
   --debug        Enable verbose logging and disable TLS verification (default: false)
   --help, -h     show help (default: false)
   --version, -v  print the version (default: false)

COPYRIGHT:
   Rachel Chen (@zllovesuki), licensed under MIT.

How to Build

You will need Go 1.17+ for non-Android targets. Building for Android requires NDK and Go 1.16.x.

# building the server
CGO_ENABLED=0 go build -tags 'osusergo netgo' -ldflags '-s -w -extldflags "-static"' -a -o bin/server ./cmd/server

# building the client
CGO_ENABLED=0 go build -tags 'osusergo netgo' -ldflags '-s -w -extldflags "-static"' -a -o bin/client ./cmd/client

This will build static binary ready for distribution.

Bootstrapping your Tunnel Network

  1. Configure your config.yaml, firewall rules, peer certificates, etc, then use Let's Encrypt staging environment on one node and start the server.
  2. If it created a new account and requested a new certificate, your configuration is good to go!
  3. Remove the accounts.json and bundle.json, as they are for testing only.
  4. Change the Let's Encrypt dirctory to production, then start the first node again.
  5. Depending on your DNS, it may fail authorization for the initial tries. However, once the cert has issued successfully, you can now start up other nodes one by one.
  6. They will be synchronized on startup. The client and gateway now should see a valid certificate issued by Let's Encrypt.
  7. You can run just one node as well. Clustering is optional.

TODO

  1. Write the damn tests
  2. Make client command less painful to use now with -where auto discovery
  3. Multi-peer support from the client for HA. The plumbing is there to support it.
  4. Make leader determination and ACME management less painful

t's People

Contributors

zllovesuki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

t's Issues

Improve peer graph implementation

panic: runtime error: index out of range [3] with length 3

goroutine 513 [running]:
github.com/zllovesuki/t/state.(*PeerGraph).removePeer(0xc000376f30, 0x2a0df27b1d5ea54a)
        /home/runner/work/t/t/state/peer_graph.go:80 +0x378
github.com/zllovesuki/t/state.(*PeerGraph).RemovePeer(0xc000376f30, 0x2a0df27b1d5ea54a)
        /home/runner/work/t/t/state/peer_graph.go:70 +0x4e
github.com/zllovesuki/t/server.(*Server).removePeer(0xc000276a00, 0x2a0df27b1d5ea54a)
        /home/runner/work/t/t/server/peers.go:197 +0x185
github.com/zllovesuki/t/server.(*Server).handlePeerEvents.func4(0xc000276a00, {0xe66d28, 0xc0000f3ce0})
        /home/runner/work/t/t/server/peers.go:180 +0xfa
created by github.com/zllovesuki/t/server.(*Server).handlePeerEvents
        /home/runner/work/t/t/server/peers.go:176 +0x1be

Consider using a kv instead of spare matrix

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.