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
393a403f
Unverified
Commit
393a403f
authored
Mar 29, 2018
by
Sébastien Blin
Browse files
Options
Downloads
Patches
Plain Diff
proxy_client: fix address split
parent
62e4655d
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/opendht/utils.h
+6
-0
6 additions, 0 deletions
include/opendht/utils.h
src/dht_proxy_client.cpp
+5
-13
5 additions, 13 deletions
src/dht_proxy_client.cpp
src/utils.cpp
+20
-0
20 additions, 0 deletions
src/utils.cpp
tools/tools_common.h
+1
-24
1 addition, 24 deletions
tools/tools_common.h
with
32 additions
and
37 deletions
include/opendht/utils.h
+
6
−
0
View file @
393a403f
...
...
@@ -54,6 +54,12 @@ void erase_if(std::map<Key, Item>& map, const Condition& condition)
}
}
/**
* Split "[host]:port" or "host:port" to pair<"host", "port">.
*/
OPENDHT_PUBLIC
std
::
pair
<
std
::
string
,
std
::
string
>
splitPort
(
const
std
::
string
&
s
);
class
OPENDHT_PUBLIC
DhtException
:
public
std
::
runtime_error
{
public:
DhtException
(
const
std
::
string
&
str
=
""
)
:
...
...
This diff is collapsed.
Click to expand it.
src/dht_proxy_client.cpp
+
5
−
13
View file @
393a403f
...
...
@@ -23,6 +23,7 @@
#include
"dhtrunner.h"
#include
"op_cache.h"
#include
"utils.h"
#include
<restbed>
#include
<json/json.h>
...
...
@@ -452,15 +453,8 @@ DhtProxyClient::getProxyInfos()
}
// A node can have a Ipv4 and a Ipv6. So, we need to retrieve all public ips
std
::
string
host
,
service
;
auto
serviceMarker
=
serverHost_
.
find
(
':'
);
if
(
serviceMarker
!=
std
::
string
::
npos
)
{
host
=
serverHost_
.
substr
(
0
,
serviceMarker
-
1
);
service
=
serverHost_
.
substr
(
serviceMarker
+
1
);
}
else
{
host
=
serverHost_
;
}
auto
resolved_proxies
=
SockAddr
::
resolve
(
host
,
service
);
auto
hostAndService
=
splitPort
(
serverHost_
);
auto
resolved_proxies
=
SockAddr
::
resolve
(
hostAndService
.
first
,
hostAndService
.
second
);
auto
serverHost
=
serverHost_
;
// Try to contact the proxy and set the status to connected when done.
...
...
@@ -551,10 +545,8 @@ SockAddr
DhtProxyClient
::
parsePublicAddress
(
const
Json
::
Value
&
val
)
{
auto
public_ip
=
val
.
asString
();
auto
endIp
=
public_ip
.
find_last_of
(
':'
);
auto
marker
=
(
public_ip
.
size
()
>
0
&&
public_ip
[
0
]
==
'['
)
?
1
:
0
;
std
::
string
address
=
public_ip
.
substr
(
marker
,
endIp
-
marker
*
2
);
auto
sa
=
SockAddr
::
resolve
(
address
);
auto
hostAndService
=
splitPort
(
public_ip
);
auto
sa
=
SockAddr
::
resolve
(
hostAndService
.
first
);
if
(
sa
.
empty
())
return
{};
return
sa
.
front
().
getMappedIPv4
();
}
...
...
This diff is collapsed.
Click to expand it.
src/utils.cpp
+
20
−
0
View file @
393a403f
...
...
@@ -29,6 +29,26 @@ namespace dht {
static
constexpr
std
::
array
<
uint8_t
,
12
>
MAPPED_IPV4_PREFIX
{{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0xff
,
0xff
}};
std
::
pair
<
std
::
string
,
std
::
string
>
splitPort
(
const
std
::
string
&
s
)
{
if
(
s
.
empty
())
return
{};
if
(
s
[
0
]
==
'['
)
{
std
::
size_t
closure
=
s
.
find_first_of
(
']'
);
std
::
size_t
found
=
s
.
find_last_of
(
':'
);
if
(
closure
==
std
::
string
::
npos
)
return
{
s
,
""
};
if
(
found
==
std
::
string
::
npos
or
found
<
closure
)
return
{
s
.
substr
(
1
,
closure
-
1
),
""
};
return
{
s
.
substr
(
1
,
closure
-
1
),
s
.
substr
(
found
+
1
)};
}
std
::
size_t
found
=
s
.
find_last_of
(
':'
);
std
::
size_t
first
=
s
.
find_first_of
(
':'
);
if
(
found
==
std
::
string
::
npos
or
found
!=
first
)
return
{
s
,
""
};
return
{
s
.
substr
(
0
,
found
),
s
.
substr
(
found
+
1
)};
}
std
::
vector
<
SockAddr
>
SockAddr
::
resolve
(
const
std
::
string
&
host
,
const
std
::
string
&
service
)
{
...
...
This diff is collapsed.
Click to expand it.
tools/tools_common.h
+
1
−
24
View file @
393a403f
...
...
@@ -45,29 +45,6 @@
#include
<sstream>
#include
<fstream>
/**
* Split "[host]:port" or "host:port" to pair<"host", "port">.
*/
std
::
pair
<
std
::
string
,
std
::
string
>
splitPort
(
const
std
::
string
&
s
)
{
if
(
s
.
empty
())
return
{};
if
(
s
[
0
]
==
'['
)
{
std
::
size_t
closure
=
s
.
find_first_of
(
']'
);
std
::
size_t
found
=
s
.
find_last_of
(
':'
);
if
(
closure
==
std
::
string
::
npos
)
return
{
s
,
""
};
if
(
found
==
std
::
string
::
npos
or
found
<
closure
)
return
{
s
.
substr
(
1
,
closure
-
1
),
""
};
return
{
s
.
substr
(
1
,
closure
-
1
),
s
.
substr
(
found
+
1
)};
}
std
::
size_t
found
=
s
.
find_last_of
(
':'
);
std
::
size_t
first
=
s
.
find_first_of
(
':'
);
if
(
found
==
std
::
string
::
npos
or
found
!=
first
)
return
{
s
,
""
};
return
{
s
.
substr
(
0
,
found
),
s
.
substr
(
found
+
1
)};
}
/*
* The mapString shall have the following format:
*
...
...
@@ -181,7 +158,7 @@ parseArgs(int argc, char **argv) {
params
.
network
=
strtoul
(
optarg
,
nullptr
,
0
);
break
;
case
'b'
:
params
.
bootstrap
=
splitPort
((
optarg
[
0
]
==
'='
)
?
optarg
+
1
:
optarg
);
params
.
bootstrap
=
dht
::
splitPort
((
optarg
[
0
]
==
'='
)
?
optarg
+
1
:
optarg
);
if
(
not
params
.
bootstrap
.
first
.
empty
()
and
params
.
bootstrap
.
second
.
empty
())
{
params
.
bootstrap
.
second
=
std
::
to_string
(
DHT_DEFAULT_PORT
);
}
...
...
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