comparison extensions/rt_redirect/rt_redir.h @ 1260:4f6f61e67599

Store redirect information for ALL_SESSION and ALL_USER in a hash. This is a speedup if many of these exist (compared to checking a linked list for matches as before). Refactor a bit while here. Use the uthash code from Troy D. Hanson, http://troydhanson.github.com/uthash/
author Thomas Klausner <tk@giga.or.at>
date Mon, 24 Mar 2014 13:21:41 +0100
parents 82280e745a89
children
comparison
equal deleted inserted replaced
1259:82280e745a89 1260:4f6f61e67599
1 /********************************************************************************************************* 1 /*********************************************************************************************************
2 * Software License Agreement (BSD License) * 2 * Software License Agreement (BSD License) *
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> and *
4 * * 4 * Thomas Klausner <tk@giga.or.at> *
5 * Copyright (c) 2013, WIDE Project and NICT * 5 * *
6 * Copyright (c) 2013, 2014, WIDE Project and NICT *
6 * All rights reserved. * 7 * All rights reserved. *
7 * * 8 * *
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * 9 * Redistribution and use of this software in source and binary forms, with or without modification, are *
9 * permitted provided that the following conditions are met: * 10 * permitted provided that the following conditions are met: *
10 * * 11 * *
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
34 *********************************************************************************************************/ 35 *********************************************************************************************************/
35 36
36 /* Diameter Redirect management */ 37 /* Diameter Redirect management */
37 #include <freeDiameter/extension.h> 38 #include <freeDiameter/extension.h>
39
40 #include "uthash.h"
38 41
39 /* There are 2 locks in this module. The priority is established as follow to avoid deadlocks: 42 /* There are 2 locks in this module. The priority is established as follow to avoid deadlocks:
40 exp_peer mutex > usages rwlock. 43 exp_peer mutex > usages rwlock.
41 (e.g., the rwlock can be taken while holding the mutex, but not the other way) 44 (e.g., the rwlock can be taken while holding the mutex, but not the other way)
42 */ 45 */
127 size_t l; 130 size_t l;
128 } from; /* whom this rule was received from (next hop) ? */ 131 } from; /* whom this rule was received from (next hop) ? */
129 132
130 struct fd_list target_peers_list; /* The list of Redirect-Hosts for this entry */ 133 struct fd_list target_peers_list; /* The list of Redirect-Hosts for this entry */
131 134
132 struct timespec timeout; /* When does this entry expires? */ 135 struct timespec timeout; /* When does this entry expire? */
133 struct fd_list exp_list; /* chain in the expire_list list, ordered by expiration date, protected by exp_peer_lock */ 136 struct fd_list exp_list; /* chain in the expire_list list, ordered by expiration date, protected by exp_peer_lock */
134 137
135 enum redir_h_u type; /* Type of this entry */ 138 enum redir_h_u type; /* Type of this entry */
136 struct fd_list redir_list; /* link in redirects_usages lists. Lists are ordered by the data value. Protected by rw locks */ 139 struct fd_list redir_list; /* link in redirects_usages lists. Lists are ordered by the data value. Protected by rw locks */
137 union matchdata data; /* The strings are duplicated & must be freed in this structure */ 140 union matchdata data; /* The strings are duplicated & must be freed in this structure */
141 UT_hash_handle hh; /* magic entry for hash table */
138 }; 142 };
139 143
140 /* The array where the redir_entries are stored */ 144 /* The array where the redir_entries are stored */
141 struct redir_line { 145 struct redir_line {
142 enum fd_rt_out_score score; 146 enum fd_rt_out_score score;
143 pthread_rwlock_t lock; /* protect the list */ 147 pthread_rwlock_t lock; /* protect the list */
144 struct fd_list sentinel; /* list of redir_entry, the "o" field of the sentinel points to the redir_line entry */ 148 struct fd_list sentinel; /* list of redir_entry, the "o" field of the sentinel points to the redir_line entry */
145 }; 149 };
146 extern struct redir_line redirects_usages[]; 150 extern struct redir_line redirects_usages[];
151 /* the hash table where entries are stored for ALL_SESSION and ALL_USER */
152 extern struct redir_entry *redirect_hash_table[];
147 153
148 /* Accelerator to the line lock */ 154 /* Accelerator to the line lock */
149 #define RWLOCK_REDIR( _entry ) ( &(redirects_usages[(_entry)->type].lock) ) 155 #define RWLOCK_REDIR( _entry ) ( &(redirects_usages[(_entry)->type].lock) )
150 156
151 /* Lock that must be owned before calling some functions */ 157 /* Lock that must be owned before calling some functions */
155 extern struct dict_object * redir_dict_dr; 161 extern struct dict_object * redir_dict_dr;
156 extern struct dict_object * redir_dict_un; 162 extern struct dict_object * redir_dict_un;
157 163
158 /* Functions on redir_entry */ 164 /* Functions on redir_entry */
159 int redir_entry_init(); 165 int redir_entry_init();
166 int redir_entry_fini();
160 int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t rhu, struct msg * qry, DiamId_t nh, size_t nhlen, os0_t oh, size_t ohlen); 167 int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t rhu, struct msg * qry, DiamId_t nh, size_t nhlen, os0_t oh, size_t ohlen);
161 extern int (*redir_entry_cmp_key[])(union matchdata * , union matchdata *); /* compare functions */ 168 extern int (*redir_entry_cmp_key[])(union matchdata * , union matchdata *); /* compare functions */
162 int redir_entry_insert(struct redir_entry * e); 169 int redir_entry_insert(struct redir_entry * e);
163 int redir_entry_destroy(struct redir_entry * e); 170 int redir_entry_destroy(struct redir_entry * e);
164 171
"Welcome to our mercurial repository"