infohash: add getRandom()

This commit is contained in:
Adrien Béraud committed 2015-08-04 14:02:04 -04:00
1 parent 830c39e8f6
commit 948475301e
4 files changed
+22 -1

No files matched your search

+7
View File
@@ -70,6 +70,8 @@ cdef extern from "opendht/infohash.h" namespace "dht":
unsigned commonBits(InfoHash a, InfoHash b)
@staticmethod
InfoHash get(string s)
@staticmethod
InfoHash getRandom()
cdef extern from "opendht/value.h" namespace "dht":
cdef cppclass Value:
@@ -183,6 +185,11 @@ cdef class PyInfoHash(_WithID):
h = PyInfoHash()
h._infohash = InfoHash.get(key.encode())
return h
@staticmethod
def getRandom():
h = PyInfoHash()
h._infohash = InfoHash.getRandom()
return h
cdef class PyNode(_WithID):
cdef shared_ptr[Node] _node
+1 -1
View File
@@ -12,7 +12,7 @@ sys.path.append('..')
from opendht import *
def random_hash():
return PyInfoHash(''.join(random.SystemRandom().choice(string.hexdigits) for _ in range(40)).encode())
return PyInfoHash.getRandom()
def start_cluster(i):
global procs