mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 12:28:42 +00:00
infohash: add getRandom()
This commit is contained in:
1 parent
830c39e8f6
commit
948475301e
4 files changed
+22
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user