github.com/yaling888/clash@v1.53.0/transport/header/dtls/dtls.go (about) 1 package dtls 2 3 import ( 4 "math/rand/v2" 5 ) 6 7 type DTLS struct { 8 epoch uint16 9 length uint16 10 sequence uint32 11 } 12 13 func (*DTLS) Size() int { 14 return 13 15 } 16 17 func (d *DTLS) Fill(b []byte) { 18 b[0] = 23 19 b[1] = 254 20 b[2] = 253 21 b[3] = byte(d.epoch >> 8) 22 b[4] = byte(d.epoch) 23 b[5] = 0 24 b[6] = 0 25 b[7] = byte(d.sequence >> 24) 26 b[8] = byte(d.sequence >> 16) 27 b[9] = byte(d.sequence >> 8) 28 b[10] = byte(d.sequence) 29 d.sequence++ 30 b[11] = byte(d.length >> 8) 31 b[12] = byte(d.length) 32 d.length += 17 33 if d.length > 100 { 34 d.length -= 50 35 } 36 } 37 38 func New() *DTLS { 39 return &DTLS{ 40 epoch: uint16(rand.Uint64() >> 49), 41 sequence: 0, 42 length: 17, 43 } 44 }