send a NEW_TOKEN from after completing the handshake (as a server)

This commit is contained in:
Marten Seemann 2019-06-01 17:12:54 +08:00
parent 7c7bcede6c
commit 34543848f0
9 changed files with 97 additions and 29 deletions

View file

@ -89,7 +89,7 @@ type server struct {
sessionHandler packetHandlerManager
// set as a member, so they can be set in the tests
newSession func(connection, sessionRunner, protocol.ConnectionID /* original connection ID */, protocol.ConnectionID /* destination connection ID */, protocol.ConnectionID /* source connection ID */, *Config, *tls.Config, *handshake.TransportParameters, utils.Logger, protocol.VersionNumber) (quicSession, error)
newSession func(connection, sessionRunner, protocol.ConnectionID /* original connection ID */, protocol.ConnectionID /* destination connection ID */, protocol.ConnectionID /* source connection ID */, *Config, *tls.Config, *handshake.TransportParameters, *handshake.TokenGenerator, utils.Logger, protocol.VersionNumber) (quicSession, error)
serverError error
errorChan chan struct{}
@ -198,7 +198,11 @@ var defaultAcceptToken = func(clientAddr net.Addr, token *Token) bool {
if token == nil {
return false
}
if time.Now().After(token.SentTime.Add(protocol.RetryTokenValidity)) {
validity := protocol.TokenValidity
if token.IsRetryToken {
validity = protocol.RetryTokenValidity
}
if time.Now().After(token.SentTime.Add(validity)) {
return false
}
var sourceAddr string
@ -387,8 +391,9 @@ func (s *server) handleInitialImpl(p *receivedPacket, hdr *wire.Header) (quicSes
c, err := s.tokenGenerator.DecodeToken(hdr.Token)
if err == nil {
token = &Token{
RemoteAddr: c.RemoteAddr,
SentTime: c.SentTime,
IsRetryToken: c.IsRetryToken,
RemoteAddr: c.RemoteAddr,
SentTime: c.SentTime,
}
origDestConnectionID = c.OriginalDestConnectionID
}
@ -457,6 +462,7 @@ func (s *server) createNewSession(
s.config,
s.tlsConf,
params,
s.tokenGenerator,
s.logger,
version,
)