void hosts::do_store(const address& host, result_handler handler) { if (!host.is_valid()) log::debug(LOG_PROTOCOL) << "Invalid host address from peer"; else if (find(host) != buffer_.end()) log::debug(LOG_PROTOCOL) << "Redundant host address from peer"; else buffer_.push_back(host); // We don't treat invalid address as an error, just log it. handler(error::success); }
code hosts::store(const address& host) { if (!host.is_valid()) { LOG_DEBUG(LOG_NETWORK) << "Invalid host address from peer"; // We don't treat invalid address as an error, just log it. return error::success; } /////////////////////////////////////////////////////////////////////////// // Critical Section mutex_.lock_upgrade(); if (stopped_) { mutex_.unlock_upgrade(); //--------------------------------------------------------------------- return error::service_stopped; } if (find(host) == buffer_.end()) { mutex_.unlock_upgrade_and_lock(); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ buffer_.push_back(host); mutex_.unlock(); //--------------------------------------------------------------------- return error::success; } mutex_.unlock_upgrade(); /////////////////////////////////////////////////////////////////////////// LOG_DEBUG(LOG_NETWORK) << "Redundant host address from peer"; // We don't treat redundant address as an error, just log it. return error::success; }