hole

package module
v0.0.0-...-c2ab390 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2017 License: MIT Imports: 15 Imported by: 4

README

A hole to pass through the gateway.

Build Status

When I visit raspberry pi' ssh server on some places, I must set port forwarding on the home route, and set a dynamic DNS. If the route is not your's, you will helpless.

I think it may have another way, so I try ssh port forwarding ssh -CfNgR remote-port:localhost:local-port user@remote, then visit the remote-port.

The hole is an other way similar ssh port forwarding. On the global server create a holed, and the target host start hole. Last you can visit the holed to replace the real server.

The hole suit the situation: A(private) can connect B(global), C(private) can connect B, but B can't connect C, B can't connect A, and A can't connect C.

The hole support protocol tcp tcp6 and unix socket.

Install

go get -v github.com/Lupino/hole/cmd/holed
go get -v github.com/Lupino/hole/cmd/hole

Quick start

# Start on B
holed -addr=tcp://B-IP:B-PORT
# Start on C
hole -addr=tcp://B-IP:B-PORT -src=tcp://localhost:C-PORT
# On A just vist tcp://B-IP:B-PORT to replace visit C server

Example:

# A IP is 192.168.1.101
# B IP is 120.26.120.168
# C IP is 172.17.3.10

# Now on B server
holed -addr=tcp://120.26.120.168:4000

# On C server
hole -addr=tcp://120.26.120.168:4000 -src=tcp://127.0.0.1:22

# On A server
ssh root@120.26.120.168 -p 4000

# Now A can visit C via B server

Connect with tls

go get -v github.com/Lupino/hole/cmd/hole-keys
hole-keys
holed -use-tls
hole -use-tls

Documentation

Overview

Package hole : A hole to pass through the gateway.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMagicNotMatch raise when the magic is no match.
	ErrMagicNotMatch = errors.New("Magic not match.")
	// MagicRequest a request magic.
	MagicRequest = []byte("\x00REQ")
	// MagicResponse a response magic.
	MagicResponse = []byte("\x00RES")
)
View Source
var NullChar = []byte("\x00\x01")

Split the message payload

Functions

func DecodePacket

func DecodePacket(payload []byte) (sessionID, data []byte)

DecodePacket decode the data and sessionID from a packet.

func EncodePacket

func EncodePacket(sessionID, data []byte) []byte

EncodePacket encode the data with sessionID.

func MakeHeader

func MakeHeader(data []byte) ([]byte, error)

MakeHeader make a very simple 4 bytes header.

func ParseHeader

func ParseHeader(header []byte) uint32

ParseHeader parse a very simple 4 bytes header and extract the data length.

func PipeThenClose

func PipeThenClose(src io.Reader, dst io.WriteCloser)

PipeThenClose copies data from src to dst, closes dst when done.

Types

type Client

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

Client define a client.

func NewClient

func NewClient(subAddr string) *Client

NewClient create a new client.

func (*Client) ConfigTLS

func (client *Client) ConfigTLS(certFile, privFile string)

ConfigTLS config the client.

func (*Client) Connect

func (client *Client) Connect(addr string) (err error)

Connect connent to hole server.

func (*Client) NewSession

func (client *Client) NewSession(sessionID []byte) Session

NewSession create a session.

func (*Client) Process

func (client *Client) Process()

Process the client.

type Conn

type Conn struct {
	net.Conn
	RequestMagic  []byte
	ResponseMagic []byte
	// contains filtered or unexported fields
}

Conn a custom connect

func NewClientConn

func NewClientConn(conn net.Conn) Conn

NewClientConn create a client connection

func NewConn

func NewConn(conn net.Conn, reqMagic, resMagic []byte) Conn

NewConn create a connection

func NewServerConn

func NewServerConn(conn net.Conn) Conn

NewServerConn create a server connection

func (*Conn) Receive

func (conn *Conn) Receive() (rdata []byte, rerr error)

Receive waits for a new message on conn, and receives its payload.

func (*Conn) Send

func (conn *Conn) Send(data []byte) error

Send a new message.

type ReadStream

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

ReadStream define the base read stream.

func NewReadStream

func NewReadStream() *ReadStream

NewReadStream create a read strean

func (*ReadStream) FeedData

func (r *ReadStream) FeedData(buf []byte)

FeedData feed buffer from a socket or other.

func (*ReadStream) FeedEOF

func (r *ReadStream) FeedEOF()

FeedEOF feed eof when the stream is closed.

func (*ReadStream) Read

func (r *ReadStream) Read(buf []byte) (length int, err error)

type Server

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

Server define a server type.

func NewServer

func NewServer() *Server

NewServer create a new server.

func (*Server) AssignClient

func (server *Server) AssignClient(conn net.Conn) bool

AssignClient assign a client connection.

func (*Server) ConfigTLS

func (server *Server) ConfigTLS(certFile, privFile string)

ConfigTLS config tls for server

func (*Server) Serve

func (server *Server) Serve(addr string)

Serve on an address. The network net must be a stream-oriented network: "tcp", "tcp4", "tcp6", "unix" or "unixpacket".

type Session

type Session struct {
	ID []byte
	// contains filtered or unexported fields
}

Session define session.

func NewSession

func NewSession(sessionID []byte, conn Conn) Session

NewSession create a new session with sessionID and conn.

type WriteStream

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

WriteStream define the base write stream.

func (*WriteStream) Close

func (w *WriteStream) Close() error

Close the write stream.

func (*WriteStream) Write

func (w *WriteStream) Write(data []byte) (n int, err error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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