Commit ff5d688c authored by Marcus Lundblad's avatar Marcus Lundblad Committed by Youness Alaoui

Store permissions in a GList instead of a GHashTable

parent 1252f780
...@@ -89,7 +89,8 @@ typedef struct { ...@@ -89,7 +89,8 @@ typedef struct {
uint8_t ms_connection_id[20]; uint8_t ms_connection_id[20];
uint32_t ms_sequence_num; uint32_t ms_sequence_num;
bool ms_connection_id_valid; bool ms_connection_id_valid;
GHashTable *permissions; /* stores installed permissions */ GList *permissions; /* the peers (NiceAddress) for which
there is an installed permission */
GHashTable *sent_permissions; /* ongoing permission installed */ GHashTable *sent_permissions; /* ongoing permission installed */
GHashTable *send_data_queues; /* stores a send data queue for per peer */ GHashTable *send_data_queues; /* stores a send data queue for per peer */
guint permission_timeout_source; /* timer used to invalidate permissions */ guint permission_timeout_source; /* timer used to invalidate permissions */
...@@ -218,10 +219,6 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr, ...@@ -218,10 +219,6 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr,
priv->server_addr = *server_addr; priv->server_addr = *server_addr;
priv->compatibility = compatibility; priv->compatibility = compatibility;
priv->send_requests = g_queue_new (); priv->send_requests = g_queue_new ();
priv->permissions =
g_hash_table_new_full (priv_nice_address_hash ,
(GEqualFunc) nice_address_equal ,
(GDestroyNotify) nice_address_free, NULL);
priv->sent_permissions = priv->sent_permissions =
g_hash_table_new_full (priv_nice_address_hash , g_hash_table_new_full (priv_nice_address_hash ,
(GEqualFunc) nice_address_equal , (GEqualFunc) nice_address_equal ,
...@@ -278,7 +275,8 @@ socket_close (NiceSocket *sock) ...@@ -278,7 +275,8 @@ socket_close (NiceSocket *sock)
} }
g_queue_free (priv->send_requests); g_queue_free (priv->send_requests);
g_hash_table_destroy (priv->permissions); g_list_foreach (priv->permissions, (GFunc) nice_address_free, NULL);
g_list_free (priv->permissions);
g_hash_table_destroy (priv->send_data_queues); g_hash_table_destroy (priv->send_data_queues);
g_source_remove (priv->permission_timeout_source); g_source_remove (priv->permission_timeout_source);
...@@ -341,7 +339,10 @@ stun_message_ensure_ms_realm(StunMessage *msg, uint8_t *realm) ...@@ -341,7 +339,10 @@ stun_message_ensure_ms_realm(StunMessage *msg, uint8_t *realm)
static gboolean static gboolean
priv_has_permission_for_peer (TurnPriv *priv, const NiceAddress *to) priv_has_permission_for_peer (TurnPriv *priv, const NiceAddress *to)
{ {
return g_hash_table_lookup (priv->permissions, to) != NULL; GList *found = g_list_find_custom (priv->permissions, to,
(GCompareFunc) nice_address_equal);
return found != NULL;
} }
static gboolean static gboolean
...@@ -567,7 +568,9 @@ priv_permission_timeout (gpointer data) ...@@ -567,7 +568,9 @@ priv_permission_timeout (gpointer data)
agent_lock (); agent_lock ();
/* remove all permissions for this agent (the permission for the peer /* remove all permissions for this agent (the permission for the peer
we are sending to will be renewed) */ we are sending to will be renewed) */
g_hash_table_remove_all (priv->permissions); g_list_foreach (priv->permissions, (GFunc) nice_address_free, NULL);
g_list_free (priv->permissions);
priv->permissions = NULL;
agent_unlock (); agent_unlock ();
return TRUE; return TRUE;
...@@ -817,7 +820,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock, ...@@ -817,7 +820,8 @@ nice_turn_socket_parse_recv (NiceSocket *sock, NiceSocket **from_sock,
nice_address_free (to); nice_address_free (to);
} else { } else {
/* we now have a permission installed for this peer */ /* we now have a permission installed for this peer */
g_hash_table_insert (priv->permissions, to, to); priv->permissions =
g_list_append(priv->permissions, to);
g_hash_table_remove (priv->sent_permissions, to); g_hash_table_remove (priv->sent_permissions, to);
/* install timer to schedule refresh of the permission */ /* install timer to schedule refresh of the permission */
...@@ -1001,7 +1005,7 @@ priv_retransmissions_create_permission_tick_unlocked (TurnPriv *priv) ...@@ -1001,7 +1005,7 @@ priv_retransmissions_create_permission_tick_unlocked (TurnPriv *priv)
message, assume we can just send the data, the server message, assume we can just send the data, the server
might not support RFC TURN, or connectivity check will might not support RFC TURN, or connectivity check will
fail eventually anyway */ fail eventually anyway */
g_hash_table_insert (priv->permissions, to, to); priv->permissions = g_list_append (priv->permissions, to);
g_hash_table_remove (priv->sent_permissions, to); g_hash_table_remove (priv->sent_permissions, to);
socket_dequeue_all_data (priv, to); socket_dequeue_all_data (priv, to);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment