@@ -27,7 +27,7 @@ type Context struct {
2727
2828 mu sync.RWMutex
2929
30- logger * slog.Logger
30+ Logger * slog.Logger
3131}
3232
3333func newContext (conn quic.Connection , stream quic.Stream , logger * slog.Logger ) (ctx * Context ) {
@@ -40,18 +40,22 @@ func newContext(conn quic.Connection, stream quic.Stream, logger *slog.Logger) (
4040 ctx .Conn = conn
4141 ctx .Stream = stream
4242 ctx .connID = conn .RemoteAddr ().String ()
43- ctx .logger = logger .With ("conn_id" , conn .RemoteAddr ().String (), "stream_id" , stream .StreamID ())
43+ ctx .Logger = logger .With ("conn_id" , conn .RemoteAddr ().String (), "stream_id" , stream .StreamID ())
4444 return
4545}
4646
4747const clientInfoKey = "client_info"
4848
4949// ClientInfo holds client info, you can use `*Context.ClientInfo()` to get it after handshake.
5050type ClientInfo struct {
51- clientID string
52- clientType byte
53- clientName string
54- authName string
51+ // ID is client id from handshake.
52+ ID string
53+ // Type is client type from handshake.
54+ Type byte
55+ // Name is client name from handshake.
56+ Name string
57+ // AuthName is client authName from handshake.
58+ AuthName string
5559}
5660
5761// ClientInfo get client info from context.
@@ -67,17 +71,17 @@ func (c *Context) ClientInfo() *ClientInfo {
6771func (c * Context ) WithFrame (f frame.Frame ) * Context {
6872 if f .Type () == frame .TagOfHandshakeFrame {
6973 handshakeFrame := f .(* frame.HandshakeFrame )
70- c .logger = c .logger .With (
74+ c .Logger = c .Logger .With (
7175 "client_id" , handshakeFrame .ClientID ,
7276 "client_type" , ClientType (handshakeFrame .ClientType ).String (),
7377 "client_name" , handshakeFrame .Name ,
7478 "auth_name" , handshakeFrame .AuthName (),
7579 )
7680 c .Set (clientInfoKey , & ClientInfo {
77- clientID : handshakeFrame .ClientID ,
78- clientType : handshakeFrame .ClientType ,
79- clientName : handshakeFrame .Name ,
80- authName : handshakeFrame .AuthName (),
81+ ID : handshakeFrame .ClientID ,
82+ Type : handshakeFrame .ClientType ,
83+ Name : handshakeFrame .Name ,
84+ AuthName : handshakeFrame .AuthName (),
8185 })
8286 }
8387 c .Frame = f
@@ -86,7 +90,7 @@ func (c *Context) WithFrame(f frame.Frame) *Context {
8690
8791// Clean the context.
8892func (c * Context ) Clean () {
89- c .logger .Debug ("conn context clean" , "conn_id" , c .connID )
93+ c .Logger .Debug ("conn context clean" , "conn_id" , c .connID )
9094 c .reset ()
9195 ctxPool .Put (c )
9296}
@@ -96,15 +100,15 @@ func (c *Context) reset() {
96100 c .connID = ""
97101 c .Stream = nil
98102 c .Frame = nil
99- c .logger = nil
103+ c .Logger = nil
100104 for k := range c .Keys {
101105 delete (c .Keys , k )
102106 }
103107}
104108
105109// CloseWithError closes the stream and cleans the context.
106110func (c * Context ) CloseWithError (code yerr.ErrorCode , msg string ) {
107- c .logger .Debug ("conn context close, " , "err_code" , code , "err_msg" , msg )
111+ c .Logger .Debug ("conn context close, " , "err_code" , code , "err_msg" , msg )
108112 if c .Stream != nil {
109113 c .Stream .Close ()
110114 }
0 commit comments