dtunnel

package module
v0.0.0-...-87abdd7 Latest Latest
Warning

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

Go to latest
Published: May 25, 2014 License: GPL-3.0 Imports: 18 Imported by: 0

README

diff-tunnel

diff-tunnel

Documentation

Index

Constants

View Source
const (
	MAX_CACHE_SIZE int = 5 * 1024 * 1024
	MAX_BUFF_SIZE  int = 500 * 1024
)
View Source
const (
	INVALID uint16 = 0

	TCP_CONNECT     uint16 = 1
	TCP_CONNECT_REP uint16 = 2
	TCP_DATA        uint16 = 3

	HTTP_CONNECT uint16 = 11
	HTTP_DATA    uint16 = 12

	CACHE_SHARE uint16 = 21

	//CACHE_SHARE uint16 = 51
	ERROR uint16 = 255
)
View Source
const (
	FLAG_TCP          uint16 = 1
	FLAG_UDP          uint16 = 2
	FLAG_HTTP         uint16 = 4
	FLAG_STREAM_BEGIN uint16 = 8
	FLAG_STREAM_END   uint16 = 16
)
View Source
const (
	CT_RAW        uint16 = 0
	CT_CACHE_DIFF uint16 = 1
)
View Source
const (
	HEADER_SIZE = 18
)
View Source
const (
	VERSION_1 uint8 = 1
)

Variables

View Source
var CT_NAMES map[uint16]string = map[uint16]string{
	CT_RAW:        "CT_RAW",
	CT_CACHE_DIFF: "CT_CACHE_DIFF",
}
View Source
var ErrorCompressFail = errors.New("CompressFail")
View Source
var ErrorDecompressFail = errors.New("DecompressFail")
View Source
var FLAG_NAMES map[uint16]string = map[uint16]string{
	FLAG_TCP:          "FLAG_TCP",
	FLAG_UDP:          "FLAG_UDP",
	FLAG_HTTP:         "FLAG_HTTP",
	FLAG_STREAM_BEGIN: "FLAG_STREAM_BEGIN",
	FLAG_STREAM_END:   "FLAG_STREAM_END",
}
View Source
var InvalidBody error = errors.New("Invalid Body")
View Source
var InvalidFrameCount error = errors.New("Invalid Frame Count")
View Source
var InvalidHeader error = errors.New("Invalid Header")
View Source
var TYPE_NAMES map[uint16]string = map[uint16]string{
	TCP_CONNECT:     "TCP_CONNECT",
	TCP_CONNECT_REP: "TCP_CONNECT_REP",
	TCP_DATA:        "TCP_DATA",
	CACHE_SHARE:     "CACHE_SHARE",
	ERROR:           "ERROR",
}

Functions

func MakeDiff

func MakeDiff(old []byte, new_ []byte) []byte

func NewCacheCompressorWriter

func NewCacheCompressorWriter(writer io.Writer, cache Cache, cacheKey []byte, cacheDigest []byte, update bool) io.WriteCloser

func Patch

func Patch(old []byte, patch []byte) []byte

Types

type Body

type Body interface {
	encoding.BinaryMarshaler
	encoding.BinaryUnmarshaler
	String() string
}

type Cache

type Cache interface {
	Set(key []byte, value []byte) error
	Get(key []byte) ([]byte, bool)
	GetDigest(key []byte) ([]byte, bool)
	Del(key []byte) bool
	Digest(data []byte) []byte
}

type CacheCompressor

type CacheCompressor struct {
	*CacheCompressorWriter
	// contains filtered or unexported fields
}

func (*CacheCompressor) Bytes

func (c *CacheCompressor) Bytes() []byte

func (*CacheCompressor) WriteTo

func (c *CacheCompressor) WriteTo(w io.Writer) (n int64, err error)

type CacheCompressorWriter

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

func (*CacheCompressorWriter) Close

func (c *CacheCompressorWriter) Close() error

func (*CacheCompressorWriter) Flush

func (c *CacheCompressorWriter) Flush() error

func (*CacheCompressorWriter) Write

func (c *CacheCompressorWriter) Write(b []byte) (n int, err error)

type CacheItem

type CacheItem struct {
	CacheKey []byte
	Digest   []byte
}

type CacheManager

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

func (*CacheManager) GetPeer

func (cm *CacheManager) GetPeer(pid string) (peer *PeerCache, ok bool)

func (*CacheManager) GetPeerDigest

func (cm *CacheManager) GetPeerDigest(pid string, key []byte) (digest []byte, ok bool)

func (*CacheManager) UpdatePeer

func (cm *CacheManager) UpdatePeer(pid string, item *CacheItem) error

type CacheShareData

type CacheShareData struct {
	Payload []CacheItem
}

func (*CacheShareData) MarshalBinary

func (d *CacheShareData) MarshalBinary() (b []byte, err error)

func (*CacheShareData) String

func (d *CacheShareData) String() string

func (*CacheShareData) UnmarshalBinary

func (d *CacheShareData) UnmarshalBinary(b []byte) (err error)

type CacheWorker

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

func NewCacheWorker

func NewCacheWorker(cm *CacheManager) *CacheWorker

func (*CacheWorker) GetReqChannel

func (w *CacheWorker) GetReqChannel() chan *Msg

func (*CacheWorker) Run

func (w *CacheWorker) Run(repChan chan *Msg) error

type CachedTunnelReader

type CachedTunnelReader struct {
	*TunnelReader
	// contains filtered or unexported fields
}

func (*CachedTunnelReader) Close

func (c *CachedTunnelReader) Close() error

func (*CachedTunnelReader) Read

func (c *CachedTunnelReader) Read(b []byte) (n int, err error)

type CachedTunnelWriter

type CachedTunnelWriter struct {
	*TunnelWriter
	// contains filtered or unexported fields
}

A CachedTunnelWriter will cache the data, send them with one msg when close

func NewCachedTunnelWriter

func NewCachedTunnelWriter(w *TunnelWriter, comp Compressor) *CachedTunnelWriter

func (*CachedTunnelWriter) Close

func (c *CachedTunnelWriter) Close() (err error)

func (*CachedTunnelWriter) Write

func (c *CachedTunnelWriter) Write(b []byte) (n int, err error)

type Compressor

type Compressor interface {
	CompressorWriter
	Bytes() []byte
	WriteTo(w io.Writer) (int64, error)
}

func NewCacheCompressor

func NewCacheCompressor(cache Cache, cacheKey []byte, cacheDigest []byte, update bool) Compressor

type CompressorWriter

type CompressorWriter interface {
	io.WriteCloser
}

type DiffContent

type DiffContent struct {
	CacheKey []byte
	PatchTo  []byte
	Diff     []byte
}

type ErrorData

type ErrorData struct {
	ContentType uint16
	Payload     []byte
}

func (*ErrorData) MarshalBinary

func (d *ErrorData) MarshalBinary() (b []byte, err error)

func (*ErrorData) String

func (d *ErrorData) String() string

func (*ErrorData) UnmarshalBinary

func (d *ErrorData) UnmarshalBinary(b []byte) (err error)
type Header struct {
	Version  uint8
	StreamId UID
	MsgType  uint16
	Flag     uint16
	Reserved uint8
}

20 bytes

func (*Header) AddFlag

func (h *Header) AddFlag(flag uint16)

func (*Header) GetStreamId

func (h *Header) GetStreamId() UID

func (*Header) IsEndOfStream

func (h *Header) IsEndOfStream() bool

func (*Header) MarshalBinary

func (h *Header) MarshalBinary() ([]byte, error)

func (*Header) SetFlag

func (h *Header) SetFlag(flag uint16)

func (*Header) SetStreamId

func (h *Header) SetStreamId(sid UID)

func (*Header) TestFlag

func (h *Header) TestFlag(flag uint16) bool

func (*Header) UnmarshalBinary

func (h *Header) UnmarshalBinary(data []byte) error

type HttpProxyServer

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

func NewHttpProxyServer

func NewHttpProxyServer(tc *TunnelClient) *HttpProxyServer

func (*HttpProxyServer) ListenAndServe

func (s *HttpProxyServer) ListenAndServe(bind string) error

func (*HttpProxyServer) ServeHTTP

func (s *HttpProxyServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HttpTransport

type HttpTransport interface {
	RoundTrip(r *http.Request) (io.ReadCloser, error)
}

type HttpWorker

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

func (*HttpWorker) GetReqChannel

func (w *HttpWorker) GetReqChannel() chan *Msg

func (*HttpWorker) Run

func (w *HttpWorker) Run(repChan chan *Msg) error

type HttpWorkerFactory

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

func (*HttpWorkerFactory) MakeStreamWorker

func (s *HttpWorkerFactory) MakeStreamWorker(sid UID) Worker

type LocalCache

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

func (*LocalCache) Del

func (c *LocalCache) Del(key []byte) bool

func (*LocalCache) Digest

func (c *LocalCache) Digest(data []byte) []byte

func (*LocalCache) Get

func (c *LocalCache) Get(key []byte) (value []byte, ok bool)

func (*LocalCache) GetDigest

func (c *LocalCache) GetDigest(key []byte) (digest []byte, ok bool)

func (*LocalCache) Set

func (c *LocalCache) Set(key []byte, value []byte) error

type Msg

type Msg struct {
	Envelope [][]byte
	*Header
	Body
}

func (*Msg) GetFlagNames

func (m *Msg) GetFlagNames() []string

func (*Msg) GetMsgType

func (m *Msg) GetMsgType() uint16

func (*Msg) GetMsgTypeName

func (m *Msg) GetMsgTypeName() string

func (*Msg) String

func (m *Msg) String() string

type MsgBuilder

type MsgBuilder interface {
	MakeMsg(mt uint16, ct uint16, data []byte, flags uint16) *Msg
	MakeErrorMsg(err error, flags uint16) *Msg
}

func NewMsgBuilder

func NewMsgBuilder(sid UID, envelope [][]byte, flags uint16) MsgBuilder

func NewMsgBuilderFromMsg

func NewMsgBuilderFromMsg(tpl *Msg) MsgBuilder

type MultiStreamWorker

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

func (*MultiStreamWorker) GetReqChannel

func (w *MultiStreamWorker) GetReqChannel() chan *Msg

func (*MultiStreamWorker) Run

func (w *MultiStreamWorker) Run(repChan chan *Msg) error

type PeerCache

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

handle cache update

func (*PeerCache) Get

func (rc *PeerCache) Get(key []byte) (digest []byte, ok bool)

func (*PeerCache) Set

func (rc *PeerCache) Set(key []byte, digest []byte) error

type StreamWorkerMaker

type StreamWorkerMaker interface {
	MakeStreamWorker(sid UID) Worker
}

type TcpData

type TcpData struct {
	ContentType uint16
	Payload     []byte
}

func (*TcpData) GetPayload

func (td *TcpData) GetPayload() []byte

func (*TcpData) MarshalBinary

func (td *TcpData) MarshalBinary() (b []byte, err error)

func (*TcpData) String

func (td *TcpData) String() string

func (*TcpData) UnmarshalBinary

func (td *TcpData) UnmarshalBinary(b []byte) (err error)

type TcpTransport

type TcpTransport interface {
	ConnectTcp(address string) (net.Conn, error)
}

type TcpWorker

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

func (*TcpWorker) GetReqChannel

func (w *TcpWorker) GetReqChannel() chan *Msg

func (*TcpWorker) Run

func (w *TcpWorker) Run(repChan chan *Msg) error

type TcpWorkerFactory

type TcpWorkerFactory struct{}

func (*TcpWorkerFactory) MakeStreamWorker

func (s *TcpWorkerFactory) MakeStreamWorker(sid UID) Worker

type TimeoutWriter

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

func (*TimeoutWriter) Flush

func (w *TimeoutWriter) Flush() error

func (*TimeoutWriter) Write

func (w *TimeoutWriter) Write(b []byte) (n int, err error)

type TunnelClient

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

func NewTunnelClient

func NewTunnelClient(remote string) (*TunnelClient, error)

func NewTunnelClientKeyPair

func NewTunnelClientKeyPair(remote string, server_pub string, pub string, secret string) (*TunnelClient, error)

func (*TunnelClient) Close

func (c *TunnelClient) Close() error

func (*TunnelClient) ConnectTcp

func (c *TunnelClient) ConnectTcp(host string) (net.Conn, error)

func (*TunnelClient) RoundTrip

func (c *TunnelClient) RoundTrip(r *http.Request) (io.ReadCloser, error)

implement http.RoundTrip interface send http request via the tunnel

func (*TunnelClient) Run

func (c *TunnelClient) Run() error

type TunnelConn

type TunnelConn struct {
	io.Reader
	io.WriteCloser
}

TunnelConn

func (*TunnelConn) LocalAddr

func (c *TunnelConn) LocalAddr() net.Addr

func (*TunnelConn) RemoteAddr

func (c *TunnelConn) RemoteAddr() net.Addr

func (*TunnelConn) SetDeadline

func (c *TunnelConn) SetDeadline(t time.Time) error

func (*TunnelConn) SetReadDeadline

func (c *TunnelConn) SetReadDeadline(t time.Time) error

func (*TunnelConn) SetWriteDeadline

func (c *TunnelConn) SetWriteDeadline(t time.Time) error

type TunnelReader

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

Read bytes from Msg channel

func (*TunnelReader) Close

func (c *TunnelReader) Close() error

func (*TunnelReader) Read

func (c *TunnelReader) Read(b []byte) (n int, err error)

type TunnelServer

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

func NewTunnelServer

func NewTunnelServer(bind string) (*TunnelServer, error)

func NewTunnelServerKeyPair

func NewTunnelServerKeyPair(bind string, pub string, secret string) (*TunnelServer, error)

func (*TunnelServer) Close

func (s *TunnelServer) Close() error

func (*TunnelServer) Run

func (s *TunnelServer) Run() error

type TunnelWriter

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

func (*TunnelWriter) Close

func (c *TunnelWriter) Close() error

func (*TunnelWriter) Write

func (c *TunnelWriter) Write(b []byte) (n int, err error)

type UID

type UID [12]byte

func MakeUID

func MakeUID() UID

type Worker

type Worker interface {
	GetReqChannel() chan *Msg
	Run(repChan chan *Msg) error
}

func NewMultiStreamHttpWorker

func NewMultiStreamHttpWorker(cm *CacheManager) Worker

func NewMultiStreamTcpWorker

func NewMultiStreamTcpWorker() Worker

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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