packet_packer.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. package quic
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. "net"
  7. "sync"
  8. "time"
  9. "github.com/lucas-clemente/quic-go/internal/ackhandler"
  10. "github.com/lucas-clemente/quic-go/internal/handshake"
  11. "github.com/lucas-clemente/quic-go/internal/protocol"
  12. "github.com/lucas-clemente/quic-go/internal/utils"
  13. "github.com/lucas-clemente/quic-go/internal/wire"
  14. )
  15. type packedPacket struct {
  16. header *wire.Header
  17. raw []byte
  18. frames []wire.Frame
  19. encryptionLevel protocol.EncryptionLevel
  20. }
  21. func (p *packedPacket) ToAckHandlerPacket() *ackhandler.Packet {
  22. return &ackhandler.Packet{
  23. PacketNumber: p.header.PacketNumber,
  24. PacketType: p.header.Type,
  25. Frames: p.frames,
  26. Length: protocol.ByteCount(len(p.raw)),
  27. EncryptionLevel: p.encryptionLevel,
  28. SendTime: time.Now(),
  29. }
  30. }
  31. type sealingManager interface {
  32. GetSealer() (protocol.EncryptionLevel, handshake.Sealer)
  33. GetSealerForCryptoStream() (protocol.EncryptionLevel, handshake.Sealer)
  34. GetSealerWithEncryptionLevel(protocol.EncryptionLevel) (handshake.Sealer, error)
  35. }
  36. type streamFrameSource interface {
  37. HasCryptoStreamData() bool
  38. PopCryptoStreamFrame(protocol.ByteCount) *wire.StreamFrame
  39. PopStreamFrames(protocol.ByteCount) []*wire.StreamFrame
  40. }
  41. type packetPacker struct {
  42. destConnID protocol.ConnectionID
  43. srcConnID protocol.ConnectionID
  44. perspective protocol.Perspective
  45. version protocol.VersionNumber
  46. cryptoSetup sealingManager
  47. token []byte
  48. divNonce []byte
  49. packetNumberGenerator *packetNumberGenerator
  50. getPacketNumberLen func(protocol.PacketNumber) protocol.PacketNumberLen
  51. streams streamFrameSource
  52. controlFrameMutex sync.Mutex
  53. controlFrames []wire.Frame
  54. stopWaiting *wire.StopWaitingFrame
  55. ackFrame *wire.AckFrame
  56. omitConnectionID bool
  57. maxPacketSize protocol.ByteCount
  58. hasSentPacket bool // has the packetPacker already sent a packet
  59. numNonRetransmittableAcks int
  60. }
  61. func newPacketPacker(
  62. destConnID protocol.ConnectionID,
  63. srcConnID protocol.ConnectionID,
  64. initialPacketNumber protocol.PacketNumber,
  65. getPacketNumberLen func(protocol.PacketNumber) protocol.PacketNumberLen,
  66. remoteAddr net.Addr, // only used for determining the max packet size
  67. token []byte,
  68. divNonce []byte,
  69. cryptoSetup sealingManager,
  70. streamFramer streamFrameSource,
  71. perspective protocol.Perspective,
  72. version protocol.VersionNumber,
  73. ) *packetPacker {
  74. maxPacketSize := protocol.ByteCount(protocol.MinInitialPacketSize)
  75. // If this is not a UDP address, we don't know anything about the MTU.
  76. // Use the minimum size of an Initial packet as the max packet size.
  77. if udpAddr, ok := remoteAddr.(*net.UDPAddr); ok {
  78. // If ip is not an IPv4 address, To4 returns nil.
  79. // Note that there might be some corner cases, where this is not correct.
  80. // See https://stackoverflow.com/questions/22751035/golang-distinguish-ipv4-ipv6.
  81. if udpAddr.IP.To4() == nil {
  82. maxPacketSize = protocol.MaxPacketSizeIPv6
  83. } else {
  84. maxPacketSize = protocol.MaxPacketSizeIPv4
  85. }
  86. }
  87. return &packetPacker{
  88. cryptoSetup: cryptoSetup,
  89. divNonce: divNonce,
  90. token: token,
  91. destConnID: destConnID,
  92. srcConnID: srcConnID,
  93. perspective: perspective,
  94. version: version,
  95. streams: streamFramer,
  96. getPacketNumberLen: getPacketNumberLen,
  97. packetNumberGenerator: newPacketNumberGenerator(initialPacketNumber, protocol.SkipPacketAveragePeriodLength),
  98. maxPacketSize: maxPacketSize,
  99. }
  100. }
  101. // PackConnectionClose packs a packet that ONLY contains a ConnectionCloseFrame
  102. func (p *packetPacker) PackConnectionClose(ccf *wire.ConnectionCloseFrame) (*packedPacket, error) {
  103. frames := []wire.Frame{ccf}
  104. encLevel, sealer := p.cryptoSetup.GetSealer()
  105. header := p.getHeader(encLevel)
  106. raw, err := p.writeAndSealPacket(header, frames, sealer)
  107. return &packedPacket{
  108. header: header,
  109. raw: raw,
  110. frames: frames,
  111. encryptionLevel: encLevel,
  112. }, err
  113. }
  114. func (p *packetPacker) PackAckPacket() (*packedPacket, error) {
  115. if p.ackFrame == nil {
  116. return nil, errors.New("packet packer BUG: no ack frame queued")
  117. }
  118. encLevel, sealer := p.cryptoSetup.GetSealer()
  119. header := p.getHeader(encLevel)
  120. frames := []wire.Frame{p.ackFrame}
  121. if p.stopWaiting != nil { // a STOP_WAITING will only be queued when using gQUIC
  122. p.stopWaiting.PacketNumber = header.PacketNumber
  123. p.stopWaiting.PacketNumberLen = header.PacketNumberLen
  124. frames = append(frames, p.stopWaiting)
  125. p.stopWaiting = nil
  126. }
  127. p.ackFrame = nil
  128. raw, err := p.writeAndSealPacket(header, frames, sealer)
  129. return &packedPacket{
  130. header: header,
  131. raw: raw,
  132. frames: frames,
  133. encryptionLevel: encLevel,
  134. }, err
  135. }
  136. // PackRetransmission packs a retransmission
  137. // For packets sent after completion of the handshake, it might happen that 2 packets have to be sent.
  138. // This can happen e.g. when a longer packet number is used in the header.
  139. func (p *packetPacker) PackRetransmission(packet *ackhandler.Packet) ([]*packedPacket, error) {
  140. if packet.EncryptionLevel != protocol.EncryptionForwardSecure {
  141. p, err := p.packHandshakeRetransmission(packet)
  142. return []*packedPacket{p}, err
  143. }
  144. var controlFrames []wire.Frame
  145. var streamFrames []*wire.StreamFrame
  146. for _, f := range packet.Frames {
  147. if sf, ok := f.(*wire.StreamFrame); ok {
  148. sf.DataLenPresent = true
  149. streamFrames = append(streamFrames, sf)
  150. } else {
  151. controlFrames = append(controlFrames, f)
  152. }
  153. }
  154. var packets []*packedPacket
  155. encLevel, sealer := p.cryptoSetup.GetSealer()
  156. for len(controlFrames) > 0 || len(streamFrames) > 0 {
  157. var frames []wire.Frame
  158. var payloadLength protocol.ByteCount
  159. header := p.getHeader(encLevel)
  160. headerLength, err := header.GetLength(p.version)
  161. if err != nil {
  162. return nil, err
  163. }
  164. maxSize := p.maxPacketSize - protocol.ByteCount(sealer.Overhead()) - headerLength
  165. // for gQUIC: add a STOP_WAITING for *every* retransmission
  166. if p.version.UsesStopWaitingFrames() {
  167. if p.stopWaiting == nil {
  168. return nil, errors.New("PacketPacker BUG: Handshake retransmissions must contain a STOP_WAITING frame")
  169. }
  170. // create a new StopWaitingFrame, since we might need to send more than one packet as a retransmission
  171. swf := &wire.StopWaitingFrame{
  172. LeastUnacked: p.stopWaiting.LeastUnacked,
  173. PacketNumber: header.PacketNumber,
  174. PacketNumberLen: header.PacketNumberLen,
  175. }
  176. payloadLength += swf.Length(p.version)
  177. frames = append(frames, swf)
  178. }
  179. for len(controlFrames) > 0 {
  180. frame := controlFrames[0]
  181. length := frame.Length(p.version)
  182. if payloadLength+length > maxSize {
  183. break
  184. }
  185. payloadLength += length
  186. frames = append(frames, frame)
  187. controlFrames = controlFrames[1:]
  188. }
  189. // temporarily increase the maxFrameSize by the (minimum) length of the DataLen field
  190. // this leads to a properly sized packet in all cases, since we do all the packet length calculations with StreamFrames that have the DataLen set
  191. // however, for the last STREAM frame in the packet, we can omit the DataLen, thus yielding a packet of exactly the correct size
  192. // for gQUIC STREAM frames, DataLen is always 2 bytes
  193. // for IETF draft style STREAM frames, the length is encoded to either 1 or 2 bytes
  194. if p.version.UsesIETFFrameFormat() {
  195. maxSize++
  196. } else {
  197. maxSize += 2
  198. }
  199. for len(streamFrames) > 0 && payloadLength+protocol.MinStreamFrameSize < maxSize {
  200. // TODO: optimize by setting DataLenPresent = false on all but the last STREAM frame
  201. frame := streamFrames[0]
  202. frameToAdd := frame
  203. sf, err := frame.MaybeSplitOffFrame(maxSize-payloadLength, p.version)
  204. if err != nil {
  205. return nil, err
  206. }
  207. if sf != nil {
  208. frameToAdd = sf
  209. } else {
  210. streamFrames = streamFrames[1:]
  211. }
  212. payloadLength += frameToAdd.Length(p.version)
  213. frames = append(frames, frameToAdd)
  214. }
  215. if sf, ok := frames[len(frames)-1].(*wire.StreamFrame); ok {
  216. sf.DataLenPresent = false
  217. }
  218. raw, err := p.writeAndSealPacket(header, frames, sealer)
  219. if err != nil {
  220. return nil, err
  221. }
  222. packets = append(packets, &packedPacket{
  223. header: header,
  224. raw: raw,
  225. frames: frames,
  226. encryptionLevel: encLevel,
  227. })
  228. }
  229. p.stopWaiting = nil
  230. return packets, nil
  231. }
  232. // packHandshakeRetransmission retransmits a handshake packet, that was sent with less than forward-secure encryption
  233. func (p *packetPacker) packHandshakeRetransmission(packet *ackhandler.Packet) (*packedPacket, error) {
  234. sealer, err := p.cryptoSetup.GetSealerWithEncryptionLevel(packet.EncryptionLevel)
  235. if err != nil {
  236. return nil, err
  237. }
  238. // make sure that the retransmission for an Initial packet is sent as an Initial packet
  239. if packet.PacketType == protocol.PacketTypeInitial {
  240. p.hasSentPacket = false
  241. }
  242. header := p.getHeader(packet.EncryptionLevel)
  243. header.Type = packet.PacketType
  244. var frames []wire.Frame
  245. if p.version.UsesStopWaitingFrames() { // for gQUIC: pack a STOP_WAITING first
  246. if p.stopWaiting == nil {
  247. return nil, errors.New("PacketPacker BUG: Handshake retransmissions must contain a STOP_WAITING frame")
  248. }
  249. swf := p.stopWaiting
  250. swf.PacketNumber = header.PacketNumber
  251. swf.PacketNumberLen = header.PacketNumberLen
  252. p.stopWaiting = nil
  253. frames = append([]wire.Frame{swf}, packet.Frames...)
  254. } else {
  255. frames = packet.Frames
  256. }
  257. raw, err := p.writeAndSealPacket(header, frames, sealer)
  258. return &packedPacket{
  259. header: header,
  260. raw: raw,
  261. frames: frames,
  262. encryptionLevel: packet.EncryptionLevel,
  263. }, err
  264. }
  265. // PackPacket packs a new packet
  266. // the other controlFrames are sent in the next packet, but might be queued and sent in the next packet if the packet would overflow MaxPacketSize otherwise
  267. func (p *packetPacker) PackPacket() (*packedPacket, error) {
  268. hasCryptoStreamFrame := p.streams.HasCryptoStreamData()
  269. // if this is the first packet to be send, make sure it contains stream data
  270. if !p.hasSentPacket && !hasCryptoStreamFrame {
  271. return nil, nil
  272. }
  273. if hasCryptoStreamFrame {
  274. return p.packCryptoPacket()
  275. }
  276. encLevel, sealer := p.cryptoSetup.GetSealer()
  277. header := p.getHeader(encLevel)
  278. headerLength, err := header.GetLength(p.version)
  279. if err != nil {
  280. return nil, err
  281. }
  282. if p.stopWaiting != nil {
  283. p.stopWaiting.PacketNumber = header.PacketNumber
  284. p.stopWaiting.PacketNumberLen = header.PacketNumberLen
  285. }
  286. maxSize := p.maxPacketSize - protocol.ByteCount(sealer.Overhead()) - headerLength
  287. payloadFrames, err := p.composeNextPacket(maxSize, p.canSendData(encLevel))
  288. if err != nil {
  289. return nil, err
  290. }
  291. // Check if we have enough frames to send
  292. if len(payloadFrames) == 0 {
  293. return nil, nil
  294. }
  295. // Don't send out packets that only contain a StopWaitingFrame
  296. if len(payloadFrames) == 1 && p.stopWaiting != nil {
  297. return nil, nil
  298. }
  299. if p.ackFrame != nil {
  300. // check if this packet only contains an ACK (and maybe a STOP_WAITING)
  301. if len(payloadFrames) == 1 || (p.stopWaiting != nil && len(payloadFrames) == 2) {
  302. if p.numNonRetransmittableAcks >= protocol.MaxNonRetransmittableAcks {
  303. payloadFrames = append(payloadFrames, &wire.PingFrame{})
  304. p.numNonRetransmittableAcks = 0
  305. } else {
  306. p.numNonRetransmittableAcks++
  307. }
  308. } else {
  309. p.numNonRetransmittableAcks = 0
  310. }
  311. }
  312. p.stopWaiting = nil
  313. p.ackFrame = nil
  314. raw, err := p.writeAndSealPacket(header, payloadFrames, sealer)
  315. if err != nil {
  316. return nil, err
  317. }
  318. return &packedPacket{
  319. header: header,
  320. raw: raw,
  321. frames: payloadFrames,
  322. encryptionLevel: encLevel,
  323. }, nil
  324. }
  325. func (p *packetPacker) packCryptoPacket() (*packedPacket, error) {
  326. encLevel, sealer := p.cryptoSetup.GetSealerForCryptoStream()
  327. header := p.getHeader(encLevel)
  328. headerLength, err := header.GetLength(p.version)
  329. if err != nil {
  330. return nil, err
  331. }
  332. maxLen := p.maxPacketSize - protocol.ByteCount(sealer.Overhead()) - protocol.NonForwardSecurePacketSizeReduction - headerLength
  333. sf := p.streams.PopCryptoStreamFrame(maxLen)
  334. sf.DataLenPresent = false
  335. frames := []wire.Frame{sf}
  336. raw, err := p.writeAndSealPacket(header, frames, sealer)
  337. if err != nil {
  338. return nil, err
  339. }
  340. return &packedPacket{
  341. header: header,
  342. raw: raw,
  343. frames: frames,
  344. encryptionLevel: encLevel,
  345. }, nil
  346. }
  347. func (p *packetPacker) composeNextPacket(
  348. maxFrameSize protocol.ByteCount,
  349. canSendStreamFrames bool,
  350. ) ([]wire.Frame, error) {
  351. var payloadLength protocol.ByteCount
  352. var payloadFrames []wire.Frame
  353. // STOP_WAITING and ACK will always fit
  354. if p.ackFrame != nil { // ACKs need to go first, so that the sentPacketHandler will recognize them
  355. payloadFrames = append(payloadFrames, p.ackFrame)
  356. l := p.ackFrame.Length(p.version)
  357. payloadLength += l
  358. }
  359. if p.stopWaiting != nil { // a STOP_WAITING will only be queued when using gQUIC
  360. payloadFrames = append(payloadFrames, p.stopWaiting)
  361. payloadLength += p.stopWaiting.Length(p.version)
  362. }
  363. p.controlFrameMutex.Lock()
  364. for len(p.controlFrames) > 0 {
  365. frame := p.controlFrames[len(p.controlFrames)-1]
  366. length := frame.Length(p.version)
  367. if payloadLength+length > maxFrameSize {
  368. break
  369. }
  370. payloadFrames = append(payloadFrames, frame)
  371. payloadLength += length
  372. p.controlFrames = p.controlFrames[:len(p.controlFrames)-1]
  373. }
  374. p.controlFrameMutex.Unlock()
  375. if payloadLength > maxFrameSize {
  376. return nil, fmt.Errorf("Packet Packer BUG: packet payload (%d) too large (%d)", payloadLength, maxFrameSize)
  377. }
  378. if !canSendStreamFrames {
  379. return payloadFrames, nil
  380. }
  381. // temporarily increase the maxFrameSize by the (minimum) length of the DataLen field
  382. // this leads to a properly sized packet in all cases, since we do all the packet length calculations with StreamFrames that have the DataLen set
  383. // however, for the last STREAM frame in the packet, we can omit the DataLen, thus yielding a packet of exactly the correct size
  384. // for gQUIC STREAM frames, DataLen is always 2 bytes
  385. // for IETF draft style STREAM frames, the length is encoded to either 1 or 2 bytes
  386. if p.version.UsesIETFFrameFormat() {
  387. maxFrameSize++
  388. } else {
  389. maxFrameSize += 2
  390. }
  391. fs := p.streams.PopStreamFrames(maxFrameSize - payloadLength)
  392. if len(fs) != 0 {
  393. fs[len(fs)-1].DataLenPresent = false
  394. }
  395. for _, f := range fs {
  396. payloadFrames = append(payloadFrames, f)
  397. }
  398. return payloadFrames, nil
  399. }
  400. func (p *packetPacker) QueueControlFrame(frame wire.Frame) {
  401. switch f := frame.(type) {
  402. case *wire.StopWaitingFrame:
  403. p.stopWaiting = f
  404. case *wire.AckFrame:
  405. p.ackFrame = f
  406. default:
  407. p.controlFrameMutex.Lock()
  408. p.controlFrames = append(p.controlFrames, f)
  409. p.controlFrameMutex.Unlock()
  410. }
  411. }
  412. func (p *packetPacker) getHeader(encLevel protocol.EncryptionLevel) *wire.Header {
  413. pnum := p.packetNumberGenerator.Peek()
  414. packetNumberLen := p.getPacketNumberLen(pnum)
  415. header := &wire.Header{
  416. PacketNumber: pnum,
  417. PacketNumberLen: packetNumberLen,
  418. Version: p.version,
  419. }
  420. if p.version.UsesIETFHeaderFormat() && encLevel != protocol.EncryptionForwardSecure {
  421. header.IsLongHeader = true
  422. header.SrcConnectionID = p.srcConnID
  423. if !p.version.UsesVarintPacketNumbers() {
  424. header.PacketNumberLen = protocol.PacketNumberLen4
  425. }
  426. // Set the payload len to maximum size.
  427. // Since it is encoded as a varint, this guarantees us that the header will end up at most as big as GetLength() returns.
  428. header.PayloadLen = p.maxPacketSize
  429. if !p.hasSentPacket && p.perspective == protocol.PerspectiveClient {
  430. header.Type = protocol.PacketTypeInitial
  431. header.Token = p.token
  432. } else {
  433. header.Type = protocol.PacketTypeHandshake
  434. }
  435. }
  436. if !p.omitConnectionID || encLevel != protocol.EncryptionForwardSecure {
  437. header.DestConnectionID = p.destConnID
  438. }
  439. if !p.version.UsesTLS() {
  440. if p.perspective == protocol.PerspectiveServer && encLevel == protocol.EncryptionSecure {
  441. header.Type = protocol.PacketType0RTT
  442. header.DiversificationNonce = p.divNonce
  443. }
  444. if p.perspective == protocol.PerspectiveClient && encLevel != protocol.EncryptionForwardSecure {
  445. header.VersionFlag = true
  446. }
  447. }
  448. return header
  449. }
  450. func (p *packetPacker) writeAndSealPacket(
  451. header *wire.Header,
  452. payloadFrames []wire.Frame,
  453. sealer handshake.Sealer,
  454. ) ([]byte, error) {
  455. raw := *getPacketBuffer()
  456. buffer := bytes.NewBuffer(raw[:0])
  457. // the payload length is only needed for Long Headers
  458. if header.IsLongHeader {
  459. if header.Type == protocol.PacketTypeInitial {
  460. headerLen, _ := header.GetLength(p.version)
  461. header.PayloadLen = protocol.ByteCount(protocol.MinInitialPacketSize) - headerLen
  462. } else {
  463. payloadLen := protocol.ByteCount(sealer.Overhead())
  464. for _, frame := range payloadFrames {
  465. payloadLen += frame.Length(p.version)
  466. }
  467. header.PayloadLen = payloadLen
  468. }
  469. }
  470. if err := header.Write(buffer, p.perspective, p.version); err != nil {
  471. return nil, err
  472. }
  473. payloadStartIndex := buffer.Len()
  474. // the Initial packet needs to be padded, so the last STREAM frame must have the data length present
  475. if header.Type == protocol.PacketTypeInitial {
  476. lastFrame := payloadFrames[len(payloadFrames)-1]
  477. if sf, ok := lastFrame.(*wire.StreamFrame); ok {
  478. sf.DataLenPresent = true
  479. }
  480. }
  481. for _, frame := range payloadFrames {
  482. if err := frame.Write(buffer, p.version); err != nil {
  483. return nil, err
  484. }
  485. }
  486. // if this is an IETF QUIC Initial packet, we need to pad it to fulfill the minimum size requirement
  487. // in gQUIC, padding is handled in the CHLO
  488. if header.Type == protocol.PacketTypeInitial {
  489. paddingLen := protocol.MinInitialPacketSize - sealer.Overhead() - buffer.Len()
  490. if paddingLen > 0 {
  491. buffer.Write(bytes.Repeat([]byte{0}, paddingLen))
  492. }
  493. }
  494. if size := protocol.ByteCount(buffer.Len() + sealer.Overhead()); size > p.maxPacketSize {
  495. return nil, fmt.Errorf("PacketPacker BUG: packet too large (%d bytes, allowed %d bytes)", size, p.maxPacketSize)
  496. }
  497. raw = raw[0:buffer.Len()]
  498. _ = sealer.Seal(raw[payloadStartIndex:payloadStartIndex], raw[payloadStartIndex:], header.PacketNumber, raw[:payloadStartIndex])
  499. raw = raw[0 : buffer.Len()+sealer.Overhead()]
  500. num := p.packetNumberGenerator.Pop()
  501. if num != header.PacketNumber {
  502. return nil, errors.New("packetPacker BUG: Peeked and Popped packet numbers do not match")
  503. }
  504. p.hasSentPacket = true
  505. return raw, nil
  506. }
  507. func (p *packetPacker) canSendData(encLevel protocol.EncryptionLevel) bool {
  508. if p.perspective == protocol.PerspectiveClient {
  509. return encLevel >= protocol.EncryptionSecure
  510. }
  511. return encLevel == protocol.EncryptionForwardSecure
  512. }
  513. func (p *packetPacker) SetOmitConnectionID() {
  514. p.omitConnectionID = true
  515. }
  516. func (p *packetPacker) ChangeDestConnectionID(connID protocol.ConnectionID) {
  517. p.destConnID = connID
  518. }
  519. func (p *packetPacker) SetMaxPacketSize(size protocol.ByteCount) {
  520. p.maxPacketSize = utils.MinByteCount(p.maxPacketSize, size)
  521. }