Skip to content

Commit be2682e

Browse files
davidv1992rnijveld
authored andcommitted
Fixed slave only mode.
1 parent 5901729 commit be2682e

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

statime/src/port/mod.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -380,22 +380,37 @@ impl<'a, A: AcceptableMasterList, C: Clock, F: Filter, R: Rng, S: PtpInstanceSta
380380

381381
/// Handle the announce receipt timer going off
382382
pub fn handle_announce_receipt_timer(&mut self) -> PortActionIterator<'_> {
383-
// we didn't hear announce messages from other masters, so become master
384-
// ourselves
385-
match self.port_state {
386-
PortState::Master => (),
387-
_ => self.set_forced_port_state(PortState::Master),
388-
}
383+
if self
384+
.instance_state
385+
.with_ref(|state| state.default_ds.slave_only)
386+
{
387+
// We didn't hear messages from the master anymore, reset to the listening state
388+
// since we can't become master.
389+
if !matches!(self.port_state, PortState::Listening) {
390+
self.set_forced_port_state(PortState::Listening);
391+
}
389392

390-
// Immediately start sending syncs and announces
391-
actions![
392-
PortAction::ResetAnnounceTimer {
393-
duration: core::time::Duration::from_secs(0)
394-
},
395-
PortAction::ResetSyncTimer {
396-
duration: core::time::Duration::from_secs(0)
393+
// consistent with Port<InBmca>::new()
394+
let duration = self.config.announce_duration(&mut self.rng);
395+
actions![PortAction::ResetAnnounceReceiptTimer { duration }]
396+
} else {
397+
// we didn't hear announce messages from other masters, so become master
398+
// ourselves
399+
match self.port_state {
400+
PortState::Master => (),
401+
_ => self.set_forced_port_state(PortState::Master),
397402
}
398-
]
403+
404+
// Immediately start sending syncs and announces
405+
actions![
406+
PortAction::ResetAnnounceTimer {
407+
duration: core::time::Duration::from_secs(0)
408+
},
409+
PortAction::ResetSyncTimer {
410+
duration: core::time::Duration::from_secs(0)
411+
}
412+
]
413+
}
399414
}
400415

401416
/// Handle the filter update timer going off

0 commit comments

Comments
 (0)