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
51c35d8b
Commit
51c35d8b
authored
5 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
value: add priority
parent
fea73642
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/value.h
+15
-2
15 additions, 2 deletions
include/opendht/value.h
src/value.cpp
+9
-0
9 additions, 0 deletions
src/value.cpp
with
24 additions
and
2 deletions
include/opendht/value.h
+
15
−
2
View file @
51c35d8b
...
...
@@ -43,6 +43,7 @@
namespace
dht
{
static
const
std
::
string
VALUE_KEY_PRIO
(
"p"
);
struct
Value
;
struct
Query
;
...
...
@@ -408,7 +409,9 @@ struct OPENDHT_PUBLIC Value
Value
(
Value
&&
o
)
noexcept
:
id
(
o
.
id
),
owner
(
std
::
move
(
o
.
owner
)),
recipient
(
o
.
recipient
),
type
(
o
.
type
),
data
(
std
::
move
(
o
.
data
)),
user_type
(
std
::
move
(
o
.
user_type
)),
seq
(
o
.
seq
),
signature
(
std
::
move
(
o
.
signature
)),
cypher
(
std
::
move
(
o
.
cypher
))
{}
type
(
o
.
type
),
data
(
std
::
move
(
o
.
data
)),
user_type
(
std
::
move
(
o
.
user_type
)),
seq
(
o
.
seq
)
,
signature
(
std
::
move
(
o
.
signature
)),
cypher
(
std
::
move
(
o
.
cypher
))
,
priority
(
o
.
priority
)
{}
template
<
typename
Type
>
Value
(
const
Type
&
vs
)
...
...
@@ -518,9 +521,12 @@ struct OPENDHT_PUBLIC Value
template
<
typename
Packer
>
void
msgpack_pack
(
Packer
&
pk
)
const
{
pk
.
pack_map
(
2
);
pk
.
pack_map
(
2
+
(
priority
?
1
:
0
)
);
pk
.
pack
(
std
::
string
(
"id"
));
pk
.
pack
(
id
);
pk
.
pack
(
std
::
string
(
"dat"
));
msgpack_pack_to_encrypt
(
pk
);
if
(
priority
)
{
pk
.
pack
(
VALUE_KEY_PRIO
);
pk
.
pack
(
priority
);
}
}
template
<
typename
Packer
>
...
...
@@ -602,6 +608,13 @@ struct OPENDHT_PUBLIC Value
*/
Blob
cypher
{};
/**
* Priority of this value (used for push notifications)
* 0 = high priority
* 1 = normal priority
*/
unsigned
priority
{
0
};
private
:
friend
class
SecureDht
;
/* Cache for crypto ops */
...
...
This diff is collapsed.
Click to expand it.
src/value.cpp
+
9
−
0
View file @
51c35d8b
...
...
@@ -108,6 +108,10 @@ Value::msgpack_unpack(const msgpack::object& o)
msgpack_unpack_body
(
*
rdat
);
}
else
throw
msgpack
::
type_error
();
if
(
auto
rprio
=
findMapValue
(
o
,
VALUE_KEY_PRIO
))
{
priority
=
rprio
->
as
<
unsigned
>
();
}
}
void
...
...
@@ -195,6 +199,9 @@ Value::Value(const Json::Value& json)
const
auto
&
jutype
=
json
[
"utype"
];
if
(
jutype
.
isString
())
user_type
=
jutype
.
asString
();
const
auto
&
jprio
=
json
[
"prio"
];
if
(
jprio
.
isIntegral
())
priority
=
jprio
.
asUInt
();
}
Json
::
Value
...
...
@@ -219,6 +226,8 @@ Value::toJson() const
if
(
not
user_type
.
empty
())
val
[
"utype"
]
=
user_type
;
}
if
(
priority
)
val
[
"prio"
]
=
priority
;
return
val
;
}
...
...
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