From 42068aae4d21a8ef3af5a1acc2d78c0a868d688d Mon Sep 17 00:00:00 2001 From: Bart Wyatt Date: Tue, 18 Sep 2018 17:55:02 -0400 Subject: [PATCH] PORT Consolidated Security Fixes for 1.2.6 to 1.3.0 - Consider peers for syncing at most once Co-authored-by: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> --- plugins/net_plugin/net_plugin.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/net_plugin/net_plugin.cpp b/plugins/net_plugin/net_plugin.cpp index d907e7f7390..bb3b33a8f23 100644 --- a/plugins/net_plugin/net_plugin.cpp +++ b/plugins/net_plugin/net_plugin.cpp @@ -1344,19 +1344,16 @@ namespace eosio { } //scan the list of peers looking for another able to provide sync blocks. - while (cptr != cend) { + auto cstart_it = cptr; + do { //select the first one which is current and break out. - if ((*cptr)->current()) { + if((*cptr)->current()) { source = *cptr; break; } - else { - // advance the iterator in a round robin fashion. - if (++cptr == my_impl->connections.end()) { + if(++cptr == my_impl->connections.end()) cptr = my_impl->connections.begin(); - } - } - } + } while(cptr != cstart_it); // no need to check the result, either source advanced or the whole list was checked and the old source is reused. } }