bsck

package module
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2018 License: GPL-3.0 Imports: 21 Imported by: 1

README

Bond Socket

bond socket provider a server/client channel like ssh tunneling, it can forward port between multi node.

Features

  • auto reconnect and keepalive betwenn client to server.
  • control forward by dynamic uri like node1->node2->tcp://xxxx:xx
  • port forward between multi node, it can be normal client -> bsck server -> normal server or normal client -> bsck server -> bsck slaver -> normal server or normal client -> bsck client -> bsck server -> bsck slaver -> normal server or ...
    • case1: ssh client -> bsck client -> bsck server -> ssh server for solving ssh connect lost frequently and ssh once to inner server.
    • case2: browser -> bsck client -> bsck server -> web server for browser to inner web server.
  • provider bash access on each node.
  • provider webdav access on each node.
  • provider remove execute command on each node.
  • provider balanced socks5 server that using node in bsck router as proxy server or multi upstream socks5 server.
  • provider gui to edit forward/channel configure.

Package Reference

  • bsck the main code to implement bond socket, it export all api to embedd bond socket in app.
  • dialer the main code to implement dial to raw socket or other useful feature like bash/webdav.
    • echo run an echo server, it always is using when using bs-ping command
    • cmd start comamnd on node and pipe standard i/o as bsck connect.
    • web start webdav server on node and pipe it as bsck connect.
    • tcp dial tcp connect to other server and pipe it as bsck connect.
  • bsrouter the app to start bond socket node, it run bsck server/client/slaver at the same time.
    • gui the gui app to start bond socket client, it can edit forward/channel.
  • bsconsole the agent app to make noraml app can using bond socket.

Install

Manual Install
  • install basic comamnd
go get github.com/sutils/bsck/bsrouter
go get github.com/sutils/bsck/bsconsole
  • install other command
cp -f $GOPATH/src/github.com/sutils/bsck/bsconsole/bs-ssh.sh $GOPATH/bin/bs-ssh
cp -f $GOPATH/src/github.com/sutils/bsck/bsconsole/bs-scp.sh $GOPATH/bin/bs-scp
cp -f $GOPATH/src/github.com/sutils/bsck/bsconsole/bs-sftp.sh $GOPATH/bin/bs-sftp
ln -sf $GOPATH/bin/bsconsole $GOPATH/bin/bs-ping
ln -sf $GOPATH/bin/bsconsole $GOPATH/bin/bs-state
ln -sf $GOPATH/bin/bsconsole $GOPATH/bin/bs-bash
ln -sf $GOPATH/bin/bsconsole $GOPATH/bin/bs-sh
Install from binary
  • download binary from releases
  • uncompress to xx
  • cd xx/bsrouter
  • ./bsrouter-install.sh -i -c for client or ./bsrouter-install.sh -i -s for service

Command Reference

  • bsrouter start bond socket server/client/slaver by configure, it will auto scan configure ordered by args,./.bsrouter.json",./bsrouter.json,HOME/.bsrouter/bsrouter.json,HOME/.bsrouter.json,/etc/bsrouter/bsrouter.json,/etc/bsrouer.json
  • bsconsole the node agent command, it will auto scan configure ordered like bsrouter
    • bsconsole 'node1->tcp://cmd?exec=bash' connect to node bash
    • bsconsole 'node1->tcp://cmd?exec=xxx' start xxx command on node1
    • bsconsole -win32 'node1->tcp://cmd?exec=cmd' start window cmd on node1
  • bs-bash <node router> connect to node bash, equal to bsconsole 'node1->tcp://cmd?exec=bash'
  • bs-sh <node router> connect to node sh, equal to bsconsole 'node1->tcp://cmd?exec=sh'
  • bs-ping <node router> ping to node
    • bs-ping node1 ping to node1
    • bs-ping node1->nodex ping to nodex by router node1->nodex
  • bs-state <node router> list node state
    • bs-state node1 list node1 state
    • bs-state node1->nodex list nodex state
  • bs-ssh <bsck uri> <ssh options> start ssh connect
    • bs-ssh 'node1->tcp://xxx:22' -lroot start connect ssh server which after node1
  • bs-sftp <bsck uri> <ssh options> start sftp connect
    • bs-sftp 'node1->tcp://xxx:22' -lroot start sftp to ssh server which after node1
  • bs-scp <bsck uri> <scp options> start scp connect
    • bs-scp 'node1->tcp://xxx:22' xxx root@bshost:/tmp/ copy xxx file to server after node1, the bshost will be auto repeaced.

Configure

configure file reference
  • name the node name

  • listen the node listen port.

  • cert,key the ssl cert

  • dialer the raw connect dialer configure.

    • std enable all standard dialer by 1, it container cmd,echo,web,tcp dialer. if only want enable some dialer, can be
    {
      "dialer": {
          "cmd": {
              "PS1": "xxx"
          },
          "echo":{
    
          }
      }
    }
    
  • acl the access control on bsck server

  • web listen web and websocket on address, it always is used by bsconsole

  • socks5 listen socks5 on address, it always is used by bsconsole or socks5 balance server.

bsck server
  • generate ssl cert by
openssl req -new -nodes -x509 -out "/etc/bsrouter/bsrouter.pem" -keyout "/etc/bsrouter/bsrouter.key" -days 3650 -subj "/C=CN/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=xxx/emailAddress=cert@xxxx"
  • edit configure on /etc/bsrouter/bsrouter.json
{
    "name": "server1",
    "listen": ":12023",
    "cert": "/etc/bsrouter/bsrouter.pem",
    "key": "/etc/bsrouter/bsrouter.key",
    "dialer": {
        "std": 1
    },
    "acl": {
        "slave1": "1111",
        "client1": "2222"
    },
    "showlog": 0,
    "logflags": 16
}
bsck slaver
  • generate ssl cert by
openssl req -new -nodes -x509 -out "/etc/bsrouter/bsrouter.pem" -keyout "/etc/bsrouter/bsrouter.key" -days 3650 -subj "/C=CN/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=xxx/emailAddress=cert@xxxx"
  • edit configure on /etc/bsrouter/bsrouter.json
{
    "name": "slave1",
    "cert": "/etc/bsrouter/bsrouter.pem",
    "key": "/etc/bsrouter/bsrouter.key",
    "dialer": {
        "std": 1
    },
    "channels": [
        {
            "enable": true,
            "token": "1111",
            "local": "",
            "remote": "xxx:12023",
            "index": 0
        }
    ],
    "showlog": 0,
    "logflags": 16
}
bsck client
  • generate ssl cert by
openssl req -new -nodes -x509 -out "$HOME/.bsrouter/bsrouter.pem" -keyout "$HOME/.bsrouter/bsrouter.key" -days 3650 -subj "/C=CN/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=xxx/emailAddress=cert@xxxx"
  • edit configure on $HOME/.bsrouter/bsrouter.json
{
    "name": "client1",
    "cert": "/xx/.bsrouter/bsrouter.pem",
    "key": "/xx/.bsrouter/bsrouter.key",
    "web": {
        "auth": "",
        "listen": ":12024",
        "suffix": ""
    },
    "channels": [
        {
            "enable": true,
            "token": "2222",
            "local": "",
            "remote": "xxx:12023",
            "index": 0
        }
    ],
    "showlog": 0,
    "logflags": 16
}
testing (optional)
  • bs-ping server1 test connect to server1 (optional)
bsconsole using config /xxx/.bsrouter/bsrouter.json
64 Bytes from server1->tcp://echo time=9.600463ms
64 Bytes from server1->tcp://echo time=5.248072ms
  • bs-ping 'server1->slaver1' test connect to slaver1 (optional)
bsconsole using config /xxx/.bsrouter/bsrouter.json
64 Bytes from server1->slaver1->tcp://echo time=11.600463ms
64 Bytes from server1->slaver1->tcp://echo time=12.248072ms
  • bs-state get client1 state when do ping (optional)
bsconsole using config /Users/vty/.bsrouter/bsrouter.json
[Channels]
 ->server1
   0    5   2018-10-24 11:30:33   channel{name:server1,index:0,cid:44,info:x.x.x.x:12023}


[Table]
 channel{name:server1,index:0,cid:44,info:x.x.x.x:12023} 52 <-> raw{uri:tcp://echo,router:server1->tcp://echo,info:ws://:12024} 52
  • bsconsole server1 start bash on server1 (optional)
bsconsole using config /xxx/.bsrouter/bsrouter.json
[bsrouter@xx ~]$
  • bs-ssh 'server1->slaver1->tcp://x.x.x.x:22' -lroot test connect to ssh server (optional)
configure port forward permanent
  • edit /xx/.bsrouter/bsrouter.json and add forwards configure.
{
    "name": "client1",
    "cert": "/xx/.bsrouter/bsrouter.pem",
    "key": "/xx/.bsrouter/bsrouter.key",
    "web": {
        "auth": "",
        "listen": ":12024",
        "suffix": ""
    },
    "channels": [
        {
            "enable": true,
            "token": "2222",
            "local": "",
            "remote": "xxx:12023",
            "index": 0
        }
    ],
    "forwards": {
        "test1~ws://": "server1->tcp://host1:22",
        "test1-1~tcp://localhost:10022": "server1->slaver1->tcp://host1:22",
        "test2~vnc://localhost": "server1->slaver1->tcp://host2:5900",
        "test2-1~tcp://localhost:15900": "server1->slaver1->tcp://host2:5900",
        "test3~rdp://localhost": "server1->slaver1->tcp://host3:3389"
        "test3-1~tcp://localhost:13389": "server1->slaver1->tcp://host3:3389"
        "test4~ws://": "server1->slaver1->tcp://cmd?exec=ping www.google.com"
    },
    "rdp_dir": "/tmp/bsrouter/",
    "vnc_dir": "/tmp/bsrouter/",
    "showlog": 0,
    "logflags": 16
}
  • in this case, bsck foward ssh/vnc/rdp

    • bs-ssh test1 -lroot to ssh connect host1
    • ssh -p 10022 localhost -lroot to ssh connect host1
    • connect host2 by vnc client: open vnc client then open test2.vnc file on /tmp/bsrouter/
    • connect host2 by vnc client: open vnc client then using localhost:15900 to connect
    • connect host3 by rdp client: open rdp client then open test3.rdp file on /tmp/bsrouter/
    • connect host3 by rdp client: open rdp client then using localhost:13389 to connect
    • bsconsole test4 execute ping on slaver1
  • more for forward configure, see Forward Reference

configure balance socks5 proxy
  • edit /xx/.bsrouter/bsrouter.json and add proxy configure.
{
    "name": "client1",
    "cert": "/xx/.bsrouter/bsrouter.pem",
    "key": "/xx/.bsrouter/bsrouter.key",
    "web": {
        "auth": "",
        "listen": ":12024",
        "suffix": ""
    },
    "socks5": ":11081",
    "channels": [
        {
            "enable": true,
            "token": "2222",
            "local": "",
            "remote": "xxx:12023",
            "index": 0
        }
    ],
    "proxy": {
        "id": "proxy",
        "type": "balance",
        "matcher": "^.*://.*$",
        "dialers": [
            {
                "id": "r1",
                "type": "router",
                "router": "server1->${URI}"
            },
            {
                "id": "r2",
                "type": "router",
                "router": "server1->slaver1->${URI}"
            },
            ,
            {
                "id": "r3",
                "type": "socks",
                "address": "xxx:xxx"
            }
        ],
        "filter": [
            {
                "matcher": "^.*x1.*$",
                "access": 1
            },
            {
                "matcher": "^.*x2.*$",
                "access": 1
            },
            {
                "matcher": "^.*$",
                "access": 0
            }
        ],
        "policy": [
            {
                "matcher": "^.*x1.*$",
                "limit": [
                    3000,
                    10
                ]
            },
            {
                "matcher": "^.*x2.*$",
                "limit": [
                    3000,
                    10
                ]
            }
        ]
    },
    "showlog": 0,
    "logflags": 16
}
  • in this case, havin two proxy dialer in two router server,slaver1 and one upstream proxy, only host contain x1,x2 can connect, and limit x1,x2 connect count by 10 time per 3000ms. this case is always used on crawler.

Dialer Reference

cmd
{
    "dialer": {
        "cmd": {
            "PS1": "bsrouter",
            "Dir": "/tmp",
            "Env":{
                "a": 1,
                "b": 2
            }
        }
    }
}
  • PS1 the shell ps1
  • Dir the start directroy
  • LC the i/o encoding.
  • Env the enviroment values
  • reuse_timeout the reuse session timeout.
echo
{
    "dialer": {
        "echo": {}
    }
}
socks
{
    "dialer": {
        "socks": {
            "id": "s1",
            "address": "xxx:xx",
            "matcher": "^.*$"
        }
    }
}
  • id the dialer id (required)
  • address the socks5 server address (required)
  • matcher match uri to access to connect. (optional)
web
{
    "dialer": {
        "web": {}
    }
}
tcp
{
    "dialer": {
        "tcp": {
            "bind": "xxxx:xx"
        }
    }
}
  • bind bind to local address before connect to remote.

Forward Reference

remote uri

the remote uri scheme is node1->node1->..->nodex->protocol://host:port?arg=val

supported protocol

  • tcp://host:port?arg=val normal tcp dialer, the arguments
    • bind bind to local address before connect to remote (optional)
  • tcp://cmd?arg=val execute command on node
    • exec the command and command argument to exec (required)
    • LC the i/o encoding
    • reuse enable/disable reuse session, 1 is enable, 0 is disable.
  • tcp://echo start echo server
  • http://web start web server on node
    • dir the webdav work directory.
local uri

the local uri scheme is alias~protocol://user:password@host:port, the alias can be used on bsconsole,bs-sftp,bs-scp,bs-ssh

supported protocol

  • alias~tcp://host:port listen tcp by host:port
  • alias~socks://host:port listen socks5 by host:port,
  • alias~rdp://user@host:port listen tcp by host:port, and generate rdp file on rdp_dir by alias.rdp, password is not supported by rdp file
  • alias~vnc://:passwrod@host:port listen tcp by host:port, and generate rdp file on vnc_dir by alias.vnc, user is not needed, password is encrypted
  • alias~web:// foward web by http://localhost:port/dav/alias to uri when web configure is enabled.
  • alias~ws:// foward websocekt by ws://localhost:port/ws/alias to uri when web configure is enabled.

GUI Reference

  • generate ssl cert by
openssl req -new -nodes -x509 -out "./bsrouter.pem" -keyout "./bsrouter.key" -days 3650 -subj "/C=CN/ST=NRW/L=Earth/O=Random Company/OU=IT/CN=xxx/emailAddress=cert@xxxx"
  • copy bsrouter.pem,bsrouter.key to ~/.bsrouter/

  • open GUI program and edit basic,channels,forwards

Documentation

Overview

Package bsck provider tcp socket proxy router

the supported router is client->(slaver->master->slaver)*-server,

the channel of slaver to master can be multi physical tcp connect by different router

Index

Constants

View Source
const (
	//CmdLogin is the command of login to master
	CmdLogin = 10
	//CmdLoginBack is the command of login return from master
	CmdLoginBack = 11
	//CmdDial is the command of tcp dial by router
	CmdDial = 100
	//CmdDialBack is the command of tcp dial back from master/slaver
	CmdDialBack = 101
	//CmdData is the command of transfter tcp data
	CmdData = 110
	//CmdClosed is the command of tcp closed.
	CmdClosed = 120
	//CmdHeartbeat is the command of heartbeat on slaver/master
	CmdHeartbeat = 130
)
View Source
const (
	//ConnTypeRaw is the type of raw connection
	ConnTypeRaw = 100
	//ConnTypeChannel is the type of channel connection
	ConnTypeChannel = 200
)
View Source
const (
	SocksUriTypeNormal = 0
	SocksUriTypeBS     = 1
)

Variables

Log is the bsck package default log

View Source
var ShowLog = 0

ShowLog will show more log.

Functions

func DebugLog

func DebugLog(format string, args ...interface{})

func ErrorLog

func ErrorLog(format string, args ...interface{})

func InfoLog

func InfoLog(format string, args ...interface{})

func WarnLog

func WarnLog(format string, args ...interface{})

Types

type AuthOption

type AuthOption struct {
	//the channel index
	Index int `json:"index"`
	//the chnnale name
	Name string `json:"name"`
	//the auth token
	Token string `json:"token"`
}

AuthOption is a pojo struct to login auth.

type BufferConn

type BufferConn struct {
	*bufio.Reader                    //the buffer reader.
	io.Writer                        //the writer.
	Raw           io.ReadWriteCloser //the raw connection
}

BufferConn is an implementation of buffer connecton

func NewBufferConn

func NewBufferConn(raw io.ReadWriteCloser, bufferSize int) (buf *BufferConn)

NewBufferConn will return new BufferConn

func (*BufferConn) Close

func (b *BufferConn) Close() (err error)

Close will close raw.

func (*BufferConn) String

func (b *BufferConn) String() string

type Channel

type Channel struct {
	io.ReadWriteCloser                //the raw connection
	Option             *ChannelOption //the option

	Heartbeat int64
	// contains filtered or unexported fields
}

Channel is an implementation of the Conn interface for channel network connections.

func (*Channel) ID

func (c *Channel) ID() uint64

ID is an implementation of Conn

func (*Channel) Index

func (c *Channel) Index() int

Index is an implementation of Conn

func (*Channel) Name

func (c *Channel) Name() string

Name is an implementation of Conn

func (*Channel) String

func (c *Channel) String() string

func (*Channel) Type

func (c *Channel) Type() int

Type is an implementation of Conn

type ChannelOption

type ChannelOption struct {
	//enable
	Enable bool `json:"enable"`
	//the auth token
	Token string `json:"token"`
	//local tcp address to connection master
	Local string `json:"local"`
	//the remote address to login
	Remote string `json:"remote"`
	//the channel index
	Index int `json:"index"`
}

ChannelOption is a pojo struct for adding channel to Router

type CmdReader

type CmdReader interface {
	ReadCmd(b []byte) (n uint32, err error)
}

CmdReader is the interface that wraps the basic ReadCmd method.

ReadCmd will read one command to b buffer, return the command length

the command mode is length(4 byte)|data

type Codable

type Codable interface {
	Code() byte
}

Codable is interface for get current code

type Conn

type Conn interface {
	//the basic ReadWriteCloser
	io.ReadWriteCloser
	//the connection id
	ID() uint64
	//the channel name
	Name() string
	//the channel index.
	Index() int
	//the connection type
	Type() int
}

Conn is the interface that wraps the connection will be running on Router.

ID is the unique of connection

Name is the channel name, it will be used when join current connection to channel

Index is the channel index, it will be used when join current connection to channel.

Type is the connection type by ConnTypeRaw/ConnTypeChannel

type ConnectedWaiter

type ConnectedWaiter interface {
	Wait() bool
	Ready()
}

type DialRawF

type DialRawF func(sid uint64, uri string) (raw Conn, err error)

DialRawF is a function type to dial raw connection.

func (DialRawF) DialRaw

func (d DialRawF) DialRaw(sid uint64, uri string) (raw Conn, err error)

DialRaw will dial raw connection

func (DialRawF) OnConnClose

func (d DialRawF) OnConnClose(conn Conn) error

OnConnClose will be called when connection is closed

type Forward

type Forward struct {
	WebSuffix string
	WebAuth   string
	Dialer    func(uri string, raw io.ReadWriteCloser) (sid uint64, err error)
	// contains filtered or unexported fields
}

func NewForward

func NewForward() *Forward

func (*Forward) AddForward

func (f *Forward) AddForward(loc, uri string) (err error)

AddForward by local uri and remote uri

func (*Forward) FindForward

func (f *Forward) FindForward(name string) (uri ForwardUri)

FindForward will return the forward

func (*Forward) HostForwardF

func (f *Forward) HostForwardF(w http.ResponseWriter, req *http.Request)

func (*Forward) ProcName

func (f *Forward) ProcName(name string, w http.ResponseWriter, req *http.Request)

func (*Forward) ProcRouter

func (f *Forward) ProcRouter(router ForwardUri, w http.ResponseWriter, req *http.Request)

func (*Forward) ProcWebSubsH

func (f *Forward) ProcWebSubsH(w http.ResponseWriter, req *http.Request)

func (*Forward) RemoveForward

func (f *Forward) RemoveForward(name string) (err error)

RemoveForward by alias name

type ForwardEntry

type ForwardEntry []interface{}

ForwardEntry is the forward entry

type ForwardUri

type ForwardUri []string

func (ForwardUri) String

func (f ForwardUri) String() string

func (ForwardUri) URL

func (f ForwardUri) URL() (local *url.URL, remote *url.URL, err error)

type InfoRWC

type InfoRWC struct {
	io.ReadWriteCloser
	Info string
}

InfoRWC is external ReadWriteCloser to get info to String

func NewInfoRWC

func NewInfoRWC(raw io.ReadWriteCloser, info string) *InfoRWC

NewInfoRWC will return new nfoRWC

func (*InfoRWC) String

func (i *InfoRWC) String() string

type PendingConn

type PendingConn struct {
	Raw io.ReadWriteCloser
	// contains filtered or unexported fields
}

PendingConn is an implementation of io.ReadWriteCloser

func NewPendingConn

func NewPendingConn(raw io.ReadWriteCloser) (conn *PendingConn)

NewPendingConn will return new endingConn

func (*PendingConn) Close

func (p *PendingConn) Close() (err error)

Close pending connection.

func (*PendingConn) Read

func (p *PendingConn) Read(b []byte) (n int, err error)

func (*PendingConn) Start

func (p *PendingConn) Start()

Start pending connection

func (*PendingConn) Write

func (p *PendingConn) Write(b []byte) (n int, err error)

type Proxy

type Proxy struct {
	*Router                      //the router
	Running        bool          //proxy is running.
	ReconnectDelay time.Duration //reconnect delay
	Cert           string        //the tls cert
	Key            string        //the tls key

	Handler RouterHandler
	// contains filtered or unexported fields
}

Proxy is an implementation of proxy router

func NewProxy

func NewProxy(name string) (proxy *Proxy)

NewProxy will return new Proxy by name

func (*Proxy) Close

func (p *Proxy) Close() (err error)

Close will close the tcp listen

func (*Proxy) DialRaw

func (p *Proxy) DialRaw(sid uint64, uri string) (raw Conn, err error)

DialRaw will dial raw connection

func (*Proxy) ListenMaster

func (p *Proxy) ListenMaster(addr string) (err error)

ListenMaster will listen master router on address

func (*Proxy) Login

func (p *Proxy) Login(option *ChannelOption) (err error)

Login will add channel by local address, master address, auth token, channel index.

func (*Proxy) LoginChannel

func (p *Proxy) LoginChannel(reconnect bool, channels ...*ChannelOption) (err error)

LoginChannel will login all channel by options.

func (*Proxy) OnConnClose

func (p *Proxy) OnConnClose(conn Conn) error

OnConnClose will be called when connection is closed

func (*Proxy) StartForward

func (p *Proxy) StartForward(name string, listen *url.URL, router string) (listener net.Listener, err error)

StartForward will forward address to uri

func (*Proxy) StopForward

func (p *Proxy) StopForward(name string) (err error)

StopForward will forward address to uri

type RawConn

type RawConn struct {
	//the raw connection
	Raw io.ReadWriteCloser
	// contains filtered or unexported fields
}

RawConn is an implementation of the Conn interface for raw network connections.

func NewRawConn

func NewRawConn(raw io.ReadWriteCloser, sid uint64, uri string) (conn *RawConn)

NewRawConn returns a new RawConn by raw connection/session id/uri

func (*RawConn) Close

func (r *RawConn) Close() (err error)

Close will close the raw connection

func (*RawConn) ID

func (r *RawConn) ID() uint64

ID is an implementation of Conn

func (*RawConn) Index

func (r *RawConn) Index() int

Index is an implementation of Conn

func (*RawConn) Name

func (r *RawConn) Name() string

Name is an implementation of Conn

func (*RawConn) Read

func (r *RawConn) Read(b []byte) (n int, err error)

func (*RawConn) ReadCmd

func (r *RawConn) ReadCmd(b []byte) (n uint32, err error)

ReadCmd is an implementation of CmdReader

func (*RawConn) Ready

func (r *RawConn) Ready()

func (*RawConn) String

func (r *RawConn) String() string

func (*RawConn) Type

func (r *RawConn) Type() int

Type is an implementation of Conn

func (*RawConn) Wait

func (r *RawConn) Wait() bool

func (*RawConn) Write

func (r *RawConn) Write(p []byte) (n int, err error)

type Router

type Router struct {
	Name       string            //current router name
	BufferSize uint32            //buffer size of connection runner
	ACL        map[string]string //the access control
	Heartbeat  time.Duration     //the delay of heartbeat
	Handler    RouterHandler     //the router handler
	// contains filtered or unexported fields
}

Router is an implementation of the router control

func NewRouter

func NewRouter(name string) (router *Router)

NewRouter will return new Router by name

func (*Router) Accept

func (r *Router) Accept(raw io.ReadWriteCloser)

Accept one raw connecton as channel, it will auth the raw connecton by ACL.

func (*Router) Bind

func (r *Router) Bind(src Conn, srcSid uint64, dst Conn, dstSid uint64)

Bind one raw connection to channel by session.

func (*Router) Close

func (r *Router) Close() (err error)

Close all channel

func (*Router) Dial

func (r *Router) Dial(uri string, raw io.ReadWriteCloser) (sid uint64, err error)

Dial to remote by uri and bind channel to raw connection.

return the session id

func (*Router) DialConn

func (r *Router) DialConn(uri string, raw io.ReadWriteCloser) (sid uint64, conn *RawConn, err error)

func (*Router) JoinConn

func (r *Router) JoinConn(conn io.ReadWriteCloser, option *ChannelOption) (err error)

JoinConn will add channel by the connected connection, auth token, channel index

func (*Router) Register

func (r *Router) Register(channel Conn)

Register one logined raw connecton to channel,

func (*Router) SelectChannel

func (r *Router) SelectChannel(name string) (dst Conn, err error)

SelectChannel will pick one channel by name.

func (*Router) StartHeartbeat

func (r *Router) StartHeartbeat()

StartHeartbeat will start the hearbeat on slaver/master

func (*Router) State

func (r *Router) State() (state util.Map)

State return the current state of router

func (*Router) SyncDial

func (r *Router) SyncDial(uri string, raw io.ReadWriteCloser) (sid uint64, err error)

func (*Router) UniqueSid

func (r *Router) UniqueSid() (sid uint64)

UniqueSid will return new session id

type RouterHandler

type RouterHandler interface {
	//dial raw connection
	DialRaw(sid uint64, uri string) (raw Conn, err error)
	//on connection close
	OnConnClose(conn Conn) error
}

RouterHandler is the interface that wraps the handler of Router.

type SocksProxy

type SocksProxy struct {
	net.Listener
	Dialer func(utype int, uri string, raw io.ReadWriteCloser) (sid uint64, err error)
}

SocksProxy is an implementation of socks5 proxy

func NewSocksProxy

func NewSocksProxy() (socks *SocksProxy)

NewSocksProxy will return new SocksProxy

func (*SocksProxy) Start

func (s *SocksProxy) Start(addr string) (err error)

Start proxy listener

type TableRouter

type TableRouter []interface{}

TableRouter is the router table item

func (TableRouter) Next

func (t TableRouter) Next(conn Conn) (target Conn, rsid uint64)

Next will return next connection and session id

func (TableRouter) String

func (t TableRouter) String() string

type WaitReadWriteCloser

type WaitReadWriteCloser struct {
	io.ReadWriteCloser
	// contains filtered or unexported fields
}

func NewWaitReadWriteCloser

func NewWaitReadWriteCloser(raw io.ReadWriteCloser) *WaitReadWriteCloser

func (*WaitReadWriteCloser) Close

func (w *WaitReadWriteCloser) Close() (err error)

func (*WaitReadWriteCloser) String

func (w *WaitReadWriteCloser) String() string

func (*WaitReadWriteCloser) Wait

func (w *WaitReadWriteCloser) Wait()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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