41 lock_guard<mutex> lock(m_mutex);
42 ProxyMapT::iterator iter = m_forward_map.find(proxy);
43 if (iter != m_forward_map.end() && (*iter).second.addr == addr) {
44 if ((*iter).second.hostname != hostname)
45 (*iter).second.hostname = hostname;
48 invalidate_old_mapping(proxy, addr, invalidated_map);
51 m_reverse_map[addr] = proxy;
57 lock_guard<mutex> lock(m_mutex);
58 char *line, *proxy, *hostname, *addr_str, *end_nl, *end_tab;
60 for (line = strtok_r((
char *)mappings.c_str(),
"\n", &end_nl); line;
61 line = strtok_r(0,
"\n", &end_nl)) {
62 proxy = strtok_r(line,
"\t", &end_tab);
64 hostname = strtok_r(0,
"\t", &end_tab);
66 addr_str = strtok_r(0,
"\t", &end_tab);
70 ProxyMapT::iterator iter = m_forward_map.find(proxy);
72 if (!strcmp(hostname,
"--DELETED--")) {
73 if (iter != m_forward_map.end()) {
74 if ((*iter).second.addr != addr) {
75 HT_WARNF(
"Proxy map removal message for %s contains %s, but map "
76 "contains %s", proxy, addr_str,
77 (*iter).second.addr.format().c_str());
79 invalidate(proxy, invalidated_map);
82 HT_WARNF(
"Removal message received for %s, but not in map.", proxy);
86 if (iter != m_forward_map.end() && (*iter).second.addr == addr) {
87 if ((*iter).second.hostname != hostname)
88 (*iter).second.hostname = hostname;
91 invalidate_old_mapping(proxy, addr, invalidated_map);
94 m_reverse_map[addr] = proxy;
101 lock_guard<mutex> lock(m_mutex);
102 invalidate(proxy, remove_map);
109 lock_guard<mutex> lock(m_mutex);
110 ProxyMapT::iterator iter = m_forward_map.find(proxy);
111 if (iter == m_forward_map.end())
113 addr = (*iter).second.addr;
114 hostname = (*iter).second.hostname;
119 lock_guard<mutex> lock(m_mutex);
121 if (iter != m_reverse_map.end())
122 return (*iter).second;
128 lock_guard<mutex> lock(m_mutex);
132 for (ProxyMapT::iterator iter = m_forward_map.begin(); iter != m_forward_map.end(); ++iter)
133 payload += (*iter).first +
"\t" + (*iter).second.hostname +
"\t" + (*iter).second.addr.format() +
"\n";
134 CommBufPtr cbuf = make_shared<CommBuf>(header, payload.length());
135 if (payload.length())
136 cbuf->append_bytes((uint8_t *)payload.c_str(), payload.length());
144 ProxyMapT::iterator iter;
148 if ((iter = m_forward_map.find(proxy)) != m_forward_map.end()) {
149 if ((*iter).second.addr != addr) {
150 invalidated_map[(*iter).first] = (*iter).second;
151 m_reverse_map.erase( (*iter).second.addr );
152 m_forward_map.erase((*iter).first);
157 if ((rev_iter = m_reverse_map.find(addr)) != m_reverse_map.end()) {
158 if ((*rev_iter).second != proxy) {
159 invalidated_map[(*rev_iter).second] =
ProxyAddressInfo(
"unknown", (*rev_iter).first);
160 m_forward_map.erase((*rev_iter).second);
161 m_reverse_map.erase((*rev_iter).first);
168 ProxyMapT::iterator iter;
173 if ((iter = m_forward_map.find(proxy)) != m_forward_map.end()) {
174 (*iter).second.hostname =
"--DELETED--";
175 invalidated_map[(*iter).first] = (*iter).second;
176 addr = (*iter).second.addr;
177 m_forward_map.erase((*iter).first);
183 if ((rev_iter = m_reverse_map.find(addr)) != m_reverse_map.end()) {
184 if ((*rev_iter).second == proxy)
185 m_reverse_map.erase((*rev_iter).first);
190 lock_guard<mutex> lock(m_mutex);
191 ProxyMapT::iterator iter;
193 for (iter = m_forward_map.begin(); iter != m_forward_map.end(); ++iter)
194 str +=
format(
"(%s,%s,%s),", (*iter).first.c_str(),
195 (*iter).second.hostname.c_str(), (*iter).second.addr.format().c_str());
#define HT_WARNF(msg,...)
std::string String
A String is simply a typedef to std::string.
bool get_mapping(const String &proxy, String &hostname, InetAddr &addr)
Returns proxy map data for proxy.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Po::typed_value< String > * str(String *v=0)
CommBufPtr create_update_message()
Creates a proxy map update message.
String get_proxy(InetAddr &addr)
Returns proxy name for addr.
Declarations for ProxyMap.
Unordered map specialization for InetAddr keys.
Encapsulate an internet address.
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Holds address and hostname associated with a proxy name.
void invalidate_old_mapping(const String &proxy, const InetAddr &addr, ProxyMapT &invalidated_mappings)
Invalidates (removes) mapping, if changed, from forward and reverse maps.
std::unordered_map< String, ProxyAddressInfo > ProxyMapT
Forward mapping hash type from proxy name to ProxyAddressInfo.
Compatibility Macros for C/C++.
void remove_mapping(const String &proxy, ProxyMapT &remove_map)
Removes a mapping.
void update_mappings(String &mappings, ProxyMapT &invalidated_map, ProxyMapT &new_map)
Update mappings from proxy map update message string.
void invalidate(const String &proxy, ProxyMapT &invalidated_mappings)
Invalidates (removes) mapping from forward and reverse maps.
void update_mapping(const String &proxy, const String &hostname, const InetAddr &addr, ProxyMapT &invalidated_map, ProxyMapT &new_map)
Updates a proxy name mapping.
String extensions and helpers: sets, maps, append operators etc.