mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-08 13:29:56 +00:00
Protocol version check
This commit is contained in:
parent
fc4d573f3d
commit
7b841aa203
@ -106,8 +106,13 @@ func (c *Client) connectToServer() error {
|
||||
}
|
||||
|
||||
func (c *Client) handleControlStream(qs quic.Session, stream quic.Stream) (bool, string, error) {
|
||||
// Send protocol version
|
||||
_, err := stream.Write([]byte{protocolVersion})
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
// Send client hello
|
||||
err := struc.Pack(stream, &clientHello{
|
||||
err = struc.Pack(stream, &clientHello{
|
||||
Rate: transmissionRate{
|
||||
SendBPS: c.sendBPS,
|
||||
RecvBPS: c.recvBPS,
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
protocolVersion = uint8(1)
|
||||
protocolVersion = uint8(2)
|
||||
protocolTimeout = 10 * time.Second
|
||||
|
||||
closeErrorCodeGeneric = 0
|
||||
|
@ -4,16 +4,14 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/lunixbochs/struc"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/tobyxdd/hysteria/pkg/acl"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
const dialTimeout = 10 * time.Second
|
||||
|
||||
type AuthFunc func(addr net.Addr, auth []byte, sSend uint64, sRecv uint64) (bool, string)
|
||||
type TCPRequestFunc func(addr net.Addr, auth []byte, reqAddr string, action acl.Action, arg string)
|
||||
type TCPErrorFunc func(addr net.Addr, auth []byte, reqAddr string, err error)
|
||||
@ -132,8 +130,18 @@ func (s *Server) handleClient(cs quic.Session) {
|
||||
|
||||
// Auth & negotiate speed
|
||||
func (s *Server) handleControlStream(cs quic.Session, stream quic.Stream) ([]byte, bool, error) {
|
||||
// Check version
|
||||
vb := make([]byte, 1)
|
||||
_, err := stream.Read(vb)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
if vb[0] != protocolVersion {
|
||||
return nil, false, fmt.Errorf("unsupported protocol version %d, expecting %d", vb[0], protocolVersion)
|
||||
}
|
||||
// Parse client hello
|
||||
var ch clientHello
|
||||
err := struc.Unpack(stream, &ch)
|
||||
err = struc.Unpack(stream, &ch)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user