Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
修复shadowsocks的udp传输错误问题, fix #201
Browse files Browse the repository at this point in the history
该问题来自vs的一个超陈旧的 udp bug,应该是自从实现了dns功能之后就存在了

当时写错了,把拷贝buf的方向写反了,而且错误地返回了EOF

同时realTargetAddr的network从dual写为udp的位置也需要提前

而且ss实际上不需要也不可能自己处理拨号。

我真是太笨拙了, 犯下这么多错。
  • Loading branch information
e1732a364fed committed Dec 21, 2022
1 parent d4a3a29 commit c8ce504
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,12 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,

var dialedCommonConn any

not_dial_here := !(realTargetAddr.Network == "udp" && client.GetCreator().UseUDPAsMsgConn())
switch realTargetAddr.Network {
case netLayer.DualNetworkName:
realTargetAddr.Network = targetAddr.Network
}

dialhere := !(realTargetAddr.Network == "udp" && client.GetCreator().UseUDPAsMsgConn())

/*
direct和shadowsocks的udp是自己拨号的,因为它用到了udp的包特性
Expand All @@ -1210,7 +1215,7 @@ func dialClient(iics incomingInserverConnState, targetAddr netLayer.Addr,

var muxC advLayer.MuxClient

if not_dial_here {
if dialhere {

if adv != "" && advClient.IsMux() {

Expand Down
4 changes: 2 additions & 2 deletions netLayer/udpConn.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ func (uc *UDPConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
if !ok {
return 0, uc.peerAddr, io.EOF
}
n = copy(msg.Data, p)
return n, uc.peerAddr, io.EOF
n = copy(p, msg.Data)
return n, uc.peerAddr, nil //io.EOF

case <-uc.readDeadline.Wait():
return 0, uc.peerAddr, os.ErrDeadlineExceeded
Expand Down
2 changes: 1 addition & 1 deletion proxy/shadowsocks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
type ClientCreator struct{ proxy.CreatorCommonStruct }

func (ClientCreator) UseUDPAsMsgConn() bool {
return true
return false
}
func (ClientCreator) MultiTransportLayer() bool {
return true
Expand Down

0 comments on commit c8ce504

Please sign in to comment.