quic

package
v1.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package quic defines functions to listen and dial quic, with some customizable congestion settings.

quic的包装太简单了, 直接参考 https://github.com/lucas-clemente/quic-go/blob/master/example/echo/echo.go

Hysteria Brutal Congestion Control

这里我们 还选择性 使用 hysteria的 brutal阻控. 见 https://github.com/tobyxdd/quic-go 中 toby的 *-mod 分支, 里面会多一个 congestion 文件夹.

我们这里利用其阻控,但是没有使用hysteria的通知速率和 auth的 数据头,也就是说我们这里是纯quic协议的情况下使用了hysteria的优点。

我们要是以后不使用hysteria的话,只需删掉 useHysteria 里的代码, 删掉 pacer.go/brutal.go, 并删掉 go.mod中的replace部分. 然后proxy.go里的 相关配置部分也要删掉 在 prepareTLS_for* 函数中 的相关配置 即可.

Imperfect Package

引用的 lucas-clemente/quic-go 包 是不完美的,它对阻塞控制支持不好,而且cpu占用率高。以后有更好的包的话要及时切换到好包。

我在macm1里实测,内网单机极速测速的情况下,本来tcp的vlesss能达到3000mbps的速度,到了vless+quic就只能达到 1333mbps左右。

实际上就是因为quic-go包占用cpu太猛了,导致cpu占用率达到100%瓶颈,所以速度无法进一步提高。

Index

Constants

View Source
const (
	//100mbps
	Default_hysteriaMaxByteCount           = 1024 * 1024 / 8 * 100
	Default_Server_maxStreamCountInOneConn = 4 //一个 Connection 中 stream越多, 性能越低, 因此我们这里限制为4

)

Variables

View Source
var (
	//h3
	DefaultAlpnList = []string{"h3"}
)
View Source
var TheCustomRate = 0.75

Functions

func CloseConn

func CloseConn(conn any)

func ListenInitialLayers

func ListenInitialLayers(addr string, tlsConf tls.Config, arg arguments, newSubConnFunc func(net.Conn)) (returnCloser io.Closer)

non-blocking

func SniffQUIC added in v1.2.2

func SniffQUIC(b []byte) (sni string)

来自v2ray, 实际上就是先嗅探quic,之后再嗅探tls层。也就是说quic握手包是套在tls握手包外面的。

Types

type BrutalSender

type BrutalSender struct {
	// contains filtered or unexported fields
}

func NewBrutalSender

func NewBrutalSender(bps congestion.ByteCount) *BrutalSender

func (*BrutalSender) CanSend

func (b *BrutalSender) CanSend(bytesInFlight congestion.ByteCount) bool

func (*BrutalSender) GetCongestionWindow

func (b *BrutalSender) GetCongestionWindow() congestion.ByteCount

func (*BrutalSender) HasPacingBudget

func (b *BrutalSender) HasPacingBudget() bool

func (*BrutalSender) InRecovery

func (b *BrutalSender) InRecovery() bool

func (*BrutalSender) InSlowStart

func (b *BrutalSender) InSlowStart() bool

func (*BrutalSender) MaybeExitSlowStart

func (b *BrutalSender) MaybeExitSlowStart()

func (*BrutalSender) OnPacketAcked

func (b *BrutalSender) OnPacketAcked(number congestion.PacketNumber, ackedBytes congestion.ByteCount,
	priorInFlight congestion.ByteCount, eventTime time.Time)

func (*BrutalSender) OnPacketLost

func (b *BrutalSender) OnPacketLost(number congestion.PacketNumber, lostBytes congestion.ByteCount,
	priorInFlight congestion.ByteCount)

func (*BrutalSender) OnPacketSent

func (b *BrutalSender) OnPacketSent(sentTime time.Time, bytesInFlight congestion.ByteCount,
	packetNumber congestion.PacketNumber, bytes congestion.ByteCount, isRetransmittable bool)

func (*BrutalSender) OnRetransmissionTimeout

func (b *BrutalSender) OnRetransmissionTimeout(packetsRetransmitted bool)

func (*BrutalSender) SetMaxDatagramSize

func (b *BrutalSender) SetMaxDatagramSize(size congestion.ByteCount)

func (*BrutalSender) SetRTTStatsProvider

func (b *BrutalSender) SetRTTStatsProvider(rttStats congestion.RTTStatsProvider)

func (*BrutalSender) TimeUntilSend

func (b *BrutalSender) TimeUntilSend(bytesInFlight congestion.ByteCount) time.Time

type BrutalSender_M

type BrutalSender_M struct {
	// contains filtered or unexported fields
}

func NewBrutalSender_M

func NewBrutalSender_M(bps congestion.ByteCount) *BrutalSender_M

func (*BrutalSender_M) CanSend

func (b *BrutalSender_M) CanSend(bytesInFlight congestion.ByteCount) bool

func (*BrutalSender_M) GetCongestionWindow

func (b *BrutalSender_M) GetCongestionWindow() congestion.ByteCount

func (*BrutalSender_M) HasPacingBudget

func (b *BrutalSender_M) HasPacingBudget() bool

func (*BrutalSender_M) InRecovery

func (b *BrutalSender_M) InRecovery() bool

func (*BrutalSender_M) InSlowStart

func (b *BrutalSender_M) InSlowStart() bool

func (*BrutalSender_M) MaybeExitSlowStart

func (b *BrutalSender_M) MaybeExitSlowStart()

func (*BrutalSender_M) OnPacketAcked

func (b *BrutalSender_M) OnPacketAcked(number congestion.PacketNumber, ackedBytes congestion.ByteCount, priorInFlight congestion.ByteCount, eventTime time.Time)

func (*BrutalSender_M) OnPacketLost

func (b *BrutalSender_M) OnPacketLost(number congestion.PacketNumber, lostBytes congestion.ByteCount, priorInFlight congestion.ByteCount)

func (*BrutalSender_M) OnPacketSent

func (b *BrutalSender_M) OnPacketSent(sentTime time.Time, bytesInFlight congestion.ByteCount,
	packetNumber congestion.PacketNumber, bytes congestion.ByteCount, isRetransmittable bool)

func (*BrutalSender_M) OnRetransmissionTimeout

func (b *BrutalSender_M) OnRetransmissionTimeout(packetsRetransmitted bool)

func (*BrutalSender_M) SetMaxDatagramSize

func (b *BrutalSender_M) SetMaxDatagramSize(size congestion.ByteCount)

func (*BrutalSender_M) SetRTTStatsProvider

func (b *BrutalSender_M) SetRTTStatsProvider(rttStats congestion.RTTStatsProvider)

func (*BrutalSender_M) TimeUntilSend

func (b *BrutalSender_M) TimeUntilSend(bytesInFlight congestion.ByteCount) time.Time

type Client

type Client struct {
	Creator
	// contains filtered or unexported fields
}

implements advLayer.MuxClient

func NewClient

func NewClient(addr *netLayer.Addr, tConf tls.Config, args arguments) *Client

func (*Client) DialSubConn

func (c *Client) DialSubConn(thing any) (net.Conn, error)

func (*Client) GetCommonConn

func (c *Client) GetCommonConn(_ net.Conn) (any, error)

获取已拨号的连接 / 重新从底层拨号。返回 可作 c.DialSubConn 参数 的值.

func (*Client) GetCreator added in v1.2.0

func (*Client) GetCreator() advLayer.Creator

func (*Client) GetPath

func (c *Client) GetPath() string

func (*Client) IsEarly

func (c *Client) IsEarly() bool

type Creator

type Creator struct{}

func (Creator) CanHandleHeaders added in v1.2.0

func (Creator) CanHandleHeaders() bool

func (Creator) GetDefaultAlpn

func (Creator) GetDefaultAlpn() (alpn string, mustUse bool)

func (Creator) IsMux added in v1.2.0

func (Creator) IsMux() bool

func (Creator) IsSuper added in v1.2.0

func (Creator) IsSuper() bool

func (Creator) NewClientFromConf

func (Creator) NewClientFromConf(conf *advLayer.Conf) (advLayer.Client, error)

func (Creator) NewServerFromConf

func (Creator) NewServerFromConf(conf *advLayer.Conf) (advLayer.Server, error)

func (Creator) PackageID

func (Creator) PackageID() string

func (Creator) ProtocolName added in v1.2.0

func (Creator) ProtocolName() string

type Server

type Server struct {
	Creator
	// contains filtered or unexported fields
}

implements advLayer.SuperMuxServer

func (*Server) GetPath

func (s *Server) GetPath() string

quic 没path配置;return ""

func (*Server) StartHandle

func (s *Server) StartHandle(underlay net.Conn, newSubConnFunc func(net.Conn), _ func(httpLayer.FallbackMeta))

阻塞,不支持回落。

func (*Server) StartListen

func (s *Server) StartListen(newSubConnFunc func(net.Conn)) (baseConn io.Closer)

func (*Server) Stop

func (s *Server) Stop()

type StreamConn

type StreamConn struct {
	quic.Stream
	// contains filtered or unexported fields
}

implements net.Conn.

func (*StreamConn) Close

func (sc *StreamConn) Close() error

func (*StreamConn) LocalAddr

func (sc *StreamConn) LocalAddr() net.Addr

func (*StreamConn) Reject added in v1.2.4

func (sc *StreamConn) Reject()

implements netLayer.RejectConn, placeholder

func (*StreamConn) RejectBehaviorDefined added in v1.2.4

func (sc *StreamConn) RejectBehaviorDefined() bool

implements netLayer.RejectConn, return false

func (*StreamConn) RemoteAddr

func (sc *StreamConn) RemoteAddr() net.Addr

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL