mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
send IETF draft style version negotiation packets
Send a gQUIC Version Negotiation Packet, if the client packet has a Public Header. If the client has an IETF draft style header, send an IETF draft style Version Negotiation Packet.
This commit is contained in:
parent
515babb4bd
commit
b0f34e776e
6 changed files with 108 additions and 36 deletions
|
@ -7,18 +7,36 @@ import (
|
|||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
)
|
||||
|
||||
// ComposeVersionNegotiation composes a Version Negotiation Packet
|
||||
// TODO(894): implement the IETF draft format of Version Negotiation Packets
|
||||
func ComposeVersionNegotiation(connectionID protocol.ConnectionID, versions []protocol.VersionNumber) []byte {
|
||||
// ComposeGQUICVersionNegotiation composes a Version Negotiation Packet for gQUIC
|
||||
func ComposeGQUICVersionNegotiation(connID protocol.ConnectionID, versions []protocol.VersionNumber) []byte {
|
||||
fullReply := &bytes.Buffer{}
|
||||
ph := Header{
|
||||
ConnectionID: connectionID,
|
||||
ConnectionID: connID,
|
||||
PacketNumber: 1,
|
||||
VersionFlag: true,
|
||||
}
|
||||
err := ph.writePublicHeader(fullReply, protocol.PerspectiveServer, protocol.VersionWhatever)
|
||||
if err != nil {
|
||||
if err := ph.writePublicHeader(fullReply, protocol.PerspectiveServer, protocol.VersionWhatever); err != nil {
|
||||
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
for _, v := range versions {
|
||||
utils.BigEndian.WriteUint32(fullReply, uint32(v))
|
||||
}
|
||||
return fullReply.Bytes()
|
||||
}
|
||||
|
||||
// ComposeVersionNegotiation composes a Version Negotiation according to the IETF draft
|
||||
func ComposeVersionNegotiation(connID protocol.ConnectionID, pn protocol.PacketNumber, versions []protocol.VersionNumber) []byte {
|
||||
fullReply := &bytes.Buffer{}
|
||||
ph := Header{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeVersionNegotiation,
|
||||
ConnectionID: connID,
|
||||
PacketNumber: pn,
|
||||
}
|
||||
if err := ph.writeHeader(fullReply); err != nil {
|
||||
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
for _, v := range versions {
|
||||
utils.BigEndian.WriteUint32(fullReply, uint32(v))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue