c# - What is the ideal structure for handling nonce? -
i keep track of .... of nonces. should track nonce value , expiration date. structure should allow fast lookup of nonce, dictionary, allow reasonably efficient cleanup, e.g., pop expired nonces , stop when no longer need pop them. recommend? expiration hacks (e.g., limited size rotating buffer) too.
without further information typical usage patterns, dictionary keyed nonce containing expiration value , reverse lookup of exipration time set of nonces expire @ time seems efficient.
if know lifetime of nonces , stage within lifetime typically accessed, may more efficient use following strategy instead:
- have buckets represent expiration time range.
- in each bucket, have dictionary keyed nonce, value being expiration time.
- when nonce comes in, in recent bucket first. if not there, check additional buckets in order of expiration.
- if find nonce in bucket, verify it's expiration date has not passed.
- cleanup simple of disposing buckets past allowed nonce duration.
the disadvantage of solution potentially examine several buckets find given nonce, , examine every bucket invalid nonce. advantage avoid need index expiration date list of nonces expiring efficient cleanup. tune bucket size (in terms of timespan), should have idea of when during lifetime of nonce used.
note that, if nonce validation needs survive server restart or work in server farm want form of permanent storage (e.g. database). still use same strategies.
Comments
Post a Comment