Documentation
¶
Index ¶
- Constants
- func Get_cmdKey(uuid [16]byte) []byte
- func ParseAddr(s string) (byte, []byte, uint16, error)
- func PrintAllClientNames()
- func PrintAllServerNames()
- func RegisterClient(name string, c ClientCreator)
- func RegisterServer(name string, c ServerCreator)
- func RelayTCP(selfLocalServerConn, selfRemoteConn net.Conn)
- func RelayUDP(putter UDP_Putter, extractor UDP_Extractor)
- func StrToUUID(s string) (uuid [16]byte, err error)
- func TimestampHash(unixSec int64) []byte
- func UUIDToStr(u [16]byte) string
- type Client
- type ClientCreator
- type ID
- type Server
- type ServerCreator
- type TargetAddr
- type UDPAddrData
- type UDPRequestReader
- type UDPRequestWriter
- type UDPResponseReader
- type UDPResponseWriter
- type UDP_Client
- type UDP_Extractor
- type UDP_Pipe
- type UDP_Putter
- type UniUDP_Extractor
- type UniUDP_Putter
- type User
- type UserConn
Constants ¶
const ( CmdTCP byte CmdUDP CmdMux )
CMD types, for vless and vmess
const ( AtypIP4 byte = 1 AtypDomain byte = 2 AtypIP6 byte = 3 )
Atyp, for vless and vmess; 注意与 trojan和socks5的区别,trojan和socks5的相同含义的值是1,3,4
const Http403response = `HTTP/1.1 403 Forbidden
Connection: close
Cache-Control: max-age=3600, public
Content-Length: 0
`
const (
MaxUDP_packetLen = 64 * 1024 // 关于 udp包数据长度,我参考 https://cloud.tencent.com/developer/article/1021196
)
Variables ¶
This section is empty.
Functions ¶
func Get_cmdKey ¶
GetKey returns the key of AES-128-CFB encrypter Key:MD5(UUID + []byte('c48619fe-8f02-49e0-b9e9-edf763e17e21'))
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 TimestampHash ¶
TimestampHash returns the iv of AES-128-CFB encrypter IV:MD5(X + X + X + X),X = []byte(timestamp.now) (8 bytes, Big Endian)
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 ¶
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 ¶
ClientCreator is a function to create client.
type Server ¶
type Server interface {
Name() string
Addr() string //本地监听地址
Handshake(underlay net.Conn) (io.ReadWriter, *TargetAddr, error)
Stop()
}
Server interface
func ServerFromURL ¶
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 ¶
ServerCreator is a function to create proxy server
type TargetAddr ¶
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) ToUDPAddr ¶
func (a *TargetAddr) ToUDPAddr() *net.UDPAddr
func (*TargetAddr) UrlString ¶
func (a *TargetAddr) UrlString() string
type UDPAddrData ¶
type UDPRequestReader ¶
type UDPRequestWriter ¶
写入一个UDP请求
type UDPResponseReader ¶
拉取一个新的 UDP 响应
type UDPResponseWriter ¶
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 (*UDP_Pipe) GetNewUDPResponse ¶
func (*UDP_Pipe) WriteUDPRequest ¶
会保存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)