mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
fix #141, 修订代码; direct若配置了sendThough,则会打印该地址
This commit is contained in:
8
main.go
8
main.go
@@ -254,7 +254,7 @@ func handleNewIncomeConnection(inServer proxy.Server, defaultClientForThis proxy
|
||||
addrstr := wrappedConn.RemoteAddr().String()
|
||||
ce.Write(
|
||||
zap.String("from", addrstr),
|
||||
zap.String("handler", proxy.GetVSI_url(inServer)),
|
||||
zap.String("handler", proxy.GetVSI_url(inServer, "")),
|
||||
)
|
||||
|
||||
iics.cachedRemoteAddr = addrstr
|
||||
@@ -1130,7 +1130,7 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,
|
||||
ce.Write(
|
||||
zap.String("Fallback from", iics.cachedRemoteAddr),
|
||||
zap.String("Target", targetAddr.UrlString()),
|
||||
zap.String("through", proxy.GetVSI_url(client)),
|
||||
zap.String("through", proxy.GetVSI_url(client, targetAddr.Network)),
|
||||
zap.Int("with xver", iics.fallbackXver),
|
||||
)
|
||||
|
||||
@@ -1138,7 +1138,7 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,
|
||||
ce.Write(
|
||||
zap.String("Fallback from", iics.cachedRemoteAddr),
|
||||
zap.String("Target", targetAddr.UrlString()),
|
||||
zap.String("through", proxy.GetVSI_url(client)),
|
||||
zap.String("through", proxy.GetVSI_url(client, targetAddr.Network)),
|
||||
)
|
||||
|
||||
}
|
||||
@@ -1146,7 +1146,7 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,
|
||||
ce.Write(
|
||||
zap.String("From", iics.cachedRemoteAddr),
|
||||
zap.String("Target", targetAddr.UrlString()),
|
||||
zap.String("through", proxy.GetVSI_url(client)),
|
||||
zap.String("through", proxy.GetVSI_url(client, targetAddr.Network)),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -113,7 +113,8 @@ defaultPart:
|
||||
|
||||
} else {
|
||||
//一般情况下,unix domain socket 会到达这里,其他情况则都被前面代码捕获到了
|
||||
if sockopt == nil {
|
||||
|
||||
if sockopt == nil && localAddr == nil {
|
||||
resultConn, err = net.DialTimeout(a.Network, a.String(), DialTimeout)
|
||||
} else {
|
||||
resultConn, err = a.DialWithOpt(sockopt, localAddr)
|
||||
@@ -161,6 +162,7 @@ func (a Addr) DialWithOpt(sockopt *Sockopt, localAddr net.Addr) (net.Conn, error
|
||||
} else {
|
||||
a.Network = "tcp4"
|
||||
}
|
||||
dialer.FallbackDelay = -1
|
||||
}
|
||||
case "udp":
|
||||
if ta, ok := localAddr.(*net.UDPAddr); ok && ta != nil {
|
||||
|
||||
@@ -57,6 +57,13 @@ func (*DirectClient) GetCreator() ClientCreator {
|
||||
return DirectCreator{}
|
||||
}
|
||||
|
||||
func (d *DirectClient) AddrStr() string {
|
||||
if d.LocalTCPAddr() != nil {
|
||||
return d.LocalTCPAddr().String()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// 若 underlay 为nil,则会对target进行拨号, 否则返回underlay本身
|
||||
func (d *DirectClient) Handshake(underlay net.Conn, firstPayload []byte, target netLayer.Addr) (result io.ReadWriteCloser, err error) {
|
||||
if d.Network() == "udp" {
|
||||
|
||||
@@ -117,21 +117,30 @@ type UserServer interface {
|
||||
//
|
||||
// An Example of a full name: tcp+tls+ws+vless.
|
||||
func GetFullName(pc BaseInterface) string {
|
||||
if n := pc.Name(); n == DirectName {
|
||||
return n
|
||||
} else {
|
||||
|
||||
return getFullNameBuilder(pc, n).String()
|
||||
}
|
||||
return getFullNameBuilder(pc, pc.Name()).String()
|
||||
}
|
||||
|
||||
// return GetFullName(pc) + "://" + pc.AddrStr() (+ #tag)
|
||||
func GetVSI_url(pc BaseInterface) string {
|
||||
func GetVSI_url(pc BaseInterface, targetNetwork string) string {
|
||||
n := pc.Name()
|
||||
|
||||
sb := getFullNameBuilder(pc, n)
|
||||
sb.WriteString("://")
|
||||
sb.WriteString(pc.AddrStr())
|
||||
if n == DirectName {
|
||||
if targetNetwork == "tcp" {
|
||||
if lta := pc.GetBase().LTA; lta != nil {
|
||||
sb.WriteString(lta.String())
|
||||
}
|
||||
} else if targetNetwork == "udp" {
|
||||
if lua := pc.GetBase().LUA; lua != nil {
|
||||
sb.WriteString(lua.String())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if t := pc.GetTag(); t != "" {
|
||||
sb.WriteByte('#')
|
||||
sb.WriteString(t)
|
||||
|
||||
@@ -405,9 +405,10 @@ For:
|
||||
}
|
||||
|
||||
targetAddr = netLayer.Addr{
|
||||
IP: theIP,
|
||||
Name: theName,
|
||||
Port: thePort,
|
||||
IP: theIP,
|
||||
Name: theName,
|
||||
Port: thePort,
|
||||
Network: "tcp",
|
||||
}
|
||||
|
||||
return underlay, nil, targetAddr, nil
|
||||
|
||||
@@ -80,7 +80,7 @@ func (ClientCreator) URLToDialConf(url *url.URL, dc *proxy.DialConf, format int)
|
||||
type Client struct {
|
||||
proxy.Base
|
||||
|
||||
version int
|
||||
version byte
|
||||
|
||||
user utils.V2rayUser
|
||||
|
||||
@@ -95,12 +95,12 @@ func (c *Client) Name() string {
|
||||
if c.version == 0 {
|
||||
return Name
|
||||
}
|
||||
return Name + "_" + strconv.Itoa(c.version)
|
||||
return Name + "_" + strconv.Itoa(int(c.version))
|
||||
|
||||
// 根据 https://forum.golangbridge.org/t/fmt-sprintf-vs-string-concatenation/23006
|
||||
// 直接 + 比 fmt.Sprintf 快不少.
|
||||
}
|
||||
func (c *Client) Version() int { return c.version }
|
||||
func (c *Client) Version() int { return int(c.version) }
|
||||
func (c *Client) GetUser() utils.User {
|
||||
return c.user
|
||||
}
|
||||
|
||||
@@ -275,7 +275,7 @@ realPart:
|
||||
return nil, &UDPConn{
|
||||
Conn: underlay,
|
||||
V2rayUser: thisUUIDBytes,
|
||||
version: int(version),
|
||||
version: version,
|
||||
optionalReader: io.MultiReader(readbuf, underlay),
|
||||
raddr: targetAddr,
|
||||
remainFirstBufLen: readbuf.Len(),
|
||||
@@ -287,7 +287,7 @@ realPart:
|
||||
uc := &UserTCPConn{
|
||||
Conn: underlay,
|
||||
V2rayUser: thisUUIDBytes,
|
||||
version: int(version),
|
||||
version: version,
|
||||
optionalReader: io.MultiReader(readbuf, underlay),
|
||||
remainFirstBufLen: readbuf.Len(),
|
||||
underlayIsBasic: netLayer.IsBasicConn(underlay),
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/e1732a364fed/v2ray_simple/utils"
|
||||
)
|
||||
|
||||
//实现 net.Conn, io.ReaderFrom, utils.User, utils.MultiWriter, utils.MultiReader, netLayer.Splicer, netLayer.ConnWrapper
|
||||
// 实现 net.Conn, io.ReaderFrom, utils.User, utils.MultiWriter, utils.MultiReader, netLayer.Splicer, netLayer.ConnWrapper
|
||||
type UserTCPConn struct {
|
||||
net.Conn
|
||||
|
||||
@@ -23,7 +23,7 @@ type UserTCPConn struct {
|
||||
|
||||
underlayIsBasic bool
|
||||
|
||||
version int
|
||||
version byte
|
||||
isServerEnd bool //for v0
|
||||
|
||||
isntFirstPacket bool //for v0
|
||||
@@ -33,14 +33,14 @@ type UserTCPConn struct {
|
||||
}
|
||||
|
||||
func (u *UserTCPConn) GetProtocolVersion() int {
|
||||
return u.version
|
||||
return int(u.version)
|
||||
}
|
||||
|
||||
func (c *UserTCPConn) GetRawConn() net.Conn {
|
||||
return c.Conn
|
||||
}
|
||||
|
||||
//当前连接状态是否可以直接写入底层Conn而不经任何改动/包装
|
||||
// 当前连接状态是否可以直接写入底层Conn而不经任何改动/包装
|
||||
func (c *UserTCPConn) canDirectWrite() bool {
|
||||
return c.version == 1 || (c.version == 0 && !(c.isServerEnd && !c.isntFirstPacket))
|
||||
}
|
||||
@@ -154,13 +154,13 @@ func (c *UserTCPConn) Write(p []byte) (int, error) {
|
||||
}
|
||||
}
|
||||
|
||||
//专门适用于 裸奔splice的情况
|
||||
// 专门适用于 裸奔splice的情况
|
||||
func (c *UserTCPConn) ReadFrom(r io.Reader) (written int64, err error) {
|
||||
|
||||
return netLayer.TryReadFrom_withSplice(c, c.Conn, r, c.canDirectWrite)
|
||||
}
|
||||
|
||||
//如果是udp,则是多线程不安全的,如果是tcp,则安不安全看底层的链接。
|
||||
// 如果是udp,则是多线程不安全的,如果是tcp,则安不安全看底层的链接。
|
||||
// 这里规定,如果是UDP,则 每次 Read 得到的都是一个 完整的UDP 数据包,除非p给的太小……
|
||||
func (c *UserTCPConn) Read(p []byte) (int, error) {
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ type UDPConn struct {
|
||||
|
||||
remainFirstBufLen int
|
||||
|
||||
version int
|
||||
version byte
|
||||
|
||||
udp_multi bool
|
||||
isClientEnd bool
|
||||
@@ -47,7 +47,7 @@ func (u *UDPConn) Fullcone() bool {
|
||||
}
|
||||
|
||||
func (u *UDPConn) GetProtocolVersion() int {
|
||||
return u.version
|
||||
return int(u.version)
|
||||
}
|
||||
|
||||
func (u *UDPConn) WriteMsgTo(p []byte, raddr netLayer.Addr) error {
|
||||
|
||||
Reference in New Issue
Block a user