@@ -55,10 +55,10 @@ type connID struct {
55
55
send sentVal
56
56
}
57
57
58
- func (s * connIDState ) initClient (newID newConnIDFunc ) error {
58
+ func (s * connIDState ) initClient (c * Conn ) error {
59
59
// Client chooses its initial connection ID, and sends it
60
60
// in the Source Connection ID field of the first Initial packet.
61
- locid , err := newID (0 )
61
+ locid , err := c . newConnID (0 )
62
62
if err != nil {
63
63
return err
64
64
}
@@ -70,18 +70,20 @@ func (s *connIDState) initClient(newID newConnIDFunc) error {
70
70
71
71
// Client chooses an initial, transient connection ID for the server,
72
72
// and sends it in the Destination Connection ID field of the first Initial packet.
73
- remid , err := newID (- 1 )
73
+ remid , err := c . newConnID (- 1 )
74
74
if err != nil {
75
75
return err
76
76
}
77
77
s .remote = append (s .remote , connID {
78
78
seq : - 1 ,
79
79
cid : remid ,
80
80
})
81
+ const retired = false
82
+ c .listener .connIDsChanged (c , retired , s .local [:])
81
83
return nil
82
84
}
83
85
84
- func (s * connIDState ) initServer (newID newConnIDFunc , dstConnID []byte ) error {
86
+ func (s * connIDState ) initServer (c * Conn , dstConnID []byte ) error {
85
87
// Client-chosen, transient connection ID received in the first Initial packet.
86
88
// The server will not use this as the Source Connection ID of packets it sends,
87
89
// but remembers it because it may receive packets sent to this destination.
@@ -92,7 +94,7 @@ func (s *connIDState) initServer(newID newConnIDFunc, dstConnID []byte) error {
92
94
93
95
// Server chooses a connection ID, and sends it in the Source Connection ID of
94
96
// the response to the clent.
95
- locid , err := newID (0 )
97
+ locid , err := c . newConnID (0 )
96
98
if err != nil {
97
99
return err
98
100
}
@@ -101,6 +103,8 @@ func (s *connIDState) initServer(newID newConnIDFunc, dstConnID []byte) error {
101
103
cid : locid ,
102
104
})
103
105
s .nextLocalSeq = 1
106
+ const retired = false
107
+ c .listener .connIDsChanged (c , retired , s .local [:])
104
108
return nil
105
109
}
106
110
@@ -125,20 +129,21 @@ func (s *connIDState) dstConnID() (cid []byte, ok bool) {
125
129
126
130
// setPeerActiveConnIDLimit sets the active_connection_id_limit
127
131
// transport parameter received from the peer.
128
- func (s * connIDState ) setPeerActiveConnIDLimit (lim int64 , newID newConnIDFunc ) error {
132
+ func (s * connIDState ) setPeerActiveConnIDLimit (c * Conn , lim int64 ) error {
129
133
s .peerActiveConnIDLimit = lim
130
- return s .issueLocalIDs (newID )
134
+ return s .issueLocalIDs (c )
131
135
}
132
136
133
- func (s * connIDState ) issueLocalIDs (newID newConnIDFunc ) error {
137
+ func (s * connIDState ) issueLocalIDs (c * Conn ) error {
134
138
toIssue := min (int (s .peerActiveConnIDLimit ), maxPeerActiveConnIDLimit )
135
139
for i := range s .local {
136
140
if s .local [i ].seq != - 1 && ! s .local [i ].retired {
137
141
toIssue --
138
142
}
139
143
}
144
+ prev := len (s .local )
140
145
for toIssue > 0 {
141
- cid , err := newID (s .nextLocalSeq )
146
+ cid , err := c . newConnID (s .nextLocalSeq )
142
147
if err != nil {
143
148
return err
144
149
}
@@ -151,14 +156,16 @@ func (s *connIDState) issueLocalIDs(newID newConnIDFunc) error {
151
156
s .needSend = true
152
157
toIssue --
153
158
}
159
+ const retired = false
160
+ c .listener .connIDsChanged (c , retired , s .local [prev :])
154
161
return nil
155
162
}
156
163
157
164
// handlePacket updates the connection ID state during the handshake
158
165
// (Initial and Handshake packets).
159
- func (s * connIDState ) handlePacket (side connSide , ptype packetType , srcConnID []byte ) {
166
+ func (s * connIDState ) handlePacket (c * Conn , ptype packetType , srcConnID []byte ) {
160
167
switch {
161
- case ptype == packetTypeInitial && side == clientSide :
168
+ case ptype == packetTypeInitial && c . side == clientSide :
162
169
if len (s .remote ) == 1 && s .remote [0 ].seq == - 1 {
163
170
// We're a client connection processing the first Initial packet
164
171
// from the server. Replace the transient remote connection ID
@@ -168,7 +175,7 @@ func (s *connIDState) handlePacket(side connSide, ptype packetType, srcConnID []
168
175
cid : cloneBytes (srcConnID ),
169
176
}
170
177
}
171
- case ptype == packetTypeInitial && side == serverSide :
178
+ case ptype == packetTypeInitial && c . side == serverSide :
172
179
if len (s .remote ) == 0 {
173
180
// We're a server connection processing the first Initial packet
174
181
// from the client. Set the client's connection ID.
@@ -177,11 +184,13 @@ func (s *connIDState) handlePacket(side connSide, ptype packetType, srcConnID []
177
184
cid : cloneBytes (srcConnID ),
178
185
})
179
186
}
180
- case ptype == packetTypeHandshake && side == serverSide :
187
+ case ptype == packetTypeHandshake && c . side == serverSide :
181
188
if len (s .local ) > 0 && s .local [0 ].seq == - 1 {
182
189
// We're a server connection processing the first Handshake packet from
183
190
// the client. Discard the transient, client-chosen connection ID used
184
191
// for Initial packets; the client will never send it again.
192
+ const retired = true
193
+ c .listener .connIDsChanged (c , retired , s .local [0 :1 ])
185
194
s .local = append (s .local [:0 ], s .local [1 :]... )
186
195
}
187
196
}
@@ -263,17 +272,19 @@ func (s *connIDState) retireRemote(rcid *connID) {
263
272
s .needSend = true
264
273
}
265
274
266
- func (s * connIDState ) handleRetireConnID (seq int64 , newID newConnIDFunc ) error {
275
+ func (s * connIDState ) handleRetireConnID (c * Conn , seq int64 ) error {
267
276
if seq >= s .nextLocalSeq {
268
277
return localTransportError (errProtocolViolation )
269
278
}
270
279
for i := range s .local {
271
280
if s .local [i ].seq == seq {
281
+ const retired = true
282
+ c .listener .connIDsChanged (c , retired , s .local [i :i + 1 ])
272
283
s .local = append (s .local [:i ], s .local [i + 1 :]... )
273
284
break
274
285
}
275
286
}
276
- s .issueLocalIDs (newID )
287
+ s .issueLocalIDs (c )
277
288
return nil
278
289
}
279
290
@@ -355,7 +366,12 @@ func cloneBytes(b []byte) []byte {
355
366
return n
356
367
}
357
368
358
- type newConnIDFunc func (seq int64 ) ([]byte , error )
369
+ func (c * Conn ) newConnID (seq int64 ) ([]byte , error ) {
370
+ if c .testHooks != nil {
371
+ return c .testHooks .newConnID (seq )
372
+ }
373
+ return newRandomConnID (seq )
374
+ }
359
375
360
376
func newRandomConnID (_ int64 ) ([]byte , error ) {
361
377
// It is not necessary for connection IDs to be cryptographically secure,
0 commit comments