Files
v2ray_simple/advLayer/quic/conn.go
e1732a364fed f28f0d0bee 修订代码, 默认loglevel 改为 Log_info.
对一般用户而言,还是需要使用Info等级 来了解一下 一般的 日志情况,等到使用熟练之后,且确认运行没有错误后, 可以自行调为 warning 来提升性能

发现 bubble包 还自己引入了 命令行参数,这十分不可取,所以我们还是直接使用其代码。

将其它包中 的 命令行参数 统一 移动 到 cmd/verysimple 中;tls lazy 特性因为还在 调试阶段,所以 命令行参数 仍然放到 v2ray_simple 包中。
2022-04-26 13:22:18 +08:00

53 lines
1.2 KiB
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 quic
import (
"net"
"sync/atomic"
"github.com/lucas-clemente/quic-go"
)
// 对 quic.Connection 的一个包装。
//用于 跟踪 一个 session 中 所开启的 stream的数量.
type connState struct {
quic.Connection
id [16]byte
openedStreamCount int32
}
//给 quic.Stream 添加 方法使其满足 net.Conn.
// quic.Stream 唯独不支持 LocalAddr 和 RemoteAddr 方法.
// 因为它是通过 StreamID 来识别连接. 不过session是有的。
type StreamConn struct {
quic.Stream
laddr, raddr net.Addr
relatedConnState *connState
isclosed bool
}
func (sc StreamConn) LocalAddr() net.Addr {
return sc.laddr
}
func (sc StreamConn) RemoteAddr() net.Addr {
return sc.raddr
}
//这里必须要同时调用 CancelRead 和 CancelWrite
// 因为 quic-go这个设计的是双工的调用Close实际上只是间接调用了 CancelWrite
// 看 quic-go包中的 quic.SendStream 的注释就知道了.
func (sc StreamConn) Close() error {
if sc.isclosed {
return nil
}
sc.isclosed = true
sc.CancelRead(quic.StreamErrorCode(quic.ConnectionRefused))
sc.CancelWrite(quic.StreamErrorCode(quic.ConnectionRefused))
if rss := sc.relatedConnState; rss != nil {
atomic.AddInt32(&rss.openedStreamCount, -1)
}
return sc.Stream.Close()
}