python: implement Value.owner, Value.recipient

This commit is contained in:
Adrien Béraud committed 2015-08-25 21:39:33 +02:00
1 parent e60b6bead5
commit 6b6d18b750
2 files changed
+24 -8

No files matched your search

+12
View File
@@ -118,6 +118,18 @@ cdef class Value(object):
self._value.reset(new cpp.Value(val, len(val)))
def __str__(self):
return self._value.get().toString().decode()
property owner:
def __get__(self):
h = InfoHash()
h._infohash = self._value.get().owner.getId()
return h
property recipient:
def __get__(self):
h = InfoHash()
h._infohash = self._value.get().recipient
return h
def __set__(self, InfoHash h):
self._value.get().recipient = h._infohash
property data:
def __get__(self):
return string(<char*>self._value.get().data.data(), self._value.get().data.size())
+12 -8
View File
@@ -39,14 +39,6 @@ cdef extern from "opendht/infohash.h" namespace "dht":
@staticmethod
InfoHash getRandom()
cdef extern from "opendht/value.h" namespace "dht":
cdef cppclass Value:
Value() except +
Value(vector[uint8_t]) except +
Value(const uint8_t* dat_ptr, size_t dat_len) except +
string toString() const
vector[uint8_t] data
cdef extern from "opendht/crypto.h" namespace "dht::crypto":
ctypedef pair[shared_ptr[PrivateKey], shared_ptr[Certificate]] Identity
cdef Identity generateIdentity(string name, Identity ca, unsigned bits)
@@ -63,6 +55,18 @@ cdef extern from "opendht/crypto.h" namespace "dht::crypto":
Certificate()
InfoHash getId() const
cdef extern from "opendht/value.h" namespace "dht":
cdef cppclass Value:
Value() except +
Value(vector[uint8_t]) except +
Value(const uint8_t* dat_ptr, size_t dat_len) except +
string toString() const
uint64_t id
PublicKey owner
InfoHash recipient
vector[uint8_t] data
string user_type
cdef extern from "opendht/dht.h" namespace "dht":
cdef cppclass Node:
Node() except +