Skip to content

Commit

Permalink
afsocket: do not keep connection alive when hostname changes
Browse files Browse the repository at this point in the history
Signed-off-by: László Várady <[email protected]>
  • Loading branch information
MrAnno committed Dec 18, 2024
1 parent 7d1cac5 commit 4648b61
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions modules/afsocket/afinet-dest.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static const gint MAX_UDP_PAYLOAD_SIZE = 65507;
typedef struct _AFInetDestKeptAliveConnection
{
AFSocketDestKeptAliveConnection super;
gchar *hostname;
} AFInetDestKeptAliveConnection;

typedef struct _AFInetDestDriverTLSVerifyData
Expand Down Expand Up @@ -710,6 +711,18 @@ afinet_dd_free(LogPipe *s)
afsocket_dd_free(s);
}

gboolean
afinet_dd_should_restore_connection(AFSocketDestDriver *s, AFSocketDestKeptAliveConnection *c)
{
AFInetDestDriver *self = (AFInetDestDriver *) s;
AFInetDestKeptAliveConnection *conn = (AFInetDestKeptAliveConnection *) c;

if (g_strcmp0(_afinet_dd_get_hostname(self), conn->hostname) != 0)
return FALSE;

return afsocket_dd_should_restore_connection_method(&self->super, c);
}

static void
afinet_dd_restore_connection(AFSocketDestDriver *s, AFSocketDestKeptAliveConnection *item)
{
Expand Down Expand Up @@ -743,17 +756,22 @@ _kept_alive_connection_free(AFSocketDestKeptAliveConnection *s)
{
AFInetDestKeptAliveConnection *self = (AFInetDestKeptAliveConnection *) s;

g_free(self->hostname);

afsocket_kept_alive_connection_free_method(&self->super);
}

static AFInetDestKeptAliveConnection *
_kept_alive_connection_new(const gchar *transport, const gchar *proto, GSockAddr *dest_addr, LogWriter *writer)
_kept_alive_connection_new(const gchar *transport, const gchar *proto, const gchar *hostname,
GSockAddr *dest_addr, LogWriter *writer)
{
AFInetDestKeptAliveConnection *self = g_new(AFInetDestKeptAliveConnection, 1);
afsocket_kept_alive_connection_init_instance(&self->super, transport, proto, dest_addr, writer);

self->super.free_fn = _kept_alive_connection_free;

self->hostname = g_strdup(hostname);

return self;
}

Expand All @@ -764,8 +782,8 @@ afinet_dd_save_connection(AFSocketDestDriver *s)

const gchar *transport = transport_mapper_get_transport(self->super.transport_mapper);
const gchar *proto = transport_mapper_get_logproto(self->super.transport_mapper);
AFInetDestKeptAliveConnection *item = _kept_alive_connection_new(transport, proto, self->super.dest_addr,
self->super.writer);
AFInetDestKeptAliveConnection *item = _kept_alive_connection_new(transport, proto, _afinet_dd_get_hostname(self),
self->super.dest_addr, self->super.writer);

afsocket_dd_save_connection(&self->super, &item->super);
}
Expand All @@ -783,6 +801,7 @@ afinet_dd_new_instance(TransportMapper *transport_mapper, gchar *hostname, Globa
self->super.construct_writer = afinet_dd_construct_writer;
self->super.setup_addresses = afinet_dd_setup_addresses;
self->super.get_dest_name = afinet_dd_get_dest_name;
self->super.should_restore_connection = afinet_dd_should_restore_connection;
self->super.restore_connection = afinet_dd_restore_connection;
self->super.save_connection = afinet_dd_save_connection;

Expand Down

0 comments on commit 4648b61

Please sign in to comment.