Giter VIP home page Giter VIP logo

depot's Introduction

depot

Proxy program using socks5 to create tunnel between client application and your internal net host. For example, it's useful for connecting the transmission on your host NAS by transmission-remote-gui on anywhere, as shown below:

--- client ---+------- server -------+------- local ------------------

client <--[socks5]--> depot-server <---> depot-local <--[localhost]--> app

Once the socks connection is established, the reqeust of client must be sent to address 127.0.0.1:port via this connection and it will be transferred to app eventually. It seems client is communicating with app directly.

Features

  • Web interface to wathch status of connections.
  • Socks5 connection (username/no-username)

Internal

connections

  • control connection
    • connect server and local
    • send socks request from server to local
    • send alive message from local to server
  • socks connection
    • connect client and server
    • send socks request from client to server
    • for pipe
  • tunnel connection
    • connect server and local
    • for pipe
  • app connection
    • connect local and app
    • for pipe

process

  1. Server listens on the control port and socks port.
   +---+
   | C |
   +---+
   +---+
   | S |
   +---+
  1. Local connects to the control port, and establish a control connection by handshaking. Local will wait for socks request on this connection. l->c: "hello server" c->l: "hello local"
   +---+
   | C |
   +---+
      +-+      handshake      +-+
      |c|<------------------->|l|
      +-+      [ctrlConn]     +-+
   +---+
   | S |
   +---+
  1. Server listens on the tunnel port, and waits for socks request.
   +---+
   | C |
   +---+
      +-+                     +-+
      |c|<------------------->|l|
      +-+      [ctrlConn]     +-+
   +---+
   | S |
   +---+
   +---+
   | T |
   +---+
  1. Client connects to the socks port and establish an socks connection after handshaking and authenticating.
                           +---+
                           | C |
                           +---+
                              +-+                     +-+
                              |c|<------------------->|l|
                              +-+      [ctrlConn]     +-+
                           +---+
                           | S |
                           +---+
    +-+  handshake/auth   +-+
    |r|<----------------->|s|
    +-+   [socksConn]     +-+
                           +---+
                           | T |
                           +---+
  1. Client sends the socks request to server. Server validates the request and send it to local via control connection.
                           +---+
                           | C |
                           +---+
                              +-+   2.socks request   +-+
                              |c|<------------------->|l|
                              +-+     [ctrlConn]      +-+
                           +---+
                           | S |
                           +---+
    +-+  1.socks request  +-+
    |r|<----------------->|s|
    +-+   [socksConn]     +-+
                           +---+
                           | T |
                           +---+
  1. Local parses the socks request and open an app connection to the target host:port (i.e. app). After that, local sends success reply to server, and server sends reply to client.
                           +---+
                           | C |
                           +---+
                              +-+     2.reply         +-+
                              |c|<------------------->|l|
                              +-+     [ctrlConn]      +-+
                           +---+                      +-+   1.connect   +-+
                           | S |                      |b|<------------->|a|
                           +---+                      +-+   [appConn]   +-+
    +-+    3.reply        +-+
    |r|<----------------->|s|
    +-+   [socksConn]     +-+
                           +---+
                           | T |
                           +---+
  1. Local connects to the tunnel port of server and establishs the tunnel connection by sending the socks request back as a handshake.
                           +---+
                           | C |
                           +---+
                              +-+                     +-+
                              |c|<------------------->|l|
                              +-+     [ctrlConn]      +-+
                           +---+                      +-+               +-+
                           | S |                      |b|<------------->|a|
                           +---+                      +-+   [appConn]   +-+
    +-+                   +-+
    |r|<----------------->|s|
    +-+   [socksConn]     +-+
                           +---+
                           | T |
                           +---+
						      +-+  connect/handshake  +-+
							  |t|<------------------->|d|
						      +-+     [tunnelConn]    +-+
  1. At this time, all necessary connetions are already established. Pipe them together (s&t, d&b) and the connection between client and app will work well. Client can communicate with app with socket r.
                           +---+
                           | C |
                           +---+
                              +-+       alive         +-+
                              |c|<------------------->|l|
                              +-+      [ctrlConn]     +-+
                           +---+                        
                           | S |                        
                           +---+                        
    +-+                   +-+ +-+                   +-+ +-+                +-+
    |r|<----------------->|s|-|t|<----------------->|d|-|b|<-------------->|a|
    +-+   [socksConn]     +-+ +-+     [tunnelConn]  +-+ +-+    [appConn]   +-+
                           +---+
                           | T |
                           +---+

The final pipeline is:

         socksConn <--> tunnelConn <--> appConn

The ctrlConn is used by local to send alive message. And once local exits, this connection would be closed. In the other hand, once server exits, local should close all connections and try to connect to control port of server again and again.

TODO

  • local should try to connect to server repeatly and send heartbeat message to server after connecting.
  • provide methods to watch the status of server and local.
  • how to handle multiple socks reqeusts?

License

See the LICENSE file.

depot's People

Contributors

choueric avatar

Watchers

 avatar James Cloos avatar

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.