chore: rename "cs" to "cc" (client session -> client connection)

This commit is contained in:
Toby 2022-10-22 12:02:41 -07:00
parent 223a9a4203
commit b1d9ab6c6a
2 changed files with 22 additions and 22 deletions

View File

@ -97,11 +97,11 @@ func NewServer(addr string, tlsConfig *tls.Config, quicConfig *quic.Config,
func (s *Server) Serve() error {
for {
cs, err := s.listener.Accept(context.Background())
cc, err := s.listener.Accept(context.Background())
if err != nil {
return err
}
go s.handleClient(cs)
go s.handleClient(cc)
}
}
@ -111,36 +111,36 @@ func (s *Server) Close() error {
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
ctx, ctxCancel := context.WithTimeout(context.Background(), protocolTimeout)
stream, err := cs.AcceptStream(ctx)
stream, err := cc.AcceptStream(ctx)
ctxCancel()
if err != nil {
_ = cs.CloseWithError(closeErrorCodeProtocol, "protocol error")
_ = cc.CloseWithError(closeErrorCodeProtocol, "protocol error")
return
}
// Handle the control stream
auth, ok, err := s.handleControlStream(cs, stream)
auth, ok, err := s.handleControlStream(cc, stream)
if err != nil {
_ = cs.CloseWithError(closeErrorCodeProtocol, "protocol error")
_ = cc.CloseWithError(closeErrorCodeProtocol, "protocol error")
return
}
if !ok {
_ = cs.CloseWithError(closeErrorCodeAuth, "auth error")
_ = cc.CloseWithError(closeErrorCodeAuth, "auth error")
return
}
// 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.upCounterVec, s.downCounterVec, s.connGaugeVec)
err = sc.Run()
_ = cs.CloseWithError(closeErrorCodeGeneric, "")
s.disconnectFunc(cs.RemoteAddr(), auth, err)
_ = cc.CloseWithError(closeErrorCodeGeneric, "")
s.disconnectFunc(cc.RemoteAddr(), auth, err)
}
// 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
vb := make([]byte, 1)
_, err := stream.Read(vb)
@ -168,7 +168,7 @@ func (s *Server) handleControlStream(cs quic.Connection, stream quic.Stream) ([]
serverRecvBPS = s.recvBPS
}
// Auth
ok, msg := s.connectFunc(cs.RemoteAddr(), ch.Auth, serverSendBPS, serverRecvBPS)
ok, msg := s.connectFunc(cc.RemoteAddr(), ch.Auth, serverSendBPS, serverRecvBPS)
// Response
err = struc.Pack(stream, &serverHello{
OK: ok,
@ -183,7 +183,7 @@ func (s *Server) handleControlStream(cs quic.Connection, stream quic.Stream) ([]
}
// Set the congestion accordingly
if ok {
cs.SetCongestionControl(congestion.NewBrutalSender(serverSendBPS))
cc.SetCongestionControl(congestion.NewBrutalSender(serverSendBPS))
}
return ch.Auth, ok, nil
}

View File

@ -20,7 +20,7 @@ import (
const udpBufferSize = 65535
type serverClient struct {
CS quic.Connection
CC quic.Connection
Transport *transport.ServerTransport
Auth []byte
ClientAddr net.Addr
@ -40,17 +40,17 @@ type serverClient struct {
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,
CUDPRequestFunc UDPRequestFunc, CUDPErrorFunc UDPErrorFunc,
UpCounterVec, DownCounterVec *prometheus.CounterVec,
ConnGaugeVec *prometheus.GaugeVec,
) *serverClient {
sc := &serverClient{
CS: cs,
CC: cc,
Transport: tr,
Auth: auth,
ClientAddr: cs.RemoteAddr(),
ClientAddr: cc.RemoteAddr(),
DisableUDP: disableUDP,
ACLEngine: ACLEngine,
CTCPRequestFunc: CTCPRequestFunc,
@ -72,7 +72,7 @@ func (c *serverClient) Run() error {
if !c.DisableUDP {
go func() {
for {
msg, err := c.CS.ReceiveMessage()
msg, err := c.CC.ReceiveMessage()
if err != nil {
break
}
@ -81,7 +81,7 @@ func (c *serverClient) Run() error {
}()
}
for {
stream, err := c.CS.AcceptStream(context.Background())
stream, err := c.CC.AcceptStream(context.Background())
if err != nil {
return err
}
@ -330,7 +330,7 @@ func (c *serverClient) handleUDP(stream quic.Stream) {
}
// try no frag first
_ = struc.Pack(&msgBuf, &msg)
sendErr := c.CS.SendMessage(msgBuf.Bytes())
sendErr := c.CC.SendMessage(msgBuf.Bytes())
if sendErr != nil {
if errSize, ok := sendErr.(quic.ErrMessageToLarge); ok {
// need to frag
@ -339,7 +339,7 @@ func (c *serverClient) handleUDP(stream quic.Stream) {
for _, fragMsg := range fragMsgs {
msgBuf.Reset()
_ = struc.Pack(&msgBuf, &fragMsg)
_ = c.CS.SendMessage(msgBuf.Bytes())
_ = c.CC.SendMessage(msgBuf.Bytes())
}
}
}