chore: renames

This commit is contained in:
Toby 2022-10-23 10:10:04 -07:00
parent ce86fd918a
commit 83764ba9de
3 changed files with 18 additions and 18 deletions

View File

@ -94,18 +94,18 @@ func (c *Client) connect() error {
stream, err := quicConn.OpenStreamSync(ctx) stream, err := quicConn.OpenStreamSync(ctx)
ctxCancel() ctxCancel()
if err != nil { if err != nil {
_ = closeErrorProtocol.Send(quicConn) _ = qErrorProtocol.Send(quicConn)
_ = pktConn.Close() _ = pktConn.Close()
return err return err
} }
ok, msg, err := c.handleControlStream(quicConn, stream) ok, msg, err := c.handleControlStream(quicConn, stream)
if err != nil { if err != nil {
_ = closeErrorProtocol.Send(quicConn) _ = qErrorProtocol.Send(quicConn)
_ = pktConn.Close() _ = pktConn.Close()
return err return err
} }
if !ok { if !ok {
_ = closeErrorAuth.Send(quicConn) _ = qErrorAuth.Send(quicConn)
_ = pktConn.Close() _ = pktConn.Close()
return fmt.Errorf("auth error: %s", msg) 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 // Send client hello
err = struc.Pack(stream, &clientHello{ err = struc.Pack(stream, &clientHello{
Rate: transmissionRate{ Rate: maxRate{
SendBPS: c.sendBPS, SendBPS: c.sendBPS,
RecvBPS: c.recvBPS, RecvBPS: c.recvBPS,
}, },
@ -296,7 +296,7 @@ func (c *Client) DialUDP() (UDPConn, error) {
func (c *Client) Close() error { func (c *Client) Close() error {
c.reconnectMutex.Lock() c.reconnectMutex.Lock()
defer c.reconnectMutex.Unlock() defer c.reconnectMutex.Unlock()
err := closeErrorGeneric.Send(c.quicConn) err := qErrorGeneric.Send(c.quicConn)
_ = c.pktConn.Close() _ = c.pktConn.Close()
c.closed = true c.closed = true
return err return err

View File

@ -11,35 +11,35 @@ const (
protocolTimeout = 10 * time.Second protocolTimeout = 10 * time.Second
) )
type closeError struct { type qError struct {
Code quic.ApplicationErrorCode Code quic.ApplicationErrorCode
Msg string 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) return c.CloseWithError(e.Code, e.Msg)
} }
var ( var (
closeErrorGeneric = closeError{0, ""} qErrorGeneric = qError{0, ""}
closeErrorProtocol = closeError{1, "protocol error"} qErrorProtocol = qError{1, "protocol error"}
closeErrorAuth = closeError{2, "auth error"} qErrorAuth = qError{2, "auth error"}
) )
type transmissionRate struct { type maxRate struct {
SendBPS uint64 SendBPS uint64
RecvBPS uint64 RecvBPS uint64
} }
type clientHello struct { type clientHello struct {
Rate transmissionRate Rate maxRate
AuthLen uint16 `struc:"sizeof=Auth"` AuthLen uint16 `struc:"sizeof=Auth"`
Auth []byte Auth []byte
} }
type serverHello struct { type serverHello struct {
OK bool OK bool
Rate transmissionRate Rate maxRate
MessageLen uint16 `struc:"sizeof=Message"` MessageLen uint16 `struc:"sizeof=Message"`
Message string Message string
} }

View File

@ -117,17 +117,17 @@ func (s *Server) handleClient(cc quic.Connection) {
stream, err := cc.AcceptStream(ctx) stream, err := cc.AcceptStream(ctx)
ctxCancel() ctxCancel()
if err != nil { if err != nil {
_ = closeErrorProtocol.Send(cc) _ = qErrorProtocol.Send(cc)
return return
} }
// Handle the control stream // Handle the control stream
auth, ok, err := s.handleControlStream(cc, stream) auth, ok, err := s.handleControlStream(cc, stream)
if err != nil { if err != nil {
_ = closeErrorProtocol.Send(cc) _ = qErrorProtocol.Send(cc)
return return
} }
if !ok { if !ok {
_ = closeErrorAuth.Send(cc) _ = qErrorAuth.Send(cc)
return return
} }
// Start accepting streams and messages // 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.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()
_ = closeErrorGeneric.Send(cc) _ = qErrorGeneric.Send(cc)
s.disconnectFunc(cc.RemoteAddr(), auth, err) s.disconnectFunc(cc.RemoteAddr(), auth, err)
} }
@ -172,7 +172,7 @@ func (s *Server) handleControlStream(cc quic.Connection, stream quic.Stream) ([]
// Response // Response
err = struc.Pack(stream, &serverHello{ err = struc.Pack(stream, &serverHello{
OK: ok, OK: ok,
Rate: transmissionRate{ Rate: maxRate{
SendBPS: serverSendBPS, SendBPS: serverSendBPS,
RecvBPS: serverRecvBPS, RecvBPS: serverRecvBPS,
}, },