tunnel_pool

package
v1.0.8-0...-ea572ad Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2020 License: AGPL-3.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrorWaitSec          = 3  // If a tunnel cannot be dialed, will wait for this period and retry infinitely
	TunnelBlockTimeoutSec = 8  // If a tunnel cannot send a block within the limit, will treat it a dead tunnel
	EmptyPoolDestroySec   = 60 // The pool will be destroyed(server side) if no tunnel dialed in
	SendQueueSize         = 48 // SendQueue channel cap
	RecvQueueSize         = 48 // RecvQueue channel cap
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientManager

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

func NewClientManager

func NewClientManager(tunnelNum int, endpoint string, peerID uint32, cipher tunnel.Cipher) ClientManager

func (*ClientManager) DecreaseNotify

func (cm *ClientManager) DecreaseNotify(pool *TunnelPool)

Keep tunnelPool size above tunnelNum

func (*ClientManager) Notify

func (cm *ClientManager) Notify(pool *TunnelPool)

type Manager

type Manager interface {
	Notify(pool *TunnelPool)         // When TunnelPool size changed, Notify should be called
	DecreaseNotify(pool *TunnelPool) // When TunnelPool size decreased, DecreaseNotify should be called
}

type ServerManager

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

func NewServerManager

func NewServerManager(removePeerFunc context.CancelFunc) ServerManager

func (*ServerManager) DecreaseNotify

func (sm *ServerManager) DecreaseNotify(pool *TunnelPool)

func (*ServerManager) Notify

func (sm *ServerManager) Notify(pool *TunnelPool)

If tunnelPool size is zero for more than EmptyPoolDestroySec, delete it

type Tunnel

type Tunnel struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewActiveTunnel

func NewActiveTunnel(conn net.Conn, ciph tunnel.Cipher, peerID uint32) (Tunnel, error)

Create a new tunnel from a net.Conn and cipher with random tunnelID

func NewPassiveTunnel

func NewPassiveTunnel(conn net.Conn, ciph tunnel.Cipher) (Tunnel, error)

func (*Tunnel) GetPeerID

func (tunnel *Tunnel) GetPeerID() uint32

func (*Tunnel) InboundRelay

func (tunnel *Tunnel) InboundRelay(output chan<- block.Block)

Read bytes from connection, parse it to block then put in recv channel

func (*Tunnel) OutboundRelay

func (tunnel *Tunnel) OutboundRelay(normalQueue, retryQueue chan block.Block)

Read block from send channel, pack it and send

type TunnelPool

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

func NewTunnelPool

func NewTunnelPool(peerID uint32, manager Manager, peerContext context.Context) *TunnelPool

func (*TunnelPool) AddTunnel

func (tp *TunnelPool) AddTunnel(tunnel *Tunnel)

Add a tunnel to tunnelPool and start bi-relay

func (*TunnelPool) GetRecvQueue

func (tp *TunnelPool) GetRecvQueue() chan block.Block

func (*TunnelPool) GetSendQueue

func (tp *TunnelPool) GetSendQueue() chan block.Block

func (*TunnelPool) RemoveTunnel

func (tp *TunnelPool) RemoveTunnel(tunnel *Tunnel)

Remove a tunnel from tunnelPool and stop bi-relay

Jump to

Keyboard shortcuts

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