Files
v2ray_simple/netLayer/udp_test.go
hahahrfool ce735dbb99 修订udp代码; dial配置 添加 fullcone 选项;默认为非fullcone
现在整个程序均通过了go test, main 也可以正常运行了。

Relay_UDP 函数添加流量计数;

发现之前 Relay函数的流量计数 在main.go里参数传反了,导致实际上计数的是上传而不是下载,已修复

对fullcone的情况做了特别考量。MsgConn的 Close函数在fullcone时不能随便被调用。

因此我添加了一个 CloseConnWithRaddr(raddr Addr) error  方法,以及 Fullcone() bool     方法

在utils包的init部分使用 rand 随机种子
2022-04-08 20:31:59 +08:00

25 lines
491 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package netLayer
import (
"net"
"testing"
"time"
"github.com/hahahrfool/v2ray_simple/utils"
)
func TestUDP(t *testing.T) {
//测试setdeadline的情况. 实测证明 SetReadDeadline 在Read过程中也可以使用 这样就可以防止阻塞
laddr, _ := net.ResolveUDPAddr("udp", ":"+RandPortStr())
udpConn, _ := net.ListenUDP("udp", laddr)
go func() {
time.Sleep(time.Second)
udpConn.SetReadDeadline(time.Now())
}()
udpConn.ReadFrom(utils.GetPacket())
t.Log("ok")
}