diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-02-25 16:22:29 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-02-25 16:22:29 -0500 |
commit | 2ab3389ed64827fee4e756e5a3ffc5ff579b1a05 (patch) | |
tree | 221c82d3a06aa60c1e156d972e120784d95b62a4 /src/or/networkstatus.c | |
parent | 8b93dacbcfbca7b4653f7a9b727bdc209aff1e7c (diff) | |
parent | 215930a7de3682e311badc94edc5be761b61e0c0 (diff) | |
download | tor-2ab3389ed64827fee4e756e5a3ffc5ff579b1a05.tar.gz tor-2ab3389ed64827fee4e756e5a3ffc5ff579b1a05.zip |
Merge remote branch 'mikeperry/consensus-bw-weights5-merge'
Conflicts:
ChangeLog
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r-- | src/or/networkstatus.c | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index a507f1be2d..9023bc6208 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -1264,7 +1264,6 @@ update_consensus_networkstatus_fetch_time(time_t now) time_to_download_next_consensus = now; log_info(LD_DIR, "No live consensus; we should fetch one immediately."); } - } /** Return 1 if there's a reason we shouldn't try any directory @@ -2038,6 +2037,25 @@ networkstatus_dump_bridge_status_to_file(time_t now) tor_free(status); } +int32_t +get_net_param_from_list(smartlist_t *net_params, const char *param_name, + int default_val) +{ + size_t name_len = strlen(param_name); + + SMARTLIST_FOREACH_BEGIN(net_params, const char *, p) { + if (!strcmpstart(p, param_name) && p[name_len] == '=') { + int ok=0; + long v = tor_parse_long(p+name_len+1, 10, INT32_MIN, + INT32_MAX, &ok, NULL); + if (ok) + return (int32_t) v; + } + } SMARTLIST_FOREACH_END(p); + + return default_val; +} + /** Return the value of a integer parameter from the networkstatus <b>ns</b> * whose name is <b>param_name</b>. If <b>ns</b> is NULL, try loading the * latest consensus ourselves. Return <b>default_val</b> if no latest @@ -2046,27 +2064,30 @@ int32_t networkstatus_get_param(networkstatus_t *ns, const char *param_name, int32_t default_val) { - size_t name_len; - if (!ns) /* if they pass in null, go find it ourselves */ ns = networkstatus_get_latest_consensus(); if (!ns || !ns->net_params) return default_val; - name_len = strlen(param_name); + return get_net_param_from_list(ns->net_params, param_name, default_val); +} - SMARTLIST_FOREACH_BEGIN(ns->net_params, const char *, p) { - if (!strcmpstart(p, param_name) && p[name_len] == '=') { - int ok=0; - long v = tor_parse_long(p+name_len+1, 10, INT32_MIN, - INT32_MAX, &ok, NULL); - if (ok) - return (int32_t) v; - } - } SMARTLIST_FOREACH_END(p); +/** Return the value of a integer bw weight parameter from the networkstatus + * <b>ns</b> whose name is <b>weight_name</b>. If <b>ns</b> is NULL, try + * loading the latest consensus ourselves. Return <b>default_val</b> if no + * latest consensus, or if it has no parameter called <b>param_name</b>. */ +int32_t +networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight_name, + int32_t default_val) +{ + if (!ns) /* if they pass in null, go find it ourselves */ + ns = networkstatus_get_latest_consensus(); - return default_val; + if (!ns || !ns->weight_params) + return default_val; + + return get_net_param_from_list(ns->weight_params, weight_name, default_val); } /** Return the name of the consensus flavor <b>flav</b> as used to identify |