check expiry in hashcash

This commit is contained in:
Eric Wustrow
2012-07-17 22:51:53 -04:00
parent 702b9ca394
commit 4b5ba56a2d
+3 -2
View File
@@ -10,6 +10,7 @@ from google.protobuf.message import DecodeError
MaximumSessionAge = 100 # seconds, to demonstrate session timeout
MaximumChallengeAge = 600 # to demonstrate challenge timeout
HashcashExpiry = 60*60
difficulty = 23 # bits of hashcash required with new requests
@@ -134,8 +135,8 @@ class session(object):
def check_hashcash(self, h):
"""Is the hashcash string h valid for a request to this server?"""
# TODO: should enforce hashcash expiry.
if hashcash.check(h, chocolate_server_name, difficulty):
if hashcash.check(stamp=h, resource=chocolate_server_name, \
bits=difficulty, check_expiration=HashcashExpiry):
# sessions.sadd returns True upon adding to a set and
# False if the item was already in the set.
return sessions.sadd("spent-hashcash", h)