多项对接口的修改,为ss做准备:

取消Client的LocalAddr,改为 LocalTCPAddr 和 LocalUDPAddr
删除direct中的对应条目。这样可更清晰地配置双本地地址

将设置sendthrough设置双地址的代码移动到 proxy.newClient函数

这样不仅direct可指定不同的tcp和udp的本地地址,任何client协议都可以了

为ClientCreator 接口 添加 UseUDPAsMsgConn 方法,direct和ss返回true

在ss的client的EstablishUDPChannel进行自行拨号

在ss的server建立后,自动循环监听udp,绕过vs的基本监听机制。因为vs架构的限制,一个代理只能有一个唯一的传输层协议。

ServerCreator 接口 添加 AfterCommonConfServer 方法
This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent f7d1bf5e48
commit a9a746ba2f
23 changed files with 240 additions and 141 deletions

38
main.go
View File

@@ -33,7 +33,7 @@ import (
_ "github.com/e1732a364fed/v2ray_simple/proxy/vmess"
)
//statistics
// statistics
var (
ActiveConnectionCount int32
AllDownloadBytesSinceStart uint64
@@ -46,7 +46,7 @@ var (
DirectClient, _ = proxy.ClientFromURL(proxy.DirectURL)
)
//用于回落到h2c
// 用于回落到h2c
var (
fallback_h2c_transport = &http2.Transport{
DialTLS: func(n, a string, cfg *tls.Config) (net.Conn, error) {
@@ -59,7 +59,8 @@ var (
fb_h2c_PROXYprotocolAddrMap_mutex sync.RWMutex
)
/*ListenSer 函数 是本包 最重要的函数。可以 直接使用 本函数 来手动开启新的 自定义的 转发流程。
/*
ListenSer 函数 是本包 最重要的函数。可以 直接使用 本函数 来手动开启新的 自定义的 转发流程。
监听 inServer, 然后试图转发到一个 proxy.Client。如果env没给出则会转发到 defaultOutClient。
若 env 不为 nil, 则会 进行分流或回落。具有env的情况下可能会转发到 非 defaultOutClient 的其他 proxy.Client.
@@ -382,7 +383,7 @@ func handleNewIncomeConnection(inServer proxy.Server, defaultClientForThis proxy
handshakeInserver_and_passToOutClient(iics)
}
//被 handshakeInserver_and_passToOutClient 调用
// 被 handshakeInserver_and_passToOutClient 调用
func handshakeInserver(iics *incomingInserverConnState) (wlc net.Conn, udp_wlc netLayer.MsgConn, targetAddr netLayer.Addr, err error) {
inServer := iics.inServer
if inServer == nil {
@@ -522,7 +523,7 @@ func handshakeInserver(iics *incomingInserverConnState) (wlc net.Conn, udp_wlc n
//
// iics 不使用指针, 因为iics不能公用因为 在多路复用时 iics.wrappedConn 是会变化的。
//
//被 handleNewIncomeConnection 和 ListenSer 调用。
// 被 handleNewIncomeConnection 和 ListenSer 调用。
func handshakeInserver_and_passToOutClient(iics incomingInserverConnState) {
wlc, udp_wlc, targetAddr, err := handshakeInserver(&iics)
@@ -558,7 +559,7 @@ func handshakeInserver_and_passToOutClient(iics incomingInserverConnState) {
}
//被 handshakeInserver_and_passToOutClient 和 handshakeInserver 的innerMux部分 以及 tproxy 调用。 iics.inServer可能为nil。
// 被 handshakeInserver_and_passToOutClient 和 handshakeInserver 的innerMux部分 以及 tproxy 调用。 iics.inServer可能为nil。
// 本函数 可能是 本文件中 最长的 函数。分别处理 回落firstpayloadsniffdns解析分流以及lazy最终转发到 某个 outClient。
//
// 最终会调用 dialClient_andRelay. 若isfallback为true传入的 wlc 和 udp_wlc 必须为niltargetAddr必须为空值。
@@ -982,7 +983,7 @@ func passToOutClient(iics incomingInserverConnState, isfallback bool, wlc net.Co
dialClient_andRelay(iics, targetAddr, client, isTlsLazy_clientEnd, wlc, udp_wlc)
}
//dialClient 对实际client进行拨号处理传输层, tls层, 高级层等所有层级后,进行代理层握手。
// dialClient 对实际client进行拨号处理传输层, tls层, 高级层等所有层级后,进行代理层握手。
// result = 0 表示拨号成功, result = -1 表示 拨号失败, result = 1 表示 拨号成功 并 已经自行处理了转发阶段(用于lazy和 innerMux ); -10 标识 因为 client为reject 而关闭了连接。
// 在 dialClient_andRelay 中被调用。在udp为multi channel时也有用到.
func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,
@@ -1104,13 +1105,12 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,
var dialedCommonConn any
not_direct := !(client.Name() == proxy.DirectName)
not_udpSpecial := !(realTargetAddr.Network == "udp" && client.GetCreator().UseUDPAsMsgConn())
/*
direct 的udp 是自己拨号的,因为要考虑到fullcone。
direct 的tcp也是自己拨号因为还考虑到 sockopt
shadowsocks的udp是自己拨号的因为它用到了udp的包特性
不是direct的udp的话也要分情况:
不是shadowsocks的udp的话也要分情况:
如果是单路的, 则我们在此dial, 如果是多路复用, 则不行, 因为要复用同一个连接
Instead, 我们要试图 取出已经拨号好了的 连接
*/
@@ -1120,7 +1120,7 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,
var muxC advLayer.MuxClient
if not_direct {
if not_udpSpecial {
if adv != "" && advClient.IsMux() {
@@ -1150,7 +1150,14 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,
}
}
clientConn, err = realTargetAddr.Dial(client.GetSockopt(), client.LocalAddr())
var na net.Addr
if realTargetAddr.Network == "tcp" {
na = client.LocalTCPAddr()
} else if realTargetAddr.Network == "udp" {
na = client.LocalUDPAddr()
}
clientConn, err = realTargetAddr.Dial(client.GetSockopt(), na)
if err != nil {
if err == netLayer.ErrMachineCantConnectToIpv6 {
@@ -1175,6 +1182,8 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,
return
}
} else {
goto shakeStep
}
if xver := iics.fallbackXver; xver > 0 && xver < 3 {
@@ -1340,6 +1349,7 @@ advLayerHandshakeStep:
}
}
shakeStep:
////////////////////////////// 代理层 握手阶段 /////////////////////////////////////
if !isudp || hasInnerMux {
@@ -1405,7 +1415,7 @@ advLayerHandshakeStep:
return
} //dialClient
//在 dialClient 中调用。 如果调用不成功则result < 0. 若成功, 则 result == 0.
// 在 dialClient 中调用。 如果调用不成功则result < 0. 若成功, 则 result == 0.
func dialInnerProxy(client proxy.Client, wlc net.Conn, wrc io.ReadWriteCloser, iics incomingInserverConnState, innerProxyName string, targetAddr netLayer.Addr, isudp bool) (realwrc io.ReadWriteCloser, realudp_wrc netLayer.MsgConn, result int) {
smuxSession := client.GetClientInnerMuxSession(wrc)

View File

@@ -14,14 +14,14 @@ const (
)
//若字符串无法被解析为网络类型,则返回 UnknownNetwork
// 若字符串无法被解析为网络类型,则返回 UnknownNetwork
func StrToTransportProtocol(s string) uint16 {
switch s {
case "tcp", "tcp4", "tcp6", "TCP", "TCP4", "TCP6":
return TCP
case "udp", "udp4", "udp6", "UDP", "UDP4", "UDP6":
return UDP
case "dual", "mix", "mixed", "Mix", "MIX":
case DualNetworkName, "mix", "mixed", "Mix", "MIX":
return Dual
case "unix", "Unix", "UNIX":
return UNIX

View File

@@ -88,7 +88,6 @@ type Base struct {
DialConf *DialConf
Addr string
LA net.Addr //for client's LocalAddr
TLS bool
Tag string //可用于路由, 见 netLayer.route.go
TransportLayer string
@@ -115,18 +114,25 @@ type Base struct {
Innermux *smux.Session //用于存储 client的已拨号的mux连接
sync.Mutex
//用于sendthrough
LTA *net.TCPAddr
LUA *net.UDPAddr
}
func (b *Base) GetBase() *Base {
return b
}
func (b *Base) Network() string {
return b.TransportLayer
func (b *Base) LocalTCPAddr() *net.TCPAddr {
return b.LTA
}
func (b *Base) LocalUDPAddr() *net.UDPAddr {
return (b.LUA)
}
func (b *Base) LocalAddr() net.Addr {
return b.LA
func (b *Base) Network() string {
return b.TransportLayer
}
func (b *Base) GetXver() int {
@@ -445,3 +451,31 @@ func (b *Base) InitAdvLayer() {
b.AdvS = advSer
}
}
func (d *Base) DialTCP(target netLayer.Addr) (result net.Conn, err error) {
if d.Sockopt != nil {
if d.LTA == nil {
result, err = target.DialWithOpt(d.Sockopt, nil) //避免把nil的 *net.TCPAddr 装箱到 net.Addr里
} else {
result, err = target.DialWithOpt(d.Sockopt, d.LTA)
}
} else {
if d.LTA == nil {
result, err = target.Dial(nil, nil)
} else {
result, err = target.Dial(nil, d.LTA)
}
}
return
}
func (d *Base) DialUDP(target netLayer.Addr) (mc *netLayer.UDPMsgConn, err error) {
mc, err = netLayer.NewUDPMsgConn(d.LUA, d.IsFullcone, false, d.Sockopt)
return
}

View File

@@ -1,6 +1,7 @@
package proxy
import (
"net"
"net/url"
"strings"
@@ -35,6 +36,13 @@ func PrintAllClientNames() {
}
}
type CreatorCommonStruct struct{}
func (CreatorCommonStruct) MultiTransportLayer() bool {
return false
}
func (CreatorCommonStruct) AfterCommonConfServer(Server) {}
type CreatorCommon interface {
//若为true则表明该协议可同时使用tcp和udp来传输数据。direct, socks5 和 shadowsocks 都为true。
//此时是否开启udp取决于Network(), 如果为dual, 则均支持; 如果仅为tcp或者udp则不支持。
@@ -52,6 +60,9 @@ type ClientCreator interface {
//iv: initial value, can be nil.
URLToDialConf(url *url.URL, iv *DialConf, format int) (*DialConf, error)
//DialConfToURL(url *DialConf, format int) (*url.URL, error)
UseUDPAsMsgConn() bool //默认情况下UDP会被包装成流式协议除非指出需要利用udp的固定包长度特性; direct 和 shadowsocks会返回true.
}
// 可通过标准配置或url 来初始化。
@@ -59,6 +70,7 @@ type ServerCreator interface {
CreatorCommon
NewServer(*ListenConf) (Server, error)
AfterCommonConfServer(Server)
URLToListenConf(url *url.URL, iv *ListenConf, format int) (*ListenConf, error)
//ListenConfToURL(url *ListenConf, format int) (*url.URL, error)
@@ -111,26 +123,33 @@ func newClient(creator ClientCreator, dc *DialConf, knownTls bool) (Client, erro
e = prepareTLS_forClient(c, dc)
}
if dc.SendThrough != "" {
if c.Network() == netLayer.DualNetworkName {
//多个传输层的话完全由proxy自行配置 localAddr。
} else {
st, err := netLayer.StrToNetAddr(c.Network(), dc.SendThrough)
if err != nil {
return nil, utils.ErrInErr{ErrDesc: "parse sendthrough addr failed", ErrDetail: err}
} else {
c.GetBase().LA = st
}
}
setSendThroughByNetwork(c.GetBase(), dc.SendThrough)
}
return c, e
}
func setSendThroughByNetwork(b *Base, throughStr string) error {
st, err := netLayer.StrToNetAddr(netLayer.DualNetworkName, throughStr)
if err != nil {
return utils.ErrInErr{ErrDesc: "parse sendthrough addr failed", ErrDetail: err}
}
switch b.Network() {
case netLayer.DualNetworkName:
b.LTA = st.(*netLayer.TCPUDPAddr).TCPAddr
b.LUA = st.(*netLayer.TCPUDPAddr).UDPAddr
case "tcp":
b.LTA = st.(*net.TCPAddr)
case "udp":
b.LUA = st.(*net.UDPAddr)
}
return nil
}
// SetAddrStr, ConfigCommon
func configCommonForClient(cli BaseInterface, dc *DialConf) error {
if cli.Name() != DirectName {
@@ -183,6 +202,7 @@ func newServer(creator ServerCreator, lc *ListenConf, knownTls bool) (Server, er
}
}
creator.AfterCommonConfServer(ser)
return ser, nil
}

View File

@@ -16,8 +16,13 @@ const (
)
// implements ClientCreator for direct
type DirectCreator struct{}
type DirectCreator struct{ CreatorCommonStruct }
func (DirectCreator) UseUDPAsMsgConn() bool {
return true
}
// true
func (DirectCreator) MultiTransportLayer() bool {
return true
}
@@ -40,27 +45,17 @@ func (DirectCreator) NewClient(dc *DialConf) (Client, error) {
dc.Network = netLayer.DualNetworkName
}
if dc.SendThrough != "" {
st, err := netLayer.StrToNetAddr(netLayer.DualNetworkName, dc.SendThrough)
if err != nil {
return nil, err
}
d.localTCPAddr = st.(*netLayer.TCPUDPAddr).TCPAddr
d.localUDPAddr = st.(*netLayer.TCPUDPAddr).UDPAddr
}
return d, nil
}
type DirectClient struct {
Base
localTCPAddr *net.TCPAddr
localUDPAddr *net.UDPAddr
}
func (*DirectClient) Name() string { return DirectName }
func (*DirectClient) GetCreator() ClientCreator {
return DirectCreator{}
}
// 若 underlay 为nil则会对target进行拨号, 否则返回underlay本身
func (d *DirectClient) Handshake(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (result io.ReadWriteCloser, err error) {
@@ -70,23 +65,7 @@ func (d *DirectClient) Handshake(underlay net.Conn, firstPayload []byte, target
if underlay == nil {
if d.Sockopt != nil {
if d.localTCPAddr == nil {
result, err = target.DialWithOpt(d.Sockopt, nil) //避免把nil的 *net.TCPAddr 装箱到 net.Addr里
} else {
result, err = target.DialWithOpt(d.Sockopt, d.localTCPAddr)
}
} else {
if d.localTCPAddr == nil {
result, err = target.Dial(nil, nil)
} else {
result, err = target.Dial(nil, d.localTCPAddr)
}
}
result, err = d.Base.DialTCP(target)
} else {
result = underlay
@@ -114,10 +93,10 @@ func (d *DirectClient) EstablishUDPChannel(_ net.Conn, firstPayload []byte, targ
if len(firstPayload) == 0 {
return netLayer.NewUDPMsgConn(d.localUDPAddr, d.IsFullcone, false, d.Sockopt)
return d.Base.DialUDP(target)
} else {
mc, err := netLayer.NewUDPMsgConn(d.localUDPAddr, d.IsFullcone, false, d.Sockopt)
mc, err := d.Base.DialUDP(target)
if err != nil {
return nil, err
}

View File

@@ -52,11 +52,7 @@ func init() {
proxy.RegisterServer(name, &ServerCreator{})
}
type ServerCreator struct{}
func (ServerCreator) MultiTransportLayer() bool {
return false
}
type ServerCreator struct{ proxy.CreatorCommonStruct }
func (ServerCreator) URLToListenConf(url *url.URL, lc *proxy.ListenConf, format int) (*proxy.ListenConf, error) {
if format != proxy.StandardMode {

View File

@@ -45,11 +45,7 @@ func init() {
proxy.RegisterServer(Name, &ServerCreator{})
}
type ServerCreator struct{}
func (ServerCreator) MultiTransportLayer() bool {
return false
}
type ServerCreator struct{ proxy.CreatorCommonStruct }
func (ServerCreator) URLToListenConf(u *url.URL, lc *proxy.ListenConf, format int) (*proxy.ListenConf, error) {
if format != proxy.UrlStandardFormat {

View File

@@ -60,7 +60,11 @@ type Client interface {
InnerMuxEstablished() bool
CloseInnerMuxSession()
LocalAddr() net.Addr //用于在拨号时选用一个特定的ip拨号。
//用于在拨号时选用一个特定的ip拨号。
LocalTCPAddr() *net.TCPAddr
LocalUDPAddr() *net.UDPAddr
GetCreator() ClientCreator
sync.Locker //用于锁定 innerMux
}

View File

@@ -56,12 +56,11 @@ func tryRejectWithHttpRespAndClose(rejectType string, underlay net.Conn) {
}
// implements ClientCreator and ServerCreator for reject
type RejectCreator struct{}
type RejectCreator struct{ CreatorCommonStruct }
func (RejectCreator) MultiTransportLayer() bool {
func (RejectCreator) UseUDPAsMsgConn() bool {
return false
}
func (RejectCreator) NewClient(dc *DialConf) (Client, error) {
r := &RejectClient{}
@@ -132,6 +131,10 @@ type RejectClient struct {
rejectCommon
}
func (*RejectClient) GetCreator() ClientCreator {
return RejectCreator{}
}
// optionally response 403 and close the underlay, return io.EOF.
func (c *RejectClient) Handshake(underlay net.Conn, _ []byte, _ netLayer.Addr) (result io.ReadWriteCloser, err error) {
tryRejectWithHttpRespAndClose(c.theType, underlay)

View File

@@ -15,10 +15,13 @@ func init() {
proxy.RegisterClient(Name, ClientCreator{})
}
type ClientCreator struct{}
type ClientCreator struct{ proxy.CreatorCommonStruct }
func (ClientCreator) UseUDPAsMsgConn() bool {
return true
}
func (ClientCreator) MultiTransportLayer() bool {
return false
return true
}
func (ClientCreator) URLToDialConf(u *url.URL, dc *proxy.DialConf, format int) (*proxy.DialConf, error) {
if format != proxy.UrlStandardFormat {
@@ -59,7 +62,9 @@ func newClient(mp MethodPass) *Client {
cipher: initShadowCipher(mp),
}
}
func (*Client) GetCreator() proxy.ClientCreator {
return ClientCreator{}
}
func (*Client) Name() string {
return Name
}
@@ -83,25 +88,34 @@ func (c *Client) Handshake(underlay net.Conn, firstPayload []byte, target netLay
}
func (c *Client) EstablishUDPChannel(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (mc netLayer.MsgConn, err error) {
var ok bool
var pc net.PacketConn
pc, ok := underlay.(net.PacketConn)
if ok {
if c.cipher != nil {
pc = c.cipher.PacketConn(pc)
}
mc = &shadowUDPPacketConn{
PacketConn: pc,
raddr: underlay.RemoteAddr(),
taddr: target.ToUDPAddr(),
}
if firstPayload != nil {
err = mc.WriteMsgTo(firstPayload, target)
}
return
if underlay != nil {
pc, ok = underlay.(net.PacketConn)
}
return nil, utils.ErrUnImplemented
if !ok {
pc, err = c.Base.DialUDP(target)
if err != nil {
return
}
}
if c.cipher != nil {
pc = c.cipher.PacketConn(pc)
}
mc = &shadowUDPPacketConn{
PacketConn: pc,
raddr: underlay.RemoteAddr(),
taddr: target.ToUDPAddr(),
}
if firstPayload != nil {
err = mc.WriteMsgTo(firstPayload, target)
}
return
}

View File

@@ -16,10 +16,10 @@ func init() {
proxy.RegisterServer(Name, &ServerCreator{})
}
type ServerCreator struct{}
type ServerCreator struct{ proxy.CreatorCommonStruct }
func (ServerCreator) MultiTransportLayer() bool {
return false
return true
}
func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error) {
@@ -31,7 +31,7 @@ func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error) {
var mp MethodPass
if mp.InitWithStr(uuidStr) {
return newServer(mp), nil
return newServer(mp, lc), nil
}
@@ -54,6 +54,38 @@ func (ServerCreator) URLToListenConf(u *url.URL, lc *proxy.ListenConf, format in
}
// loop read udp
// func (ServerCreator) AfterCommonConfServer(s proxy.Server) {
// if s.Network() == "udp" || s.Network() == netLayer.DualNetworkName {
// ss := s.(*Server)
// uc, err := net.ListenUDP("udp", ss.LUA)
// if err != nil {
// log.Panicln("shadowsocks listen udp failed", err)
// }
// pc := ss.cipher.PacketConn(uc)
// for {
// buf := utils.GetPacket()
// defer utils.PutPacket(buf)
// n, saddr, err := pc.ReadFrom(buf)
// if err != nil {
// if ce := utils.CanLogErr("shadowsocks read udp failed"); ce != nil {
// ce.Write(zap.Error(err))
// }
// return
// }
// r := bytes.NewBuffer(buf[:n])
// taddr, err := GetAddrFrom(r)
// if err != nil {
// if ce := utils.CanLogErr("shadowsocks GetAddrFrom failed"); ce != nil {
// ce.Write(zap.Error(err))
// }
// return
// }
// }
// }
// }
type Server struct {
proxy.Base
@@ -62,10 +94,12 @@ type Server struct {
cipher core.Cipher
}
func newServer(info MethodPass) *Server {
return &Server{
func newServer(info MethodPass, lc *proxy.ListenConf) *Server {
s := &Server{
cipher: initShadowCipher(info),
}
return s
}
func (*Server) Name() string {
return Name

View File

@@ -16,9 +16,9 @@ func init() {
proxy.RegisterClient(Name, ClientCreator{})
}
type ClientCreator struct{}
type ClientCreator struct{ proxy.CreatorCommonStruct }
func (ClientCreator) MultiTransportLayer() bool {
func (ClientCreator) UseUDPAsMsgConn() bool {
return false
}
@@ -38,6 +38,9 @@ type Client struct {
proxy.Base
}
func (*Client) GetCreator() proxy.ClientCreator {
return ClientCreator{}
}
func (c *Client) Name() string {
return Name
}

View File

@@ -15,11 +15,7 @@ func init() {
proxy.RegisterServer(Name, &ServerCreator{})
}
type ServerCreator struct{}
func (ServerCreator) MultiTransportLayer() bool {
return false
}
type ServerCreator struct{ proxy.CreatorCommonStruct }
func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error) {
s := &Server{}

View File

@@ -15,7 +15,11 @@ func init() {
proxy.RegisterClient(Name, &ClientCreator{})
}
type ClientCreator struct{}
type ClientCreator struct{ proxy.CreatorCommonStruct }
func (ClientCreator) UseUDPAsMsgConn() bool {
return false
}
// true
func (ClientCreator) MultiTransportLayer() bool {
@@ -50,6 +54,9 @@ type Client struct {
utils.UserPass
}
func (*Client) GetCreator() proxy.ClientCreator {
return ClientCreator{}
}
func (*Client) Name() string {
return Name
}

View File

@@ -39,7 +39,7 @@ func NewServer() *Server {
return s
}
type ServerCreator struct{}
type ServerCreator struct{ proxy.CreatorCommonStruct }
// true
func (ServerCreator) MultiTransportLayer() bool {

View File

@@ -40,7 +40,7 @@ func init() {
proxy.RegisterServer(Name, &ServerCreator{})
}
type ServerCreator struct{}
type ServerCreator struct{ proxy.CreatorCommonStruct }
// true
func (ServerCreator) MultiTransportLayer() bool {

View File

@@ -18,11 +18,12 @@ func init() {
//作为对照,可以参考 https://github.com/p4gefau1t/trojan-go/blob/master/tunnel/trojan/client.go
type ClientCreator struct{}
type ClientCreator struct{ proxy.CreatorCommonStruct }
func (ClientCreator) MultiTransportLayer() bool {
func (ClientCreator) UseUDPAsMsgConn() bool {
return false
}
func (ClientCreator) URLToDialConf(url *url.URL, dc *proxy.DialConf, format int) (*proxy.DialConf, error) {
switch format {
case proxy.UrlStandardFormat:
@@ -56,6 +57,9 @@ type Client struct {
use_mux bool
}
func (*Client) GetCreator() proxy.ClientCreator {
return ClientCreator{}
}
func (*Client) Name() string {
return Name
}

View File

@@ -15,11 +15,8 @@ func init() {
proxy.RegisterServer(Name, &ServerCreator{})
}
type ServerCreator struct{}
type ServerCreator struct{ proxy.CreatorCommonStruct }
func (ServerCreator) MultiTransportLayer() bool {
return false
}
func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error) {
uuidStr := lc.Uuid

View File

@@ -16,11 +16,12 @@ func init() {
proxy.RegisterClient(Name, ClientCreator{})
}
type ClientCreator struct{}
type ClientCreator struct{ proxy.CreatorCommonStruct }
func (ClientCreator) MultiTransportLayer() bool {
func (ClientCreator) UseUDPAsMsgConn() bool {
return false
}
func (ClientCreator) NewClient(dc *proxy.DialConf) (proxy.Client, error) {
uuidStr := dc.Uuid
@@ -87,6 +88,9 @@ type Client struct {
use_mux bool
}
func (*Client) GetCreator() proxy.ClientCreator {
return ClientCreator{}
}
func (c *Client) Name() string {
if c.version == 0 {
return Name

View File

@@ -18,11 +18,7 @@ func init() {
proxy.RegisterServer(Name, &ServerCreator{})
}
type ServerCreator struct{}
func (ServerCreator) MultiTransportLayer() bool {
return false
}
type ServerCreator struct{ proxy.CreatorCommonStruct }
// 如果 lc.Version==0, 则只支持 v0.
func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error) {

View File

@@ -47,11 +47,12 @@ func GetEncryptAlgo(dc *proxy.DialConf) (result string) {
return result
}
type ClientCreator struct{}
type ClientCreator struct{ proxy.CreatorCommonStruct }
func (ClientCreator) MultiTransportLayer() bool {
func (ClientCreator) UseUDPAsMsgConn() bool {
return false
}
func (ClientCreator) URLToDialConf(url *url.URL, dc *proxy.DialConf, format int) (*proxy.DialConf, error) {
if format != proxy.UrlStandardFormat {
return dc, utils.ErrUnImplemented
@@ -95,6 +96,10 @@ type Client struct {
security byte
}
func (*Client) GetCreator() proxy.ClientCreator {
return ClientCreator{}
}
func (c *Client) specifySecurityByStr(security string) error {
security = strings.ToLower(security)
switch security {

View File

@@ -67,11 +67,8 @@ func authUserByAuthPairList(bs []byte, authPairList []authPair, antiReplayMachin
return
}
type ServerCreator struct{}
type ServerCreator struct{ proxy.CreatorCommonStruct }
func (ServerCreator) MultiTransportLayer() bool {
return false
}
func (ServerCreator) URLToListenConf(url *url.URL, lc *proxy.ListenConf, format int) (*proxy.ListenConf, error) {
switch format {

View File

@@ -3,7 +3,7 @@ package v2ray_simple_test
import (
"crypto/tls"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"testing"
@@ -26,7 +26,7 @@ func TestTCP_trojan_mux(t *testing.T) {
testTCP(t, "trojan", 0, "tcp", true)
}
//tcp测试我们直接使用http请求来测试
// tcp测试我们直接使用http请求来测试
func testTCP(t *testing.T, protocol string, version int, network string, innermux bool) {
utils.LogLevel = utils.Log_debug
utils.InitLog("")
@@ -157,7 +157,7 @@ func tryGetHttp(t *testing.T, client *http.Client, path string) {
t.Log("Got response, start read")
bs, err := ioutil.ReadAll(resp.Body)
bs, err := io.ReadAll(resp.Body)
if err != nil {
t.Log("get http failed read", err)
t.FailNow()