mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
将socks5的dial注册到proxy
被汇报,有人有特殊需求要在内网里dial,那么还是加上socks5的client吧
This commit is contained in:
@@ -3,12 +3,29 @@ package socks5
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"net/url"
|
||||
|
||||
"github.com/e1732a364fed/v2ray_simple/netLayer"
|
||||
"github.com/e1732a364fed/v2ray_simple/proxy"
|
||||
"github.com/e1732a364fed/v2ray_simple/utils"
|
||||
)
|
||||
|
||||
func init() {
|
||||
proxy.RegisterClient(Name, &ClientCreator{})
|
||||
}
|
||||
|
||||
type ClientCreator struct{}
|
||||
|
||||
func (ClientCreator) NewClientFromURL(*url.URL) (proxy.Client, error) {
|
||||
s := &Client{}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (ClientCreator) NewClient(*proxy.DialConf) (proxy.Client, error) {
|
||||
s := &Client{}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
proxy.Base
|
||||
}
|
||||
@@ -17,7 +34,7 @@ func (*Client) Name() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
func (*Client) Handshake(underlay net.Conn, target netLayer.Addr) (result io.ReadWriteCloser, err error) {
|
||||
func (*Client) Handshake(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (result io.ReadWriteCloser, err error) {
|
||||
|
||||
if underlay == nil {
|
||||
panic("socks5 client handshake, nil underlay is not allowed")
|
||||
@@ -62,6 +79,9 @@ func (*Client) Handshake(underlay net.Conn, target netLayer.Addr) (result io.Rea
|
||||
return nil, utils.NumErr{Prefix: "socks5 client handshake failed when reading response", N: 2}
|
||||
|
||||
}
|
||||
if len(firstPayload) > 0 {
|
||||
underlay.Write(firstPayload)
|
||||
}
|
||||
|
||||
return underlay, nil
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ type Server struct {
|
||||
|
||||
type ServerCreator struct{}
|
||||
|
||||
func (ServerCreator) NewServerFromURL(u *url.URL) (proxy.Server, error) {
|
||||
func (ServerCreator) NewServerFromURL(*url.URL) (proxy.Server, error) {
|
||||
s := &Server{}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (ServerCreator) NewServer(dc *proxy.ListenConf) (proxy.Server, error) {
|
||||
func (ServerCreator) NewServer(*proxy.ListenConf) (proxy.Server, error) {
|
||||
s := &Server{}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user