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
97b20705
Commit
97b20705
authored
Oct 16, 2019
by
Sébastien Blin
Committed by
Adrien Béraud
Oct 22, 2019
Browse files
Options
Downloads
Patches
Plain Diff
rust: add put bindings
parent
431da16b
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
rust/examples/dhtnode.rs
+6
-3
6 additions, 3 deletions
rust/examples/dhtnode.rs
rust/src/lib.rs
+29
-0
29 additions, 0 deletions
rust/src/lib.rs
with
35 additions
and
3 deletions
rust/examples/dhtnode.rs
+
6
−
3
View file @
97b20705
...
@@ -28,10 +28,11 @@ struct Handler {
...
@@ -28,10 +28,11 @@ struct Handler {
fn
main
()
{
fn
main
()
{
println!
(
"{}"
,
InfoHash
::
random
());
println!
(
"{}"
,
InfoHash
::
random
());
println!
(
"{}"
,
InfoHash
::
new
());
println!
(
"{}"
,
InfoHash
::
new
());
println!
(
"{}"
,
InfoHash
::
get
(
"
toto
"
));
println!
(
"{}"
,
InfoHash
::
get
(
"
alice
"
));
let
mut
dht
=
DhtRunner
::
new
();
let
mut
dht
=
DhtRunner
::
new
();
dht
.run
(
1412
);
dht
.run
(
1412
);
// TODO take slice in boostrap
dht
.bootstrap
(
dht
.bootstrap
(
&
CString
::
new
(
"bootstrap.jami.net"
)
.unwrap
(),
&
CString
::
new
(
"bootstrap.jami.net"
)
.unwrap
(),
&
CString
::
new
(
"4222"
)
.unwrap
()
&
CString
::
new
(
"4222"
)
.unwrap
()
...
@@ -41,9 +42,11 @@ fn main() {
...
@@ -41,9 +42,11 @@ fn main() {
_data
:
8
,
_data
:
8
,
};
};
loop
{
loop
{
println!
(
"Get /
toto
"
);
println!
(
"Get /
alice
"
);
let
ptr
=
&
mut
handler
as
*
mut
_
as
*
mut
c_void
;
let
ptr
=
&
mut
handler
as
*
mut
_
as
*
mut
c_void
;
dht
.get
(
&
InfoHash
::
get
(
"toto"
),
get_cb
,
done_cb
,
ptr
);
dht
.get
(
&
InfoHash
::
get
(
"alice"
),
get_cb
,
done_cb
,
ptr
);
let
v
=
Value
::
new
(
"hi!"
);
dht
.put
(
&
InfoHash
::
get
(
"bob"
),
Box
::
into_raw
(
v
),
done_cb
,
ptr
);
thread
::
sleep
(
ten_secs
);
thread
::
sleep
(
ten_secs
);
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
rust/src/lib.rs
+
29
−
0
View file @
97b20705
...
@@ -42,6 +42,8 @@ extern {
...
@@ -42,6 +42,8 @@ extern {
fn
dht_infohash_get
(
h
:
*
mut
InfoHash
,
dat
:
*
mut
uint8_t
,
dat_size
:
size_t
);
fn
dht_infohash_get
(
h
:
*
mut
InfoHash
,
dat
:
*
mut
uint8_t
,
dat_size
:
size_t
);
fn
dht_value_get_data
(
data
:
*
const
Value
)
->
DataView
;
fn
dht_value_get_data
(
data
:
*
const
Value
)
->
DataView
;
fn
dht_value_unref
(
data
:
*
mut
Value
);
fn
dht_value_new
(
data
:
*
const
uint8_t
,
size
:
size_t
)
->
*
mut
Value
;
fn
dht_runner_new
()
->
*
mut
DhtRunner
;
fn
dht_runner_new
()
->
*
mut
DhtRunner
;
fn
dht_runner_delete
(
dht
:
*
mut
DhtRunner
);
fn
dht_runner_delete
(
dht
:
*
mut
DhtRunner
);
...
@@ -51,6 +53,9 @@ extern {
...
@@ -51,6 +53,9 @@ extern {
get_cb
:
extern
fn
(
*
mut
Value
,
*
mut
c_void
),
get_cb
:
extern
fn
(
*
mut
Value
,
*
mut
c_void
),
done_cb
:
extern
fn
(
bool
,
*
mut
c_void
),
done_cb
:
extern
fn
(
bool
,
*
mut
c_void
),
cb_user_data
:
*
mut
c_void
);
cb_user_data
:
*
mut
c_void
);
fn
dht_runner_put
(
dht
:
*
mut
DhtRunner
,
h
:
*
const
InfoHash
,
v
:
*
const
Value
,
done_cb
:
extern
fn
(
bool
,
*
mut
c_void
),
cb_user_data
:
*
mut
c_void
);
}
}
impl
InfoHash
{
impl
InfoHash
{
...
@@ -118,6 +123,15 @@ impl DhtRunner {
...
@@ -118,6 +123,15 @@ impl DhtRunner {
dht_runner_get
(
&
mut
*
self
,
h
,
get_cb
,
done_cb
,
cb_user_data
)
dht_runner_get
(
&
mut
*
self
,
h
,
get_cb
,
done_cb
,
cb_user_data
)
}
}
}
}
pub
fn
put
(
&
mut
self
,
h
:
&
InfoHash
,
v
:
*
const
Value
,
done_cb
:
extern
fn
(
bool
,
*
mut
c_void
),
cb_user_data
:
*
mut
c_void
)
{
unsafe
{
dht_runner_put
(
&
mut
*
self
,
h
,
v
,
done_cb
,
cb_user_data
)
}
}
}
}
impl
Drop
for
DhtRunner
{
impl
Drop
for
DhtRunner
{
...
@@ -129,6 +143,13 @@ impl Drop for DhtRunner {
...
@@ -129,6 +143,13 @@ impl Drop for DhtRunner {
}
}
impl
Value
{
impl
Value
{
pub
fn
new
(
data
:
&
str
)
->
Box
<
Value
>
{
unsafe
{
Box
::
from_raw
(
dht_value_new
(
data
.as_bytes
()
.as_ptr
(),
data
.as_bytes
()
.len
()))
}
}
fn
dataview
(
&
self
)
->
DataView
{
fn
dataview
(
&
self
)
->
DataView
{
unsafe
{
unsafe
{
dht_value_get_data
(
self
)
dht_value_get_data
(
self
)
...
@@ -136,6 +157,14 @@ impl Value {
...
@@ -136,6 +157,14 @@ impl Value {
}
}
}
}
impl
Drop
for
Value
{
fn
drop
(
&
mut
self
)
{
unsafe
{
dht_value_unref
(
&
mut
*
self
)
}
}
}
impl
fmt
::
Display
for
Value
{
impl
fmt
::
Display
for
Value
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
<
'_
>
)
->
fmt
::
Result
{
unsafe
{
unsafe
{
...
...
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