Also load peer host->contract mapping.

Not only use peer IP for contract matching, but also newly introduced
peer host, if no IP is found.
1.3
Andreas Granig 14 years ago
parent 1f19898ae5
commit aa920d254f

@ -508,6 +508,10 @@ void cdr_set_provider(cdr_entry_t *cdr)
{
g_strlcpy(cdr->source_provider_id, val, sizeof(cdr->source_provider_id));
}
else if((val = g_hash_table_lookup(med_peer_host_table, cdr->source_domain)) != NULL)
{
g_strlcpy(cdr->source_provider_id, val, sizeof(cdr->source_provider_id));
}
else
{
g_strlcpy(cdr->source_provider_id, "0", sizeof(cdr->source_provider_id));
@ -528,6 +532,10 @@ void cdr_set_provider(cdr_entry_t *cdr)
{
g_strlcpy(cdr->destination_provider_id, val, sizeof(cdr->destination_provider_id));
}
else if((val = g_hash_table_lookup(med_peer_host_table, cdr->destination_domain)) != NULL)
{
g_strlcpy(cdr->destination_provider_id, val, sizeof(cdr->destination_provider_id));
}
else
{
g_strlcpy(cdr->destination_provider_id, "0", sizeof(cdr->destination_provider_id));

@ -22,6 +22,7 @@ int mediator_lockfd = -1;
u_int64_t mediator_count = 0;
GHashTable *med_peer_ip_table = NULL;
GHashTable *med_peer_host_table = NULL;
GHashTable *med_uuid_table = NULL;
@ -29,9 +30,10 @@ GHashTable *med_uuid_table = NULL;
static int mediator_load_maps()
{
med_peer_ip_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
med_peer_host_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
med_uuid_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
if(medmysql_load_maps(med_peer_ip_table))
if(medmysql_load_maps(med_peer_ip_table, med_peer_host_table))
return -1;
if(medmysql_load_uuids(med_uuid_table))
return -1;
@ -50,6 +52,8 @@ static void mediator_destroy_maps()
{
if(med_peer_ip_table)
g_hash_table_destroy(med_peer_ip_table);
if(med_peer_host_table)
g_hash_table_destroy(med_peer_host_table);
if(med_uuid_table)
g_hash_table_destroy(med_uuid_table);
}
@ -59,6 +63,8 @@ static void mediator_print_maps()
{
syslog(LOG_DEBUG, "Peer IP map:");
g_hash_table_foreach(med_peer_ip_table, mediator_print_mapentry, NULL);
syslog(LOG_DEBUG, "Peer host map:");
g_hash_table_foreach(med_peer_host_table, mediator_print_mapentry, NULL);
syslog(LOG_DEBUG, "UUID map:");
g_hash_table_foreach(med_uuid_table, mediator_print_mapentry, NULL);
}

@ -13,7 +13,7 @@
"src_leg, dst_leg, id " \
"from acc where callid = '%s' order by time_hires asc"
#define MED_LOAD_PEER_QUERY "select h.ip, g.peering_contract_id " \
#define MED_LOAD_PEER_QUERY "select h.ip, h.host, g.peering_contract_id " \
"from provisioning.voip_peer_hosts h, provisioning.voip_peer_groups g " \
"where g.id = h.group_id"
#define MED_LOAD_UUID_QUERY "select vs.uuid, r.contract_id from billing.voip_subscribers vs, " \
@ -416,7 +416,7 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_
}
/**********************************************************************/
int medmysql_load_maps(GHashTable *ip_table)
int medmysql_load_maps(GHashTable *ip_table, GHashTable *host_table)
{
MYSQL_RES *res;
MYSQL_ROW row;
@ -441,9 +441,9 @@ int medmysql_load_maps(GHashTable *ip_table)
{
ip_id = NULL;
if(row[0] == NULL || row[1] == NULL)
if(row[0] == NULL || row[2] == NULL)
{
syslog(LOG_CRIT, "Error loading peer hosts, a column is NULL");
syslog(LOG_CRIT, "Error loading peer hosts, a mandatory column is NULL");
ret = -1;
goto out;
}
@ -468,6 +468,18 @@ int medmysql_load_maps(GHashTable *ip_table)
g_hash_table_insert(ip_table, key, ip_id);
}
}
if(host_table != NULL && row[1] != NULL) // host column is optional
{
if(g_hash_table_lookup(host_table, row[1]) != NULL)
{
syslog(LOG_WARNING, "Skipping duplicate host '%s'", row[1]);
}
else
{
key = (gpointer)g_strdup(row[1]);
g_hash_table_insert(host_table, key, ip_id);
}
}
}
out:

@ -28,7 +28,7 @@ int medmysql_trash_entries(const char *callid, struct medmysql_batches *);
int medmysql_backup_entries(const char *callid, struct medmysql_batches *);
int medmysql_delete_entries(const char *callid, struct medmysql_batches *);
int medmysql_insert_cdrs(cdr_entry_t *records, u_int64_t count, struct medmysql_batches *);
int medmysql_load_maps(GHashTable *ip_table);
int medmysql_load_maps(GHashTable *ip_table, GHashTable *host_table);
int medmysql_load_uuids(GHashTable *uuid_table);
int medmysql_batch_start(struct medmysql_batches *);
int medmysql_batch_end(struct medmysql_batches *);

Loading…
Cancel
Save