mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 04:37:36 +03:00
refactor session creation in the server
This commit is contained in:
parent
bab0384444
commit
ecc86aa1ab
2 changed files with 32 additions and 43 deletions
61
server.go
61
server.go
|
@ -401,10 +401,10 @@ func (s *baseServer) handleInitialImpl(p *receivedPacket, hdr *wire.Header) erro
|
|||
}
|
||||
|
||||
var (
|
||||
token *Token
|
||||
retrySrcConnectionID *protocol.ConnectionID
|
||||
token *Token
|
||||
retrySrcConnID *protocol.ConnectionID
|
||||
)
|
||||
origDestConnectionID := hdr.DestConnectionID
|
||||
origDestConnID := hdr.DestConnectionID
|
||||
if len(hdr.Token) > 0 {
|
||||
c, err := s.tokenGenerator.DecodeToken(hdr.Token)
|
||||
if err == nil {
|
||||
|
@ -414,8 +414,8 @@ func (s *baseServer) handleInitialImpl(p *receivedPacket, hdr *wire.Header) erro
|
|||
SentTime: c.SentTime,
|
||||
}
|
||||
if token.IsRetryToken {
|
||||
origDestConnectionID = c.OriginalDestConnectionID
|
||||
retrySrcConnectionID = &c.RetrySrcConnectionID
|
||||
origDestConnID = c.OriginalDestConnectionID
|
||||
retrySrcConnID = &c.RetrySrcConnectionID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -451,68 +451,47 @@ func (s *baseServer) handleInitialImpl(p *receivedPacket, hdr *wire.Header) erro
|
|||
return err
|
||||
}
|
||||
s.logger.Debugf("Changing connection ID to %s.", connID)
|
||||
sess := s.createNewSession(
|
||||
p.remoteAddr,
|
||||
origDestConnectionID,
|
||||
retrySrcConnectionID,
|
||||
hdr.DestConnectionID,
|
||||
hdr.SrcConnectionID,
|
||||
connID,
|
||||
hdr.Version,
|
||||
)
|
||||
if sess == nil {
|
||||
p.buffer.Release()
|
||||
return nil
|
||||
}
|
||||
sess.handlePacket(p)
|
||||
s.zeroRTTQueue.DequeueToSession(hdr.DestConnectionID, sess)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *baseServer) createNewSession(
|
||||
remoteAddr net.Addr,
|
||||
origDestConnID protocol.ConnectionID,
|
||||
retrySrcConnID *protocol.ConnectionID,
|
||||
clientDestConnID protocol.ConnectionID,
|
||||
destConnID protocol.ConnectionID,
|
||||
srcConnID protocol.ConnectionID,
|
||||
version protocol.VersionNumber,
|
||||
) quicSession {
|
||||
var sess quicSession
|
||||
if added := s.sessionHandler.AddWithConnID(clientDestConnID, srcConnID, func() packetHandler {
|
||||
if added := s.sessionHandler.AddWithConnID(hdr.DestConnectionID, connID, func() packetHandler {
|
||||
var tracer logging.ConnectionTracer
|
||||
if s.config.Tracer != nil {
|
||||
// Use the same connection ID that is passed to the client's GetLogWriter callback.
|
||||
connID := clientDestConnID
|
||||
connID := hdr.DestConnectionID
|
||||
if origDestConnID.Len() > 0 {
|
||||
connID = origDestConnID
|
||||
}
|
||||
tracer = s.config.Tracer.TracerForConnection(protocol.PerspectiveServer, connID)
|
||||
}
|
||||
sess = s.newSession(
|
||||
newSendConn(s.conn, remoteAddr),
|
||||
newSendConn(s.conn, p.remoteAddr),
|
||||
s.sessionHandler,
|
||||
origDestConnID,
|
||||
retrySrcConnID,
|
||||
clientDestConnID,
|
||||
destConnID,
|
||||
srcConnID,
|
||||
s.sessionHandler.GetStatelessResetToken(srcConnID),
|
||||
hdr.DestConnectionID,
|
||||
hdr.SrcConnectionID,
|
||||
connID,
|
||||
s.sessionHandler.GetStatelessResetToken(connID),
|
||||
s.config,
|
||||
s.tlsConf,
|
||||
s.tokenGenerator,
|
||||
s.acceptEarlySessions,
|
||||
tracer,
|
||||
s.logger,
|
||||
version,
|
||||
hdr.Version,
|
||||
)
|
||||
sess.handlePacket(p)
|
||||
return sess
|
||||
}); !added {
|
||||
return nil
|
||||
}
|
||||
go sess.run()
|
||||
go s.handleNewSession(sess)
|
||||
return sess
|
||||
if sess == nil {
|
||||
p.buffer.Release()
|
||||
return nil
|
||||
}
|
||||
s.zeroRTTQueue.DequeueToSession(hdr.DestConnectionID, sess)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *baseServer) handleNewSession(sess quicSession) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue