implement the recent changes to the version negotiation packet

This commit is contained in:
Marten Seemann 2017-12-05 07:31:12 +07:00
parent 5d900346fd
commit 45e43ada40
13 changed files with 87 additions and 100 deletions

View file

@ -2,6 +2,7 @@ package wire
import (
"bytes"
"crypto/rand"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
@ -11,9 +12,10 @@ import (
func ComposeGQUICVersionNegotiation(connID protocol.ConnectionID, versions []protocol.VersionNumber) []byte {
fullReply := &bytes.Buffer{}
ph := Header{
ConnectionID: connID,
PacketNumber: 1,
VersionFlag: true,
ConnectionID: connID,
PacketNumber: 1,
VersionFlag: true,
IsVersionNegotiation: true,
}
if err := ph.writePublicHeader(fullReply, protocol.PerspectiveServer, protocol.VersionWhatever); err != nil {
utils.Errorf("error composing version negotiation packet: %s", err.Error())
@ -29,18 +31,20 @@ func ComposeGQUICVersionNegotiation(connID protocol.ConnectionID, versions []pro
func ComposeVersionNegotiation(
connID protocol.ConnectionID,
pn protocol.PacketNumber,
versionOffered protocol.VersionNumber,
versions []protocol.VersionNumber,
) []byte {
fullReply := &bytes.Buffer{}
ph := Header{
IsLongHeader: true,
Type: protocol.PacketTypeVersionNegotiation,
ConnectionID: connID,
PacketNumber: pn,
Version: versionOffered,
r := make([]byte, 1)
_, _ = rand.Read(r) // ignore the error here. It is not critical to have perfect random here.
h := Header{
IsLongHeader: true,
Type: protocol.PacketType(r[0] | 0x80),
ConnectionID: connID,
PacketNumber: pn,
Version: 0,
IsVersionNegotiation: true,
}
if err := ph.writeHeader(fullReply); err != nil {
if err := h.writeHeader(fullReply); err != nil {
utils.Errorf("error composing version negotiation packet: %s", err.Error())
return nil
}