mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 04:07:35 +03:00
attach a tracing ID to the session context
This commit is contained in:
parent
3138a45fde
commit
4917760726
7 changed files with 45 additions and 3 deletions
|
@ -37,8 +37,9 @@ type client struct {
|
|||
|
||||
session quicSession
|
||||
|
||||
tracer logging.ConnectionTracer
|
||||
logger utils.Logger
|
||||
tracer logging.ConnectionTracer
|
||||
tracingID uint64
|
||||
logger utils.Logger
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -208,6 +209,7 @@ func dialContext(
|
|||
if c.tracer != nil {
|
||||
c.tracer.StartedConnection(c.conn.LocalAddr(), c.conn.RemoteAddr(), c.srcConnID, c.destConnID)
|
||||
}
|
||||
c.tracingID = nextSessionTracingID()
|
||||
if err := c.dial(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -285,6 +287,7 @@ func (c *client) dial(ctx context.Context) error {
|
|||
c.use0RTT,
|
||||
c.hasNegotiatedVersion,
|
||||
c.tracer,
|
||||
c.tracingID,
|
||||
c.logger,
|
||||
c.version,
|
||||
)
|
||||
|
|
|
@ -42,6 +42,7 @@ var _ = Describe("Client", func() {
|
|||
enable0RTT bool,
|
||||
hasNegotiatedVersion bool,
|
||||
tracer logging.ConnectionTracer,
|
||||
tracingID uint64,
|
||||
logger utils.Logger,
|
||||
v protocol.VersionNumber,
|
||||
) quicSession
|
||||
|
@ -129,6 +130,7 @@ var _ = Describe("Client", func() {
|
|||
_ bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -161,6 +163,7 @@ var _ = Describe("Client", func() {
|
|||
_ bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -193,6 +196,7 @@ var _ = Describe("Client", func() {
|
|||
_ bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -231,6 +235,7 @@ var _ = Describe("Client", func() {
|
|||
enable0RTT bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -273,6 +278,7 @@ var _ = Describe("Client", func() {
|
|||
enable0RTT bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -320,6 +326,7 @@ var _ = Describe("Client", func() {
|
|||
_ bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -362,6 +369,7 @@ var _ = Describe("Client", func() {
|
|||
_ bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -413,6 +421,7 @@ var _ = Describe("Client", func() {
|
|||
_ bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -532,6 +541,7 @@ var _ = Describe("Client", func() {
|
|||
_ bool,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
versionP protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -571,6 +581,7 @@ var _ = Describe("Client", func() {
|
|||
_ bool,
|
||||
hasNegotiatedVersion bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
versionP protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
|
|
@ -75,6 +75,13 @@ type ErrorCode = protocol.ApplicationErrorCode
|
|||
// when the server rejects a 0-RTT connection attempt.
|
||||
var Err0RTTRejected = errors.New("0-RTT rejected")
|
||||
|
||||
// SessionTracingKey can be used to associate a ConnectionTracer with a Session.
|
||||
// It is set on the Session.Context() context,
|
||||
// as well as on the context passed to logging.Tracer.NewConnectionTracer.
|
||||
var SessionTracingKey = sessionTracingCtxKey{}
|
||||
|
||||
type sessionTracingCtxKey struct{}
|
||||
|
||||
// Stream is the interface implemented by QUIC streams
|
||||
type Stream interface {
|
||||
ReceiveStream
|
||||
|
|
|
@ -87,6 +87,7 @@ type baseServer struct {
|
|||
*handshake.TokenGenerator,
|
||||
bool, /* enable 0-RTT */
|
||||
logging.ConnectionTracer,
|
||||
uint64,
|
||||
utils.Logger,
|
||||
protocol.VersionNumber,
|
||||
) quicSession
|
||||
|
@ -474,6 +475,7 @@ func (s *baseServer) handleInitialImpl(p *receivedPacket, hdr *wire.Header) erro
|
|||
s.tokenGenerator,
|
||||
s.acceptEarlySessions,
|
||||
tracer,
|
||||
nextSessionTracingID(),
|
||||
s.logger,
|
||||
hdr.Version,
|
||||
)
|
||||
|
|
|
@ -338,6 +338,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
enable0RTT bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -595,6 +596,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
enable0RTT bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -654,6 +656,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -707,6 +710,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -737,6 +741,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -808,6 +813,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -919,6 +925,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -992,6 +999,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
enable0RTT bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -1034,6 +1042,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -1097,6 +1106,7 @@ var _ = Describe("Server", func() {
|
|||
_ *handshake.TokenGenerator,
|
||||
_ bool,
|
||||
_ logging.ConnectionTracer,
|
||||
_ uint64,
|
||||
_ utils.Logger,
|
||||
_ protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"net"
|
||||
"reflect"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/ackhandler"
|
||||
|
@ -140,6 +141,9 @@ func (e errVersionNegotiation) Error() string {
|
|||
return fmt.Sprintf("no compatible QUIC version found (we support %s, server offered %s)", e.ourVersions, e.theirVersions)
|
||||
}
|
||||
|
||||
var sessionTracingID uint64 // to be accessed atomically
|
||||
func nextSessionTracingID() uint64 { return atomic.AddUint64(&sessionTracingID, 1) }
|
||||
|
||||
// A Session is a QUIC session
|
||||
type session struct {
|
||||
// Destination connection ID used during the handshake.
|
||||
|
@ -252,6 +256,7 @@ var newSession = func(
|
|||
tokenGenerator *handshake.TokenGenerator,
|
||||
enable0RTT bool,
|
||||
tracer logging.ConnectionTracer,
|
||||
tracingID uint64,
|
||||
logger utils.Logger,
|
||||
v protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -291,6 +296,7 @@ var newSession = func(
|
|||
s.version,
|
||||
)
|
||||
s.preSetup()
|
||||
s.ctx, s.ctxCancel = context.WithCancel(context.WithValue(context.Background(), SessionTracingKey, tracingID))
|
||||
s.sentPacketHandler, s.receivedPacketHandler = ackhandler.NewAckHandler(
|
||||
0,
|
||||
getMaxPacketSize(s.conn.RemoteAddr()),
|
||||
|
@ -381,6 +387,7 @@ var newClientSession = func(
|
|||
enable0RTT bool,
|
||||
hasNegotiatedVersion bool,
|
||||
tracer logging.ConnectionTracer,
|
||||
tracingID uint64,
|
||||
logger utils.Logger,
|
||||
v protocol.VersionNumber,
|
||||
) quicSession {
|
||||
|
@ -416,6 +423,7 @@ var newClientSession = func(
|
|||
s.version,
|
||||
)
|
||||
s.preSetup()
|
||||
s.ctx, s.ctxCancel = context.WithCancel(context.WithValue(context.Background(), SessionTracingKey, tracingID))
|
||||
s.sentPacketHandler, s.receivedPacketHandler = ackhandler.NewAckHandler(
|
||||
initialPacketNumber,
|
||||
getMaxPacketSize(s.conn.RemoteAddr()),
|
||||
|
@ -524,7 +532,6 @@ func (s *session) preSetup() {
|
|||
s.receivedPackets = make(chan *receivedPacket, protocol.MaxSessionUnprocessedPackets)
|
||||
s.closeChan = make(chan closeError, 1)
|
||||
s.sendingScheduled = make(chan struct{}, 1)
|
||||
s.ctx, s.ctxCancel = context.WithCancel(context.Background())
|
||||
s.handshakeCtx, s.handshakeCtxCancel = context.WithCancel(context.Background())
|
||||
|
||||
now := time.Now()
|
||||
|
|
|
@ -107,6 +107,7 @@ var _ = Describe("Session", func() {
|
|||
tokenGenerator,
|
||||
false,
|
||||
tracer,
|
||||
1234,
|
||||
utils.DefaultLogger,
|
||||
protocol.VersionTLS,
|
||||
).(*session)
|
||||
|
@ -2478,6 +2479,7 @@ var _ = Describe("Client Session", func() {
|
|||
false,
|
||||
false,
|
||||
tracer,
|
||||
1234,
|
||||
utils.DefaultLogger,
|
||||
protocol.VersionTLS,
|
||||
).(*session)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue