return response;
}
-int delete_clients() {
+int delete_client(int client_id) {
int response = 0; // okay unless something happens
- int i;
- for (i = 0; i < MAX_CLIENTS; i++) {
- if (clients[i].shm_interface_name[0] != '\0') {
- if (clients[i].shared_memory != NULL) {
- // mmap cleanup
- if (munmap(clients[i].shared_memory, sizeof(struct shm_structure)) != 0) {
- debug(1, "error unmapping shared memory");
- response = -1;
- }
- // shm_open cleanup
- if (shm_unlink(clients[i].shm_interface_name) == -1) {
- debug(1, "error unlinking shared memory \"%s\"", clients[i].shm_interface_name);
- response = -1;
- }
+ if (clients[client_id].shm_interface_name[0] != '\0') {
+ if (clients[client_id].shared_memory != NULL) {
+ // mmap cleanup
+ if (munmap(clients[client_id].shared_memory, sizeof(struct shm_structure)) != 0) {
+ debug(1, "error unmapping shared memory");
+ response = -1;
+ }
+ // shm_open cleanup
+ if (shm_unlink(clients[client_id].shm_interface_name) == -1) {
+ debug(1, "error unlinking shared memory \"%s\"", clients[client_id].shm_interface_name);
+ response = -1;
}
- clients[i].shm_interface_name[0] = '\0'; // remove the name, just in case
}
+ clients[client_id].shm_interface_name[0] = '\0'; // remove the name to signify it's vacant
}
return response;
}
+int delete_clients() {
+ int response = 0; // okay unless something happens
+ int i;
+ for (i = 0; i < MAX_CLIENTS; i++)
+ if (delete_client(i) != 0)
+ response = -1;
+ return response;
+}
+
int find_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info) {
// return the index of the clock in the clock information arrays or -1
int response = -1;
}
}
-void debug_log_nqptp_status(int level) {
-/*
- int records_in_use = 0;
- int i;
- for (i = 0; i < MAX_CLOCKS; i++)
- if ((clocks_private[i].flags & (1 << clock_is_in_use)) != 0)
- records_in_use++;
- debug(level, "");
- if (records_in_use > 0) {
- debug(level, "Current NQPTP Status:");
- uint32_t peer_mask = (1 << clock_is_a_timing_peer);
- uint32_t peer_clock_mask = peer_mask | (1 << clock_is_valid);
- uint32_t peer_master_mask = peer_clock_mask | (1 << clock_is_master);
- uint32_t peer_becoming_master_mask = peer_clock_mask | (1 << clock_is_becoming_master);
- uint32_t non_peer_clock_mask = (1 << clock_is_valid);
- uint32_t non_peer_master_mask = non_peer_clock_mask | (1 << clock_is_master);
- for (i = 0; i < MAX_CLOCKS; i++) {
- if ((clocks_private[i].flags & (1 << clock_is_in_use)) != 0) {
- if ((clocks_private[i].flags & peer_master_mask) == peer_master_mask) {
- debug(level, " Peer Master: %" PRIx64 " %s.", clocks_private[i].clock_id,
- clocks_private[i].ip);
- } else if ((clocks_private[i].flags & peer_becoming_master_mask) ==
- peer_becoming_master_mask) {
- debug(level, " Peer Becoming Master: %" PRIx64 " %s.", clocks_private[i].clock_id,
- clocks_private[i].ip);
- } else if ((clocks_private[i].flags & peer_clock_mask) == peer_clock_mask) {
- debug(level, " Peer Clock: %" PRIx64 " %s.", clocks_private[i].clock_id,
- clocks_private[i].ip);
- } else if ((clocks_private[i].flags & peer_mask) == peer_mask) {
- debug(level, " Peer: %s.", clocks_private[i].ip);
- } else if ((clocks_private[i].flags & non_peer_master_mask) == non_peer_master_mask) {
- debug(level, " Non Peer Master: %" PRIx64 " %s.", clocks_private[i].clock_id,
- clocks_private[i].ip);
- } else if ((clocks_private[i].flags & non_peer_clock_mask) == non_peer_clock_mask) {
- debug(level, " Non Peer Clock: %16" PRIx64 " %s.", clocks_private[i].clock_id,
- clocks_private[i].ip);
- } else {
- debug(level, " Non Peer Record: %s.", clocks_private[i].ip);
+void debug_log_nqptp_status(__attribute__((unused)) int level) {
+ /*
+ int records_in_use = 0;
+ int i;
+ for (i = 0; i < MAX_CLOCKS; i++)
+ if ((clocks_private[i].flags & (1 << clock_is_in_use)) != 0)
+ records_in_use++;
+ debug(level, "");
+ if (records_in_use > 0) {
+ debug(level, "Current NQPTP Status:");
+ uint32_t peer_mask = (1 << clock_is_a_timing_peer);
+ uint32_t peer_clock_mask = peer_mask | (1 << clock_is_valid);
+ uint32_t peer_master_mask = peer_clock_mask | (1 << clock_is_master);
+ uint32_t peer_becoming_master_mask = peer_clock_mask | (1 << clock_is_becoming_master);
+ uint32_t non_peer_clock_mask = (1 << clock_is_valid);
+ uint32_t non_peer_master_mask = non_peer_clock_mask | (1 << clock_is_master);
+ for (i = 0; i < MAX_CLOCKS; i++) {
+ if ((clocks_private[i].flags & (1 << clock_is_in_use)) != 0) {
+ if ((clocks_private[i].flags & peer_master_mask) == peer_master_mask) {
+ debug(level, " Peer Master: %" PRIx64 " %s.", clocks_private[i].clock_id,
+ clocks_private[i].ip);
+ } else if ((clocks_private[i].flags & peer_becoming_master_mask) ==
+ peer_becoming_master_mask) {
+ debug(level, " Peer Becoming Master: %" PRIx64 " %s.", clocks_private[i].clock_id,
+ clocks_private[i].ip);
+ } else if ((clocks_private[i].flags & peer_clock_mask) == peer_clock_mask) {
+ debug(level, " Peer Clock: %" PRIx64 " %s.", clocks_private[i].clock_id,
+ clocks_private[i].ip);
+ } else if ((clocks_private[i].flags & peer_mask) == peer_mask) {
+ debug(level, " Peer: %s.", clocks_private[i].ip);
+ } else if ((clocks_private[i].flags & non_peer_master_mask) == non_peer_master_mask) {
+ debug(level, " Non Peer Master: %" PRIx64 " %s.", clocks_private[i].clock_id,
+ clocks_private[i].ip);
+ } else if ((clocks_private[i].flags & non_peer_clock_mask) == non_peer_clock_mask) {
+ debug(level, " Non Peer Clock: %16" PRIx64 " %s.", clocks_private[i].clock_id,
+ clocks_private[i].ip);
+ } else {
+ debug(level, " Non Peer Record: %s.", clocks_private[i].ip);
+ }
}
}
+ } else {
+ debug(level, "Current NQPTP Status: no records in use.");
}
- } else {
- debug(level, "Current NQPTP Status: no records in use.");
- }
-*/
+ */
}
int uint32_cmp(uint32_t a, uint32_t b, const char *cause) {
}
}
-void old_update_master() {
-
- // This implements the IEEE 1588-2008 best master clock algorithm.
-
- // However, since nqptp is not a ptp clock, some of it doesn't apply.
- // Specifically, the Identity of Receiver stuff doesn't apply, since the
- // program is merely monitoring Announce message data and isn't a PTP clock itself
- // and thus does not have any kind or receiver identity itself.
-
- // Clock information coming from the same clock over IPv4 and IPv6 should have different
- // port numbers.
-
- // Figure 28 can be therefore be simplified considerably:
-
- // Since nqptp can not be a receiver, and since nqptp can not originate a clock
- // (and anyway nqptp filters out packets coming from self)
- // we can do a single comparison of stepsRemoved and pick the shorter, if any.
-
- // Figure 28 reduces to checking steps removed and then, if necessary, checking identities.
- // If we see two identical sets of information, it is an error,
- // but we leave things as they are.
- int old_master = -1;
- // find the current master clock if there is one and turn off all mastership
- int i;
- for (i = 0; i < MAX_CLOCKS; i++) {
- if ((clocks_private[i].flags & (1 << clock_is_master)) != 0)
- if (old_master == -1)
- old_master = i; // find old master
- clocks_private[i].flags &= ~(1 << clock_is_master); // turn them all off
- clocks_private[i].flags &= ~(1 << clock_is_becoming_master); // turn them all off
- }
-
- int best_so_far = -1;
- int timing_peer_count = 0;
- uint32_t acceptance_mask =
-// (1 << clock_is_qualified) | (1 << clock_is_a_timing_peer) | (1 << clock_is_valid);
- (1 << clock_is_qualified) | (1 << clock_is_a_timing_peer);
- for (i = 0; i < MAX_CLOCKS; i++) {
- if ((clocks_private[i].flags & acceptance_mask) == acceptance_mask) {
- // found a possible clock candidate
- timing_peer_count++;
- int outcome;
- if (best_so_far == -1) {
- best_so_far = i;
- } else {
- // Do the data set comparison detailed in Figure 27 and Figure 28 on pp89-90
- if (clocks_private[i].grandmasterIdentity ==
- clocks_private[best_so_far].grandmasterIdentity) {
- // Do the relevant part of Figure 28:
- outcome = uint32_cmp(clocks_private[i].stepsRemoved,
- clocks_private[best_so_far].stepsRemoved, "steps removed");
- // we need to check the portIdentify, which is the clock_id and the clock_port_number
- if (outcome == 0)
- outcome = uint64_cmp(clocks_private[i].clock_id, clocks_private[best_so_far].clock_id,
- "clock id");
- if (outcome == 0)
- outcome =
- uint32_cmp(clocks_private[i].clock_port_number,
- clocks_private[best_so_far].clock_port_number, "clock port number");
- if (outcome == 0) {
- debug(1,
- "Best Master Clock algorithm: two separate but identical potential clock "
- "masters: %" PRIx64 ".",
- clocks_private[best_so_far].clock_id);
- }
-
- } else {
- outcome =
- uint32_cmp(clocks_private[i].grandmasterPriority1,
- clocks_private[best_so_far].grandmasterPriority1, "grandmasterPriority1");
- if (outcome == 0)
- outcome = uint32_cmp(clocks_private[i].grandmasterClass,
- clocks_private[best_so_far].grandmasterClass, "grandmasterClass");
- if (outcome == 0)
- outcome =
- uint32_cmp(clocks_private[i].grandmasterAccuracy,
- clocks_private[best_so_far].grandmasterAccuracy, "grandmasterAccuracy");
- if (outcome == 0)
- outcome =
- uint32_cmp(clocks_private[i].grandmasterVariance,
- clocks_private[best_so_far].grandmasterVariance, "grandmasterVariance");
- if (outcome == 0)
- outcome = uint32_cmp(clocks_private[i].grandmasterPriority2,
- clocks_private[best_so_far].grandmasterPriority2,
- "grandmasterPriority2");
- if (outcome == 0)
- // this can't fail, as it's a condition of entering this section that they are different
- outcome =
- uint64_cmp(clocks_private[i].grandmasterIdentity,
- clocks_private[best_so_far].grandmasterIdentity, "grandmasterIdentity");
- }
- if (outcome == -1)
- best_so_far = i;
- }
- }
- }
- if (best_so_far == -1) {
- // no master clock
- // if (old_master != -1) {
- // but there was a master clock, so remove it
- debug(1, "Remove master clock.");
- update_master_clock_info(0, 0, NULL, 0, 0, 0);
- //}
- if (timing_peer_count == 0)
- debug(2, "no valid qualified clocks ");
- else
- debug(1, "no master clock!");
- } else {
- // we found a master clock
-
- if (old_master != best_so_far) {
- // if the master is a new one
- clocks_private[best_so_far].flags |= (1 << clock_is_becoming_master);
- } else {
- // if it's the same one as before
- clocks_private[best_so_far].flags |= (1 << clock_is_master);
- }
- }
- debug_log_nqptp_status(2);
-}
-
void update_master(int client_id) {
- old_update_master(); // TODO -- for compatibility
// This implements the IEEE 1588-2008 best master clock algorithm.
int best_so_far = -1;
int timing_peer_count = 0;
-// uint32_t clock_specific_acceptance_mask = (1 << clock_is_qualified) | (1 << clock_is_valid);
+ // uint32_t clock_specific_acceptance_mask = (1 << clock_is_qualified) | (1 << clock_is_valid);
uint32_t clock_specific_acceptance_mask = (1 << clock_is_qualified);
uint32_t client_specific_acceptance_mask = (1 << clock_is_a_timing_peer);
for (i = 0; i < MAX_CLOCKS; i++) {
// no master clock
// if (old_master != -1) {
// but there was a master clock, so remove it
- debug(1, "Remove master clock.");
+ debug(1, "Remove master clock information from interface %s.", get_client_name(client_id));
update_master_clock_info(client_id, 0, NULL, 0, 0, 0);
//}
if (timing_peer_count == 0)
}
if (clock_is_a_master_somewhere == 0) {
clocks_private[best_so_far].client_flags[client_id] |= (1 << clock_is_becoming_master);
- // clocks_private[best_so_far].flags |= (1 << clock_is_becoming_master); // to avoid searching
+ clocks_private[best_so_far].last_sync_time = 0; // declare it was never synced before
+
} else {
- clocks_private[best_so_far].client_flags[client_id] |= (1 << clock_is_master);
- // the smi will be updated when the next followup occurs
+ clocks_private[best_so_far].client_flags[client_id] |= (1 << clock_is_master);
}
} else {
// if it's the same one as before
void update_master_clock_info(int client_id, uint64_t master_clock_id, const char *ip,
uint64_t local_time, uint64_t local_to_master_offset,
uint64_t mastership_start_time) {
- // for compatibility
- old_update_master_clock_info(master_clock_id, ip, local_time, local_to_master_offset,
- mastership_start_time);
if (clients[client_id].shm_interface_name[0] != '\0') {
// debug(1,"update_master_clock_info start");
if (clients[client_id].shared_memory->master_clock_id != master_clock_id)
typedef enum {
clock_is_in_use,
clock_is_one_of_ours,
-// clock_is_valid,
clock_is_a_timing_peer,
clock_is_qualified,
clock_is_becoming_master,
clock_is_master
} clock_flags;
-/*
-typedef enum {
- clock_is_a_timing_peer,
- clock_is_becoming_master,
- clock_is_master
-} client_flags;
-*/
-
// information about each clock source
typedef struct {
char ip[64]; // 64 is nicely aligned and bigger than INET6_ADDRSTRLEN (46)
int find_client_id(char *client_shared_memory_interface_name);
int get_client_id(char *client_shared_memory_interface_name);
-const char *get_client_name(int id);
+const char *get_client_name(int client_id);
+int delete_client(int client_id);
int delete_clients();
extern clock_source_private_data clocks_private[MAX_CLOCKS];
char *smi_name = strsep(&ip_list, " ");
char *command = NULL;
if (smi_name != NULL) {
- debug(1, "SMI Name: \"%s\"", smi_name);
int client_id = 0;
if (ip_list != NULL)
command = strsep(&ip_list, " ");
clock_private_info[i].announcements_without_followups =
0; // to allow a possibly silent clock to be revisited when added to a timing
// peer list
+ clock_private_info[i].follow_up_number = 0;
}
while (ip_list != NULL) {
char *new_ip = strsep(&ip_list, " ");
debug(2, "announcement seen from %" PRIx64 " at %s.", clock_private_info->clock_id,
clock_private_info->ip);
- if (clock_private_info->announcements_without_followups < 5)
+ if (clock_private_info->announcements_without_followups < 5) // don't keep going forever
+ // a value of 4 means it's parked --
+ // it has seen three, poked the clock and doesn't want to do any more.
clock_private_info->announcements_without_followups++;
int i;
for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
if ((clock_private_info->client_flags[temp_client_id] &
(1 << clock_is_a_timing_peer)) != 0) {
- debug(1, "clock_is_qualified -- updating clock mastership for client \"%s\"",
+ debug(1,
+ "clock_is_qualified %" PRIx64
+ " at %s -- updating clock mastership for client \"%s\"",
+ clock_private_info->clock_id, clock_private_info->ip,
get_client_name(temp_client_id));
update_master(temp_client_id);
}
if (clock_private_info->follow_up_number < 100)
clock_private_info->follow_up_number++;
- clock_private_info->announcements_without_followups = 0; // we've seen a followup
+ if (clock_private_info->announcements_without_followups < 4) // if we haven't signalled already
+ clock_private_info->announcements_without_followups = 0; // we've seen a followup
debug(2, "FOLLOWUP from %" PRIx64 ", %s.", clock_private_info->clock_id, &clock_private_info->ip);
uint64_t offset = preciseOriginTimestamp - reception_time;
time_since_previous_offset = reception_time - clock_private_info->previous_offset_time;
}
- int clock_is_becoming_master_somewhere = 0;
- {
- int temp_client_id;
- for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
- if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_becoming_master)) !=
- 0) {
- clock_is_becoming_master_somewhere = 1;
- }
- }
- }
- if ((clock_private_info->flags & (1 << clock_is_becoming_master)) != 0)
+ int clock_is_becoming_master_somewhere = 0;
+ {
+ int temp_client_id;
+ for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
+ if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_becoming_master)) !=
+ 0) {
clock_is_becoming_master_somewhere = 1;
+ }
+ }
+ }
+ if ((clock_private_info->flags & (1 << clock_is_becoming_master)) != 0)
+ clock_is_becoming_master_somewhere = 1;
if (clock_is_becoming_master_somewhere != 0) {
// we now definitely have at least one sample since a request was made to
// designate this clock a master, so we assume it is legitimate. That is, we assume
// that the clock originator knows that it a clock master by now.
clock_private_info->mastership_start_time = clock_private_info->local_time;
-
+
// designate the clock as master wherever is was becoming a master
{
int temp_client_id;
for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
- if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_becoming_master)) != 0) {
- debug(1, "clock_is_becoming_master -- updating to clock_is_master for client \"%s\"",
+ if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_becoming_master)) !=
+ 0) {
+ debug(1,
+ "clock_is_becoming_master %" PRIx64
+ " at %s -- changing to clock_is_master for client \"%s\"",
+ clock_private_info->clock_id, clock_private_info->ip,
get_client_name(temp_client_id));
clock_private_info->client_flags[temp_client_id] &= ~(1 << clock_is_becoming_master);
clock_private_info->client_flags[temp_client_id] |= (1 << clock_is_master);
}
}
}
-
- clock_private_info->flags &= ~(1 << clock_is_becoming_master); // won't need this
- clock_private_info->flags |= 1 << clock_is_master; // won't need this
+
clock_private_info->previous_offset_time = 0;
debug_log_nqptp_status(2);
} else if ((clock_private_info->previous_offset_time != 0) &&
// i.e. if it's not becoming a master and there has been a previous follow_up
int64_t time_since_last_sync = reception_time - clock_private_info->last_sync_time;
int64_t sync_timeout = 300000000000; // nanoseconds
- debug(2, "Sync interval: %f seconds.", 0.000000001 * time_since_last_sync);
- if (time_since_last_sync < sync_timeout) {
+ if (clock_private_info->last_sync_time == 0)
+ debug(2, "Never synced.");
+ else
+ debug(2, "Sync interval: %f seconds.", 0.000000001 * time_since_last_sync);
+ if ((clock_private_info->last_sync_time != 0) && (time_since_last_sync < sync_timeout)) {
// Do acceptance checking.
int clock_is_a_master_somewhere = 0;
int temp_client_id;
for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
- if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) !=
- 0) {
+ if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) != 0) {
clock_is_a_master_somewhere = 1;
}
}
- if (clock_is_a_master_somewhere != 0)
+ if ((clock_is_a_master_somewhere != 0) && (clock_private_info->last_sync_time == 0))
+ debug(1, "Synchronising master clock %" PRIx64 " at %s.", clock_private_info->clock_id,
+ clock_private_info->ip);
+ if ((clock_is_a_master_somewhere != 0) && (clock_private_info->last_sync_time != 0))
debug(1, "Resynchronising master clock %" PRIx64 " at %s.", clock_private_info->clock_id,
clock_private_info->ip);
// leave the offset as it was coming in and take it as a sync time
int temp_client_id;
for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_master)) != 0) {
- debug(1, "clock_is_master -- updating master clock info for client \"%s\"",
+ debug(2, "clock_is_master -- updating master clock info for client \"%s\"",
get_client_name(temp_client_id));
update_master_clock_info(temp_client_id, clock_private_info->clock_id,
(const char *)&clock_private_info->ip, reception_time, offset,
clock_private_info->mastership_start_time);
}
}
-
- // TODO -- remove the following when we are done
- if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
- update_master_clock_info(0, clock_private_info->clock_id, (const char *)&clock_private_info->ip,
- reception_time, offset, clock_private_info->mastership_start_time);
- debug(3, "clock: %" PRIx64 ", time: %" PRIu64 ", offset: %" PRId64 ", jitter: %+f ms.",
- clock_private_info->clock_id, reception_time, offset, 0.000001 * jitter);
- }
- /*
- if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) {
- debug(2, "follow_up seen from %" PRIx64 " at %s.", clock_private_info->clock_id,
- clock_private_info->ip);
- clock_private_info->flags |=
- (1 << clock_is_valid); // valid because it has at least one follow_up
-
- for (temp_client_id = 0; temp_client_id < MAX_CLIENTS; temp_client_id++) {
- if ((clock_private_info->client_flags[temp_client_id] & (1 << clock_is_a_timing_peer)) != 0) {
- debug(1, "clock_is_valid has become true -- updating clock mastership for client \"%s\"",
- get_client_name(temp_client_id));
- update_master(temp_client_id);
- }
- }
- update_master(0); // TODO -- won't be needed
- }
- */
}
}
*/
-struct shm_structure *shared_memory = NULL; // this is where public clock info is available
int epoll_fd;
-void old_update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t local_time,
- uint64_t local_to_master_offset, uint64_t mastership_start_time) {
-
- // debug(1,"update_master_clock_info start");
- if (shared_memory->master_clock_id != master_clock_id)
- debug_log_nqptp_status(1);
- int rc = pthread_mutex_lock(&shared_memory->shm_mutex);
- if (rc != 0)
- warn("Can't acquire mutex to update master clock!");
- shared_memory->master_clock_id = master_clock_id;
- if (ip != NULL) {
- strncpy((char *)&shared_memory->master_clock_ip, ip,
- FIELD_SIZEOF(struct shm_structure, master_clock_ip) - 1);
- shared_memory->master_clock_start_time = mastership_start_time;
- shared_memory->local_time = local_time;
- shared_memory->local_to_master_time_offset = local_to_master_offset;
- } else {
- shared_memory->master_clock_ip[0] = '\0';
- shared_memory->master_clock_start_time = 0;
- shared_memory->local_time = 0;
- shared_memory->local_to_master_time_offset = 0;
- }
- rc = pthread_mutex_unlock(&shared_memory->shm_mutex);
- if (rc != 0)
- warn("Can't release mutex after updating master clock!");
- // debug(1,"update_master_clock_info done");
-}
-
void goodbye(void) {
// close any open sockets
unsigned int i;
close(sockets_open_stuff.sockets[i].number);
// close off shared memory interfaces
- if (shared_memory != NULL) {
- // mmap cleanup
- if (munmap(shared_memory, sizeof(struct shm_structure)) != 0)
- debug(1, "error unmapping shared memory");
- // shm_open cleanup
- if (shm_unlink(STORAGE_ID) == -1)
- debug(1, "error unlinking shared memory \"%s\"", STORAGE_ID);
- }
-
delete_clients();
if (epoll_fd != -1)
sockets_open_stuff.sockets_open = 0;
epoll_fd = -1;
- shared_memory = NULL;
// control-c (SIGINT) cleanly
struct sigaction act;
char buf[BUFLEN];
- pthread_mutexattr_t shared;
- int err;
-
// open sockets 319 and 320
open_sockets_at_port(319, &sockets_open_stuff);
open_sockets_at_port(NQPTP_CONTROL_PORT,
&sockets_open_stuff); // this for messages from the client
- // open a shared memory interface.
- int shm_fd = -1;
-
- mode_t oldumask = umask(0);
- shm_fd = shm_open(STORAGE_ID, O_RDWR | O_CREAT, 0666);
- if (shm_fd == -1) {
- die("cannot open shared memory \"%s\".", STORAGE_ID);
- }
- (void)umask(oldumask);
-
- if (ftruncate(shm_fd, sizeof(struct shm_structure)) == -1) {
- die("failed to set size of shared memory \"%s\".", STORAGE_ID);
- }
-
-#ifdef CONFIG_FOR_FREEBSD
- shared_memory = (struct shm_structure *)mmap(NULL, sizeof(struct shm_structure),
- PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
-#endif
-
-#ifdef CONFIG_FOR_LINUX
- shared_memory =
- (struct shm_structure *)mmap(NULL, sizeof(struct shm_structure), PROT_READ | PROT_WRITE,
- MAP_LOCKED | MAP_SHARED, shm_fd, 0);
-#endif
-
- if (shared_memory == (struct shm_structure *)-1) {
- die("failed to mmap shared memory \"%s\".", STORAGE_ID);
- }
-
- if ((close(shm_fd) == -1)) {
- warn("error closing \"/nqptp\" after mapping.");
- }
-
- // zero it
- memset(shared_memory, 0, sizeof(struct shm_structure));
- shared_memory->version = NQPTP_SHM_STRUCTURES_VERSION;
-
- /*create mutex attr */
- err = pthread_mutexattr_init(&shared);
- if (err != 0) {
- die("mutex attribute initialization failed - %s.", strerror(errno));
- }
- pthread_mutexattr_setpshared(&shared, 1);
- /*create a mutex */
- err = pthread_mutex_init((pthread_mutex_t *)&shared_memory->shm_mutex, &shared);
- if (err != 0) {
- die("mutex initialization failed - %s.", strerror(errno));
- }
-
// start the timed tasks
uint64_t broadcasting_task(uint64_t call_time, void *private_data);
int i;
for (i = 0; i < MAX_CLOCKS; i++) {
if ((clocks_private[i].announcements_without_followups == 3) &&
+ (clocks_private[i].follow_up_number == 0) && // only check at the start
((clocks_private[i].flags & (1 << clock_is_one_of_ours)) == 0)) {
debug(1, "Found a silent clock %" PRIx64 " at %s.", clocks_private[i].clock_id,
clocks_private[i].ip);
// send an Announce message to attempt to waken this silent PTP clock by
// getting it to negotiate with an apparently better clock
- // that then immediately sends another Announce message indicating that it's worse
+ // that then immediately sends another Announce message indicating that it's inferior
+
+ clocks_private[i].announcements_without_followups++; // set to 4 to indicate done/parked
struct ptp_announce_message *msg;
size_t msg_length = sizeof(struct ptp_announce_message);
#include "nqptp-shm-structures.h"
-#define STORAGE_ID "/nqptp"
#define MAX_CLOCKS 64
#define MAX_CLIENTS 16
#define MAX_OPEN_SOCKETS 16
// Instances" -- of a "PTP Network" it wishes to monitor. This is a "timing group" in AirPlay 2
// parlance, it seems.
-void old_update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t local_time,
- uint64_t local_to_master_offset, uint64_t mastership_start_time);
-
#endif