From 97690dc493a3b8ffa92043fbb6fca55e4dd9cf9e Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 26 Mar 2022 15:18:05 +0100 Subject: [PATCH] rename the closed session to closed conn --- closed_session.go => closed_conn.go | 48 +++++++++---------- closed_session_test.go => closed_conn_test.go | 28 +++++------ session.go | 4 +- session_test.go | 20 ++++---- 4 files changed, 50 insertions(+), 50 deletions(-) rename closed_session.go => closed_conn.go (51%) rename closed_session_test.go => closed_conn_test.go (59%) diff --git a/closed_session.go b/closed_conn.go similarity index 51% rename from closed_session.go rename to closed_conn.go index 312790202..35c2d7390 100644 --- a/closed_session.go +++ b/closed_conn.go @@ -7,15 +7,15 @@ import ( "github.com/lucas-clemente/quic-go/internal/utils" ) -// A closedLocalSession is a session that we closed locally. -// When receiving packets for such a session, we need to retransmit the packet containing the CONNECTION_CLOSE frame, +// A closedLocalConn is a connection that we closed locally. +// When receiving packets for such a connection, we need to retransmit the packet containing the CONNECTION_CLOSE frame, // with an exponential backoff. -type closedLocalSession struct { +type closedLocalConn struct { conn sendConn connClosePacket []byte closeOnce sync.Once - closeChan chan struct{} // is closed when the session is closed or destroyed + closeChan chan struct{} // is closed when the connection is closed or destroyed receivedPackets chan *receivedPacket counter uint64 // number of packets received @@ -25,16 +25,16 @@ type closedLocalSession struct { logger utils.Logger } -var _ packetHandler = &closedLocalSession{} +var _ packetHandler = &closedLocalConn{} -// newClosedLocalSession creates a new closedLocalSession and runs it. -func newClosedLocalSession( +// newClosedLocalConn creates a new closedLocalConn and runs it. +func newClosedLocalConn( conn sendConn, connClosePacket []byte, perspective protocol.Perspective, logger utils.Logger, ) packetHandler { - s := &closedLocalSession{ + s := &closedLocalConn{ conn: conn, connClosePacket: connClosePacket, perspective: perspective, @@ -46,7 +46,7 @@ func newClosedLocalSession( return s } -func (s *closedLocalSession) run() { +func (s *closedLocalConn) run() { for { select { case p := <-s.receivedPackets: @@ -57,14 +57,14 @@ func (s *closedLocalSession) run() { } } -func (s *closedLocalSession) handlePacket(p *receivedPacket) { +func (s *closedLocalConn) handlePacket(p *receivedPacket) { select { case s.receivedPackets <- p: default: } } -func (s *closedLocalSession) handlePacketImpl(_ *receivedPacket) { +func (s *closedLocalConn) handlePacketImpl(_ *receivedPacket) { s.counter++ // exponential backoff // only send a CONNECTION_CLOSE for the 1st, 2nd, 4th, 8th, 16th, ... packet arriving @@ -79,34 +79,34 @@ func (s *closedLocalSession) handlePacketImpl(_ *receivedPacket) { } } -func (s *closedLocalSession) shutdown() { +func (s *closedLocalConn) shutdown() { s.destroy(nil) } -func (s *closedLocalSession) destroy(error) { +func (s *closedLocalConn) destroy(error) { s.closeOnce.Do(func() { close(s.closeChan) }) } -func (s *closedLocalSession) getPerspective() protocol.Perspective { +func (s *closedLocalConn) getPerspective() protocol.Perspective { return s.perspective } -// A closedRemoteSession is a session that was closed remotely. -// For such a session, we might receive reordered packets that were sent before the CONNECTION_CLOSE. +// A closedRemoteConn is a connection that was closed remotely. +// For such a connection, we might receive reordered packets that were sent before the CONNECTION_CLOSE. // We can just ignore those packets. -type closedRemoteSession struct { +type closedRemoteConn struct { perspective protocol.Perspective } -var _ packetHandler = &closedRemoteSession{} +var _ packetHandler = &closedRemoteConn{} -func newClosedRemoteSession(pers protocol.Perspective) packetHandler { - return &closedRemoteSession{perspective: pers} +func newClosedRemoteConn(pers protocol.Perspective) packetHandler { + return &closedRemoteConn{perspective: pers} } -func (s *closedRemoteSession) handlePacket(*receivedPacket) {} -func (s *closedRemoteSession) shutdown() {} -func (s *closedRemoteSession) destroy(error) {} -func (s *closedRemoteSession) getPerspective() protocol.Perspective { return s.perspective } +func (s *closedRemoteConn) handlePacket(*receivedPacket) {} +func (s *closedRemoteConn) shutdown() {} +func (s *closedRemoteConn) destroy(error) {} +func (s *closedRemoteConn) getPerspective() protocol.Perspective { return s.perspective } diff --git a/closed_session_test.go b/closed_conn_test.go similarity index 59% rename from closed_session_test.go rename to closed_conn_test.go index c329d7920..e81b0050e 100644 --- a/closed_session_test.go +++ b/closed_conn_test.go @@ -12,45 +12,45 @@ import ( . "github.com/onsi/gomega" ) -var _ = Describe("Closed local session", func() { +var _ = Describe("Closed local connection", func() { var ( - sess packetHandler + conn packetHandler mconn *MockSendConn ) BeforeEach(func() { mconn = NewMockSendConn(mockCtrl) - sess = newClosedLocalSession(mconn, []byte("close"), protocol.PerspectiveClient, utils.DefaultLogger) + conn = newClosedLocalConn(mconn, []byte("close"), protocol.PerspectiveClient, utils.DefaultLogger) }) AfterEach(func() { - Eventually(areClosedSessionsRunning).Should(BeFalse()) + Eventually(areClosedConnsRunning).Should(BeFalse()) }) It("tells its perspective", func() { - Expect(sess.getPerspective()).To(Equal(protocol.PerspectiveClient)) - // stop the session - sess.shutdown() + Expect(conn.getPerspective()).To(Equal(protocol.PerspectiveClient)) + // stop the connection + conn.shutdown() }) It("repeats the packet containing the CONNECTION_CLOSE frame", func() { written := make(chan []byte) mconn.EXPECT().Write(gomock.Any()).Do(func(p []byte) { written <- p }).AnyTimes() for i := 1; i <= 20; i++ { - sess.handlePacket(&receivedPacket{}) + conn.handlePacket(&receivedPacket{}) if i == 1 || i == 2 || i == 4 || i == 8 || i == 16 { Eventually(written).Should(Receive(Equal([]byte("close")))) // receive the CONNECTION_CLOSE } else { Consistently(written, 10*time.Millisecond).Should(HaveLen(0)) } } - // stop the session - sess.shutdown() + // stop the connection + conn.shutdown() }) - It("destroys sessions", func() { - Eventually(areClosedSessionsRunning).Should(BeTrue()) - sess.destroy(errors.New("destroy")) - Eventually(areClosedSessionsRunning).Should(BeFalse()) + It("destroys connections", func() { + Eventually(areClosedConnsRunning).Should(BeTrue()) + conn.destroy(errors.New("destroy")) + Eventually(areClosedConnsRunning).Should(BeFalse()) }) }) diff --git a/session.go b/session.go index d5f00b5e9..c8df0c789 100644 --- a/session.go +++ b/session.go @@ -1517,7 +1517,7 @@ func (s *session) handleCloseError(closeErr *closeError) { // If this is a remote close we're done here if closeErr.remote { - s.connIDGenerator.ReplaceWithClosed(newClosedRemoteSession(s.perspective)) + s.connIDGenerator.ReplaceWithClosed(newClosedRemoteConn(s.perspective)) return } if closeErr.immediate { @@ -1528,7 +1528,7 @@ func (s *session) handleCloseError(closeErr *closeError) { if err != nil { s.logger.Debugf("Error sending CONNECTION_CLOSE: %s", err) } - cs := newClosedLocalSession(s.conn, connClosePacket, s.perspective, s.logger) + cs := newClosedLocalConn(s.conn, connClosePacket, s.perspective, s.logger) s.connIDGenerator.ReplaceWithClosed(cs) } diff --git a/session_test.go b/session_test.go index 98d049e20..9763ead94 100644 --- a/session_test.go +++ b/session_test.go @@ -37,10 +37,10 @@ func areSessionsRunning() bool { return strings.Contains(b.String(), "quic-go.(*session).run") } -func areClosedSessionsRunning() bool { +func areClosedConnsRunning() bool { var b bytes.Buffer pprof.Lookup("goroutine").WriteTo(&b, 1) - return strings.Contains(b.String(), "quic-go.(*closedLocalSession).run") + return strings.Contains(b.String(), "quic-go.(*closedLocalConn).run") } var _ = Describe("Connection", func() { @@ -74,9 +74,9 @@ var _ = Describe("Connection", func() { expectReplaceWithClosed := func() { sessionRunner.EXPECT().ReplaceWithClosed(clientDestConnID, gomock.Any()).MaxTimes(1) sessionRunner.EXPECT().ReplaceWithClosed(srcConnID, gomock.Any()).Do(func(_ protocol.ConnectionID, s packetHandler) { - Expect(s).To(BeAssignableToTypeOf(&closedLocalSession{})) + Expect(s).To(BeAssignableToTypeOf(&closedLocalConn{})) s.shutdown() - Eventually(areClosedSessionsRunning).Should(BeFalse()) + Eventually(areClosedConnsRunning).Should(BeFalse()) }) } @@ -330,10 +330,10 @@ var _ = Describe("Connection", func() { } streamManager.EXPECT().CloseWithError(expectedErr) sessionRunner.EXPECT().ReplaceWithClosed(srcConnID, gomock.Any()).Do(func(_ protocol.ConnectionID, s packetHandler) { - Expect(s).To(BeAssignableToTypeOf(&closedRemoteSession{})) + Expect(s).To(BeAssignableToTypeOf(&closedRemoteConn{})) }) sessionRunner.EXPECT().ReplaceWithClosed(clientDestConnID, gomock.Any()).Do(func(_ protocol.ConnectionID, s packetHandler) { - Expect(s).To(BeAssignableToTypeOf(&closedRemoteSession{})) + Expect(s).To(BeAssignableToTypeOf(&closedRemoteConn{})) }) cryptoSetup.EXPECT().Close() gomock.InOrder( @@ -361,10 +361,10 @@ var _ = Describe("Connection", func() { } streamManager.EXPECT().CloseWithError(testErr) sessionRunner.EXPECT().ReplaceWithClosed(srcConnID, gomock.Any()).Do(func(_ protocol.ConnectionID, s packetHandler) { - Expect(s).To(BeAssignableToTypeOf(&closedRemoteSession{})) + Expect(s).To(BeAssignableToTypeOf(&closedRemoteConn{})) }) sessionRunner.EXPECT().ReplaceWithClosed(clientDestConnID, gomock.Any()).Do(func(_ protocol.ConnectionID, s packetHandler) { - Expect(s).To(BeAssignableToTypeOf(&closedRemoteSession{})) + Expect(s).To(BeAssignableToTypeOf(&closedRemoteConn{})) }) cryptoSetup.EXPECT().Close() gomock.InOrder( @@ -2439,7 +2439,7 @@ var _ = Describe("Client Connection", func() { expectReplaceWithClosed := func() { sessionRunner.EXPECT().ReplaceWithClosed(srcConnID, gomock.Any()).Do(func(_ protocol.ConnectionID, s packetHandler) { s.shutdown() - Eventually(areClosedSessionsRunning).Should(BeFalse()) + Eventually(areClosedConnsRunning).Should(BeFalse()) }) } @@ -2753,7 +2753,7 @@ var _ = Describe("Client Connection", func() { expectClose := func(applicationClose bool) { if !closed { sessionRunner.EXPECT().ReplaceWithClosed(gomock.Any(), gomock.Any()).Do(func(_ protocol.ConnectionID, s packetHandler) { - Expect(s).To(BeAssignableToTypeOf(&closedLocalSession{})) + Expect(s).To(BeAssignableToTypeOf(&closedLocalConn{})) s.shutdown() }) if applicationClose {