From df7a06c8dcd35068a030b25c91d629fc0ceedfa5 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Tue, 26 May 2015 12:12:46 +0300 Subject: [PATCH] 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 --- locator/token_metadata.cc | 9 +++++++++ locator/token_metadata.hh | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/locator/token_metadata.cc b/locator/token_metadata.cc index 1fb61c939a..923910a876 100644 --- a/locator/token_metadata.cc +++ b/locator/token_metadata.cc @@ -27,6 +27,15 @@ const std::vector& token_metadata::sorted_tokens() const { return _sorted_tokens; } +std::vector token_metadata::get_tokens(const inet_address& addr) const { + std::vector 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. */ diff --git a/locator/token_metadata.hh b/locator/token_metadata.hh index 49f766b403..e86539305d 100644 --- a/locator/token_metadata.hh +++ b/locator/token_metadata.hh @@ -49,6 +49,10 @@ public: const token& first_token(const token& start); size_t first_token_index(const token& start); std::experimental::optional get_endpoint(const token& token) const; + std::vector get_tokens(const inet_address& addr) const; + const std::map& get_token_to_endpoint() const { + return _token_to_endpoint_map; + } }; }