proxy

package
v1.1.1-0...-9fb3f7c Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdTCP byte
	CmdUDP
	CmdMux
)

CMD types, for vless and vmess

View Source
const (
	AtypIP4    byte = 1
	AtypDomain byte = 2
	AtypIP6    byte = 3
)

Atyp, for vless and vmess; 注意与 trojan和socks5的区别,trojan和socks5的相同含义的值是1,3,4

View Source
const Http403response = `HTTP/1.1 403 Forbidden
Connection: close
Cache-Control: max-age=3600, public
Content-Length: 0

`
View Source
const (
	MaxUDP_packetLen = 64 * 1024 // 关于 udp包数据长度,我参考 https://cloud.tencent.com/developer/article/1021196
)

Variables

This section is empty.

Functions

func Get_cmdKey

func Get_cmdKey(uuid [16]byte) []byte

GetKey returns the key of AES-128-CFB encrypter Key:MD5(UUID + []byte('c48619fe-8f02-49e0-b9e9-edf763e17e21'))

func ParseAddr

func ParseAddr(s string) (byte, []byte, uint16, error)

ParseAddr parses the address in string s

, return atyp, addr, uint16(portnum), err

func PrintAllClientNames

func PrintAllClientNames()

func PrintAllServerNames

func PrintAllServerNames()

func RegisterClient

func RegisterClient(name string, c ClientCreator)

RegisterClient is used to register a client.

func RegisterServer

func RegisterServer(name string, c ServerCreator)

RegisterServer is used to register a proxy server

func RelayTCP

func RelayTCP(selfLocalServerConn, selfRemoteConn net.Conn)

阻塞

func RelayUDP

func RelayUDP(putter UDP_Putter, extractor UDP_Extractor)

阻塞.

func StrToUUID

func StrToUUID(s string) (uuid [16]byte, err error)

StrToUUID converts string to uuid

func TimestampHash

func TimestampHash(unixSec int64) []byte

TimestampHash returns the iv of AES-128-CFB encrypter IV:MD5(X + X + X + X),X = []byte(timestamp.now) (8 bytes, Big Endian)

func UUIDToStr

func UUIDToStr(u [16]byte) string

Types

type Client

type Client interface {
	Name() string
	AddrStr() string //远程 服务器的 地址
	SetAddrStr(string)

	// Handshake的 underlay有可能传入nil,所以要求 所有的 Client 都要能够自己dial
	Handshake(underlay net.Conn, target *TargetAddr) (io.ReadWriter, error)
}

Client is used to create connection.

func ClientFromURL

func ClientFromURL(s string) (Client, error)

ClientFromURL calls the registered creator to create client. dialer is the default upstream dialer so cannot be nil, we can use Default when calling this function.

type ClientCreator

type ClientCreator func(url *url.URL) (Client, error)

ClientCreator is a function to create client.

type ID

type ID struct {
	UUID   [16]byte
	CmdKey [16]byte
}

func NewID

func NewID(s string) (*ID, error)

type Server

type Server interface {
	Name() string
	Addr() string //本地监听地址
	Handshake(underlay net.Conn) (io.ReadWriter, *TargetAddr, error)
	Stop()
}

Server interface

func ServerFromURL

func ServerFromURL(s string) (Server, error)

ServerFromURL calls the registered creator to create proxy servers dialer is the default upstream dialer so cannot be nil, we can use Default when calling this function

type ServerCreator

type ServerCreator func(url *url.URL) (Server, error)

ServerCreator is a function to create proxy server

type TargetAddr

type TargetAddr struct {
	Name  string // fully-qualified domain name
	IP    net.IP
	Port  int
	IsUDP bool
}

An Addr represents a address that you want to access by proxy. Either Name or IP is used exclusively.

func NewTargetAddr

func NewTargetAddr(addr string) (*TargetAddr, error)

func NewTargetAddrFromUDPAddr

func NewTargetAddrFromUDPAddr(addr *net.UDPAddr) *TargetAddr

func (*TargetAddr) AddressBytes

func (a *TargetAddr) AddressBytes() ([]byte, byte)

Returned address bytes and type

func (*TargetAddr) Dial

func (target *TargetAddr) Dial() (net.Conn, error)

func (*TargetAddr) Host

func (a *TargetAddr) Host() string

Returned host string

func (*TargetAddr) String

func (a *TargetAddr) String() string

Return host:port string

func (*TargetAddr) ToUDPAddr

func (a *TargetAddr) ToUDPAddr() *net.UDPAddr

func (*TargetAddr) UrlString

func (a *TargetAddr) UrlString() string

type UDPAddrData

type UDPAddrData struct {
	Addr *net.UDPAddr
	Data []byte
}

type UDPRequestReader

type UDPRequestReader interface {
	GetNewUDPRequest() (*net.UDPAddr, []byte, error)
}

type UDPRequestWriter

type UDPRequestWriter interface {
	WriteUDPRequest(*net.UDPAddr, []byte) error
}

写入一个UDP请求

type UDPResponseReader

type UDPResponseReader interface {
	GetNewUDPResponse() (*net.UDPAddr, []byte, error)
}

拉取一个新的 UDP 响应

type UDPResponseWriter

type UDPResponseWriter interface {
	WriteUDPResponse(*net.UDPAddr, []byte) error
}

type UDP_Client

type UDP_Client interface {
	Client
	UDP_Putter
}

type UDP_Extractor

type UDP_Extractor interface {
	UDPRequestReader
	UDPResponseWriter
}

UDP_Extractor, 用于从一个虚拟的协议中提取出 udp请求

从一个未知协议中读取UDP请求,然后试图得到该请求的回应(大概率是直接通过direct发出) 并写回

type UDP_Pipe

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

一种简单的本地 UDP_Extractor + UDP_Putter

func NewUDP_Pipe

func NewUDP_Pipe() *UDP_Pipe

func (*UDP_Pipe) GetNewUDPRequest

func (u *UDP_Pipe) GetNewUDPRequest() (*net.UDPAddr, []byte, error)

func (*UDP_Pipe) GetNewUDPResponse

func (u *UDP_Pipe) GetNewUDPResponse() (*net.UDPAddr, []byte, error)

func (*UDP_Pipe) WriteUDPRequest

func (u *UDP_Pipe) WriteUDPRequest(addr *net.UDPAddr, bs []byte) error

会保存bs的副本,不必担心数据被改变的问题。

func (*UDP_Pipe) WriteUDPResponse

func (u *UDP_Pipe) WriteUDPResponse(addr *net.UDPAddr, bs []byte) error

会保存bs的副本,不必担心数据被改变的问题。

type UDP_Putter

type UDP_Putter interface {
	UDPRequestWriter
	UDPResponseReader
}

UDP_Putter, 用于把 udp请求转换成 虚拟的协议

向一个特定的协议 写入 UDP请求,然后试图读取 该请求的回应

type UniUDP_Extractor

type UniUDP_Extractor struct {
	io.ReadWriter
	// contains filtered or unexported fields
}

最简单的 UDP_Extractor,用于服务端; 不处理内部数据,直接认为客户端传来的内部数据的目标为一个特定值。

	收到的响应数据的来源 如果和 targetAddr 相同的话,直接写入传入的 ReadWriter
 收到的外界数据的来源 如果和 targetAddr 不同的话,那肯定就是使用了fullcone,那么要传入 unknownRemoteAddrMsgWriter; 如果New时传入unknownRemoteAddrMsgWriter的 是nil的话,那么意思就是不支持fullcone,将直接舍弃这一部分数据。

func NewUniUDP_Extractor

func NewUniUDP_Extractor(addr *net.UDPAddr, rw io.ReadWriter, unknownRemoteAddrMsgWriter UDPResponseWriter) *UniUDP_Extractor

新建,unknownRemoteAddrMsgWriter 用于写入 未知来源响应,rw 用于普通的客户请求的目标的响应

func (*UniUDP_Extractor) GetNewUDPRequest

func (e *UniUDP_Extractor) GetNewUDPRequest() (*net.UDPAddr, []byte, error)

从客户端连接中 提取出 它的 UDP请求,就是直接读取数据。然后搭配上之前设置好的地址

func (*UniUDP_Extractor) WriteUDPResponse

func (e *UniUDP_Extractor) WriteUDPResponse(addr *net.UDPAddr, bs []byte) (err error)

WriteUDPResponse 写入远程服务器的响应;要分情况讨论。 因为是单一目标extractor,所以正常情况下 传入的response 的源地址 也 应和 e.targetAddr 相同,

如果地址不同的话,那肯定就是使用了fullcone,那么要传入 unknownRemoteAddrMsgWriter

type UniUDP_Putter

type UniUDP_Putter struct {
	io.ReadWriter
	// contains filtered or unexported fields
}

最简单的 UDP_Putter,用于客户端; 不处理内部数据,直接认为要 发送给服务端的信息 要发送到一个特定的地址

如果指定的地址不是 默认的地址,则发送到 unknownRemoteAddrMsgWriter

对于 vless v1来说, unknownRemoteAddrMsgWriter 要做的 就是 新建一个与服务端的 请求udp的连接,

然后这个新连接就变成了新的 UniUDP_Putter

func (*UniUDP_Putter) GetNewUDPResponse

func (e *UniUDP_Putter) GetNewUDPResponse() (*net.UDPAddr, []byte, error)

func (*UniUDP_Putter) WriteUDPRequest

func (e *UniUDP_Putter) WriteUDPRequest(addr *net.UDPAddr, bs []byte) (err error)

type User

type User interface {
	GetIdentityStr() string //每个user唯一,通过比较这个string 即可 判断两个User 是否相等
}

type UserConn

type UserConn interface {
	io.ReadWriter
	User
	GetProtocolVersion() int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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