Pārlūkot izejas kodu

fix dtls header

Darien Raymond 7 gadi atpakaļ
vecāks
revīzija
5b4eef5c7b
1 mainītis faili ar 13 papildinājumiem un 10 dzēšanām
  1. 13 10
      transport/internet/headers/tls/dtls.go

+ 13 - 10
transport/internet/headers/tls/dtls.go

@@ -16,7 +16,7 @@ type DTLS struct {
 
 // Size implements PacketHeader.
 func (*DTLS) Size() int32 {
-	return 1 + 2 + 2 + 3 + 2
+	return 1 + 2 + 2 + 6 + 2
 }
 
 // Write implements PacketHeader.
@@ -26,17 +26,20 @@ func (d *DTLS) Write(b []byte) (int, error) {
 	b[2] = 253
 	b[3] = byte(d.epoch >> 8)
 	b[4] = byte(d.epoch)
-	b[5] = byte(d.sequence >> 16)
-	b[6] = byte(d.sequence >> 8)
-	b[7] = byte(d.sequence)
+	b[5] = 0
+	b[6] = 0
+	b[7] = byte(d.sequence >> 24)
+	b[8] = byte(d.sequence >> 16)
+	b[9] = byte(d.sequence >> 8)
+	b[10] = byte(d.sequence)
 	d.sequence++
-	b[8] = byte(d.length >> 8)
-	b[9] = byte(d.length)
+	b[11] = byte(d.length >> 8)
+	b[12] = byte(d.length)
 	d.length += 17
-	if d.length > 1024 {
-		d.length -= 1024
+	if d.length > 100 {
+		d.length -= 50
 	}
-	return 10, nil
+	return 13, nil
 }
 
 // New creates a new UTP header for the given config.
@@ -44,7 +47,7 @@ func New(ctx context.Context, config interface{}) (interface{}, error) {
 	return &DTLS{
 		epoch:    dice.RollUint16(),
 		sequence: 0,
-		length:   uint16(dice.Roll(1024) + 100),
+		length:   17,
 	}, nil
 }