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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
46d59141
Commit
46d59141
authored
9 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
tools: add "-v" cmd argument to enable logging
parent
8d92884c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/dhtnode.cpp
+180
-172
180 additions, 172 deletions
tools/dhtnode.cpp
tools/tools_common.h
+6
-1
6 additions, 1 deletion
tools/tools_common.h
with
186 additions
and
173 deletions
tools/dhtnode.cpp
+
180
−
172
View file @
46d59141
...
@@ -59,6 +59,8 @@ void print_node_info(const DhtRunner& dht, const dht_params& params) {
...
@@ -59,6 +59,8 @@ void print_node_info(const DhtRunner& dht, const dht_params& params) {
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
DhtRunner
dht
;
try
{
auto
params
=
parseArgs
(
argc
,
argv
);
auto
params
=
parseArgs
(
argc
,
argv
);
if
(
params
.
help
)
{
if
(
params
.
help
)
{
print_usage
();
print_usage
();
...
@@ -76,9 +78,11 @@ main(int argc, char **argv)
...
@@ -76,9 +78,11 @@ main(int argc, char **argv)
crt
=
dht
::
crypto
::
generateIdentity
(
"DHT Node"
,
ca_tmp
);
crt
=
dht
::
crypto
::
generateIdentity
(
"DHT Node"
,
ca_tmp
);
}
}
DhtRunner
dht
;
dht
.
run
(
params
.
port
,
crt
,
true
,
params
.
is_bootstrap_node
);
dht
.
run
(
params
.
port
,
crt
,
true
,
params
.
is_bootstrap_node
);
if
(
params
.
log
)
enableLogging
(
dht
);
if
(
not
params
.
bootstrap
.
empty
())
{
if
(
not
params
.
bootstrap
.
empty
())
{
std
::
cout
<<
"Bootstrap: "
<<
params
.
bootstrap
[
0
]
<<
":"
<<
params
.
bootstrap
[
1
]
<<
std
::
endl
;
std
::
cout
<<
"Bootstrap: "
<<
params
.
bootstrap
[
0
]
<<
":"
<<
params
.
bootstrap
[
1
]
<<
std
::
endl
;
dht
.
bootstrap
(
params
.
bootstrap
[
0
].
c_str
(),
params
.
bootstrap
[
1
].
c_str
());
dht
.
bootstrap
(
params
.
bootstrap
[
0
].
c_str
(),
params
.
bootstrap
[
1
].
c_str
());
...
@@ -87,7 +91,6 @@ main(int argc, char **argv)
...
@@ -87,7 +91,6 @@ main(int argc, char **argv)
print_node_info
(
dht
,
params
);
print_node_info
(
dht
,
params
);
std
::
cout
<<
" (type 'h' or 'help' for a list of possible commands)"
<<
std
::
endl
<<
std
::
endl
;
std
::
cout
<<
" (type 'h' or 'help' for a list of possible commands)"
<<
std
::
endl
<<
std
::
endl
;
bool
do_log
{
false
};
while
(
true
)
while
(
true
)
{
{
std
::
cout
<<
">> "
;
std
::
cout
<<
">> "
;
...
@@ -149,8 +152,8 @@ main(int argc, char **argv)
...
@@ -149,8 +152,8 @@ main(int argc, char **argv)
std
::
cout
<<
addr
<<
std
::
endl
;
std
::
cout
<<
addr
<<
std
::
endl
;
continue
;
continue
;
}
else
if
(
op
==
"log"
)
{
}
else
if
(
op
==
"log"
)
{
do_log
=
!
do_
log
;
params
.
log
=
!
params
.
log
;
if
(
do_
log
)
if
(
params
.
log
)
enableLogging
(
dht
);
enableLogging
(
dht
);
else
else
disableLogging
(
dht
);
disableLogging
(
dht
);
...
@@ -246,7 +249,12 @@ main(int argc, char **argv)
...
@@ -246,7 +249,12 @@ main(int argc, char **argv)
}
}
std
::
cout
<<
std
::
endl
<<
"Stopping node..."
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
<<
"Stopping node..."
<<
std
::
endl
;
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cout
<<
std
::
endl
<<
e
.
what
()
<<
std
::
endl
;
}
dht
.
join
();
dht
.
join
();
gnutls_global_deinit
();
gnutls_global_deinit
();
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
tools/tools_common.h
+
6
−
1
View file @
46d59141
...
@@ -128,6 +128,7 @@ static const constexpr in_port_t DHT_DEFAULT_PORT = 4222;
...
@@ -128,6 +128,7 @@ static const constexpr in_port_t DHT_DEFAULT_PORT = 4222;
struct
dht_params
{
struct
dht_params
{
bool
help
{
false
};
// print help and exit
bool
help
{
false
};
// print help and exit
bool
log
{
false
};
in_port_t
port
{
DHT_DEFAULT_PORT
};
in_port_t
port
{
DHT_DEFAULT_PORT
};
bool
is_bootstrap_node
{
false
};
bool
is_bootstrap_node
{
false
};
bool
generate_identity
{
false
};
bool
generate_identity
{
false
};
...
@@ -139,6 +140,7 @@ static const struct option long_options[] = {
...
@@ -139,6 +140,7 @@ static const struct option long_options[] = {
{
"port"
,
required_argument
,
nullptr
,
'p'
},
{
"port"
,
required_argument
,
nullptr
,
'p'
},
{
"bootstrap"
,
optional_argument
,
nullptr
,
'b'
},
{
"bootstrap"
,
optional_argument
,
nullptr
,
'b'
},
{
"identity"
,
no_argument
,
nullptr
,
'i'
},
{
"identity"
,
no_argument
,
nullptr
,
'i'
},
{
"verbose"
,
no_argument
,
nullptr
,
'v'
},
{
nullptr
,
0
,
nullptr
,
0
}
{
nullptr
,
0
,
nullptr
,
0
}
};
};
...
@@ -146,7 +148,7 @@ dht_params
...
@@ -146,7 +148,7 @@ dht_params
parseArgs
(
int
argc
,
char
**
argv
)
{
parseArgs
(
int
argc
,
char
**
argv
)
{
dht_params
params
;
dht_params
params
;
int
opt
;
int
opt
;
while
((
opt
=
getopt_long
(
argc
,
argv
,
":hip:b:"
,
long_options
,
nullptr
))
!=
-
1
)
{
while
((
opt
=
getopt_long
(
argc
,
argv
,
":hi
v
p:b:"
,
long_options
,
nullptr
))
!=
-
1
)
{
switch
(
opt
)
{
switch
(
opt
)
{
case
'p'
:
{
case
'p'
:
{
int
port_arg
=
atoi
(
optarg
);
int
port_arg
=
atoi
(
optarg
);
...
@@ -168,6 +170,9 @@ parseArgs(int argc, char **argv) {
...
@@ -168,6 +170,9 @@ parseArgs(int argc, char **argv) {
case
'h'
:
case
'h'
:
params
.
help
=
true
;
params
.
help
=
true
;
break
;
break
;
case
'v'
:
params
.
log
=
true
;
break
;
case
'i'
:
case
'i'
:
params
.
generate_identity
=
true
;
params
.
generate_identity
=
true
;
break
;
break
;
...
...
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