mirror of
https://github.com/cedar2025/hysteria.git
synced 2025-06-16 01:19:54 +00:00
chore: rename "cs" to "cc" (client session -> client connection)
This commit is contained in:
parent
223a9a4203
commit
b1d9ab6c6a
@ -97,11 +97,11 @@ func NewServer(addr string, tlsConfig *tls.Config, quicConfig *quic.Config,
|
|||||||
|
|
||||||
func (s *Server) Serve() error {
|
func (s *Server) Serve() error {
|
||||||
for {
|
for {
|
||||||
cs, err := s.listener.Accept(context.Background())
|
cc, err := s.listener.Accept(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go s.handleClient(cs)
|
go s.handleClient(cc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,36 +111,36 @@ func (s *Server) Close() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) handleClient(cs quic.Connection) {
|
func (s *Server) handleClient(cc quic.Connection) {
|
||||||
// Expect the client to create a control stream to send its own information
|
// Expect the client to create a control stream to send its own information
|
||||||
ctx, ctxCancel := context.WithTimeout(context.Background(), protocolTimeout)
|
ctx, ctxCancel := context.WithTimeout(context.Background(), protocolTimeout)
|
||||||
stream, err := cs.AcceptStream(ctx)
|
stream, err := cc.AcceptStream(ctx)
|
||||||
ctxCancel()
|
ctxCancel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = cs.CloseWithError(closeErrorCodeProtocol, "protocol error")
|
_ = cc.CloseWithError(closeErrorCodeProtocol, "protocol error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Handle the control stream
|
// Handle the control stream
|
||||||
auth, ok, err := s.handleControlStream(cs, stream)
|
auth, ok, err := s.handleControlStream(cc, stream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = cs.CloseWithError(closeErrorCodeProtocol, "protocol error")
|
_ = cc.CloseWithError(closeErrorCodeProtocol, "protocol error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
_ = cs.CloseWithError(closeErrorCodeAuth, "auth error")
|
_ = cc.CloseWithError(closeErrorCodeAuth, "auth error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Start accepting streams and messages
|
// Start accepting streams and messages
|
||||||
sc := newServerClient(cs, s.transport, auth, s.disableUDP, s.aclEngine,
|
sc := newServerClient(cc, s.transport, auth, s.disableUDP, s.aclEngine,
|
||||||
s.tcpRequestFunc, s.tcpErrorFunc, s.udpRequestFunc, s.udpErrorFunc,
|
s.tcpRequestFunc, s.tcpErrorFunc, s.udpRequestFunc, s.udpErrorFunc,
|
||||||
s.upCounterVec, s.downCounterVec, s.connGaugeVec)
|
s.upCounterVec, s.downCounterVec, s.connGaugeVec)
|
||||||
err = sc.Run()
|
err = sc.Run()
|
||||||
_ = cs.CloseWithError(closeErrorCodeGeneric, "")
|
_ = cc.CloseWithError(closeErrorCodeGeneric, "")
|
||||||
s.disconnectFunc(cs.RemoteAddr(), auth, err)
|
s.disconnectFunc(cc.RemoteAddr(), auth, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auth & negotiate speed
|
// Auth & negotiate speed
|
||||||
func (s *Server) handleControlStream(cs quic.Connection, stream quic.Stream) ([]byte, bool, error) {
|
func (s *Server) handleControlStream(cc quic.Connection, stream quic.Stream) ([]byte, bool, error) {
|
||||||
// Check version
|
// Check version
|
||||||
vb := make([]byte, 1)
|
vb := make([]byte, 1)
|
||||||
_, err := stream.Read(vb)
|
_, err := stream.Read(vb)
|
||||||
@ -168,7 +168,7 @@ func (s *Server) handleControlStream(cs quic.Connection, stream quic.Stream) ([]
|
|||||||
serverRecvBPS = s.recvBPS
|
serverRecvBPS = s.recvBPS
|
||||||
}
|
}
|
||||||
// Auth
|
// Auth
|
||||||
ok, msg := s.connectFunc(cs.RemoteAddr(), ch.Auth, serverSendBPS, serverRecvBPS)
|
ok, msg := s.connectFunc(cc.RemoteAddr(), ch.Auth, serverSendBPS, serverRecvBPS)
|
||||||
// Response
|
// Response
|
||||||
err = struc.Pack(stream, &serverHello{
|
err = struc.Pack(stream, &serverHello{
|
||||||
OK: ok,
|
OK: ok,
|
||||||
@ -183,7 +183,7 @@ func (s *Server) handleControlStream(cs quic.Connection, stream quic.Stream) ([]
|
|||||||
}
|
}
|
||||||
// Set the congestion accordingly
|
// Set the congestion accordingly
|
||||||
if ok {
|
if ok {
|
||||||
cs.SetCongestionControl(congestion.NewBrutalSender(serverSendBPS))
|
cc.SetCongestionControl(congestion.NewBrutalSender(serverSendBPS))
|
||||||
}
|
}
|
||||||
return ch.Auth, ok, nil
|
return ch.Auth, ok, nil
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
const udpBufferSize = 65535
|
const udpBufferSize = 65535
|
||||||
|
|
||||||
type serverClient struct {
|
type serverClient struct {
|
||||||
CS quic.Connection
|
CC quic.Connection
|
||||||
Transport *transport.ServerTransport
|
Transport *transport.ServerTransport
|
||||||
Auth []byte
|
Auth []byte
|
||||||
ClientAddr net.Addr
|
ClientAddr net.Addr
|
||||||
@ -40,17 +40,17 @@ type serverClient struct {
|
|||||||
udpDefragger defragger
|
udpDefragger defragger
|
||||||
}
|
}
|
||||||
|
|
||||||
func newServerClient(cs quic.Connection, tr *transport.ServerTransport, auth []byte, disableUDP bool, ACLEngine *acl.Engine,
|
func newServerClient(cc quic.Connection, tr *transport.ServerTransport, auth []byte, disableUDP bool, ACLEngine *acl.Engine,
|
||||||
CTCPRequestFunc TCPRequestFunc, CTCPErrorFunc TCPErrorFunc,
|
CTCPRequestFunc TCPRequestFunc, CTCPErrorFunc TCPErrorFunc,
|
||||||
CUDPRequestFunc UDPRequestFunc, CUDPErrorFunc UDPErrorFunc,
|
CUDPRequestFunc UDPRequestFunc, CUDPErrorFunc UDPErrorFunc,
|
||||||
UpCounterVec, DownCounterVec *prometheus.CounterVec,
|
UpCounterVec, DownCounterVec *prometheus.CounterVec,
|
||||||
ConnGaugeVec *prometheus.GaugeVec,
|
ConnGaugeVec *prometheus.GaugeVec,
|
||||||
) *serverClient {
|
) *serverClient {
|
||||||
sc := &serverClient{
|
sc := &serverClient{
|
||||||
CS: cs,
|
CC: cc,
|
||||||
Transport: tr,
|
Transport: tr,
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
ClientAddr: cs.RemoteAddr(),
|
ClientAddr: cc.RemoteAddr(),
|
||||||
DisableUDP: disableUDP,
|
DisableUDP: disableUDP,
|
||||||
ACLEngine: ACLEngine,
|
ACLEngine: ACLEngine,
|
||||||
CTCPRequestFunc: CTCPRequestFunc,
|
CTCPRequestFunc: CTCPRequestFunc,
|
||||||
@ -72,7 +72,7 @@ func (c *serverClient) Run() error {
|
|||||||
if !c.DisableUDP {
|
if !c.DisableUDP {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
msg, err := c.CS.ReceiveMessage()
|
msg, err := c.CC.ReceiveMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func (c *serverClient) Run() error {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
stream, err := c.CS.AcceptStream(context.Background())
|
stream, err := c.CC.AcceptStream(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ func (c *serverClient) handleUDP(stream quic.Stream) {
|
|||||||
}
|
}
|
||||||
// try no frag first
|
// try no frag first
|
||||||
_ = struc.Pack(&msgBuf, &msg)
|
_ = struc.Pack(&msgBuf, &msg)
|
||||||
sendErr := c.CS.SendMessage(msgBuf.Bytes())
|
sendErr := c.CC.SendMessage(msgBuf.Bytes())
|
||||||
if sendErr != nil {
|
if sendErr != nil {
|
||||||
if errSize, ok := sendErr.(quic.ErrMessageToLarge); ok {
|
if errSize, ok := sendErr.(quic.ErrMessageToLarge); ok {
|
||||||
// need to frag
|
// need to frag
|
||||||
@ -339,7 +339,7 @@ func (c *serverClient) handleUDP(stream quic.Stream) {
|
|||||||
for _, fragMsg := range fragMsgs {
|
for _, fragMsg := range fragMsgs {
|
||||||
msgBuf.Reset()
|
msgBuf.Reset()
|
||||||
_ = struc.Pack(&msgBuf, &fragMsg)
|
_ = struc.Pack(&msgBuf, &fragMsg)
|
||||||
_ = c.CS.SendMessage(msgBuf.Bytes())
|
_ = c.CC.SendMessage(msgBuf.Bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user