mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
qlog: remove unneeded mutex from the ConnectionTracer (#4299)
Events are appended to a channel, which is able to handle concurrect writes.
This commit is contained in:
parent
2fbe713bb6
commit
f3c4be6b01
1 changed files with 0 additions and 55 deletions
55
qlog/qlog.go
55
qlog/qlog.go
|
@ -7,7 +7,6 @@ import (
|
|||
"log"
|
||||
"net"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/quic-go/quic-go/internal/protocol"
|
||||
|
@ -49,8 +48,6 @@ func init() {
|
|||
const eventChanSize = 50
|
||||
|
||||
type connectionTracer struct {
|
||||
mutex sync.Mutex
|
||||
|
||||
w io.WriteCloser
|
||||
odcid protocol.ConnectionID
|
||||
perspective protocol.Perspective
|
||||
|
@ -146,9 +143,7 @@ func NewConnectionTracer(w io.WriteCloser, p protocol.Perspective, odcid protoco
|
|||
t.ECNStateUpdated(state, trigger)
|
||||
},
|
||||
ChoseALPN: func(protocol string) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), eventALPNInformation{chosenALPN: protocol})
|
||||
t.mutex.Unlock()
|
||||
},
|
||||
Debug: func(name, msg string) {
|
||||
t.Debug(name, msg)
|
||||
|
@ -230,14 +225,12 @@ func (t *connectionTracer) StartedConnection(local, remote net.Addr, srcConnID,
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventConnectionStarted{
|
||||
SrcAddr: localAddr,
|
||||
DestAddr: remoteAddr,
|
||||
SrcConnectionID: srcConnID,
|
||||
DestConnectionID: destConnID,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) NegotiatedVersion(chosen logging.VersionNumber, client, server []logging.VersionNumber) {
|
||||
|
@ -254,19 +247,15 @@ func (t *connectionTracer) NegotiatedVersion(chosen logging.VersionNumber, clien
|
|||
serverVersions[i] = versionNumber(v)
|
||||
}
|
||||
}
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventVersionNegotiated{
|
||||
clientVersions: clientVersions,
|
||||
serverVersions: serverVersions,
|
||||
chosenVersion: versionNumber(chosen),
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) ClosedConnection(e error) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventConnectionClosed{e: e})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) SentTransportParameters(tp *wire.TransportParameters) {
|
||||
|
@ -281,9 +270,7 @@ func (t *connectionTracer) RestoredTransportParameters(tp *wire.TransportParamet
|
|||
ev := t.toTransportParameters(tp)
|
||||
ev.Restore = true
|
||||
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), ev)
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) recordTransportParameters(sentBy protocol.Perspective, tp *wire.TransportParameters) {
|
||||
|
@ -294,9 +281,7 @@ func (t *connectionTracer) recordTransportParameters(sentBy protocol.Perspective
|
|||
}
|
||||
ev.SentBy = sentBy
|
||||
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), ev)
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) toTransportParameters(tp *wire.TransportParameters) *eventTransportParameters {
|
||||
|
@ -369,7 +354,6 @@ func (t *connectionTracer) sentPacket(
|
|||
for _, f := range frames {
|
||||
fs = append(fs, frame{Frame: f})
|
||||
}
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventPacketSent{
|
||||
Header: hdr,
|
||||
Length: size,
|
||||
|
@ -377,7 +361,6 @@ func (t *connectionTracer) sentPacket(
|
|||
ECN: ecn,
|
||||
Frames: fs,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) ReceivedLongHeaderPacket(hdr *logging.ExtendedHeader, size logging.ByteCount, ecn logging.ECN, frames []logging.Frame) {
|
||||
|
@ -386,7 +369,6 @@ func (t *connectionTracer) ReceivedLongHeaderPacket(hdr *logging.ExtendedHeader,
|
|||
fs[i] = frame{Frame: f}
|
||||
}
|
||||
header := *transformLongHeader(hdr)
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventPacketReceived{
|
||||
Header: header,
|
||||
Length: size,
|
||||
|
@ -394,7 +376,6 @@ func (t *connectionTracer) ReceivedLongHeaderPacket(hdr *logging.ExtendedHeader,
|
|||
ECN: ecn,
|
||||
Frames: fs,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, size logging.ByteCount, ecn logging.ECN, frames []logging.Frame) {
|
||||
|
@ -403,7 +384,6 @@ func (t *connectionTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, s
|
|||
fs[i] = frame{Frame: f}
|
||||
}
|
||||
header := *transformShortHeader(hdr)
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventPacketReceived{
|
||||
Header: header,
|
||||
Length: size,
|
||||
|
@ -411,15 +391,12 @@ func (t *connectionTracer) ReceivedShortHeaderPacket(hdr *logging.ShortHeader, s
|
|||
ECN: ecn,
|
||||
Frames: fs,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) ReceivedRetry(hdr *wire.Header) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventRetryReceived{
|
||||
Header: *transformHeader(hdr),
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) ReceivedVersionNegotiationPacket(dest, src logging.ArbitraryLenConnectionID, versions []logging.VersionNumber) {
|
||||
|
@ -427,7 +404,6 @@ func (t *connectionTracer) ReceivedVersionNegotiationPacket(dest, src logging.Ar
|
|||
for i, v := range versions {
|
||||
ver[i] = versionNumber(v)
|
||||
}
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventVersionNegotiationReceived{
|
||||
Header: packetHeaderVersionNegotiation{
|
||||
SrcConnectionID: src,
|
||||
|
@ -435,27 +411,22 @@ func (t *connectionTracer) ReceivedVersionNegotiationPacket(dest, src logging.Ar
|
|||
},
|
||||
SupportedVersions: ver,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) BufferedPacket(pt logging.PacketType, size protocol.ByteCount) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventPacketBuffered{
|
||||
PacketType: pt,
|
||||
PacketSize: size,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) DroppedPacket(pt logging.PacketType, pn logging.PacketNumber, size protocol.ByteCount, reason logging.PacketDropReason) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventPacketDropped{
|
||||
PacketType: pt,
|
||||
PacketNumber: pn,
|
||||
PacketSize: size,
|
||||
Trigger: packetDropReason(reason),
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) UpdatedMetrics(rttStats *utils.RTTStats, cwnd, bytesInFlight protocol.ByteCount, packetsInFlight int) {
|
||||
|
@ -468,46 +439,36 @@ func (t *connectionTracer) UpdatedMetrics(rttStats *utils.RTTStats, cwnd, bytesI
|
|||
BytesInFlight: bytesInFlight,
|
||||
PacketsInFlight: packetsInFlight,
|
||||
}
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventMetricsUpdated{
|
||||
Last: t.lastMetrics,
|
||||
Current: m,
|
||||
})
|
||||
t.lastMetrics = m
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) AcknowledgedPacket(protocol.EncryptionLevel, protocol.PacketNumber) {}
|
||||
|
||||
func (t *connectionTracer) LostPacket(encLevel protocol.EncryptionLevel, pn protocol.PacketNumber, lossReason logging.PacketLossReason) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventPacketLost{
|
||||
PacketType: getPacketTypeFromEncryptionLevel(encLevel),
|
||||
PacketNumber: pn,
|
||||
Trigger: packetLossReason(lossReason),
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) UpdatedCongestionState(state logging.CongestionState) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventCongestionStateUpdated{state: congestionState(state)})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) UpdatedPTOCount(value uint32) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventUpdatedPTO{Value: value})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) UpdatedKeyFromTLS(encLevel protocol.EncryptionLevel, pers protocol.Perspective) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventKeyUpdated{
|
||||
Trigger: keyUpdateTLS,
|
||||
KeyType: encLevelToKeyType(encLevel, pers),
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) UpdatedKey(generation protocol.KeyPhase, remote bool) {
|
||||
|
@ -515,7 +476,6 @@ func (t *connectionTracer) UpdatedKey(generation protocol.KeyPhase, remote bool)
|
|||
if remote {
|
||||
trigger = keyUpdateRemote
|
||||
}
|
||||
t.mutex.Lock()
|
||||
now := time.Now()
|
||||
t.recordEvent(now, &eventKeyUpdated{
|
||||
Trigger: trigger,
|
||||
|
@ -527,11 +487,9 @@ func (t *connectionTracer) UpdatedKey(generation protocol.KeyPhase, remote bool)
|
|||
KeyType: keyTypeServer1RTT,
|
||||
Generation: generation,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) DroppedEncryptionLevel(encLevel protocol.EncryptionLevel) {
|
||||
t.mutex.Lock()
|
||||
now := time.Now()
|
||||
if encLevel == protocol.Encryption0RTT {
|
||||
t.recordEvent(now, &eventKeyDiscarded{KeyType: encLevelToKeyType(encLevel, t.perspective)})
|
||||
|
@ -539,11 +497,9 @@ func (t *connectionTracer) DroppedEncryptionLevel(encLevel protocol.EncryptionLe
|
|||
t.recordEvent(now, &eventKeyDiscarded{KeyType: encLevelToKeyType(encLevel, protocol.PerspectiveServer)})
|
||||
t.recordEvent(now, &eventKeyDiscarded{KeyType: encLevelToKeyType(encLevel, protocol.PerspectiveClient)})
|
||||
}
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) DroppedKey(generation protocol.KeyPhase) {
|
||||
t.mutex.Lock()
|
||||
now := time.Now()
|
||||
t.recordEvent(now, &eventKeyDiscarded{
|
||||
KeyType: encLevelToKeyType(protocol.Encryption1RTT, protocol.PerspectiveServer),
|
||||
|
@ -553,46 +509,35 @@ func (t *connectionTracer) DroppedKey(generation protocol.KeyPhase) {
|
|||
KeyType: encLevelToKeyType(protocol.Encryption1RTT, protocol.PerspectiveClient),
|
||||
Generation: generation,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) SetLossTimer(tt logging.TimerType, encLevel protocol.EncryptionLevel, timeout time.Time) {
|
||||
t.mutex.Lock()
|
||||
now := time.Now()
|
||||
t.recordEvent(now, &eventLossTimerSet{
|
||||
TimerType: timerType(tt),
|
||||
EncLevel: encLevel,
|
||||
Delta: timeout.Sub(now),
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) LossTimerExpired(tt logging.TimerType, encLevel protocol.EncryptionLevel) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventLossTimerExpired{
|
||||
TimerType: timerType(tt),
|
||||
EncLevel: encLevel,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) LossTimerCanceled() {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventLossTimerCanceled{})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) ECNStateUpdated(state logging.ECNState, trigger logging.ECNStateTrigger) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventECNStateUpdated{state: state, trigger: trigger})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (t *connectionTracer) Debug(name, msg string) {
|
||||
t.mutex.Lock()
|
||||
t.recordEvent(time.Now(), &eventGeneric{
|
||||
name: name,
|
||||
msg: msg,
|
||||
})
|
||||
t.mutex.Unlock()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue