* Main balancing routine. This does not try to keep the same proxy for * the call if some proxies were disabled or enabled; proxy death considered * too rare. Otherwise we should implement "mature" HA clustering, which is * too expensive here. */
| 2431 | * too expensive here. |
| 2432 | */ |
| 2433 | struct rtpp_node * |
| 2434 | select_rtpp_node(struct sip_msg * msg, |
| 2435 | str callid, struct rtpp_set *set, pv_spec_p spec, int do_test) |
| 2436 | { |
| 2437 | unsigned sum, weight_sum; |
| 2438 | struct rtpp_node* node; |
| 2439 | int was_forced, sumcut, found, constant_weight_sum; |
| 2440 | pv_value_t val; |
| 2441 | |
| 2442 | if (!set) { |
| 2443 | LM_ERR("no set specified\n"); |
| 2444 | return NULL; |
| 2445 | } |
| 2446 | |
| 2447 | if (rtpp_check_reload_ver(set) != 0) { |
| 2448 | LM_ERR("cannot update rtpp proxies list (set: %d)\n", |
| 2449 | set ? set->id_set : -1); |
| 2450 | return NULL; |
| 2451 | } |
| 2452 | |
| 2453 | /* Most popular case: 1 proxy, nothing to calculate */ |
| 2454 | if (set->rtpp_node_count == 1) { |
| 2455 | node = set->rn_first; |
| 2456 | if (node->rn_disabled && node->rn_recheck_ticks <= get_ticks()) { |
| 2457 | node->rn_disabled = rtpp_test(node, 1, 0); |
| 2458 | if (node->rn_disabled) |
| 2459 | node->rn_recheck_ticks = get_ticks() + |
| 2460 | rtpproxy_disable_tout; |
| 2461 | } |
| 2462 | if (node->rn_disabled) |
| 2463 | return NULL; |
| 2464 | |
| 2465 | goto done; |
| 2466 | } |
| 2467 | |
| 2468 | /* XXX Use quick-and-dirty hashing algo */ |
| 2469 | for(sum = 0; callid.len > 0; callid.len--) |
| 2470 | sum += callid.s[callid.len - 1]; |
| 2471 | sum &= 0xff; |
| 2472 | |
| 2473 | was_forced = 0; |
| 2474 | retry: |
| 2475 | weight_sum = 0; |
| 2476 | constant_weight_sum = 0; |
| 2477 | found = 0; |
| 2478 | for (node=set->rn_first; node!=NULL; node=node->rn_next) { |
| 2479 | |
| 2480 | if (node->rn_disabled && node->rn_recheck_ticks <= get_ticks()){ |
| 2481 | /* Try to enable if it's time to try. */ |
| 2482 | node->rn_disabled = rtpp_test(node, 1, 0); |
| 2483 | if (node->rn_disabled) |
| 2484 | node->rn_recheck_ticks = get_ticks() + |
| 2485 | rtpproxy_disable_tout; |
| 2486 | } |
| 2487 | constant_weight_sum += node->rn_weight; |
| 2488 | if (!node->rn_disabled) { |
| 2489 | weight_sum += node->rn_weight; |
| 2490 | found = 1; |
no test coverage detected