diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-10-16 18:33:51 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-10-16 18:33:51 +0200 |
commit | 118ebb9d65b44fb734aee3ebd31ecdaffd38c615 (patch) | |
tree | cfb4e9f8ad1364dbfe411e6c6dc6c5139b08016c /src/send.c | |
parent | 4c188ac86175422bc44e88e037b01acaba781cb7 (diff) | |
download | fastd-118ebb9d65b44fb734aee3ebd31ecdaffd38c615.tar fastd-118ebb9d65b44fb734aee3ebd31ecdaffd38c615.zip |
Initiate handshake when a packet can't be sent because the local address is invalid
Diffstat (limited to 'src/send.c')
-rw-r--r-- | src/send.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -71,7 +71,7 @@ static inline void count_stat(fastd_stats_t *stats, size_t stat_size) { } } -static void send_type(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, uint8_t packet_type, fastd_buffer_t buffer, size_t stat_size) { +static void send_type(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, uint8_t packet_type, fastd_buffer_t buffer, size_t stat_size) { if (!sock) exit_bug(ctx, "send: sock == NULL"); @@ -124,12 +124,17 @@ static void send_type(fastd_context_t *ctx, const fastd_socket_t *sock, const fa if (ret < 0 && errno == EINVAL && msg.msg_controllen) { pr_debug2(ctx, "sendmsg failed, trying again without pktinfo"); + + if (peer && !fastd_peer_handshake_scheduled(ctx, peer)) + fastd_peer_schedule_handshake(ctx, peer, 0); + msg.msg_control = NULL; msg.msg_controllen = 0; do { ret = sendmsg(sock->fd, &msg, 0); } while (ret < 0 && errno == EINTR); + } if (ret < 0) { @@ -161,12 +166,12 @@ static void send_type(fastd_context_t *ctx, const fastd_socket_t *sock, const fa fastd_buffer_free(buffer); } -void fastd_send(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_buffer_t buffer, size_t stat_size) { - send_type(ctx, sock, local_addr, remote_addr, PACKET_DATA, buffer, stat_size); +void fastd_send(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, fastd_buffer_t buffer, size_t stat_size) { + send_type(ctx, sock, local_addr, remote_addr, peer, PACKET_DATA, buffer, stat_size); } -void fastd_send_handshake(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_buffer_t buffer) { - send_type(ctx, sock, local_addr, remote_addr, PACKET_HANDSHAKE, buffer, 0); +void fastd_send_handshake(fastd_context_t *ctx, const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, fastd_buffer_t buffer) { + send_type(ctx, sock, local_addr, remote_addr, peer, PACKET_HANDSHAKE, buffer, 0); } void fastd_send_all(fastd_context_t *ctx, fastd_peer_t *source_peer, fastd_buffer_t buffer) { |