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
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment