mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-10-05 08:46:59 +08:00

对一般用户而言,还是需要使用Info等级 来了解一下 一般的 日志情况,等到使用熟练之后,且确认运行没有错误后, 可以自行调为 warning 来提升性能 发现 bubble包 还自己引入了 命令行参数,这十分不可取,所以我们还是直接使用其代码。 将其它包中 的 命令行参数 统一 移动 到 cmd/verysimple 中;tls lazy 特性因为还在 调试阶段,所以 命令行参数 仍然放到 v2ray_simple 包中。
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
//Package quic defines functions to listen and dial quic, with some customizable congestion settings.
|
||
//
|
||
// 这里我们 还选择性 使用 hysteria的 brutal阻控.
|
||
// 见 https://github.com/tobyxdd/quic-go 中 toby的 *-mod 分支, 里面会多一个 congestion 文件夹.
|
||
package quic
|
||
|
||
import (
|
||
"log"
|
||
"reflect"
|
||
"time"
|
||
|
||
"github.com/e1732a364fed/v2ray_simple/advLayer"
|
||
"github.com/lucas-clemente/quic-go"
|
||
)
|
||
|
||
func init() {
|
||
advLayer.ProtocolsMap["quic"] = true
|
||
}
|
||
|
||
//quic的包装太简单了
|
||
|
||
//超简单,直接参考 https://github.com/lucas-clemente/quic-go/blob/master/example/echo/echo.go
|
||
|
||
//我们这里利用了hysteria的阻控,但是没有使用hysteria的通知速率和 auth的 数据头,也就是说我们这里是纯quic协议的情况下使用了hysteria的优点。
|
||
|
||
//但是我在mac里实测,内网单机极速测速的情况下,本来tcp能达到3000mbps的速度,到了quic就只能达到 1333mbps左右。
|
||
|
||
//我们要是以后不使用hysteria的话,只需删掉 useHysteria 里的代码, 删掉 pacer.go/brutal.go, 并删掉 go.mod中的replace部分.
|
||
// 然后proxy.go里的 相关配置部分也要删掉 在 prepareTLS_for* 函数中 的相关配置 即可.
|
||
|
||
const (
|
||
//100mbps
|
||
Default_hysteriaMaxByteCount = 1024 * 1024 / 8 * 100
|
||
|
||
common_maxidletimeout = time.Second * 45
|
||
common_HandshakeIdleTimeout = time.Second * 8
|
||
common_ConnectionIDLength = 12
|
||
server_maxStreamCountInOneConn = 4 //一个 Connection 中 stream越多, 性能越低, 因此我们这里限制为4
|
||
)
|
||
|
||
func isActive(s quic.Connection) bool {
|
||
select {
|
||
case <-s.Context().Done():
|
||
return false
|
||
default:
|
||
return true
|
||
}
|
||
}
|
||
|
||
func CloseConn(baseC any) {
|
||
qc, ok := baseC.(quic.Connection)
|
||
if ok {
|
||
qc.CloseWithError(0, "")
|
||
} else {
|
||
log.Panicln("quic.CloseConn called with illegal parameter", reflect.TypeOf(baseC).String(), baseC)
|
||
}
|
||
}
|
||
|
||
var (
|
||
AlpnList = []string{"h3"}
|
||
|
||
common_ListenConfig = quic.Config{
|
||
ConnectionIDLength: common_ConnectionIDLength,
|
||
HandshakeIdleTimeout: common_HandshakeIdleTimeout,
|
||
MaxIdleTimeout: common_maxidletimeout,
|
||
MaxIncomingStreams: server_maxStreamCountInOneConn,
|
||
MaxIncomingUniStreams: -1,
|
||
KeepAlive: true,
|
||
}
|
||
|
||
common_DialConfig = quic.Config{
|
||
ConnectionIDLength: common_ConnectionIDLength,
|
||
HandshakeIdleTimeout: common_HandshakeIdleTimeout,
|
||
MaxIdleTimeout: common_maxidletimeout,
|
||
KeepAlive: true,
|
||
}
|
||
)
|