Skip to content
GitLab
Explore
Sign in
Register
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
7915b987
Commit
7915b987
authored
3 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
misc: use more string_view
parent
29bdc1a4
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/infohash.cpp
+4
-2
4 additions, 2 deletions
src/infohash.cpp
src/peer_discovery.cpp
+5
-4
5 additions, 4 deletions
src/peer_discovery.cpp
with
9 additions
and
6 deletions
src/infohash.cpp
+
4
−
2
View file @
7915b987
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
#include
<sstream>
#include
<sstream>
#include
<cstdio>
#include
<cstdio>
using
namespace
std
::
literals
;
namespace
dht
{
namespace
dht
{
const
HexMap
hex_map
=
{};
const
HexMap
hex_map
=
{};
...
@@ -33,9 +35,9 @@ NodeExport::msgpack_unpack(msgpack::object o)
...
@@ -33,9 +35,9 @@ NodeExport::msgpack_unpack(msgpack::object o)
throw
msgpack
::
type_error
();
throw
msgpack
::
type_error
();
if
(
o
.
via
.
map
.
size
<
2
)
if
(
o
.
via
.
map
.
size
<
2
)
throw
msgpack
::
type_error
();
throw
msgpack
::
type_error
();
if
(
o
.
via
.
map
.
ptr
[
0
].
key
.
as
<
std
::
string
>
()
!=
"id"
)
if
(
o
.
via
.
map
.
ptr
[
0
].
key
.
as
<
std
::
string
_view
>
()
!=
"id"
sv
)
throw
msgpack
::
type_error
();
throw
msgpack
::
type_error
();
if
(
o
.
via
.
map
.
ptr
[
1
].
key
.
as
<
std
::
string
>
()
!=
"addr"
)
if
(
o
.
via
.
map
.
ptr
[
1
].
key
.
as
<
std
::
string
_view
>
()
!=
"addr"
sv
)
throw
msgpack
::
type_error
();
throw
msgpack
::
type_error
();
const
auto
&
addr
=
o
.
via
.
map
.
ptr
[
1
].
val
;
const
auto
&
addr
=
o
.
via
.
map
.
ptr
[
1
].
val
;
if
(
addr
.
type
!=
msgpack
::
type
::
BIN
)
if
(
addr
.
type
!=
msgpack
::
type
::
BIN
)
...
...
This diff is collapsed.
Click to expand it.
src/peer_discovery.cpp
+
5
−
4
View file @
7915b987
...
@@ -24,6 +24,8 @@
...
@@ -24,6 +24,8 @@
#include
<asio.hpp>
#include
<asio.hpp>
using
namespace
std
::
literals
;
namespace
dht
{
namespace
dht
{
// Organization-local Scope multicast
// Organization-local Scope multicast
...
@@ -61,7 +63,7 @@ private:
...
@@ -61,7 +63,7 @@ private:
msgpack
::
sbuffer
sbuf_
;
msgpack
::
sbuffer
sbuf_
;
std
::
map
<
std
::
string
,
msgpack
::
sbuffer
>
messages_
;
std
::
map
<
std
::
string
,
msgpack
::
sbuffer
>
messages_
;
std
::
map
<
std
::
string
,
ServiceDiscoveredCallback
>
callbackmap_
;
std
::
map
<
std
::
string
,
ServiceDiscoveredCallback
,
std
::
less
<>
>
callbackmap_
;
bool
lrunning_
{
false
};
bool
lrunning_
{
false
};
bool
drunning_
{
false
};
bool
drunning_
{
false
};
...
@@ -133,19 +135,18 @@ PeerDiscovery::DomainPeerDiscovery::loopListener()
...
@@ -133,19 +135,18 @@ PeerDiscovery::DomainPeerDiscovery::loopListener()
msgpack
::
object
obj
=
rcv
.
get
();
msgpack
::
object
obj
=
rcv
.
get
();
if
(
obj
.
type
==
msgpack
::
type
::
STR
)
{
if
(
obj
.
type
==
msgpack
::
type
::
STR
)
{
if
(
lrunning_
and
obj
.
as
<
std
::
string
>
()
==
"q"
)
if
(
lrunning_
and
obj
.
as
<
std
::
string
_view
>
()
==
"q"
sv
)
publish
(
receiveFrom_
);
publish
(
receiveFrom_
);
}
else
if
(
obj
.
type
==
msgpack
::
type
::
MAP
)
{
}
else
if
(
obj
.
type
==
msgpack
::
type
::
MAP
)
{
for
(
unsigned
i
=
0
;
i
<
obj
.
via
.
map
.
size
;
i
++
)
{
for
(
unsigned
i
=
0
;
i
<
obj
.
via
.
map
.
size
;
i
++
)
{
auto
&
o
=
obj
.
via
.
map
.
ptr
[
i
];
auto
&
o
=
obj
.
via
.
map
.
ptr
[
i
];
if
(
o
.
key
.
type
!=
msgpack
::
type
::
STR
)
if
(
o
.
key
.
type
!=
msgpack
::
type
::
STR
)
continue
;
continue
;
auto
key
=
o
.
key
.
as
<
std
::
string
>
();
ServiceDiscoveredCallback
cb
;
ServiceDiscoveredCallback
cb
;
{
{
std
::
lock_guard
<
std
::
mutex
>
lck
(
dmtx_
);
std
::
lock_guard
<
std
::
mutex
>
lck
(
dmtx_
);
if
(
drunning_
)
{
if
(
drunning_
)
{
auto
callback
=
callbackmap_
.
find
(
key
);
auto
callback
=
callbackmap_
.
find
(
o
.
key
.
as
<
std
::
string_view
>
()
);
if
(
callback
!=
callbackmap_
.
end
())
if
(
callback
!=
callbackmap_
.
end
())
cb
=
callback
->
second
;
cb
=
callback
->
second
;
}
else
}
else
...
...
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