Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit size of encrypted packet queue #628

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove unused vars, factor out function
  • Loading branch information
sukunrt committed Apr 30, 2024
commit 793cefded6573f8bfdf9a3ebe4e5bb0e7ab9217b
33 changes: 11 additions & 22 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,6 @@
workerInterval = config.FlightInterval
}

mtu := config.MTU
if mtu <= 0 {
mtu = defaultMTU
}

replayProtectionWindow := config.ReplayProtectionWindow
if replayProtectionWindow <= 0 {
replayProtectionWindow = defaultReplayProtectionWindow
}

serverName := config.ServerName
// Do not allow the use of an IP address literal as an SNI value.
// See RFC 6066, Section 3.
Expand Down Expand Up @@ -682,6 +672,14 @@
return nil
}

func (c *Conn) enqueueEncryptedPackets(packet []byte) bool {
if len(c.encryptedPackets) < maxAppDataPacketQueueSize {
c.encryptedPackets = append(c.encryptedPackets, packet)
return true
}
return false
}

func (c *Conn) handleIncomingPacket(ctx context.Context, buf []byte, enqueue bool) (bool, *alert.Alert, error) { //nolint:gocognit
h := &recordlayer.Header{}
if err := h.Unmarshal(buf); err != nil {
Expand All @@ -700,11 +698,8 @@
return false, nil, nil
}
if enqueue {
if len(c.encryptedPackets) < maxAppDataPacketQueueSize {
if ok := c.enqueueEncryptedPackets(buf); ok {
c.log.Debug("received packet of next epoch, queuing packet")
c.encryptedPackets = append(c.encryptedPackets, buf)
} else {
c.log.Debug("app data packet queue full, dropping packet")
}
}
return false, nil, nil
Expand All @@ -728,11 +723,8 @@
if h.Epoch != 0 {
if c.state.cipherSuite == nil || !c.state.cipherSuite.IsInitialized() {
if enqueue {
if len(c.encryptedPackets) < maxAppDataPacketQueueSize {
c.encryptedPackets = append(c.encryptedPackets, buf)
if ok := c.enqueueEncryptedPackets(buf); ok {
c.log.Debug("handshake not finished, queuing packet")
} else {
c.log.Debug("app data packet queue full, dropping packet")
}
}
return false, nil, nil
Expand Down Expand Up @@ -784,11 +776,8 @@
case *protocol.ChangeCipherSpec:
if c.state.cipherSuite == nil || !c.state.cipherSuite.IsInitialized() {
if enqueue {
if len(c.encryptedPackets) < maxAppDataPacketQueueSize {
c.encryptedPackets = append(c.encryptedPackets, buf)
if ok := c.enqueueEncryptedPackets(buf); ok {
c.log.Debugf("CipherSuite not initialized, queuing packet")
} else {
c.log.Debug("app data packet queue full. dropping packet")
}
}
return false, nil, nil
Expand Down Expand Up @@ -867,7 +856,7 @@
done := make(chan struct{})
ctxRead, cancelRead := context.WithCancel(context.Background())
c.cancelHandshakeReader = cancelRead
cfg.onFlightState = func(f flightVal, s handshakeState) {

Check warning on line 859 in conn.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'f' seems to be unused, consider removing or renaming it as _ (revive)
if s == handshakeFinished && !c.isHandshakeCompletedSuccessfully() {
c.setHandshakeCompletedSuccessfully()
close(done)
Expand Down
Loading