mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-21 03:39:51 +00:00
commit
e338ed60cb
4
.gitignore
vendored
4
.gitignore
vendored
@ -183,4 +183,6 @@ cmd/relay/*.json
|
|||||||
hy_linux
|
hy_linux
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
/build/
|
/build/
|
||||||
|
|
||||||
|
config*.json
|
@ -134,7 +134,7 @@ func client(config *clientConfig) {
|
|||||||
up, down, _ := config.Speed()
|
up, down, _ := config.Speed()
|
||||||
for {
|
for {
|
||||||
try += 1
|
try += 1
|
||||||
c, err := core.NewClient(config.Server, auth, tlsConfig, quicConfig, pktConnFunc, up, down,
|
c, err := core.NewClient(config.Server, auth, tlsConfig, quicConfig, pktConnFunc, up, down, config.FastOpen,
|
||||||
func(err error) {
|
func(err error) {
|
||||||
if config.QuitOnDisconnect {
|
if config.QuitOnDisconnect {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
|
@ -223,6 +223,7 @@ type clientConfig struct {
|
|||||||
ReceiveWindowConn uint64 `json:"recv_window_conn"`
|
ReceiveWindowConn uint64 `json:"recv_window_conn"`
|
||||||
ReceiveWindow uint64 `json:"recv_window"`
|
ReceiveWindow uint64 `json:"recv_window"`
|
||||||
DisableMTUDiscovery bool `json:"disable_mtu_discovery"`
|
DisableMTUDiscovery bool `json:"disable_mtu_discovery"`
|
||||||
|
FastOpen bool `json:"fast_open"`
|
||||||
Resolver string `json:"resolver"`
|
Resolver string `json:"resolver"`
|
||||||
ResolvePreference string `json:"resolve_preference"`
|
ResolvePreference string `json:"resolve_preference"`
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -92,3 +92,5 @@ require (
|
|||||||
replace github.com/lucas-clemente/quic-go => github.com/apernet/quic-go v0.31.1-0.20221119235156-55bf700f2dd4
|
replace github.com/lucas-clemente/quic-go => github.com/apernet/quic-go v0.31.1-0.20221119235156-55bf700f2dd4
|
||||||
|
|
||||||
replace github.com/LiamHaworth/go-tproxy => github.com/apernet/go-tproxy v0.0.0-20221025153553-ed04a2935f88
|
replace github.com/LiamHaworth/go-tproxy => github.com/apernet/go-tproxy v0.0.0-20221025153553-ed04a2935f88
|
||||||
|
|
||||||
|
replace github.com/elazarl/goproxy => github.com/apernet/goproxy v0.0.0-20221124043924-155acfaf278f
|
||||||
|
4
go.sum
4
go.sum
@ -49,6 +49,8 @@ github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UME
|
|||||||
github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA=
|
github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA=
|
||||||
github.com/apernet/go-tproxy v0.0.0-20221025153553-ed04a2935f88 h1:YNsl7PMiU9x/0CleMHJ7GUdS8y1aRTFwTxdSmLLEijQ=
|
github.com/apernet/go-tproxy v0.0.0-20221025153553-ed04a2935f88 h1:YNsl7PMiU9x/0CleMHJ7GUdS8y1aRTFwTxdSmLLEijQ=
|
||||||
github.com/apernet/go-tproxy v0.0.0-20221025153553-ed04a2935f88/go.mod h1:uxH+nFzlJug5OHjPYmzKwvVVb9wOToeGuLNVeerwWtc=
|
github.com/apernet/go-tproxy v0.0.0-20221025153553-ed04a2935f88/go.mod h1:uxH+nFzlJug5OHjPYmzKwvVVb9wOToeGuLNVeerwWtc=
|
||||||
|
github.com/apernet/goproxy v0.0.0-20221124043924-155acfaf278f h1:v3Bn97M5KWzdVajNphf3PxoHdsRF/RzBVovIsH/DEvY=
|
||||||
|
github.com/apernet/goproxy v0.0.0-20221124043924-155acfaf278f/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
|
||||||
github.com/apernet/quic-go v0.31.1-0.20221119235156-55bf700f2dd4 h1:rNk86XSaAK/nPyab0ZxI2uRWwYqse9JehOVG+ijOh0I=
|
github.com/apernet/quic-go v0.31.1-0.20221119235156-55bf700f2dd4 h1:rNk86XSaAK/nPyab0ZxI2uRWwYqse9JehOVG+ijOh0I=
|
||||||
github.com/apernet/quic-go v0.31.1-0.20221119235156-55bf700f2dd4/go.mod h1:0wFbizLgYzqHqtlyxyCaJKlE7bYgE6JQ+54TLd/Dq2g=
|
github.com/apernet/quic-go v0.31.1-0.20221119235156-55bf700f2dd4/go.mod h1:0wFbizLgYzqHqtlyxyCaJKlE7bYgE6JQ+54TLd/Dq2g=
|
||||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||||
@ -78,8 +80,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||||
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||||
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0=
|
|
||||||
github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
|
|
||||||
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
|
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
|
||||||
github.com/elazarl/goproxy/ext v0.0.0-20221015165544-a0805db90819 h1:PBc3oUutXxwCibSLQCmpunGvruDnoS6kdnaL7a0xwKY=
|
github.com/elazarl/goproxy/ext v0.0.0-20221015165544-a0805db90819 h1:PBc3oUutXxwCibSLQCmpunGvruDnoS6kdnaL7a0xwKY=
|
||||||
github.com/elazarl/goproxy/ext v0.0.0-20221015165544-a0805db90819/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
|
github.com/elazarl/goproxy/ext v0.0.0-20221015165544-a0805db90819/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
|
||||||
|
@ -29,6 +29,7 @@ type Client struct {
|
|||||||
|
|
||||||
sendBPS, recvBPS uint64
|
sendBPS, recvBPS uint64
|
||||||
auth []byte
|
auth []byte
|
||||||
|
fastOpen bool
|
||||||
|
|
||||||
tlsConfig *tls.Config
|
tlsConfig *tls.Config
|
||||||
quicConfig *quic.Config
|
quicConfig *quic.Config
|
||||||
@ -48,7 +49,8 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(serverAddr string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config,
|
func NewClient(serverAddr string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config,
|
||||||
pktConnFunc pktconns.ClientPacketConnFunc, sendBPS uint64, recvBPS uint64, quicReconnectFunc func(err error),
|
pktConnFunc pktconns.ClientPacketConnFunc, sendBPS uint64, recvBPS uint64, fastOpen bool,
|
||||||
|
quicReconnectFunc func(err error),
|
||||||
) (*Client, error) {
|
) (*Client, error) {
|
||||||
quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud.DisablePathMTUDiscovery
|
quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud.DisablePathMTUDiscovery
|
||||||
c := &Client{
|
c := &Client{
|
||||||
@ -56,6 +58,7 @@ func NewClient(serverAddr string, auth []byte, tlsConfig *tls.Config, quicConfig
|
|||||||
sendBPS: sendBPS,
|
sendBPS: sendBPS,
|
||||||
recvBPS: recvBPS,
|
recvBPS: recvBPS,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
|
fastOpen: fastOpen,
|
||||||
tlsConfig: tlsConfig,
|
tlsConfig: tlsConfig,
|
||||||
quicConfig: quicConfig,
|
quicConfig: quicConfig,
|
||||||
pktConnFunc: pktConnFunc,
|
pktConnFunc: pktConnFunc,
|
||||||
@ -221,21 +224,26 @@ func (c *Client) DialTCP(addr string) (net.Conn, error) {
|
|||||||
_ = stream.Close()
|
_ = stream.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Read response
|
// If fast open is enabled, we return the stream immediately
|
||||||
var sr serverResponse
|
// and defer the response handling to the first Read() call
|
||||||
err = struc.Unpack(stream, &sr)
|
if !c.fastOpen {
|
||||||
if err != nil {
|
// Read response
|
||||||
_ = stream.Close()
|
var sr serverResponse
|
||||||
return nil, err
|
err = struc.Unpack(stream, &sr)
|
||||||
}
|
if err != nil {
|
||||||
if !sr.OK {
|
_ = stream.Close()
|
||||||
_ = stream.Close()
|
return nil, err
|
||||||
return nil, fmt.Errorf("connection rejected: %s", sr.Message)
|
}
|
||||||
|
if !sr.OK {
|
||||||
|
_ = stream.Close()
|
||||||
|
return nil, fmt.Errorf("connection rejected: %s", sr.Message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return &hyTCPConn{
|
return &hyTCPConn{
|
||||||
Orig: stream,
|
Orig: stream,
|
||||||
PseudoLocalAddr: session.LocalAddr(),
|
PseudoLocalAddr: session.LocalAddr(),
|
||||||
PseudoRemoteAddr: session.RemoteAddr(),
|
PseudoRemoteAddr: session.RemoteAddr(),
|
||||||
|
Established: !c.fastOpen,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,9 +314,23 @@ type hyTCPConn struct {
|
|||||||
Orig quic.Stream
|
Orig quic.Stream
|
||||||
PseudoLocalAddr net.Addr
|
PseudoLocalAddr net.Addr
|
||||||
PseudoRemoteAddr net.Addr
|
PseudoRemoteAddr net.Addr
|
||||||
|
Established bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *hyTCPConn) Read(b []byte) (n int, err error) {
|
func (w *hyTCPConn) Read(b []byte) (n int, err error) {
|
||||||
|
if !w.Established {
|
||||||
|
var sr serverResponse
|
||||||
|
err := struc.Unpack(w.Orig, &sr)
|
||||||
|
if err != nil {
|
||||||
|
_ = w.Close()
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if !sr.OK {
|
||||||
|
_ = w.Close()
|
||||||
|
return 0, fmt.Errorf("connection rejected: %s", sr.Message)
|
||||||
|
}
|
||||||
|
w.Established = true
|
||||||
|
}
|
||||||
return w.Orig.Read(b)
|
return w.Orig.Read(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user