uint32_t count = 0;
- for(uint32_t i = 0; i < 5; i++) {
+ for(uint32_t i = 0; i < MAX_RECENT; i++) {
if(mesh->self->recent[i].sa.sa_family) {
count++;
} else {
pthread_mutex_lock(&mesh->mutex);
node_t *n = (node_t *)node;
- memmove(n->recent + 1, n->recent, 4 * sizeof(*n->recent));
+ memmove(n->recent + 1, n->recent, (MAX_RECENT - 1) * sizeof(*n->recent));
memcpy(n->recent, addr, SALEN(*addr));
if(!node_write_config(mesh, n)) {
// Append any known addresses in the config file to the list we currently have
uint32_t known_count = 0;
- for(uint32_t i = 0; i < 5; i++) {
+ for(uint32_t i = 0; i < MAX_RECENT; i++) {
if(n->recent[i].sa.sa_family) {
known_count++;
}
uint32_t count = packmsg_get_array(&in);
- if(count > 5 - known_count) {
- count = 5 - known_count;
+ for(uint32_t i = 0; i < count; i++) {
+ if(i < MAX_RECENT - known_count) {
+ n->recent[i + known_count] = packmsg_get_sockaddr(&in);
+ } else {
+ packmsg_skip_element(&in);
+ }
}
- for(uint32_t i = 0; i < count; i++) {
- n->recent[i + known_count] = packmsg_get_sockaddr(&in);
}
config_free(&config);
n->canonical_address = packmsg_get_str_dup(&in);
uint32_t count = packmsg_get_array(&in);
- if(count > 5) {
- count = 5;
- }
-
for(uint32_t i = 0; i < count; i++) {
- n->recent[i] = packmsg_get_sockaddr(&in);
+ if(i < MAX_RECENT) {
+ n->recent[i] = packmsg_get_sockaddr(&in);
+ } else {
+ packmsg_skip_element(&in);
+ }
}
return packmsg_done(&in);
uint32_t count = 0;
- for(uint32_t i = 0; i < 5; i++) {
+ for(uint32_t i = 0; i < MAX_RECENT; i++) {
if(n->recent[i].sa.sa_family) {
count++;
} else {
uint16_t want_udp: 1; /* 1 if we want working UDP because we have data to send */
} node_status_t;
+#define MAX_RECENT 5
+
typedef struct node_t {
// Public member variables
char *name; /* name of this node */
time_t last_successfull_connection;
char *canonical_address; /* The canonical address of this node, if known */
- sockaddr_t recent[5]; /* Recently seen addresses */
+ sockaddr_t recent[MAX_RECENT]; /* Recently seen addresses */
// Graph-related member variables
int distance;