Skip to content

Commit

Permalink
adjust first beacon offset
Browse files Browse the repository at this point in the history
This adjusts the beaceon time to select a beacon time in the full first window, and moves it to the next window if in the past
  • Loading branch information
madninja committed Nov 21, 2023
1 parent 8b38ed9 commit d481142
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/beaconer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,17 @@ fn mk_next_beacon_time(
next_segment + random_duration(interval)
} else {
// previous segment: Pick a time in the remainder of this
// segment
// segment. This really only happens as the current time enters
// a new segment
current_time + random_duration(next_segment - current_time)
}
}
// No next beacon time pick a time in the remainder of this segment
None => current_time + random_duration(next_segment - current_time),
// No next beacon time pick a random time in this segment as the beacon
// time and use this function again
None => {
let beacon_time = current_segment + random_duration(interval);
mk_next_beacon_time(current_time, Some(beacon_time), interval)
}
}
}

Expand Down Expand Up @@ -415,12 +420,12 @@ mod test {
let next_segment = current_segment + interval;
assert!(current_time < next_segment);

// No beacon time, should pick a time in the current segment
// No beacon time, should pick a time in the remainder of
// the current segment or in the next segment
{
let next_time = mk_next_beacon_time(current_time, None, interval);
assert!(next_time > current_time);
assert!(next_time < next_segment);
assert_eq!(current_segment, duration_trunc(next_time, interval));
assert!(next_time < next_segment + interval);
}

// Beacon time in the future
Expand Down

0 comments on commit d481142

Please sign in to comment.