pass around the stateless reset token directly, not pointers to it

Benchmarks show that it's actually faster to make a copy of this 16 byte
array than passing around a pointer to it.
This commit is contained in:
Marten Seemann
2020-07-10 11:21:12 +07:00
parent 1f676c2a6c
commit 0ef1b2f92e
7 changed files with 22 additions and 24 deletions

View File

@@ -16,11 +16,11 @@ import (
)
type statelessResetErr struct {
token *[16]byte
token [16]byte
}
func (e statelessResetErr) Error() string {
return fmt.Sprintf("received a stateless reset with token %x", *e.token)
return fmt.Sprintf("received a stateless reset with token %x", e.token)
}
// The packetHandlerMap stores packetHandlers, identified by connection ID.
@@ -317,7 +317,7 @@ func (h *packetHandlerMap) maybeHandleStatelessReset(data []byte) bool {
copy(token[:], data[len(data)-16:])
if sess, ok := h.resetTokens[token]; ok {
h.logger.Debugf("Received a stateless reset with token %#x. Closing session.", token)
go sess.destroy(statelessResetErr{token: &token})
go sess.destroy(statelessResetErr{token: token})
return true
}
return false