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
e207e592
Commit
e207e592
authored
3 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
tools/dhtcnode: count values in listen, add "ll"
parent
0302cee8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/dhtcnode.c
+17
-7
17 additions, 7 deletions
tools/dhtcnode.c
with
17 additions
and
7 deletions
tools/dhtcnode.c
+
17
−
7
View file @
e207e592
...
@@ -36,12 +36,18 @@ struct op_context {
...
@@ -36,12 +36,18 @@ struct op_context {
struct
listen_context
{
struct
listen_context
{
dht_runner
*
runner
;
dht_runner
*
runner
;
dht_op_token
*
token
;
dht_op_token
*
token
;
size_t
count
;
};
};
bool
dht_value_callback
(
const
dht_value
*
value
,
bool
expired
,
void
*
user_data
)
bool
dht_value_callback
(
const
dht_value
*
value
,
bool
expired
,
void
*
user_data
)
{
{
struct
listen_context
*
ctx
=
(
struct
listen_context
*
)
user_data
;
if
(
expired
)
ctx
->
count
--
;
else
ctx
->
count
++
;
dht_data_view
data
=
dht_value_get_data
(
value
);
dht_data_view
data
=
dht_value_get_data
(
value
);
printf
(
"
Value callback %s: %.*s
.
\n
"
,
expired
?
"expired"
:
"new"
,
(
int
)
data
.
size
,
data
.
data
);
printf
(
"
Listen: %s value: %.*s (total %zu)
.
\n
"
,
expired
?
"expired"
:
"new"
,
(
int
)
data
.
size
,
data
.
data
,
ctx
->
count
);
return
true
;
return
true
;
}
}
...
@@ -193,12 +199,11 @@ int main(int argc, char **argv)
...
@@ -193,12 +199,11 @@ int main(int argc, char **argv)
char
value
[
256
];
char
value
[
256
];
while
(
true
)
{
while
(
true
)
{
const
char
*
line_read
=
readline
(
"> "
);
const
char
*
line_read
=
readline
(
"> "
);
if
(
line_read
&&
*
line_read
)
add_history
(
line_read
);
if
(
!
line_read
)
if
(
!
line_read
)
break
;
break
;
if
(
!
strcmp
(
line_read
,
"
\0
"
)
)
if
(
!
*
line_read
)
continue
;
continue
;
add_history
(
line_read
);
memset
(
cmd
,
0
,
sizeof
cmd
);
memset
(
cmd
,
0
,
sizeof
cmd
);
memset
(
arg
,
0
,
sizeof
arg
);
memset
(
arg
,
0
,
sizeof
arg
);
...
@@ -218,6 +223,10 @@ int main(int argc, char **argv)
...
@@ -218,6 +223,10 @@ int main(int argc, char **argv)
free
(
addrs
);
free
(
addrs
);
}
}
continue
;
continue
;
}
else
if
(
!
strcmp
(
cmd
,
"ll"
))
{
dht_infohash
node_id
=
dht_runner_get_node_id
(
runner
);
printf
(
"DHT node %s running on port %u
\n
"
,
dht_infohash_print
(
&
node_id
),
dht_runner_get_bound_port
(
runner
,
AF_INET
));
continue
;
}
}
dht_infohash
key
;
dht_infohash
key
;
...
@@ -231,6 +240,7 @@ int main(int argc, char **argv)
...
@@ -231,6 +240,7 @@ int main(int argc, char **argv)
}
else
if
(
!
strcmp
(
cmd
,
"l"
))
{
}
else
if
(
!
strcmp
(
cmd
,
"l"
))
{
struct
listen_context
*
ctx
=
malloc
(
sizeof
(
struct
listen_context
));
struct
listen_context
*
ctx
=
malloc
(
sizeof
(
struct
listen_context
));
ctx
->
runner
=
runner
;
ctx
->
runner
=
runner
;
ctx
->
count
=
0
;
ctx
->
token
=
dht_runner_listen
(
runner
,
&
key
,
dht_value_callback
,
listen_context_free
,
ctx
);
ctx
->
token
=
dht_runner_listen
(
runner
,
&
key
,
dht_value_callback
,
listen_context_free
,
ctx
);
}
else
if
(
!
strcmp
(
cmd
,
"p"
))
{
}
else
if
(
!
strcmp
(
cmd
,
"p"
))
{
dht_value
*
val
=
dht_value_new_from_string
(
value
);
dht_value
*
val
=
dht_value_new_from_string
(
value
);
...
...
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