mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-10 06:29:56 +00:00
chore: renames
This commit is contained in:
parent
ce86fd918a
commit
83764ba9de
@ -94,18 +94,18 @@ func (c *Client) connect() error {
|
||||
stream, err := quicConn.OpenStreamSync(ctx)
|
||||
ctxCancel()
|
||||
if err != nil {
|
||||
_ = closeErrorProtocol.Send(quicConn)
|
||||
_ = qErrorProtocol.Send(quicConn)
|
||||
_ = pktConn.Close()
|
||||
return err
|
||||
}
|
||||
ok, msg, err := c.handleControlStream(quicConn, stream)
|
||||
if err != nil {
|
||||
_ = closeErrorProtocol.Send(quicConn)
|
||||
_ = qErrorProtocol.Send(quicConn)
|
||||
_ = pktConn.Close()
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
_ = closeErrorAuth.Send(quicConn)
|
||||
_ = qErrorAuth.Send(quicConn)
|
||||
_ = pktConn.Close()
|
||||
return fmt.Errorf("auth error: %s", msg)
|
||||
}
|
||||
@ -125,7 +125,7 @@ func (c *Client) handleControlStream(qc quic.Connection, stream quic.Stream) (bo
|
||||
}
|
||||
// Send client hello
|
||||
err = struc.Pack(stream, &clientHello{
|
||||
Rate: transmissionRate{
|
||||
Rate: maxRate{
|
||||
SendBPS: c.sendBPS,
|
||||
RecvBPS: c.recvBPS,
|
||||
},
|
||||
@ -296,7 +296,7 @@ func (c *Client) DialUDP() (UDPConn, error) {
|
||||
func (c *Client) Close() error {
|
||||
c.reconnectMutex.Lock()
|
||||
defer c.reconnectMutex.Unlock()
|
||||
err := closeErrorGeneric.Send(c.quicConn)
|
||||
err := qErrorGeneric.Send(c.quicConn)
|
||||
_ = c.pktConn.Close()
|
||||
c.closed = true
|
||||
return err
|
||||
|
@ -11,35 +11,35 @@ const (
|
||||
protocolTimeout = 10 * time.Second
|
||||
)
|
||||
|
||||
type closeError struct {
|
||||
type qError struct {
|
||||
Code quic.ApplicationErrorCode
|
||||
Msg string
|
||||
}
|
||||
|
||||
func (e closeError) Send(c quic.Connection) error {
|
||||
func (e qError) Send(c quic.Connection) error {
|
||||
return c.CloseWithError(e.Code, e.Msg)
|
||||
}
|
||||
|
||||
var (
|
||||
closeErrorGeneric = closeError{0, ""}
|
||||
closeErrorProtocol = closeError{1, "protocol error"}
|
||||
closeErrorAuth = closeError{2, "auth error"}
|
||||
qErrorGeneric = qError{0, ""}
|
||||
qErrorProtocol = qError{1, "protocol error"}
|
||||
qErrorAuth = qError{2, "auth error"}
|
||||
)
|
||||
|
||||
type transmissionRate struct {
|
||||
type maxRate struct {
|
||||
SendBPS uint64
|
||||
RecvBPS uint64
|
||||
}
|
||||
|
||||
type clientHello struct {
|
||||
Rate transmissionRate
|
||||
Rate maxRate
|
||||
AuthLen uint16 `struc:"sizeof=Auth"`
|
||||
Auth []byte
|
||||
}
|
||||
|
||||
type serverHello struct {
|
||||
OK bool
|
||||
Rate transmissionRate
|
||||
Rate maxRate
|
||||
MessageLen uint16 `struc:"sizeof=Message"`
|
||||
Message string
|
||||
}
|
||||
|
@ -117,17 +117,17 @@ func (s *Server) handleClient(cc quic.Connection) {
|
||||
stream, err := cc.AcceptStream(ctx)
|
||||
ctxCancel()
|
||||
if err != nil {
|
||||
_ = closeErrorProtocol.Send(cc)
|
||||
_ = qErrorProtocol.Send(cc)
|
||||
return
|
||||
}
|
||||
// Handle the control stream
|
||||
auth, ok, err := s.handleControlStream(cc, stream)
|
||||
if err != nil {
|
||||
_ = closeErrorProtocol.Send(cc)
|
||||
_ = qErrorProtocol.Send(cc)
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
_ = closeErrorAuth.Send(cc)
|
||||
_ = qErrorAuth.Send(cc)
|
||||
return
|
||||
}
|
||||
// Start accepting streams and messages
|
||||
@ -135,7 +135,7 @@ func (s *Server) handleClient(cc quic.Connection) {
|
||||
s.tcpRequestFunc, s.tcpErrorFunc, s.udpRequestFunc, s.udpErrorFunc,
|
||||
s.upCounterVec, s.downCounterVec, s.connGaugeVec)
|
||||
err = sc.Run()
|
||||
_ = closeErrorGeneric.Send(cc)
|
||||
_ = qErrorGeneric.Send(cc)
|
||||
s.disconnectFunc(cc.RemoteAddr(), auth, err)
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ func (s *Server) handleControlStream(cc quic.Connection, stream quic.Stream) ([]
|
||||
// Response
|
||||
err = struc.Pack(stream, &serverHello{
|
||||
OK: ok,
|
||||
Rate: transmissionRate{
|
||||
Rate: maxRate{
|
||||
SendBPS: serverSendBPS,
|
||||
RecvBPS: serverRecvBPS,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user