diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-25 01:51:36 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-04-25 01:51:36 +0200 |
commit | 5adfca9b651e0e383d463da9e8158e75cad8e7c7 (patch) | |
tree | 906d85ae42ceede085d7c84bf9cdd9e678c03ae7 /src/peer.h | |
parent | 482ddc46a62b9a6b8bd615fd35b2bac6d3b7d841 (diff) | |
download | fastd-5adfca9b651e0e383d463da9e8158e75cad8e7c7.tar fastd-5adfca9b651e0e383d463da9e8158e75cad8e7c7.zip |
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.
Diffstat (limited to 'src/peer.h')
-rw-r--r-- | src/peer.h | 27 |
1 files changed, 9 insertions, 18 deletions
@@ -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; } |