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/fastd.c | |
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/fastd.c')
-rw-r--r-- | src/fastd.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/fastd.c b/src/fastd.c index 3ee445a..80079b5 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -405,14 +405,14 @@ static inline void no_valid_address_debug(const fastd_peer_t *peer) { pr_debug("not sending a handshake to %P (no valid address resolved)", peer); } -static void send_handshake(fastd_peer_t *peer) { +static void send_handshake(fastd_peer_t *peer, fastd_remote_t *next_remote) { if (!fastd_peer_is_established(peer)) { - if (!peer->next_remote->n_addresses) { + if (!next_remote->n_addresses) { no_valid_address_debug(peer); return; } - fastd_peer_claim_address(peer, NULL, NULL, &peer->next_remote->addresses[peer->next_remote->current_address], false); + fastd_peer_claim_address(peer, NULL, NULL, &next_remote->addresses[next_remote->current_address], false); fastd_peer_reset_socket(peer); } @@ -447,33 +447,36 @@ static void handle_handshake_queue(void) { fastd_peer_schedule_handshake_default(peer); if (!fastd_peer_may_connect(peer)) { - if (peer->next_remote != NULL) { + if (peer->next_remote != -1) { pr_debug("temporarily disabling handshakes with %P", peer); - peer->next_remote = NULL; + peer->next_remote = -1; } return; } - if (peer->next_remote || fastd_peer_is_established(peer)) { - send_handshake(peer); + fastd_remote_t *next_remote = fastd_peer_get_next_remote(peer); + + if (next_remote || fastd_peer_is_established(peer)) { + send_handshake(peer, next_remote); if (fastd_peer_is_established(peer)) return; - if (++peer->next_remote->current_address < peer->next_remote->n_addresses) + if (++next_remote->current_address < next_remote->n_addresses) return; - peer->next_remote = peer->next_remote->next; + peer->next_remote++; } - if (!peer->next_remote) - peer->next_remote = peer->remotes; + if (peer->next_remote < 0 || (size_t)peer->next_remote >= VECTOR_LEN(peer->remotes)) + peer->next_remote = 0; - peer->next_remote->current_address = 0; + next_remote = fastd_peer_get_next_remote(peer); + next_remote->current_address = 0; - if (fastd_remote_is_dynamic(peer->next_remote)) - fastd_resolve_peer(peer, peer->next_remote); + if (fastd_remote_is_dynamic(next_remote)) + fastd_resolve_peer(peer, next_remote); } static bool maintain_peer(fastd_peer_t *peer) { |