sources: add flag that source is active

When source is set as active, it's receiving reachability updates (e.g.
offline NTP sources are not active).

Also add function to count active sources.
This commit is contained in:
Miroslav Lichvar
2014-04-10 16:53:28 +02:00
parent bc6b40568d
commit 8671002bd7
4 changed files with 60 additions and 12 deletions

View File

@@ -91,6 +91,9 @@ struct SRC_Instance_Record {
/* Flag indicating that we can use this source as a reference */
int selectable;
/* Flag indicating that the source is updating reachability */
int active;
/* Reachability register */
int reachability;
@@ -215,6 +218,7 @@ SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, SRC_SelectOpt
result->leap_status = LEAP_Normal;
result->ref_id = ref_id;
result->ip_addr = addr;
result->active = 0;
result->selectable = 0;
result->reachability = 0;
result->reachability_size = 0;
@@ -316,6 +320,22 @@ void SRC_AccumulateSample
/* ================================================== */
void
SRC_SetActive(SRC_Instance inst)
{
inst->active = 1;
}
/* ================================================== */
void
SRC_UnsetActive(SRC_Instance inst)
{
inst->active = 0;
}
/* ================================================== */
void
SRC_SetSelectable(SRC_Instance inst)
{
@@ -1188,6 +1208,20 @@ SRC_ReadNumberOfSources(void)
/* ================================================== */
int
SRC_ActiveSources(void)
{
int i, r;
for (i = r = 0; i < n_sources; i++)
if (sources[i]->active)
r++;
return r;
}
/* ================================================== */
int
SRC_ReportSource(int index, RPT_SourceReport *report, struct timeval *now)
{