Skip to content
Snippets Groups Projects
Commit 51c35d8b authored by Adrien Béraud's avatar Adrien Béraud
Browse files

value: add priority

parent fea73642
Branches
Tags
No related merge requests found
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
namespace dht { namespace dht {
static const std::string VALUE_KEY_PRIO("p");
struct Value; struct Value;
struct Query; struct Query;
...@@ -408,7 +409,9 @@ struct OPENDHT_PUBLIC Value ...@@ -408,7 +409,9 @@ struct OPENDHT_PUBLIC Value
Value(Value&& o) noexcept Value(Value&& o) noexcept
: id(o.id), owner(std::move(o.owner)), recipient(o.recipient), : 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> template <typename Type>
Value(const Type& vs) Value(const Type& vs)
...@@ -518,9 +521,12 @@ struct OPENDHT_PUBLIC Value ...@@ -518,9 +521,12 @@ struct OPENDHT_PUBLIC Value
template <typename Packer> template <typename Packer>
void msgpack_pack(Packer& pk) const 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("id")); pk.pack(id);
pk.pack(std::string("dat")); msgpack_pack_to_encrypt(pk); pk.pack(std::string("dat")); msgpack_pack_to_encrypt(pk);
if (priority) {
pk.pack(VALUE_KEY_PRIO); pk.pack(priority);
}
} }
template <typename Packer> template <typename Packer>
...@@ -602,6 +608,13 @@ struct OPENDHT_PUBLIC Value ...@@ -602,6 +608,13 @@ struct OPENDHT_PUBLIC Value
*/ */
Blob cypher {}; Blob cypher {};
/**
* Priority of this value (used for push notifications)
* 0 = high priority
* 1 = normal priority
*/
unsigned priority {0};
private: private:
friend class SecureDht; friend class SecureDht;
/* Cache for crypto ops */ /* Cache for crypto ops */
......
...@@ -108,6 +108,10 @@ Value::msgpack_unpack(const msgpack::object& o) ...@@ -108,6 +108,10 @@ Value::msgpack_unpack(const msgpack::object& o)
msgpack_unpack_body(*rdat); msgpack_unpack_body(*rdat);
} else } else
throw msgpack::type_error(); throw msgpack::type_error();
if (auto rprio = findMapValue(o, VALUE_KEY_PRIO)) {
priority = rprio->as<unsigned>();
}
} }
void void
...@@ -195,6 +199,9 @@ Value::Value(const Json::Value& json) ...@@ -195,6 +199,9 @@ Value::Value(const Json::Value& json)
const auto& jutype = json["utype"]; const auto& jutype = json["utype"];
if (jutype.isString()) if (jutype.isString())
user_type = jutype.asString(); user_type = jutype.asString();
const auto& jprio = json["prio"];
if (jprio.isIntegral())
priority = jprio.asUInt();
} }
Json::Value Json::Value
...@@ -219,6 +226,8 @@ Value::toJson() const ...@@ -219,6 +226,8 @@ Value::toJson() const
if (not user_type.empty()) if (not user_type.empty())
val["utype"] = user_type; val["utype"] = user_type;
} }
if (priority)
val["prio"] = priority;
return val; return val;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment