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
d9f6731d
Unverified
Commit
d9f6731d
authored
Mar 29, 2018
by
Adrien Béraud
Committed by
GitHub
Mar 29, 2018
Browse files
Options
Downloads
Plain Diff
Merge pull request #265 from AmarOk1412/fixSplit
proxy_client: fix address split
parents
62e4655d
393a403f
Branches
Branches containing commit
Tags
Tags containing commit
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 @
d9f6731d
...
@@ -54,6 +54,12 @@ void erase_if(std::map<Key, Item>& map, const Condition& condition)
...
@@ -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
{
class
OPENDHT_PUBLIC
DhtException
:
public
std
::
runtime_error
{
public:
public:
DhtException
(
const
std
::
string
&
str
=
""
)
:
DhtException
(
const
std
::
string
&
str
=
""
)
:
...
...
This diff is collapsed.
Click to expand it.
src/dht_proxy_client.cpp
+
5
−
13
View file @
d9f6731d
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include
"dhtrunner.h"
#include
"dhtrunner.h"
#include
"op_cache.h"
#include
"op_cache.h"
#include
"utils.h"
#include
<restbed>
#include
<restbed>
#include
<json/json.h>
#include
<json/json.h>
...
@@ -452,15 +453,8 @@ DhtProxyClient::getProxyInfos()
...
@@ -452,15 +453,8 @@ DhtProxyClient::getProxyInfos()
}
}
// A node can have a Ipv4 and a Ipv6. So, we need to retrieve all public ips
// A node can have a Ipv4 and a Ipv6. So, we need to retrieve all public ips
std
::
string
host
,
service
;
auto
hostAndService
=
splitPort
(
serverHost_
);
auto
serviceMarker
=
serverHost_
.
find
(
':'
);
auto
resolved_proxies
=
SockAddr
::
resolve
(
hostAndService
.
first
,
hostAndService
.
second
);
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
serverHost
=
serverHost_
;
auto
serverHost
=
serverHost_
;
// Try to contact the proxy and set the status to connected when done.
// Try to contact the proxy and set the status to connected when done.
...
@@ -551,10 +545,8 @@ SockAddr
...
@@ -551,10 +545,8 @@ SockAddr
DhtProxyClient
::
parsePublicAddress
(
const
Json
::
Value
&
val
)
DhtProxyClient
::
parsePublicAddress
(
const
Json
::
Value
&
val
)
{
{
auto
public_ip
=
val
.
asString
();
auto
public_ip
=
val
.
asString
();
auto
endIp
=
public_ip
.
find_last_of
(
':'
);
auto
hostAndService
=
splitPort
(
public_ip
);
auto
marker
=
(
public_ip
.
size
()
>
0
&&
public_ip
[
0
]
==
'['
)
?
1
:
0
;
auto
sa
=
SockAddr
::
resolve
(
hostAndService
.
first
);
std
::
string
address
=
public_ip
.
substr
(
marker
,
endIp
-
marker
*
2
);
auto
sa
=
SockAddr
::
resolve
(
address
);
if
(
sa
.
empty
())
return
{};
if
(
sa
.
empty
())
return
{};
return
sa
.
front
().
getMappedIPv4
();
return
sa
.
front
().
getMappedIPv4
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/utils.cpp
+
20
−
0
View file @
d9f6731d
...
@@ -29,6 +29,26 @@ namespace dht {
...
@@ -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
}};
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
>
std
::
vector
<
SockAddr
>
SockAddr
::
resolve
(
const
std
::
string
&
host
,
const
std
::
string
&
service
)
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 @
d9f6731d
...
@@ -45,29 +45,6 @@
...
@@ -45,29 +45,6 @@
#include
<sstream>
#include
<sstream>
#include
<fstream>
#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:
* The mapString shall have the following format:
*
*
...
@@ -181,7 +158,7 @@ parseArgs(int argc, char **argv) {
...
@@ -181,7 +158,7 @@ parseArgs(int argc, char **argv) {
params
.
network
=
strtoul
(
optarg
,
nullptr
,
0
);
params
.
network
=
strtoul
(
optarg
,
nullptr
,
0
);
break
;
break
;
case
'b'
:
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
())
{
if
(
not
params
.
bootstrap
.
first
.
empty
()
and
params
.
bootstrap
.
second
.
empty
())
{
params
.
bootstrap
.
second
=
std
::
to_string
(
DHT_DEFAULT_PORT
);
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