Tribler/dispersy — pull request #106 by boudewijn-tribler (2013-07-24 08:42:28+00:00)
Title: RequestCache cleanup.

- Identifiers are now unicode strings, these are used as keys in the
RequestCache instance and as Callback id's.

- Cache now takes a unicode string as a parameter, this is the
identifier. Older code set the identifier (outside of the Cache
constructor) once the cache was added to the RequestCache.

- NumberCache is used when, instead of a predefined unicode string,
the identifier must contain a random number. This is used by, for
instance, the introduction-request message. The random number is
available from the 'Cache.number' property, while the
'Cache.identifier' property still contains the unicode string.

Note that this means that any older code that used to encode
Cache.identifier into a request or response message must now use
Cache.number instead.

- The static method Cache.create_identifier is used to generate a
Cache specific unicode string. Parameters can be supplied to add
unique features, such as the number in NumberCache.

Note that the generic method 'handle_missing_messages' needs to get
the identifier from a message instance. This is done using
Cache.create_identifier_from_message, which in turn should call
Cache.create_identifier with the appropriate parameters obtained
from the message instance. Code that uses 'handle_missing_messages'
must ensure their Cache object supplies
'create_identifier_from_message'

- RequestCache.add(CACHE) replaces RequestCache.set(ID, CACHE).
RequestCache.add will return None when CACHE.identifier is already
in use.

- RequestCache.claim no longer exists. A valid (read unused)
identifier can be found using RequestCache.has or repeated calls to
RequestCache.add, while checking its return value.

- RequestCache.{replace, has, get} have had their parameters modified
to reflect the introduction of the unicode string identifier.