summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-04-21 20:02:43 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-04-21 20:02:43 +0200
commit505f97771ab63e32b82592a952ae9cf53adf86b9 (patch)
treecb57c1d792aadcfe771cabef7471f61da5a0d955
parent175685ed5fbc0db3a259f9cccb30d0a0be74ad30 (diff)
downloadfastd-505f97771ab63e32b82592a952ae9cf53adf86b9.tar
fastd-505f97771ab63e32b82592a952ae9cf53adf86b9.zip
Remove vector of new temporary peers
The new poll code has made this second peer list obsolete.
-rw-r--r--src/fastd.c12
-rw-r--r--src/fastd.h1
-rw-r--r--src/peer.c71
-rw-r--r--src/peer.h1
-rw-r--r--src/protocols/ec25519_fhmqvc/handshake.c2
5 files changed, 29 insertions, 58 deletions
diff --git a/src/fastd.c b/src/fastd.c
index 2649ef2..b6dabf1 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -476,14 +476,6 @@ static void handle_handshake_queue(void) {
fastd_resolve_peer(peer, peer->next_remote);
}
-static void enable_temporaries(void) {
- size_t i;
- for (i = 0; i < VECTOR_LEN(ctx.peers_temp); i++)
- fastd_peer_enable_temporary(VECTOR_INDEX(ctx.peers_temp, i));
-
- VECTOR_RESIZE(ctx.peers_temp, 0);
-}
-
static bool maintain_peer(fastd_peer_t *peer) {
if (fastd_peer_is_temporary(peer) || fastd_peer_is_established(peer)) {
/* check for peer timeout */
@@ -854,7 +846,6 @@ int main(int argc, char *argv[]) {
VECTOR_ALLOC(ctx.eth_addrs, 0);
VECTOR_ALLOC(ctx.peers, 0);
- VECTOR_ALLOC(ctx.peers_temp, 0);
fastd_peer_hashtable_init();
@@ -865,8 +856,6 @@ int main(int argc, char *argv[]) {
fastd_poll_handle();
- enable_temporaries();
-
if (fastd_timed_out(&ctx.next_maintenance))
maintenance();
@@ -907,7 +896,6 @@ int main(int argc, char *argv[]) {
fastd_peer_hashtable_free();
- VECTOR_FREE(ctx.peers_temp);
VECTOR_FREE(ctx.peers);
VECTOR_FREE(ctx.eth_addrs);
diff --git a/src/fastd.h b/src/fastd.h
index 4913a35..0f5fec0 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -239,7 +239,6 @@ struct fastd_context {
fastd_peer_group_t *peer_group;
VECTOR(fastd_peer_t*) peers;
- VECTOR(fastd_peer_t*) peers_temp;
#ifdef USE_EPOLL
int epoll_fd;
diff --git a/src/peer.c b/src/peer.c
index faba121..99fa9b3 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -267,15 +267,6 @@ static void delete_peer(fastd_peer_t *peer) {
}
}
- if (i == VECTOR_LEN(ctx.peers)) {
- for (i = 0; i < VECTOR_LEN(ctx.peers_temp); i++) {
- if (VECTOR_INDEX(ctx.peers_temp, i) == peer) {
- VECTOR_DELETE(ctx.peers_temp, i);
- break;
- }
- }
- }
-
fastd_peer_hashtable_remove(peer);
conf.protocol->free_peer_state(peer);
@@ -557,52 +548,46 @@ bool fastd_peer_may_connect(fastd_peer_t *peer) {
fastd_peer_t* fastd_peer_add(fastd_peer_config_t *peer_conf) {
fastd_peer_t *peer = calloc(1, sizeof(fastd_peer_t));
- peer->config = peer_conf;
- peer->group = find_peer_group(ctx.peer_group, peer_conf->group);
- peer->protocol_config = peer_conf->protocol_config;
+ if (peer_conf) {
+ peer->config = peer_conf;
+ peer->group = find_peer_group(ctx.peer_group, peer_conf->group);
+ peer->protocol_config = peer_conf->protocol_config;
+
+ fastd_remote_t **remote = &peer->remotes;
+ fastd_remote_config_t *remote_config = peer_conf->remotes;
- fastd_remote_t **remote = &peer->remotes;
- fastd_remote_config_t *remote_config = peer_conf->remotes;
+ while (remote_config) {
+ *remote = calloc(1, sizeof(fastd_remote_t));
+ (*remote)->ref = 1;
+ (*remote)->config = remote_config;
- while (remote_config) {
- *remote = calloc(1, sizeof(fastd_remote_t));
- (*remote)->ref = 1;
- (*remote)->config = remote_config;
+ if (!remote_config->hostname) {
+ (*remote)->n_addresses = 1;
+ (*remote)->addresses = malloc(sizeof(fastd_peer_address_t));
+ (*remote)->addresses[0] = remote_config->address;
+ }
- if (!remote_config->hostname) {
- (*remote)->n_addresses = 1;
- (*remote)->addresses = malloc(sizeof(fastd_peer_address_t));
- (*remote)->addresses[0] = remote_config->address;
+ remote = &(*remote)->next;
+ remote_config = remote_config->next;
}
- remote = &(*remote)->next;
- remote_config = remote_config->next;
+ pr_verbose("adding peer %P (group `%s')", peer, peer->group->conf->name);
}
+ else {
+ if (!fastd_shell_command_isset(&conf.on_verify))
+ exit_bug("tried to add temporary peer without on-verify command");
- pr_verbose("adding peer %P (group `%s')", peer, peer->group->conf->name);
-
- setup_peer(peer);
-
- VECTOR_ADD(ctx.peers, peer);
- fastd_poll_add_peer();
-
- return peer;
-}
-
-fastd_peer_t* fastd_peer_add_temporary(void) {
- if (!fastd_shell_command_isset(&conf.on_verify))
- exit_bug("tried to add temporary peer without on-verify command");
-
- fastd_peer_t *peer = calloc(1, sizeof(fastd_peer_t));
+ peer->group = ctx.peer_group;
- peer->group = ctx.peer_group;
- fastd_peer_seen(peer);
+ fastd_peer_seen(peer);
- pr_debug("adding temporary peer");
+ pr_debug("adding temporary peer");
+ }
setup_peer(peer);
- VECTOR_ADD(ctx.peers_temp, peer);
+ VECTOR_ADD(ctx.peers, peer);
+ fastd_poll_add_peer();
return peer;
}
diff --git a/src/peer.h b/src/peer.h
index 1fa4822..3e7e9ff 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -131,7 +131,6 @@ bool fastd_peer_config_equal(const fastd_peer_config_t *peer1, const fastd_peer_
void fastd_peer_reset(fastd_peer_t *peer);
void fastd_peer_delete(fastd_peer_t *peer);
fastd_peer_t* fastd_peer_add(fastd_peer_config_t *peer_conf);
-fastd_peer_t* fastd_peer_add_temporary(void);
bool fastd_peer_verify_temporary(fastd_peer_t *peer, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *peer_addr);
void fastd_peer_enable_temporary(fastd_peer_t *peer);
void fastd_peer_set_established(fastd_peer_t *peer);
diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c
index df53157..f3a697d 100644
--- a/src/protocols/ec25519_fhmqvc/handshake.c
+++ b/src/protocols/ec25519_fhmqvc/handshake.c
@@ -499,7 +499,7 @@ static inline fastd_peer_t* add_temporary(const fastd_peer_address_t *addr, cons
return NULL;
}
- fastd_peer_t *peer = fastd_peer_add_temporary();
+ fastd_peer_t *peer = fastd_peer_add(NULL);
peer->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t));
memcpy(&peer->protocol_config->public_key, key, PUBLICKEYBYTES);