update dtls.length logic

pull/1132/head
Darien Raymond 2018-05-25 19:34:32 +02:00
parent f9277958a5
commit 956c4f5bcf
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 8 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import (
type DTLS struct { type DTLS struct {
epoch uint16 epoch uint16
sequence uint32 sequence uint32
length uint16
} }
// Size implements PacketHeader. // Size implements PacketHeader.
@ -29,9 +30,12 @@ func (d *DTLS) Write(b []byte) (int, error) {
b[6] = byte(d.sequence >> 8) b[6] = byte(d.sequence >> 8)
b[7] = byte(d.sequence) b[7] = byte(d.sequence)
d.sequence++ d.sequence++
l := dice.RollUint16() b[8] = byte(d.length >> 8)
b[8] = byte(l >> 8) b[9] = byte(d.length)
b[9] = byte(l) d.length += 17
if d.length > 1024 {
d.length -= 1024
}
return 10, nil return 10, nil
} }
@ -40,6 +44,7 @@ func New(ctx context.Context, config interface{}) (interface{}, error) {
return &DTLS{ return &DTLS{
epoch: dice.RollUint16(), epoch: dice.RollUint16(),
sequence: 0, sequence: 0,
length: uint16(dice.Roll(1024) + 100),
}, nil }, nil
} }