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

add support for the new keyupdate interop runner test case #2782

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions integrationtests/self/key_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"fmt"
"io/ioutil"
"net"
"os"

quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/internal/handshake"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -35,7 +36,7 @@ var _ = Describe("Key Update tests", func() {

BeforeEach(func() {
// update keys as frequently as possible
os.Setenv("QUIC_GO_KEY_UPDATE_INTERVAL", "1")
handshake.KeyUpdateInterval = 1
runServer()
})

Expand Down
31 changes: 4 additions & 27 deletions internal/handshake/updatable_aead.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"crypto/tls"
"encoding/binary"
"fmt"
"os"
"strconv"
"time"

"github.com/lucas-clemente/quic-go/internal/protocol"
Expand All @@ -17,30 +15,9 @@ import (
"github.com/lucas-clemente/quic-go/logging"
)

// By setting this environment variable, the key update interval can be adjusted.
// This is not needed in production, but useful for integration and interop testing.
// Note that no matter what value is set, a key update is only initiated once it is
// permitted (i.e. once an ACK for a packet sent at the current key phase has been received).
const keyUpdateEnv = "QUIC_GO_KEY_UPDATE_INTERVAL"

var keyUpdateInterval uint64

func init() {
setKeyUpdateInterval()
}

func setKeyUpdateInterval() {
env := os.Getenv(keyUpdateEnv)
if env == "" {
keyUpdateInterval = protocol.KeyUpdateInterval
return
}
interval, err := strconv.ParseUint(env, 10, 64)
if err != nil {
panic(fmt.Sprintf("Cannot parse %s: %s", keyUpdateEnv, err))
}
keyUpdateInterval = interval
}
// KeyUpdateInterval is the maximum number of packets we send or receive before initiating a key update.
// It's a package-level variable to allow modifying it for testing purposes.
var KeyUpdateInterval uint64 = protocol.KeyUpdateInterval

type updatableAEAD struct {
suite *qtls.CipherSuiteTLS13
Expand Down Expand Up @@ -92,7 +69,7 @@ func newUpdatableAEAD(rttStats *utils.RTTStats, tracer logging.ConnectionTracer,
largestAcked: protocol.InvalidPacketNumber,
firstRcvdWithCurrentKey: protocol.InvalidPacketNumber,
firstSentWithCurrentKey: protocol.InvalidPacketNumber,
keyUpdateInterval: keyUpdateInterval,
keyUpdateInterval: KeyUpdateInterval,
rttStats: rttStats,
tracer: tracer,
logger: logger,
Expand Down
24 changes: 0 additions & 24 deletions internal/handshake/updatable_aead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/rand"
"crypto/tls"
"fmt"
"os"
"time"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -452,29 +451,6 @@ var _ = Describe("Updatable AEAD", func() {
Expect(err).ToNot(HaveOccurred())
})
})

Context("reading the key update env", func() {
AfterEach(func() {
os.Setenv(keyUpdateEnv, "")
setKeyUpdateInterval()
})

It("uses the default value if the env is not set", func() {
setKeyUpdateInterval()
Expect(keyUpdateInterval).To(BeEquivalentTo(protocol.KeyUpdateInterval))
})

It("uses the env", func() {
os.Setenv(keyUpdateEnv, "1337")
setKeyUpdateInterval()
Expect(keyUpdateInterval).To(BeEquivalentTo(1337))
})

It("panics when it can't parse the env", func() {
os.Setenv(keyUpdateEnv, "foobar")
Expect(setKeyUpdateInterval).To(Panic())
})
})
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion internal/protocol/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const MaxAckDelay = 25 * time.Millisecond
// This is the value that should be advertised to the peer.
const MaxAckDelayInclGranularity = MaxAckDelay + TimerGranularity

// KeyUpdateInterval is the maximum number of packets we send or receive before initiating a key udpate.
// KeyUpdateInterval is the maximum number of packets we send or receive before initiating a key update.
const KeyUpdateInterval = 100 * 1000

// Max0RTTQueueingDuration is the maximum time that we store 0-RTT packets in order to wait for the corresponding Initial to be received.
Expand Down
3 changes: 3 additions & 0 deletions interop/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/http3"
"github.com/lucas-clemente/quic-go/internal/handshake"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/interop/http09"
"github.com/lucas-clemente/quic-go/interop/utils"
Expand Down Expand Up @@ -86,6 +87,8 @@ func runTestcase(testcase string) error {

switch testcase {
case "handshake", "transfer", "retry":
case "keyupdate":
handshake.KeyUpdateInterval = 100
case "chacha20":
tlsConf.CipherSuites = []uint16{tls.TLS_CHACHA20_POLY1305_SHA256}
case "multiconnect":
Expand Down