mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
simplify writing of the gQUIC Version Negotiation Packet
This commit is contained in:
parent
5e82335005
commit
1e9b3f0bb2
3 changed files with 36 additions and 48 deletions
|
@ -10,17 +10,9 @@ import (
|
|||
|
||||
// ComposeGQUICVersionNegotiation composes a Version Negotiation Packet for gQUIC
|
||||
func ComposeGQUICVersionNegotiation(connID protocol.ConnectionID, versions []protocol.VersionNumber) []byte {
|
||||
buf := &bytes.Buffer{}
|
||||
ph := Header{
|
||||
ConnectionID: connID,
|
||||
PacketNumber: 1,
|
||||
VersionFlag: true,
|
||||
IsVersionNegotiation: true,
|
||||
}
|
||||
if err := ph.writePublicHeader(buf, protocol.PerspectiveServer, protocol.VersionWhatever); err != nil {
|
||||
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1+8+len(versions)*4))
|
||||
buf.Write([]byte{0x1 | 0x8}) // type byte
|
||||
utils.BigEndian.WriteUint64(buf, uint64(connID))
|
||||
for _, v := range versions {
|
||||
utils.BigEndian.WriteUint32(buf, uint32(v))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue