token_metadata expose the token and token mapping

This adds an API that expose the token to endpoint mapping and the token
that are associate with an address.

Both method will be used by the API to expose the tokens.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
Amnon Heiman
2015-05-26 12:12:46 +03:00
parent a28b90bfd3
commit df7a06c8dc
2 changed files with 13 additions and 0 deletions

View File

@@ -27,6 +27,15 @@ const std::vector<token>& token_metadata::sorted_tokens() const {
return _sorted_tokens;
}
std::vector<token> token_metadata::get_tokens(const inet_address& addr) const {
std::vector<token> res;
for (auto&& i : _token_to_endpoint_map) {
if (i.second == addr) {
res.push_back(i.first);
}
}
return res;
}
/**
* Update token map with a single token/endpoint pair in normal state.
*/

View File

@@ -49,6 +49,10 @@ public:
const token& first_token(const token& start);
size_t first_token_index(const token& start);
std::experimental::optional<inet_address> get_endpoint(const token& token) const;
std::vector<token> get_tokens(const inet_address& addr) const;
const std::map<token, inet_address>& get_token_to_endpoint() const {
return _token_to_endpoint_map;
}
};
}