alpacamux

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

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

Go to latest
Published: Nov 9, 2022 License: GPL-3.0 Imports: 9 Imported by: 0

README

alpaca-mux

A UDP proxy with multiple paths.

Topology

dns-client ──┐                                                      ┌──> dns-server
             │                                                      │
app-client   │                                                      │    app-server
      ↓      ↓                                                      │      ↑
   port-1   port-2                                               conn-2   conn-1
      ↓      ↓                ┌────── path 1 ──────┐                ↑      ↑
     udp-server -> mux-client ┼────── path 2 ──────┼ mux-server -> udp-client
                              └────── path 3 ──────┘

Proxy multiple UDP ports over a single mux session, then transport a mux session over multiple paths. The second UDP port is useful when chaining shadowsocks -> kcptun -> alpaca-mux, because kcptun does not support UDP relay.

A path can be implemented by adding iptable port forward rules on a middler server.

iptables -A PREROUTING  -t nat -p udp --dport 8001 -j DNAT --to-destination 192.168.1.200:8080
iptables -A POSTROUTING -t nat -p udp -d 192.168.1.200 --dport 8080 -j MASQUERADE

Documentation

Index

Constants

View Source
const (
	HEADER_LEN = 16
	MAX_MTU    = 1500 - 20 - 8 - HEADER_LEN // ETH-IP-UDP-MUX
	MAGIC      = 20202
)
View Source
const PATH_SIZE = 4
View Source
const RATE_LIMIT = 160000 // pps

Variables

View Source
var Log = log

Functions

func Abs

func Abs(x int64) int64

Types

type Forwarder

type Forwarder interface {
	Listen() error
	Read(buf []byte) (int, error)
	Write(buf []byte) error
}
type Header struct {
	Magic     uint32
	Length    uint16
	PathID    uint16
	Timestamp uint32
	Sequence  uint32
}

func (*Header) FromNetwork

func (h *Header) FromNetwork(data []byte)

func (*Header) ToNetwork

func (h *Header) ToNetwork() []byte

type Logger

type Logger struct {
	Level int
}

a wrapper of fmt.Printf

func (*Logger) Critical

func (l *Logger) Critical(format string, a ...interface{})

func (*Logger) Debug

func (l *Logger) Debug(format string, a ...interface{})

func (*Logger) Error

func (l *Logger) Error(format string, a ...interface{})

func (*Logger) Info

func (l *Logger) Info(format string, a ...interface{})

func (*Logger) SetLevel

func (l *Logger) SetLevel(level string)

func (*Logger) Warning

func (l *Logger) Warning(format string, a ...interface{})

type MuxClient

type MuxClient struct {
	Servers []string // upstream IP:Port pairs
	// contains filtered or unexported fields
}

func (*MuxClient) Listen

func (f *MuxClient) Listen() error

func (*MuxClient) Read

func (f *MuxClient) Read(buf []byte) (int, error)

func (*MuxClient) Write

func (f *MuxClient) Write(buf []byte) error

type MuxPeer

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

func (*MuxPeer) Init

func (p *MuxPeer) Init(localPort int, peerAddrs []string) error

func (*MuxPeer) Read

func (p *MuxPeer) Read(buf []byte) (int, error)

func (*MuxPeer) Write

func (p *MuxPeer) Write(buf []byte) error

type MuxServer

type MuxServer struct {
	Port int // server listen port
	// contains filtered or unexported fields
}

func (*MuxServer) Listen

func (f *MuxServer) Listen() error

func (*MuxServer) Read

func (f *MuxServer) Read(buf []byte) (int, error)

func (*MuxServer) Write

func (f *MuxServer) Write(buf []byte) error

type PktFilter

type PktFilter struct {
	Limit  uint32
	Latest uint32
	Mark0  []bool
	Mark1  []bool
	Mark2  []bool
}

TODO: bool is one byte, how about use 1 bit struct?

func (*PktFilter) Init

func (filter *PktFilter) Init()

func (*PktFilter) IsValid

func (filter *PktFilter) IsValid(timestamp, sequence uint32) bool

type UdpClient

type UdpClient struct {
	Servers []string // upstream IP:Port pairs
	// contains filtered or unexported fields
}

func (*UdpClient) Listen

func (f *UdpClient) Listen() error

func (*UdpClient) Read

func (f *UdpClient) Read(buf []byte) (int, error)

func (*UdpClient) Write

func (f *UdpClient) Write(buf []byte) error

type UdpServer

type UdpServer struct {
	Ports []int
	// contains filtered or unexported fields
}

func (*UdpServer) Listen

func (f *UdpServer) Listen() error

func (*UdpServer) Read

func (f *UdpServer) Read(buf []byte) (int, error)

func (*UdpServer) Write

func (f *UdpServer) Write(buf []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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