Skip to content

Commit

Permalink
quic: rename Listener to Endpoint
Browse files Browse the repository at this point in the history
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
neild committed Nov 17, 2023
1 parent 399218d commit e26b9a4
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 285 deletions.
4 changes: 2 additions & 2 deletions internal/quic/cmd/interop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func basicTest(ctx context.Context, config *quic.Config, urls []string) {
}
}

func serve(ctx context.Context, l *quic.Listener) error {
func serve(ctx context.Context, l *quic.Endpoint) error {
for {
c, err := l.Accept(ctx)
if err != nil {
Expand Down Expand Up @@ -221,7 +221,7 @@ func parseURL(s string) (u *url.URL, authority string, err error) {
return u, authority, nil
}

func fetchFrom(ctx context.Context, l *quic.Listener, addr string, urls []*url.URL) {
func fetchFrom(ctx context.Context, l *quic.Endpoint, addr string, urls []*url.URL) {
conn, err := l.Dial(ctx, "udp", addr)
if err != nil {
log.Printf("%v: %v", addr, err)
Expand Down
14 changes: 7 additions & 7 deletions internal/quic/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// Multiple goroutines may invoke methods on a Conn simultaneously.
type Conn struct {
side connSide
listener *Listener
endpoint *Endpoint
config *Config
testHooks connTestHooks
peerAddr netip.AddrPort
Expand Down Expand Up @@ -92,10 +92,10 @@ type newServerConnIDs struct {
retrySrcConnID []byte // source from server's Retry
}

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

if l.testHooks != nil {
l.testHooks.newConn(c)
if e.testHooks != nil {
e.testHooks.newConn(c)
}

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

// The connection timer sends a message to the connection loop on expiry.
Expand Down
6 changes: 3 additions & 3 deletions internal/quic/conn_close_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ func TestConnCloseReceiveInHandshake(t *testing.T) {
tc.wantIdle("no more frames to send")
}

func TestConnCloseClosedByListener(t *testing.T) {
func TestConnCloseClosedByEndpoint(t *testing.T) {
ctx := canceledContext()
tc := newTestConn(t, clientSide)
tc.handshake()

tc.listener.l.Close(ctx)
tc.wantFrame("listener closes connection before exiting",
tc.endpoint.e.Close(ctx)
tc.wantFrame("endpoint closes connection before exiting",
packetType1RTT, debugFrameConnectionCloseTransport{
code: errNo,
})
Expand Down
18 changes: 9 additions & 9 deletions internal/quic/conn_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *connIDState) initClient(c *Conn) error {
cid: locid,
})
s.nextLocalSeq = 1
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
conns.addConnID(c, locid)
})

Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *connIDState) initServer(c *Conn, cids newServerConnIDs) error {
cid: locid,
})
s.nextLocalSeq = 1
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
conns.addConnID(c, dstConnID)
conns.addConnID(c, locid)
})
Expand Down Expand Up @@ -194,7 +194,7 @@ func (s *connIDState) issueLocalIDs(c *Conn) error {
s.needSend = true
toIssue--
}
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
for _, cid := range newIDs {
conns.addConnID(c, cid)
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func (s *connIDState) validateTransportParameters(c *Conn, isRetry bool, p trans
}
token := statelessResetToken(p.statelessResetToken)
s.remote[0].resetToken = token
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
conns.addResetToken(c, token)
})
}
Expand Down Expand Up @@ -276,7 +276,7 @@ func (s *connIDState) handlePacket(c *Conn, ptype packetType, srcConnID []byte)
// the client. Discard the transient, client-chosen connection ID used
// for Initial packets; the client will never send it again.
cid := s.local[0].cid
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
conns.retireConnID(c, cid)
})
s.local = append(s.local[:0], s.local[1:]...)
Expand Down Expand Up @@ -314,7 +314,7 @@ func (s *connIDState) handleNewConnID(c *Conn, seq, retire int64, cid []byte, re
rcid := &s.remote[i]
if !rcid.retired && rcid.seq >= 0 && rcid.seq < s.retireRemotePriorTo {
s.retireRemote(rcid)
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
conns.retireResetToken(c, rcid.resetToken)
})
}
Expand Down Expand Up @@ -350,7 +350,7 @@ func (s *connIDState) handleNewConnID(c *Conn, seq, retire int64, cid []byte, re
s.retireRemote(&s.remote[len(s.remote)-1])
} else {
active++
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
conns.addResetToken(c, resetToken)
})
}
Expand Down Expand Up @@ -399,7 +399,7 @@ func (s *connIDState) handleRetireConnID(c *Conn, seq int64) error {
for i := range s.local {
if s.local[i].seq == seq {
cid := s.local[i].cid
c.listener.connsMap.updateConnIDs(func(conns *connsMap) {
c.endpoint.connsMap.updateConnIDs(func(conns *connsMap) {
conns.retireConnID(c, cid)
})
s.local = append(s.local[:i], s.local[i+1:]...)
Expand Down Expand Up @@ -463,7 +463,7 @@ func (s *connIDState) appendFrames(c *Conn, pnum packetNumber, pto bool) bool {
s.local[i].seq,
retireBefore,
s.local[i].cid,
c.listener.resetGen.tokenForConnID(s.local[i].cid),
c.endpoint.resetGen.tokenForConnID(s.local[i].cid),
) {
return false
}
Expand Down
12 changes: 6 additions & 6 deletions internal/quic/conn_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,16 +651,16 @@ func TestConnIDsCleanedUpAfterClose(t *testing.T) {
// Wait for the conn to drain.
// Then wait for the conn loop to exit,
// and force an immediate sync of the connsMap updates
// (normally only done by the listener read loop).
// (normally only done by the endpoint read loop).
tc.advanceToTimer()
<-tc.conn.donec
tc.listener.l.connsMap.applyUpdates()
tc.endpoint.e.connsMap.applyUpdates()

if got := len(tc.listener.l.connsMap.byConnID); got != 0 {
t.Errorf("%v conn ids in listener map after closing, want 0", got)
if got := len(tc.endpoint.e.connsMap.byConnID); got != 0 {
t.Errorf("%v conn ids in endpoint map after closing, want 0", got)
}
if got := len(tc.listener.l.connsMap.byResetToken); got != 0 {
t.Errorf("%v reset tokens in listener map after closing, want 0", got)
if got := len(tc.endpoint.e.connsMap.byResetToken); got != 0 {
t.Errorf("%v reset tokens in endpoint map after closing, want 0", got)
}
})
}
2 changes: 1 addition & 1 deletion internal/quic/conn_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (c *Conn) maybeSend(now time.Time) (next time.Time) {
}
}

c.listener.sendDatagram(buf, c.peerAddr)
c.endpoint.sendDatagram(buf, c.peerAddr)
}
}

Expand Down
Loading

0 comments on commit e26b9a4

Please sign in to comment.