package wireimport ()// ParseVersionNegotiationPacket parses a Version Negotiation packet.func ( []byte) (, protocol.ArbitraryLenConnectionID, []protocol.Version, error) { , , , := ParseArbitraryLenConnectionIDs()if != nil {returnnil, nil, nil, } = [:]iflen() == 0 {//nolint:staticcheck // SA1021: the packet is called Version Negotiation packetreturnnil, nil, nil, errors.New("Version Negotiation packet has empty version list") }iflen()%4 != 0 {//nolint:staticcheck // SA1021: the packet is called Version Negotiation packetreturnnil, nil, nil, errors.New("Version Negotiation packet has a version list with an invalid length") } := make([]protocol.Version, len()/4)for := 0; len() > 0; ++ { [] = protocol.Version(binary.BigEndian.Uint32([:4])) = [4:] }return , , , nil}// ComposeVersionNegotiation composes a Version Negotiationfunc (, protocol.ArbitraryLenConnectionID, []protocol.Version) []byte { := protocol.GetGreasedVersions() := 1/* type byte */ + 4/* version field */ + 1/* dest connection ID length field */ + .Len() + 1/* src connection ID length field */ + .Len() + len()*4 := make([]byte, 1+4/* type byte and version field */, ) _, _ = rand.Read([:1]) // ignore the error here. It is not critical to have perfect random here.// Setting the "QUIC bit" (0x40) is not required by the RFC, // but it allows clients to demultiplex QUIC with a long list of other protocols. // See RFC 9443 and https://mailarchive.ietf.org/arch/msg/quic/oR4kxGKY6mjtPC1CZegY1ED4beg/ for details. [0] |= 0xc0// The next 4 bytes are left at 0 (version number). = append(, uint8(.Len())) = append(, .Bytes()...) = append(, uint8(.Len())) = append(, .Bytes()...)for , := range { = binary.BigEndian.AppendUint32(, uint32()) }return}
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.