package dtls
import (
"crypto/rand"
"github.com/pion/dtls/v3/pkg/protocol"
"github.com/pion/dtls/v3/pkg/protocol/extension"
"github.com/pion/dtls/v3/pkg/protocol/handshake"
"github.com/pion/dtls/v3/pkg/protocol/recordlayer"
)
func RandomCIDGenerator (size int ) func () []byte {
return func () []byte {
cid := make ([]byte , size )
if _ , err := rand .Read (cid ); err != nil {
panic (err )
}
return cid
}
}
func OnlySendCIDGenerator () func () []byte {
return func () []byte {
return nil
}
}
func cidDatagramRouter(size int ) func ([]byte ) (string , bool ) {
return func (packet []byte ) (string , bool ) {
pkts , err := recordlayer .ContentAwareUnpackDatagram (packet , size )
if err != nil || len (pkts ) < 1 {
return "" , false
}
for _ , pkt := range pkts {
h := &recordlayer .Header {
ConnectionID : make ([]byte , size ),
}
if err := h .Unmarshal (pkt ); err != nil {
continue
}
if h .ContentType != protocol .ContentTypeConnectionID {
continue
}
return string (h .ConnectionID ), true
}
return "" , false
}
}
func cidConnIdentifier() func ([]byte ) (string , bool ) {
return func (packet []byte ) (string , bool ) {
pkts , err := recordlayer .UnpackDatagram (packet )
if err != nil || len (pkts ) < 1 {
return "" , false
}
var h recordlayer .Header
if hErr := h .Unmarshal (pkts [0 ]); hErr != nil {
return "" , false
}
if h .ContentType != protocol .ContentTypeHandshake {
return "" , false
}
var hh handshake .Header
var sh handshake .MessageServerHello
for _ , pkt := range pkts {
if hhErr := hh .Unmarshal (pkt [recordlayer .FixedHeaderSize :]); hhErr != nil {
continue
}
if err = sh .Unmarshal (pkt [recordlayer .FixedHeaderSize +handshake .HeaderLength :]); err == nil {
break
}
}
if err != nil {
return "" , false
}
for _ , ext := range sh .Extensions {
if e , ok := ext .(*extension .ConnectionID ); ok {
return string (e .CID ), true
}
}
return "" , false
}
}
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 .