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
7fe321e4
Commit
7fe321e4
authored
6 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
peerdiscovery: cleanup data serialization
parent
7f7075ca
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
include/opendht/peer_discovery.h
+0
-13
0 additions, 13 deletions
include/opendht/peer_discovery.h
src/peer_discovery.cpp
+12
-24
12 additions, 24 deletions
src/peer_discovery.cpp
with
12 additions
and
37 deletions
include/opendht/peer_discovery.h
+
0
−
13
View file @
7fe321e4
...
...
@@ -119,19 +119,6 @@ private:
* Sender Parameters Setup
*/
void
sender_setup
(
const
dht
::
InfoHash
&
nodeId
,
in_port_t
port_to_send
);
/**
* Binary Converters
*/
static
void
inttolitend
(
uint32_t
x
,
uint8_t
*
lit_int
)
{
lit_int
[
0
]
=
(
uint8_t
)(
x
>>
0
);
lit_int
[
1
]
=
(
uint8_t
)(
x
>>
8
);
}
static
uint16_t
litendtoint
(
uint8_t
*
lit_int
)
{
return
(
uint32_t
)
lit_int
[
0
]
<<
0
|
(
uint32_t
)
lit_int
[
1
]
<<
8
;
}
};
}
This diff is collapsed.
Click to expand it.
src/peer_discovery.cpp
+
12
−
24
View file @
7fe321e4
...
...
@@ -181,20 +181,15 @@ void
PeerDiscovery
::
sender_setup
(
const
dht
::
InfoHash
&
nodeId
,
in_port_t
port_to_send
)
{
nodeId_
=
nodeId
;
//Set
up
for Sender
//
Setup
sender address
sockAddrSend_
.
setFamily
(
domain_
);
sockAddrSend_
.
setAddress
(
domain_
==
AF_INET
?
MULTICAST_ADDRESS_IPV4
:
MULTICAST_ADDRESS_IPV6
);
sockAddrSend_
.
setPort
(
port_
);
//Setup for send data
int
port_node
=
port_to_send
;
uint8_t
port_node_binary
[
2
];
PeerDiscovery
::
inttolitend
(
port_node
,
port_node_binary
);
//Copy Node id and node port
memcpy
(
data_send_
.
data
(),
nodeId
.
data
(),
nodeId
.
size
());
data_send_
[
InfoHash
::
size
()]
=
port_node_binary
[
0
];
data_send_
[
InfoHash
::
size
()
+
1
]
=
port_node_binary
[
1
];
// Setup sent data
std
::
copy_n
(
nodeId
.
cbegin
(),
nodeId
.
size
(),
data_send_
.
begin
());
auto
portAddr
=
reinterpret_cast
<
in_port_t
*>
(
data_send_
.
data
()
+
dht
::
InfoHash
::
size
());
*
portAddr
=
htons
(
port_to_send
);
}
void
...
...
@@ -252,7 +247,6 @@ PeerDiscovery::listener_thread(PeerDiscoveredCallback callback)
}
if
(
data_coming
>
0
)
{
if
(
FD_ISSET
(
stop_readfd
,
&
readfds
))
{
break
;
}
std
::
array
<
uint8_t
,
dht
::
InfoHash
::
size
()
+
sizeof
(
in_port_t
)
>
data_receive
;
...
...
@@ -261,20 +255,14 @@ PeerDiscovery::listener_thread(PeerDiscoveredCallback callback)
// Data_receive_size as a value-result member will hlep to filter packs
if
(
data_receive_size
!=
data_receive
.
size
()){
perror
(
"Data Received Unmatch"
)
;
// std::cerr << "Received invalid peer discovery packet" << std::endl
;
continue
;
}
std
::
array
<
uint8_t
,
dht
::
InfoHash
::
size
()
>
data_infohash
;
uint8_t
data_port
[
2
];
memcpy
(
data_infohash
.
data
(),
data_receive
.
data
(),
dht
::
InfoHash
::
size
());
data_port
[
0
]
=
data_receive
[
dht
::
InfoHash
::
size
()];
data_port
[
1
]
=
data_receive
[
dht
::
InfoHash
::
size
()
+
1
];
auto
port
=
PeerDiscovery
::
litendtoint
(
data_port
);
auto
nodeId
=
dht
::
InfoHash
(
data_infohash
.
data
(),
dht
::
InfoHash
::
size
());
dht
::
InfoHash
nodeId
;
std
::
copy_n
(
data_receive
.
begin
(),
dht
::
InfoHash
::
size
(),
nodeId
.
begin
());
auto
portAddr
=
reinterpret_cast
<
in_port_t
*>
(
data_receive
.
data
()
+
dht
::
InfoHash
::
size
());
auto
port
=
ntohs
(
*
portAddr
);
if
(
nodeId
!=
nodeId_
){
from
.
setPort
(
port
);
callback
(
nodeId
,
from
);
...
...
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