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
48512bfd
Commit
48512bfd
authored
Feb 17, 2016
by
Simon Désaulniers
Committed by
Adrien Béraud
May 2, 2016
Browse files
Options
Downloads
Patches
Plain Diff
delete packet processing methods in dht.cpp
parent
9e950c8f
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/opendht/dht.h
+0
-104
0 additions, 104 deletions
include/opendht/dht.h
src/dht.cpp
+33
-1029
33 additions, 1029 deletions
src/dht.cpp
src/network_engine.cpp
+2
-3
2 additions, 3 deletions
src/network_engine.cpp
with
35 additions
and
1136 deletions
include/opendht/dht.h
+
0
−
104
View file @
48512bfd
...
...
@@ -795,58 +795,6 @@ private:
size_t
total_size
{};
};
enum
class
MessageType
{
Error
=
0
,
Reply
,
Ping
,
FindNode
,
GetValues
,
AnnounceValue
,
Listen
};
struct
TransPrefix
:
public
std
::
array
<
uint8_t
,
2
>
{
TransPrefix
(
const
std
::
string
&
str
)
:
std
::
array
<
uint8_t
,
2
>
({{(
uint8_t
)
str
[
0
],
(
uint8_t
)
str
[
1
]}})
{}
static
const
TransPrefix
PING
;
static
const
TransPrefix
FIND_NODE
;
static
const
TransPrefix
GET_VALUES
;
static
const
TransPrefix
ANNOUNCE_VALUES
;
static
const
TransPrefix
LISTEN
;
};
/* Transaction-ids are 4-bytes long, with the first two bytes identifying
* the kind of request, and the remaining two a sequence number in
* host order.
*/
struct
TransId
final
:
public
std
::
array
<
uint8_t
,
4
>
{
TransId
()
{}
TransId
(
const
std
::
array
<
char
,
4
>&
o
)
{
std
::
copy
(
o
.
begin
(),
o
.
end
(),
begin
());
}
TransId
(
const
TransPrefix
prefix
,
uint16_t
seqno
=
0
)
{
std
::
copy_n
(
prefix
.
begin
(),
prefix
.
size
(),
begin
());
*
reinterpret_cast
<
uint16_t
*>
(
data
()
+
prefix
.
size
())
=
seqno
;
}
TransId
(
const
char
*
q
,
size_t
l
)
:
array
<
uint8_t
,
4
>
()
{
if
(
l
>
4
)
{
length
=
0
;
}
else
{
std
::
copy_n
(
q
,
l
,
begin
());
length
=
l
;
}
}
bool
matches
(
const
TransPrefix
prefix
,
uint16_t
*
seqno_return
=
nullptr
)
const
{
if
(
std
::
equal
(
begin
(),
begin
()
+
2
,
prefix
.
begin
()))
{
if
(
seqno_return
)
*
seqno_return
=
*
reinterpret_cast
<
const
uint16_t
*>
(
&
(
*
this
)[
2
]);
return
true
;
}
else
return
false
;
}
unsigned
length
{
4
};
};
// prevent copy
Dht
(
const
Dht
&
)
=
delete
;
Dht
&
operator
=
(
const
Dht
&
)
=
delete
;
...
...
@@ -904,58 +852,6 @@ private:
using
ReportedAddr
=
std
::
pair
<
unsigned
,
Address
>
;
std
::
vector
<
ReportedAddr
>
reported_addr
;
// Networking & packet handling
int
send
(
const
char
*
buf
,
size_t
len
,
int
flags
,
const
sockaddr
*
,
socklen_t
);
int
sendPing
(
const
sockaddr
*
,
socklen_t
,
TransId
tid
);
int
sendPong
(
const
sockaddr
*
,
socklen_t
,
TransId
tid
);
int
sendFindNode
(
const
sockaddr
*
,
socklen_t
,
TransId
tid
,
const
InfoHash
&
target
,
want_t
want
,
int
confirm
);
int
sendGetValues
(
const
sockaddr
*
,
socklen_t
,
TransId
tid
,
const
InfoHash
&
target
,
want_t
want
,
int
confirm
);
int
sendNodesValues
(
const
sockaddr
*
,
socklen_t
,
TransId
tid
,
const
uint8_t
*
nodes
,
unsigned
nodes_len
,
const
uint8_t
*
nodes6
,
unsigned
nodes6_len
,
const
std
::
vector
<
ValueStorage
>&
st
,
const
Blob
&
token
);
int
sendClosestNodes
(
const
sockaddr
*
,
socklen_t
,
TransId
tid
,
const
InfoHash
&
id
,
want_t
want
,
const
Blob
&
token
=
{},
const
std
::
vector
<
ValueStorage
>&
st
=
{});
int
sendListen
(
const
sockaddr
*
,
socklen_t
,
TransId
,
const
InfoHash
&
,
const
Blob
&
token
,
int
confirm
);
int
sendListenConfirmation
(
const
sockaddr
*
,
socklen_t
,
TransId
);
int
sendAnnounceValue
(
const
sockaddr
*
,
socklen_t
,
TransId
,
const
InfoHash
&
,
const
Value
&
,
time_point
created
,
const
Blob
&
token
,
int
confirm
);
int
sendValueAnnounced
(
const
sockaddr
*
,
socklen_t
,
TransId
,
Value
::
Id
);
int
sendError
(
const
sockaddr
*
,
socklen_t
,
TransId
tid
,
uint16_t
code
,
const
char
*
message
,
bool
include_id
=
false
);
void
processMessage
(
const
uint8_t
*
buf
,
size_t
buflen
,
const
sockaddr
*
from
,
socklen_t
fromlen
);
struct
ParsedMessage
{
MessageType
type
;
InfoHash
id
;
InfoHash
info_hash
;
InfoHash
target
;
TransId
tid
;
Blob
token
;
Value
::
Id
value_id
;
time_point
created
{
time_point
::
max
()
};
Blob
nodes4
;
Blob
nodes6
;
std
::
vector
<
std
::
shared_ptr
<
Value
>>
values
;
want_t
want
;
uint16_t
error_code
;
std
::
string
ua
;
Address
addr
;
void
msgpack_unpack
(
msgpack
::
object
o
);
};
void
rotateSecrets
();
Blob
makeToken
(
const
sockaddr
*
sa
,
bool
old
)
const
;
...
...
This diff is collapsed.
Click to expand it.
src/dht.cpp
+
33
−
1029
View file @
48512bfd
This diff is collapsed.
Click to expand it.
src/network_engine.cpp
+
2
−
3
View file @
48512bfd
...
...
@@ -56,9 +56,8 @@ NetworkEngine::processMessage(const uint8_t *buf, size_t buflen, const sockaddr
void
packToken
(
msgpack
::
packer
<
msgpack
::
sbuffer
>&
pk
,
Blob
token
)
{
pk
.
pack_array
(
token
.
size
());
for
(
uint8_t
b
:
token
)
pk
.
pack
(
b
);
pk
.
pack_bin
(
token
.
size
());
pk
.
pack_bin_body
((
char
*
)
token
.
data
(),
token
.
size
());
}
void
...
...
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
sign in
to comment