Skip to content

Commit 2b9d0dd

Browse files
committed
Add version to state
1 parent 31ecedf commit 2b9d0dd

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

conn.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ func (c *Conn) HandshakeContext(ctx context.Context) error { //nolint:cyclop
311311
c.closeLock.Unlock()
312312

313313
if c.isVersion13Enabled() {
314+
c.state.version = protocol.Version1_3
314315
var initialFlight flightVal
315316
if c.state.isClient {
316317
initialFlight = flightVal(flight13_1)
@@ -1176,7 +1177,7 @@ func (c *Conn) recvHandshake() <-chan recvHandshakeState {
11761177

11771178
func (c *Conn) notify(ctx context.Context, level alert.Level, desc alert.Description) error {
11781179
if level == alert.Fatal && len(c.state.SessionID) > 0 { //nolint:nestif
1179-
if c.isVersion13Enabled() {
1180+
if c.state.version == protocol.Version1_3 {
11801181
// With compatibility mode for 1.3, CH uses a non-empty session_id
11811182
// https://datatracker.ietf.org/doc/html/rfc8446#appendix-D.4
11821183
if ss := c.fsm.(*handshakeFSM13).cfg.sessionStore; ss != nil { //nolint:forcetypeassert
@@ -1231,7 +1232,7 @@ func (c *Conn) handshake(
12311232
initialState handshakeState,
12321233
) error {
12331234
done := make(chan struct{})
1234-
if c.isVersion13Enabled() {
1235+
if c.state.version == protocol.Version1_3 {
12351236
c.fsm = &handshakeFSM13{
12361237
currentFlight: flightVal13(initialFlight),
12371238
state: &c.state,
@@ -1458,7 +1459,7 @@ func (c *Conn) sessionKey() []byte {
14581459
// As ServerName can be like 0.example.com, it's better to add
14591460
// delimiter character which is not allowed to be in
14601461
// neither address or domain name.
1461-
if c.isVersion13Enabled() {
1462+
if c.state.version == protocol.Version1_3 {
14621463
return []byte(c.rAddr.String() + "_" + c.fsm.(*handshakeFSM13).cfg.serverName) //nolint:forcetypeassert
14631464
}
14641465

state.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/pion/dtls/v3/pkg/crypto/elliptic"
1313
"github.com/pion/dtls/v3/pkg/crypto/prf"
1414
"github.com/pion/dtls/v3/pkg/crypto/signaturehash"
15+
"github.com/pion/dtls/v3/pkg/protocol"
1516
"github.com/pion/dtls/v3/pkg/protocol/handshake"
1617
"github.com/pion/transport/v4/replaydetector"
1718
)
@@ -72,6 +73,8 @@ type State struct {
7273

7374
peerSupportedProtocols []string
7475
NegotiatedProtocol string
76+
77+
version protocol.Version
7578
}
7679

7780
type serializedState struct {

0 commit comments

Comments
 (0)