From 5adfca9b651e0e383d463da9e8158e75cad8e7c7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 25 Apr 2014 01:51:36 +0200 Subject: Remove ref-counting on remotes Now that peers have a peer id we can use that to specify a peer in a resolve return. As the remote list of a peer doesn't change without the peer id changing, instead of taking a remote ref we can just use the peer id and remote index. --- src/peer.h | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'src/peer.h') diff --git a/src/peer.h b/src/peer.h index 41cee20..804dbeb 100644 --- a/src/peer.h +++ b/src/peer.h @@ -43,8 +43,8 @@ struct fastd_peer { struct timespec timeout; struct timespec keepalive_timeout; - fastd_remote_t *remotes; - fastd_remote_t *next_remote; + VECTOR(fastd_remote_t) remotes; + ssize_t next_remote; struct timespec next_handshake; fastd_dlist_head_t handshake_entry; @@ -84,10 +84,6 @@ struct fastd_peer_eth_addr { }; struct fastd_remote { - fastd_remote_t *next; - - size_t ref; - fastd_remote_config_t *config; size_t n_addresses; @@ -95,7 +91,6 @@ struct fastd_remote { fastd_peer_address_t *addresses; struct timespec last_resolve_timeout; - bool resolving; }; struct fastd_remote_config { @@ -173,6 +168,13 @@ static inline bool fastd_peer_is_temporary(const fastd_peer_t *peer) { return (!peer->config); } +static inline fastd_remote_t * fastd_peer_get_next_remote(fastd_peer_t *peer) { + if (peer->next_remote < 0) + return NULL; + + return &VECTOR_INDEX(peer->remotes, peer->next_remote); +} + static inline bool fastd_peer_is_established(const fastd_peer_t *peer) { switch(peer->state) { case STATE_ESTABLISHED: @@ -183,17 +185,6 @@ static inline bool fastd_peer_is_established(const fastd_peer_t *peer) { } } -static inline void fastd_remote_ref(fastd_remote_t *remote) { - remote->ref++; -} - -static inline void fastd_remote_unref(fastd_remote_t *remote) { - if(!--remote->ref) { - free(remote->addresses); - free(remote); - } -} - static inline bool fastd_remote_is_dynamic(const fastd_remote_t *remote) { return remote->config->hostname; } -- cgit v1.2.3