Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
8aa24f12
Commit
8aa24f12
authored
4 years ago
by
JUAN MÉNDEZ
Committed by
Adrien Béraud
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add python bindings for TypeValue
Signed-off-by:
JUAN MÉNDEZ
<
vpsink@gmail.com
>
parent
14d882d2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/opendht.pyx
+14
-2
14 additions, 2 deletions
python/opendht.pyx
python/opendht_cpp.pxd
+16
-2
16 additions, 2 deletions
python/opendht_cpp.pxd
with
30 additions
and
4 deletions
python/opendht.pyx
+
14
−
2
View file @
8aa24f12
...
@@ -36,6 +36,7 @@ from libcpp.memory cimport shared_ptr
...
@@ -36,6 +36,7 @@ from libcpp.memory cimport shared_ptr
from
cython.parallel
import
parallel
,
prange
from
cython.parallel
import
parallel
,
prange
from
cython.operator
cimport
dereference
as
deref
,
preincrement
as
inc
,
predecrement
as
dec
from
cython.operator
cimport
dereference
as
deref
,
preincrement
as
inc
,
predecrement
as
dec
from
cpython
cimport
ref
from
cpython
cimport
ref
from
datetime
import
timedelta
cimport
opendht_cpp
as
cpp
cimport
opendht_cpp
as
cpp
...
@@ -235,8 +236,9 @@ cdef class Where(object):
...
@@ -235,8 +236,9 @@ cdef class Where(object):
cdef
class
Value
(
object
):
cdef
class
Value
(
object
):
cdef
shared_ptr
[
cpp
.
Value
]
_value
cdef
shared_ptr
[
cpp
.
Value
]
_value
def
__init__
(
self
,
bytes
val
=
b
''
):
def
__init__
(
self
,
bytes
val
=
b
''
,
cpp
.
uint16_t
id
=
0
):
self
.
_value
.
reset
(
new
cpp
.
Value
(
val
,
len
(
val
)))
self
.
_value
.
reset
(
new
cpp
.
Value
(
id
,
val
,
len
(
val
)))
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
_value
.
get
().
toString
().
decode
()
return
self
.
_value
.
get
().
toString
().
decode
()
property
owner
:
property
owner
:
...
@@ -270,6 +272,14 @@ cdef class Value(object):
...
@@ -270,6 +272,14 @@ cdef class Value(object):
def
__get__
(
self
):
def
__get__
(
self
):
return
self
.
_value
.
get
().
size
()
return
self
.
_value
.
get
().
size
()
cdef
class
ValueType
(
object
):
cdef
cpp
.
ValueType
*
_value
def
__init__
(
self
,
cpp
.
uint16_t
id
,
str
name
,
expiration
:
timedelta
):
if
not
isinstance
(
expiration
,
timedelta
):
raise
TypeError
(
"
expiration argument must be of type timedelta
"
)
cdef
cpp
.
seconds
duration
=
cpp
.
seconds
(
int
(
expiration
.
total_seconds
()))
self
.
_value
=
new
cpp
.
ValueType
(
id
,
name
.
encode
(),
duration
)
cdef
class
NodeSetIter
(
object
):
cdef
class
NodeSetIter
(
object
):
cdef
map
[
cpp
.
InfoHash
,
shared_ptr
[
cpp
.
Node
]]
*
_nodes
cdef
map
[
cpp
.
InfoHash
,
shared_ptr
[
cpp
.
Node
]]
*
_nodes
cdef
map
[
cpp
.
InfoHash
,
shared_ptr
[
cpp
.
Node
]].
iterator
_curIter
cdef
map
[
cpp
.
InfoHash
,
shared_ptr
[
cpp
.
Node
]].
iterator
_curIter
...
@@ -513,6 +523,8 @@ cdef class DhtRunner(_WithID):
...
@@ -513,6 +523,8 @@ cdef class DhtRunner(_WithID):
cb_obj
=
{
'
shutdown
'
:
shutdown_cb
}
cb_obj
=
{
'
shutdown
'
:
shutdown_cb
}
ref
.
Py_INCREF
(
cb_obj
)
ref
.
Py_INCREF
(
cb_obj
)
self
.
thisptr
.
get
().
shutdown
(
cpp
.
bindShutdownCb
(
shutdown_callback
,
<
void
*>
cb_obj
))
self
.
thisptr
.
get
().
shutdown
(
cpp
.
bindShutdownCb
(
shutdown_callback
,
<
void
*>
cb_obj
))
def
registerType
(
self
,
ValueType
type
):
self
.
thisptr
.
get
().
registerType
(
deref
(
type
.
_value
))
def
enableLogging
(
self
):
def
enableLogging
(
self
):
cpp
.
enableLogging
(
self
.
thisptr
.
get
()[
0
])
cpp
.
enableLogging
(
self
.
thisptr
.
get
()[
0
])
def
disableLogging
(
self
):
def
disableLogging
(
self
):
...
...
This diff is collapsed.
Click to expand it.
python/opendht_cpp.pxd
+
16
−
2
View file @
8aa24f12
...
@@ -26,6 +26,14 @@ from libc.string cimport const_char, const_uchar
...
@@ -26,6 +26,14 @@ from libc.string cimport const_char, const_uchar
ctypedef
uint16_t
in_port_t
ctypedef
uint16_t
in_port_t
ctypedef
unsigned
short
int
sa_family_t
;
ctypedef
unsigned
short
int
sa_family_t
;
cdef
extern
from
"
<iostream>
"
namespace
"
std::chrono
"
nogil
:
cdef
cppclass
duration
[
ulong
]:
duration
()
except
+
cdef
cppclass
seconds
:
duration
seconds
(
uint64_t
)
except
+
duration
seconds
()
cdef
extern
from
"
<memory>
"
namespace
"
std
"
nogil
:
cdef
extern
from
"
<memory>
"
namespace
"
std
"
nogil
:
cdef
cppclass
shared_ptr
[
T
]:
cdef
cppclass
shared_ptr
[
T
]:
shared_ptr
()
except
+
shared_ptr
()
except
+
...
@@ -131,7 +139,6 @@ cdef extern from "opendht/value.h" namespace "dht::Value":
...
@@ -131,7 +139,6 @@ cdef extern from "opendht/value.h" namespace "dht::Value":
cdef
extern
from
"
opendht/value.h
"
namespace
"
dht::Value::Field
"
:
cdef
extern
from
"
opendht/value.h
"
namespace
"
dht::Value::Field
"
:
cdef
Field
None
cdef
Field
None
cdef
Field
Id
cdef
Field
Id
cdef
Field
ValueType
cdef
Field
OwnerPk
cdef
Field
OwnerPk
cdef
Field
SeqNum
cdef
Field
SeqNum
cdef
Field
UserType
cdef
Field
UserType
...
@@ -141,7 +148,7 @@ cdef extern from "opendht/value.h" namespace "dht":
...
@@ -141,7 +148,7 @@ cdef extern from "opendht/value.h" namespace "dht":
cdef
cppclass
Value
:
cdef
cppclass
Value
:
Value
()
except
+
Value
()
except
+
Value
(
vector
[
uint8_t
])
except
+
Value
(
vector
[
uint8_t
])
except
+
Value
(
const
uint8_t
*
dat_ptr
,
size_t
dat_len
)
except
+
Value
(
const
uint16_t
t
,
const
uint8_t
*
dat_ptr
,
size_t
dat_len
)
except
+
string
toString
()
const
string
toString
()
const
size_t
size
()
const
size_t
size
()
const
uint64_t
id
uint64_t
id
...
@@ -150,6 +157,12 @@ cdef extern from "opendht/value.h" namespace "dht":
...
@@ -150,6 +157,12 @@ cdef extern from "opendht/value.h" namespace "dht":
vector
[
uint8_t
]
data
vector
[
uint8_t
]
data
string
user_type
string
user_type
cdef
cppclass
ValueType
:
ValueType
(
uint16_t
id
,
string
name
,
seconds
expiration
)
except
+
uint16_t
id
string
name
seconds
expiration
cdef
cppclass
Query
:
cdef
cppclass
Query
:
Query
()
except
+
Query
()
except
+
Query
(
Select
s
,
Where
w
)
except
+
Query
(
Select
s
,
Where
w
)
except
+
...
@@ -234,6 +247,7 @@ cdef extern from "opendht/dhtrunner.h" namespace "dht":
...
@@ -234,6 +247,7 @@ cdef extern from "opendht/dhtrunner.h" namespace "dht":
void
run
(
const_char
*
,
const_char
*
,
const_char
*
,
Config
config
)
void
run
(
const_char
*
,
const_char
*
,
const_char
*
,
Config
config
)
void
join
()
void
join
()
void
shutdown
(
ShutdownCallback
)
void
shutdown
(
ShutdownCallback
)
void
registerType
(
ValueType
&
value
);
bool
isRunning
()
bool
isRunning
()
SockAddr
getBound
(
sa_family_t
af
)
const
SockAddr
getBound
(
sa_family_t
af
)
const
string
getStorageLog
()
const
string
getStorageLog
()
const
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment