Package apt_p2p_Khashmir :: Module khash
[hide private]
[frames] | no frames]

Module khash

source code

Functions to deal with hashes (node IDs and keys).

Classes [hide private]
  TestNewID
Test the newID function.
  TestIntify
Test the intify function.
  TestDisantance
Test the distance function.
  TestRandRange
Test the randRange function.
Functions [hide private]
 
intify(hstr)
Convert a hash (big-endian) to a long python integer.
source code
 
stringify(num)
Convert a long python integer to a hash.
source code
 
distance(a, b)
Calculate the distance between two hashes expressed as strings.
source code
 
newID(suffix='')
Get a new pseudorandom globally unique hash string.
source code
 
newIDInRange(min, max)
Get a new pseudorandom globally unique hash string in the range.
source code
 
randRange(min, max)
Get a new pseudorandom globally unique hash number in the range.
source code
 
newTID()
Get a new pseudorandom transaction ID number.
source code
Variables [hide private]
  HASH_LENGTH = 20
the length of the hash to use in bytes

Imports: sha, urandom, unittest


Function Details [hide private]

newID(suffix='')

source code 

Get a new pseudorandom globally unique hash string.

Parameters:
  • suffix - an optional string to end the ID with