Skip to content

Commit e26b9a4

Browse files
committed
quic: rename Listener to Endpoint
The name Listener is confusing, because unlike a net.Listener a quic.Listener manages outgoing connections as well as inbound ones. Rename to "endpoint" which doesn't map to any existing net package name and matches the terminology of the QUIC RFCs. For golang/go#58547 Change-Id: If87f8c67ac7dd15d89d2d082a8ba2c63ea7f6e26 Reviewed-on: https://go-review.googlesource.com/c/net/+/543298 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent 399218d commit e26b9a4

15 files changed

+285
-285
lines changed

internal/quic/cmd/interop/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func basicTest(ctx context.Context, config *quic.Config, urls []string) {
157157
}
158158
}
159159

160-
func serve(ctx context.Context, l *quic.Listener) error {
160+
func serve(ctx context.Context, l *quic.Endpoint) error {
161161
for {
162162
c, err := l.Accept(ctx)
163163
if err != nil {
@@ -221,7 +221,7 @@ func parseURL(s string) (u *url.URL, authority string, err error) {
221221
return u, authority, nil
222222
}
223223

224-
func fetchFrom(ctx context.Context, l *quic.Listener, addr string, urls []*url.URL) {
224+
func fetchFrom(ctx context.Context, l *quic.Endpoint, addr string, urls []*url.URL) {
225225
conn, err := l.Dial(ctx, "udp", addr)
226226
if err != nil {
227227
log.Printf("%v: %v", addr, err)

internal/quic/conn.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// Multiple goroutines may invoke methods on a Conn simultaneously.
2222
type Conn struct {
2323
side connSide
24-
listener *Listener
24+
endpoint *Endpoint
2525
config *Config
2626
testHooks connTestHooks
2727
peerAddr netip.AddrPort
@@ -92,10 +92,10 @@ type newServerConnIDs struct {
9292
retrySrcConnID []byte // source from server's Retry
9393
}
9494

95-
func newConn(now time.Time, side connSide, cids newServerConnIDs, peerAddr netip.AddrPort, config *Config, l *Listener) (conn *Conn, _ error) {
95+
func newConn(now time.Time, side connSide, cids newServerConnIDs, peerAddr netip.AddrPort, config *Config, e *Endpoint) (conn *Conn, _ error) {
9696
c := &Conn{
9797
side: side,
98-
listener: l,
98+
endpoint: e,
9999
config: config,
100100
peerAddr: peerAddr,
101101
msgc: make(chan any, 1),
@@ -115,8 +115,8 @@ func newConn(now time.Time, side connSide, cids newServerConnIDs, peerAddr netip
115115
// non-blocking operation.
116116
c.msgc = make(chan any, 1)
117117

118-
if l.testHooks != nil {
119-
l.testHooks.newConn(c)
118+
if e.testHooks != nil {
119+
e.testHooks.newConn(c)
120120
}
121121

122122
// initialConnID is the connection ID used to generate Initial packet protection keys.
@@ -187,7 +187,7 @@ func (c *Conn) confirmHandshake(now time.Time) {
187187
if c.side == serverSide {
188188
// When the server confirms the handshake, it sends a HANDSHAKE_DONE.
189189
c.handshakeConfirmed.setUnsent()
190-
c.listener.serverConnEstablished(c)
190+
c.endpoint.serverConnEstablished(c)
191191
} else {
192192
// The client never sends a HANDSHAKE_DONE, so we set handshakeConfirmed
193193
// to the received state, indicating that the handshake is confirmed and we
@@ -265,7 +265,7 @@ var errIdleTimeout = errors.New("idle timeout")
265265
func (c *Conn) loop(now time.Time) {
266266
defer close(c.donec)
267267
defer c.tls.Close()
268-
defer c.listener.connDrained(c)
268+
defer c.endpoint.connDrained(c)
269269
defer c.logConnectionClosed()
270270

271271
// The connection timer sends a message to the connection loop on expiry.

internal/quic/conn_close_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ func TestConnCloseReceiveInHandshake(t *testing.T) {
205205
tc.wantIdle("no more frames to send")
206206
}
207207

208-
func TestConnCloseClosedByListener(t *testing.T) {
208+
func TestConnCloseClosedByEndpoint(t *testing.T) {
209209
ctx := canceledContext()
210210
tc := newTestConn(t, clientSide)
211211
tc.handshake()
212212

213-
tc.listener.l.Close(ctx)
214-
tc.wantFrame("listener closes connection before exiting",
213+
tc.endpoint.e.Close(ctx)
214+
tc.wantFrame("endpoint closes connection before exiting",
215215
packetType1RTT, debugFrameConnectionCloseTransport{
216216
code: errNo,
217217
})

internal/quic/conn_id.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (s *connIDState) initClient(c *Conn) error {
7676
cid: locid,
7777
})
7878
s.nextLocalSeq = 1
79-
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
79+
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
8080
conns.addConnID(c, locid)
8181
})
8282

@@ -117,7 +117,7 @@ func (s *connIDState) initServer(c *Conn, cids newServerConnIDs) error {
117117
cid: locid,
118118
})
119119
s.nextLocalSeq = 1
120-
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
120+
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
121121
conns.addConnID(c, dstConnID)
122122
conns.addConnID(c, locid)
123123
})
@@ -194,7 +194,7 @@ func (s *connIDState) issueLocalIDs(c *Conn) error {
194194
s.needSend = true
195195
toIssue--
196196
}
197-
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
197+
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
198198
for _, cid := range newIDs {
199199
conns.addConnID(c, cid)
200200
}
@@ -247,7 +247,7 @@ func (s *connIDState) validateTransportParameters(c *Conn, isRetry bool, p trans
247247
}
248248
token := statelessResetToken(p.statelessResetToken)
249249
s.remote[0].resetToken = token
250-
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
250+
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
251251
conns.addResetToken(c, token)
252252
})
253253
}
@@ -276,7 +276,7 @@ func (s *connIDState) handlePacket(c *Conn, ptype packetType, srcConnID []byte)
276276
// the client. Discard the transient, client-chosen connection ID used
277277
// for Initial packets; the client will never send it again.
278278
cid := s.local[0].cid
279-
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
279+
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
280280
conns.retireConnID(c, cid)
281281
})
282282
s.local = append(s.local[:0], s.local[1:]...)
@@ -314,7 +314,7 @@ func (s *connIDState) handleNewConnID(c *Conn, seq, retire int64, cid []byte, re
314314
rcid := &s.remote[i]
315315
if !rcid.retired && rcid.seq >= 0 && rcid.seq < s.retireRemotePriorTo {
316316
s.retireRemote(rcid)
317-
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
317+
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
318318
conns.retireResetToken(c, rcid.resetToken)
319319
})
320320
}
@@ -350,7 +350,7 @@ func (s *connIDState) handleNewConnID(c *Conn, seq, retire int64, cid []byte, re
350350
s.retireRemote(&s.remote[len(s.remote)-1])
351351
} else {
352352
active++
353-
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
353+
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
354354
conns.addResetToken(c, resetToken)
355355
})
356356
}
@@ -399,7 +399,7 @@ func (s *connIDState) handleRetireConnID(c *Conn, seq int64) error {
399399
for i := range s.local {
400400
if s.local[i].seq == seq {
401401
cid := s.local[i].cid
402-
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
402+
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
403403
conns.retireConnID(c, cid)
404404
})
405405
s.local = append(s.local[:i], s.local[i+1:]...)
@@ -463,7 +463,7 @@ func (s *connIDState) appendFrames(c *Conn, pnum packetNumber, pto bool) bool {
463463
s.local[i].seq,
464464
retireBefore,
465465
s.local[i].cid,
466-
c.listener.resetGen.tokenForConnID(s.local[i].cid),
466+
c.endpoint.resetGen.tokenForConnID(s.local[i].cid),
467467
) {
468468
return false
469469
}

internal/quic/conn_id_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,16 +651,16 @@ func TestConnIDsCleanedUpAfterClose(t *testing.T) {
651651
// Wait for the conn to drain.
652652
// Then wait for the conn loop to exit,
653653
// and force an immediate sync of the connsMap updates
654-
// (normally only done by the listener read loop).
654+
// (normally only done by the endpoint read loop).
655655
tc.advanceToTimer()
656656
<-tc.conn.donec
657-
tc.listener.l.connsMap.applyUpdates()
657+
tc.endpoint.e.connsMap.applyUpdates()
658658

659-
if got := len(tc.listener.l.connsMap.byConnID); got != 0 {
660-
t.Errorf("%v conn ids in listener map after closing, want 0", got)
659+
if got := len(tc.endpoint.e.connsMap.byConnID); got != 0 {
660+
t.Errorf("%v conn ids in endpoint map after closing, want 0", got)
661661
}
662-
if got := len(tc.listener.l.connsMap.byResetToken); got != 0 {
663-
t.Errorf("%v reset tokens in listener map after closing, want 0", got)
662+
if got := len(tc.endpoint.e.connsMap.byResetToken); got != 0 {
663+
t.Errorf("%v reset tokens in endpoint map after closing, want 0", got)
664664
}
665665
})
666666
}

internal/quic/conn_send.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func (c *Conn) maybeSend(now time.Time) (next time.Time) {
170170
}
171171
}
172172

173-
c.listener.sendDatagram(buf, c.peerAddr)
173+
c.endpoint.sendDatagram(buf, c.peerAddr)
174174
}
175175
}
176176

0 commit comments

Comments
 (0)