Commit 3a1d55ef authored by Ivan Vilata-i-Balaguer's avatar Ivan Vilata-i-Balaguer
Browse files

Cache URI swarm name prefix.

To avoid having to build the whole name (which implies encoding the injector
public key) every time a URI swarm name is needed.
parent 0d6b09b4
......@@ -19,12 +19,17 @@ std::string compute_bridge_swarm_name(const ouinet::util::Ed25519PublicKey& pubk
, "/bridges");
}
std::string compute_uri_swarm_name(const ouinet::util::Ed25519PublicKey& pubkey, unsigned protocol_version, boost::string_view key)
std::string compute_uri_swarm_prefix(const ouinet::util::Ed25519PublicKey& pubkey, unsigned protocol_version)
{
return util::str
( "ed25519:", util::base32up_encode(pubkey.serialize())
, "/v", protocol_version
, "/uri/", key);
, "/uri/");
}
std::string compute_uri_swarm_name(boost::string_view prefix, boost::string_view uri)
{
return util::str(prefix, uri);
}
}} // namespaces
......@@ -38,9 +38,13 @@ std::string compute_injector_swarm_name( const ouinet::util::Ed25519PublicKey&
std::string compute_bridge_swarm_name( const ouinet::util::Ed25519PublicKey&
, unsigned protocol_version);
std::string compute_uri_swarm_name( const ouinet::util::Ed25519PublicKey&
, unsigned protocol_version
, boost::string_view key);
// Reuse the resulting prefix with `compute_uri_swarm_name` below.
std::string compute_uri_swarm_prefix( const ouinet::util::Ed25519PublicKey&
, unsigned protocol_version);
// Reuse the prefix resulting from `compute_uri_swarm_prefix` above.
std::string compute_uri_swarm_name( boost::string_view prefix
, boost::string_view uri);
}} // namespaces
......@@ -36,6 +36,7 @@ struct Client::Impl {
asio::executor ex;
shared_ptr<bt::MainlineDht> dht;
string uri_swarm_prefix;
util::Ed25519PublicKey cache_pk;
fs::path cache_dir;
unique_ptr<cache::AbstractHttpStore> http_store;
......@@ -59,6 +60,8 @@ struct Client::Impl {
, log_level_t log_level)
: ex(dht_->get_executor())
, dht(move(dht_))
, uri_swarm_prefix(bep5::compute_uri_swarm_prefix
(cache_pk, http_::protocol_version_current))
, cache_pk(cache_pk)
, cache_dir(move(cache_dir))
, http_store(move(http_store))
......@@ -70,8 +73,7 @@ struct Client::Impl {
std::string compute_swarm_name(boost::string_view dht_group) const {
return bep5::compute_uri_swarm_name(
cache_pk,
http_::protocol_version_current,
uri_swarm_prefix,
dht_group);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment