define a quic.TokenStore interface and provide a LRU implementation

This commit is contained in:
Marten Seemann
2019-08-08 11:09:21 +07:00
parent dfedde672c
commit fe0f7aff3b
3 changed files with 242 additions and 0 deletions

View File

@@ -27,6 +27,23 @@ type Token struct {
SentTime time.Time
}
// A ClientToken is a token received by the client.
// It can be used to skip address validation on future connection attempts.
type ClientToken struct {
data []byte
}
type TokenStore interface {
// Pop searches for a ClientToken associated with the given key.
// Since tokens are not supposed to be reused, it must remove the token from the cache.
// It returns nil when no token is found.
Pop(key string) (token *ClientToken)
// Put adds a token to the cache with the given key. It might get called
// multiple times in a connection.
Put(key string, token *ClientToken)
}
// An ErrorCode is an application-defined error code.
// Valid values range between 0 and MAX_UINT62.
type ErrorCode = protocol.ApplicationErrorCode