SON conn. pool
This commit is contained in:
parent
be580e0c34
commit
6febed5a36
1 changed files with 0 additions and 63 deletions
|
|
@ -982,67 +982,4 @@ void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
|
|||
}
|
||||
}
|
||||
|
||||
hive_rpc_client *sidechain_net_handler_hive::get_active_rpc_client()
|
||||
{
|
||||
return rpc_clients[n_active_rpc_client];
|
||||
}
|
||||
|
||||
void sidechain_net_handler_hive::select_active_rpc_client()
|
||||
{
|
||||
//ilog("n_active_rpc_client=${n}", ("n", n_active_rpc_client));
|
||||
if (rpc_clients.size())
|
||||
{
|
||||
int best_n = -1;
|
||||
int best_quality = -1;
|
||||
|
||||
std::vector<uint64_t> head_block_numbers;
|
||||
head_block_numbers.resize(rpc_clients.size());
|
||||
|
||||
for (size_t n=0; n < rpc_clients.size(); n++) {
|
||||
hive_rpc_client *rpc_client = rpc_clients[n];
|
||||
int quality = 0;
|
||||
head_block_numbers[n] = std::numeric_limits<uint64_t>::max();
|
||||
|
||||
// make the ping
|
||||
fc::time_point t_sent = fc::time_point::now();
|
||||
const std::string reply = rpc_client->database_api_get_dynamic_global_properties();
|
||||
fc::time_point t_received = fc::time_point::now();
|
||||
if (!reply.empty()) {
|
||||
std::stringstream ss(reply);
|
||||
boost::property_tree::ptree json;
|
||||
boost::property_tree::read_json(ss, json);
|
||||
if (json.count("result")) {
|
||||
uint64_t head_block_number = json.get<uint64_t>("result.head_block_number");
|
||||
int t = (t_received - t_sent).count();
|
||||
t += rand() % 10;
|
||||
FC_ASSERT(t != -1);
|
||||
head_block_numbers[n] = head_block_number;
|
||||
FC_ASSERT(head_block_numbers[n] != std::numeric_limits<uint64_t>::max());
|
||||
static const int t_limit = 10*1000000; // 10 sec
|
||||
if (t < t_limit)
|
||||
quality = t_limit - t; // the less time, the higher quality
|
||||
}
|
||||
}
|
||||
|
||||
//ilog("Hive RPC qual: ${n} -> ${q}", ("n", n)("q", quality));
|
||||
|
||||
// look for the best quality
|
||||
if (quality > best_quality) {
|
||||
best_n = n;
|
||||
best_quality = quality;
|
||||
}
|
||||
}
|
||||
|
||||
FC_ASSERT(best_n != -1 && best_quality != -1);
|
||||
if (best_n != n_active_rpc_client) { // if the best client is not the current one, ...
|
||||
uint64_t active_head_block_number = head_block_numbers[n_active_rpc_client];
|
||||
if (active_head_block_number == std::numeric_limits<uint64_t>::max() // ... and the current one has no known head block...
|
||||
|| head_block_numbers[best_n] >= active_head_block_number) { // ...or the best client's head is more recent than the current, ...
|
||||
n_active_rpc_client = best_n; // ...then select new one
|
||||
ilog("!!! Hive rpc_client reselected, now ${n}", ("n", n_active_rpc_client));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
Loading…
Reference in a new issue