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
fca11e62
Commit
fca11e62
authored
Apr 23, 2022
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
tools/dhtcnode: use version arg, cleanup
parent
38a7234a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/dhtcnode.c
+53
-30
53 additions, 30 deletions
tools/dhtcnode.c
with
53 additions
and
30 deletions
tools/dhtcnode.c
+
53
−
30
View file @
fca11e62
...
@@ -132,6 +132,7 @@ static const struct option long_options[] = {
...
@@ -132,6 +132,7 @@ static const struct option long_options[] = {
{
"persist"
,
required_argument
,
NULL
,
'f'
},
{
"persist"
,
required_argument
,
NULL
,
'f'
},
{
"logfile"
,
required_argument
,
NULL
,
'l'
},
{
"logfile"
,
required_argument
,
NULL
,
'l'
},
{
"syslog"
,
no_argument
,
NULL
,
'L'
},
{
"syslog"
,
no_argument
,
NULL
,
'L'
},
{
"version"
,
no_argument
,
NULL
,
'V'
},
{
NULL
,
0
,
NULL
,
0
}
{
NULL
,
0
,
NULL
,
0
}
};
};
...
@@ -169,6 +170,9 @@ parse_args(int argc, char **argv) {
...
@@ -169,6 +170,9 @@ parse_args(int argc, char **argv) {
case
's'
:
case
's'
:
params
.
service
=
true
;
params
.
service
=
true
;
break
;
break
;
case
'V'
:
params
.
version
=
true
;
break
;
default:
default:
break
;
break
;
}
}
...
@@ -176,12 +180,25 @@ parse_args(int argc, char **argv) {
...
@@ -176,12 +180,25 @@ parse_args(int argc, char **argv) {
return
params
;
return
params
;
}
}
dht_infohash
parse_key
(
const
char
*
key_str
)
{
dht_infohash
key
;
dht_infohash_from_hex_null
(
&
key
,
key_str
);
if
(
dht_infohash_is_zero
(
&
key
))
{
dht_infohash_get_from_string
(
&
key
,
key_str
);
printf
(
"Using h(%s) = %s
\n
"
,
key_str
,
dht_infohash_print
(
&
key
));
}
return
key
;
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
printf
(
"OpenDHT version %s
\n
"
,
dht_version
());
struct
dht_params
params
=
parse_args
(
argc
,
argv
);
struct
dht_params
params
=
parse_args
(
argc
,
argv
);
if
(
params
.
version
)
{
printf
(
"OpenDHT version %s
\n
"
,
dht_version
());
return
EXIT_SUCCESS
;
}
dht_runner
*
runner
=
dht_runner_new
();
dht_runner
*
runner
=
dht_runner_new
();
dht_runner_config
dht_config
;
dht_runner_config
dht_config
;
dht_runner_config_default
(
&
dht_config
);
dht_runner_config_default
(
&
dht_config
);
...
@@ -199,6 +216,7 @@ int main(int argc, char **argv)
...
@@ -199,6 +216,7 @@ int main(int argc, char **argv)
char
cmd
[
64
];
char
cmd
[
64
];
char
arg
[
64
];
char
arg
[
64
];
char
value
[
256
];
char
value
[
256
];
dht_infohash
key
;
while
(
true
)
{
while
(
true
)
{
const
char
*
line_read
=
readline
(
"> "
);
const
char
*
line_read
=
readline
(
"> "
);
if
(
!
line_read
)
if
(
!
line_read
)
...
@@ -225,40 +243,45 @@ int main(int argc, char **argv)
...
@@ -225,40 +243,45 @@ 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
;
}
}
else
if
(
!
strcmp
(
cmd
,
"ll"
))
{
dht_infohash
key
;
dht_infohash
key
=
dht_runner_get_node_id
(
runner
);
dht_infohash_from_hex
(
&
key
,
arg
);
printf
(
"DHT node %s running on port %u
\n
"
,
dht_infohash_print
(
&
key
),
dht_runner_get_bound_port
(
runner
,
AF_INET
));
if
(
dht_infohash_is_zero
(
&
key
))
{
continue
;
dht_infohash_get_from_string
(
&
key
,
arg
);
printf
(
"Using h(%s) = %s
\n
"
,
arg
,
dht_infohash_print
(
&
key
));
}
}
if
(
!
strcmp
(
cmd
,
"g"
))
{
else
if
(
!
strcmp
(
cmd
,
"g"
))
{
key
=
parse_key
(
arg
);
dht_runner_get
(
runner
,
&
key
,
dht_get_callback
,
dht_get_done_callback
,
runner
);
dht_runner_get
(
runner
,
&
key
,
dht_get_callback
,
dht_get_done_callback
,
runner
);
}
else
if
(
!
strcmp
(
cmd
,
"l"
))
{
}
else
if
(
!
strcmp
(
cmd
,
"l"
))
{
key
=
parse_key
(
arg
);
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
->
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"
))
{
key
=
parse_key
(
arg
);
dht_value
*
val
=
dht_value_new_from_string
(
value
);
dht_value
*
val
=
dht_value_new_from_string
(
value
);
dht_runner_put
(
runner
,
&
key
,
val
,
dht_put_done_callback
,
runner
,
true
);
dht_runner_put
(
runner
,
&
key
,
val
,
dht_put_done_callback
,
runner
,
true
);
dht_value_unref
(
val
);
dht_value_unref
(
val
);
}
}
else
{
printf
(
"Unkown command: %s
\n
"
,
cmd
);
}
}
}
printf
(
"Stopping..
\n
"
);
// Graceful shutdown
printf
(
"Stopping…
\n
"
);
struct
op_context
ctx
;
struct
op_context
ctx
;
ctx
.
runner
=
runner
;
ctx
.
runner
=
runner
;
atomic_init
(
&
ctx
.
stop
,
false
);
atomic_init
(
&
ctx
.
stop
,
false
);
dht_runner_shutdown
(
runner
,
dht_shutdown_callback
,
&
ctx
);
dht_runner_shutdown
(
runner
,
dht_shutdown_callback
,
&
ctx
);
// Wait until shutdown callback is called
while
(
!
atomic_load
(
&
ctx
.
stop
))
{
while
(
!
atomic_load
(
&
ctx
.
stop
))
{
usleep
(
10000
);
usleep
(
10000
);
}
}
dht_runner_delete
(
runner
);
dht_runner_delete
(
runner
);
return
0
;
return
EXIT_SUCCESS
;
}
}
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