Changeset 563:dc9764591567 in freeDiameter
- Timestamp:
- Sep 16, 2010, 4:41:44 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/routing_dispatch.c
r455 r563 844 844 CHECK_FCT( fd_rtd_init(&rtd) ); 845 845 846 /* Add all peers in OPEN state */846 /* Add all peers currently in OPEN state */ 847 847 CHECK_FCT( pthread_rwlock_rdlock(&fd_g_activ_peers_rw) ); 848 848 for (li = fd_g_activ_peers.next; li != &fd_g_activ_peers; li = li->next) { -
libfreeDiameter/rt_data.c
r403 r563 250 250 } 251 251 252 /* Reorder the list of peers */252 /* Reorder the list of peers. If several peer have the same highest score, they are randomized. */ 253 253 int fd_rtd_candidate_reorder(struct fd_list * candidates) 254 254 { 255 255 struct fd_list unordered = FD_LIST_INITIALIZER(unordered), *li; 256 struct fd_list highest = FD_LIST_INITIALIZER(highest); 257 int hs = -1; 256 258 257 259 TRACE_ENTRY("%p", candidates); … … 267 269 fd_list_unlink(&c->chain); 268 270 269 /* Find the position in ordered candidates list */ 270 for (li = candidates->next; li != candidates; li = li->next) { 271 struct rtd_candidate * cnext = (struct rtd_candidate *) li; 272 if (cnext->score >= c->score) 273 break; 274 } 275 276 /* Add the element there */ 277 fd_list_insert_before(li, &c->chain); 278 } 271 /* If this candidate has a higher score than the previous ones */ 272 if (c->score > hs) { 273 /* Then we move the previous high score items at end of the list */ 274 fd_list_move_end(candidates, &highest); 275 276 /* And the new high score is this reset */ 277 hs = c->score; 278 } 279 280 /* If this candidate equals the higher score, add it into highest list at a random place */ 281 if (c->score == hs) { 282 if (rand() & 1) { 283 fd_list_insert_after(&highest, &c->chain); 284 } else { 285 fd_list_insert_before(&highest, &c->chain); 286 } 287 /* Otherwise, insert at normal place in the list */ 288 } else { 289 /* Find the position in ordered candidates list */ 290 for (li = candidates->next; li != candidates; li = li->next) { 291 struct rtd_candidate * cnext = (struct rtd_candidate *) li; 292 if (cnext->score >= c->score) 293 break; 294 } 295 296 /* Add the element there */ 297 fd_list_insert_before(li, &c->chain); 298 } 299 } 300 301 /* Now simply move back all the "highest" candidates at the end of the list */ 302 fd_list_move_end(candidates, &highest); 279 303 280 304 return 0;
Note: See TracChangeset
for help on using the changeset viewer.