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
51a4c176
Commit
51a4c176
authored
Feb 23, 2015
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
DhtMessage : introduce Service and ServiceFilter
parent
a5f82063
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/value.h
+33
-4
33 additions, 4 deletions
include/opendht/value.h
src/value.cpp
+3
-3
3 additions, 3 deletions
src/value.cpp
with
36 additions
and
7 deletions
include/opendht/value.h
+
33
−
4
View file @
51a4c176
...
@@ -186,7 +186,7 @@ struct Value : public Serializable
...
@@ -186,7 +186,7 @@ struct Value : public Serializable
};
};
}
}
static
Filter
chainFilters
(
Filter
&
f1
,
Filter
&
f2
)
{
static
Filter
chainFilters
(
Filter
&
&
f1
,
Filter
&
&
f2
)
{
return
[
f1
,
f2
](
const
Value
&
v
){
return
[
f1
,
f2
](
const
Value
&
v
){
return
f1
(
v
)
&&
f2
(
v
);
return
f1
(
v
)
&&
f2
(
v
);
};
};
...
@@ -364,26 +364,55 @@ private:
...
@@ -364,26 +364,55 @@ private:
sockaddr_storage
ss
;
sockaddr_storage
ss
;
};
};
struct
DhtMessage
:
public
Serializable
struct
DhtMessage
:
public
Serializable
{
{
DhtMessage
(
uint16_t
s
,
Blob
msg
=
{})
:
service
(
s
),
message
(
msg
)
{}
enum
class
Service
:
uint16_t
{
UNDEFINED
=
0
,
IM_MESSAGE
,
ICE_CANDIDATES
};
DhtMessage
(
uint16_t
s
,
Blob
msg
=
{})
:
service
(
static_cast
<
Service
>
(
s
)),
message
(
msg
)
{}
DhtMessage
(
Service
s
,
Blob
msg
=
{})
:
service
(
s
),
message
(
msg
)
{}
DhtMessage
(
const
Blob
&
b
)
{
DhtMessage
(
const
Blob
&
b
)
{
unpackBlob
(
b
);
unpackBlob
(
b
);
}
}
Service
getService
()
const
{
return
service
;
}
const
Blob
&
getMessage
()
const
{
return
message
;
}
virtual
void
pack
(
Blob
&
res
)
const
;
virtual
void
pack
(
Blob
&
res
)
const
;
virtual
void
unpack
(
Blob
::
const_iterator
&
begin
,
Blob
::
const_iterator
&
end
);
virtual
void
unpack
(
Blob
::
const_iterator
&
begin
,
Blob
::
const_iterator
&
end
);
static
const
ValueType
TYPE
;
static
const
ValueType
TYPE
;
static
bool
storePolicy
(
InfoHash
,
std
::
shared_ptr
<
Value
>&
,
InfoHash
,
const
sockaddr
*
,
socklen_t
);
static
bool
storePolicy
(
InfoHash
,
std
::
shared_ptr
<
Value
>&
,
InfoHash
,
const
sockaddr
*
,
socklen_t
);
static
Value
::
Filter
ServiceFilter
(
Service
s
)
{
return
Value
::
chainFilters
(
Value
::
TypeFilter
(
TYPE
),
[
s
](
const
Value
&
v
)
{
try
{
auto
b
=
v
.
data
.
cbegin
(),
e
=
v
.
data
.
cend
();
auto
service
=
deserialize
<
Service
>
(
b
,
e
);
return
service
==
s
;
}
catch
(
const
std
::
exception
&
e
)
{
return
false
;
}
}
);
}
/** print value for debugging */
/** print value for debugging */
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
DhtMessage
&
);
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
DhtMessage
&
);
private
:
private
:
uint16_t
service
;
Service
service
;
Blob
message
;
Blob
message
;
};
};
...
...
This diff is collapsed.
Click to expand it.
src/value.cpp
+
3
−
3
View file @
51a4c176
...
@@ -227,14 +227,14 @@ std::ostream& operator<< (std::ostream& s, const DhtMessage& v)
...
@@ -227,14 +227,14 @@ std::ostream& operator<< (std::ostream& s, const DhtMessage& v)
void
void
DhtMessage
::
pack
(
Blob
&
res
)
const
DhtMessage
::
pack
(
Blob
&
res
)
const
{
{
serialize
<
int16_t
>
(
service
,
res
);
serialize
<
Service
>
(
service
,
res
);
serialize
<
Blob
>
(
message
,
res
);
serialize
<
Blob
>
(
message
,
res
);
}
}
void
void
DhtMessage
::
unpack
(
Blob
::
const_iterator
&
begin
,
Blob
::
const_iterator
&
end
)
DhtMessage
::
unpack
(
Blob
::
const_iterator
&
begin
,
Blob
::
const_iterator
&
end
)
{
{
service
=
deserialize
<
int16_t
>
(
begin
,
end
);
service
=
deserialize
<
Service
>
(
begin
,
end
);
message
=
deserialize
<
Blob
>
(
begin
,
end
);
message
=
deserialize
<
Blob
>
(
begin
,
end
);
}
}
...
@@ -242,7 +242,7 @@ bool
...
@@ -242,7 +242,7 @@ bool
DhtMessage
::
storePolicy
(
InfoHash
,
std
::
shared_ptr
<
Value
>&
v
,
InfoHash
,
const
sockaddr
*
from
,
socklen_t
fromlen
)
DhtMessage
::
storePolicy
(
InfoHash
,
std
::
shared_ptr
<
Value
>&
v
,
InfoHash
,
const
sockaddr
*
from
,
socklen_t
fromlen
)
{
{
DhtMessage
request
{
v
->
data
};
DhtMessage
request
{
v
->
data
};
if
(
request
.
service
==
0
)
if
(
request
.
service
==
Service
::
UNDEFINED
)
return
false
;
return
false
;
return
true
;
return
true
;
}
}
...
...
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