package dtls
import (
"bytes"
"context"
"github.com/pion/dtls/v3/pkg/protocol"
"github.com/pion/dtls/v3/pkg/protocol/alert"
"github.com/pion/dtls/v3/pkg/protocol/handshake"
"github.com/pion/dtls/v3/pkg/protocol/recordlayer"
)
func flight2Parse(
ctx context .Context ,
c flightConn ,
state *State ,
cache *handshakeCache ,
cfg *handshakeConfig ,
) (flightVal , *alert .Alert , error ) {
seq , msgs , ok := cache .fullPullMap (state .handshakeRecvSequence , state .cipherSuite ,
handshakeCachePullRule {handshake .TypeClientHello , cfg .initialEpoch , true , false },
)
if !ok {
return flight0Parse (ctx , c , state , cache , cfg )
}
state .handshakeRecvSequence = seq
var clientHello *handshake .MessageClientHello
if clientHello , ok = msgs [handshake .TypeClientHello ].(*handshake .MessageClientHello ); !ok {
return 0 , &alert .Alert {Level : alert .Fatal , Description : alert .InternalError }, nil
}
if !clientHello .Version .Equal (protocol .Version1_2 ) {
return 0 , &alert .Alert {Level : alert .Fatal , Description : alert .ProtocolVersion }, errUnsupportedProtocolVersion
}
if len (clientHello .Cookie ) == 0 {
return 0 , nil , nil
}
if !bytes .Equal (state .cookie , clientHello .Cookie ) {
return 0 , &alert .Alert {Level : alert .Fatal , Description : alert .AccessDenied }, errCookieMismatch
}
return flight4 , nil , nil
}
func flight2Generate(
_ flightConn ,
state *State ,
_ *handshakeCache ,
_ *handshakeConfig ,
) ([]*packet , *alert .Alert , error ) {
state .handshakeSendSequence = 0
return []*packet {
{
record : &recordlayer .RecordLayer {
Header : recordlayer .Header {
Version : protocol .Version1_2 ,
},
Content : &handshake .Handshake {
Message : &handshake .MessageHelloVerifyRequest {
Version : protocol .Version1_2 ,
Cookie : state .cookie ,
},
},
},
},
}, nil , nil
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .