diff --git a/sources.c b/sources.c index 2ba595b..3b1766b 100644 --- a/sources.c +++ b/sources.c @@ -1222,12 +1222,23 @@ SRC_SelectSource(SRC_Instance updated_inst) assert(depth == 0 && trust_depth == 0); assert(2 * n_sel_sources == n_endpoints); - if ((best_trust_depth == 0 && best_depth <= n_sel_sources / 2) || - (best_trust_depth > 0 && best_trust_depth <= n_sel_trust_sources / 2)) { + if (best_trust_depth > 0) { + best_depth = best_trust_depth; + n_sel_sources = n_sel_trust_sources; + } + + if (best_depth <= n_sel_sources / 2) { /* Could not even get half the reachable (trusted) sources to agree */ if (!reported_no_majority) { - log_selection_message(LOGS_WARN, "Can't synchronise: no majority"); + if (best_depth < 2) + log_selection_message(LOGS_WARN, "%s (no agreement among %d %ssources)", + "Can't synchronise: no majority", n_sel_sources, + best_trust_depth > 0 ? "trusted " : ""); + else + log_selection_message(LOGS_WARN, "%s (only %d of %d %ssources agree)", + "Can't synchronise: no majority", best_depth, + n_sel_sources, best_trust_depth > 0 ? "trusted " : ""); reported_no_majority = 1; report_selection_loss = 0; } diff --git a/test/simulation/009-sourceselection b/test/simulation/009-sourceselection index 547c376..139b6aa 100755 --- a/test/simulation/009-sourceselection +++ b/test/simulation/009-sourceselection @@ -24,6 +24,12 @@ for falsetickers in 3 4; do # These check are expected to fail check_source_selection && test_fail check_sync && test_fail + + if [ $falsetickers = 3 ]; then + check_log_messages "Can't synchronise: no majority (only 2 of 5 sources agree)" 1 1 || test_fail + else + check_log_messages "Can't synchronise: no majority (no agreement among 5 sources)" 1 1 || test_fail + fi done # Sources with large asymmetric delay should be excluded diff --git a/test/simulation/148-replacement b/test/simulation/148-replacement index d09fba6..ee8b2e2 100755 --- a/test/simulation/148-replacement +++ b/test/simulation/148-replacement @@ -68,7 +68,7 @@ check_source_selection && test_fail check_packet_interval || test_fail check_sync || test_fail -check_log_messages "Can't synchronise: no majority" 1 1 || test_fail +check_log_messages "Can't synchronise: no majority (no agreement among 2 sources)" 1 1 || test_fail check_log_messages "Detected falseticker" 0 2 || test_fail check_log_messages "Source 192.168.123.. replaced with" 3 60 || test_fail check_log_messages "Source 192.168.123.1 replaced with" 1 25 || test_fail