// called once a second // bool ACCT_MGR_INFO::poll() { if (!using_am()) return false; if (gstate.acct_mgr_op.gui_http->is_busy()) { return false; } if (gstate.now > next_rpc_time) { // default synch period is 1 day // next_rpc_time = gstate.now + 86400; gstate.acct_mgr_op.do_rpc(*this, false); return true; } // if not dynamic AM, we're done // if (!dynamic) { return false; } // See if some resource is starved with the current set of projects, // and if so possibly do a "starved" RPC asking for different projects // do this check once a minute // static int idle_timer = 0; if (++idle_timer < 60) { return false; } idle_timer = 0; get_nidle(); if (any_resource_idle()) { if (first_starved == 0) { first_starved = gstate.now; starved_rpc_backoff = STARVED_RPC_DELAY; starved_rpc_min_time = gstate.now + STARVED_RPC_DELAY; } else { if (gstate.now < starved_rpc_min_time) { return false; } msg_printf(NULL, MSG_INFO, "Some devices idle - requesting new projects from %s", gstate.acct_mgr_info.project_name ); gstate.acct_mgr_op.do_rpc(*this, false); starved_rpc_backoff *= 2; if (starved_rpc_backoff > 86400) { starved_rpc_backoff = 86400; } starved_rpc_min_time = gstate.now + starved_rpc_backoff; return true; } } else { first_starved = 0; } return false; }
bool ACCT_MGR_INFO::poll() { if (!using_am()) return false; if (gstate.acct_mgr_op.gui_http->is_busy()) return false; if (gstate.now > next_rpc_time) { // default synch period is 1 day // next_rpc_time = gstate.now + 86400; gstate.acct_mgr_op.do_rpc( master_url, login_name, password_hash, false ); return true; } return false; }
// called at client startup. // If currently using an AM, read its URL and login files // int ACCT_MGR_INFO::init() { MIOFILE mf; FILE* p; int retval; clear(); p = fopen(ACCT_MGR_URL_FILENAME, "r"); if (!p) { // if not using acct mgr, make sure projects not flagged, // otherwise won't be able to detach them. // for (unsigned int i=0; i<gstate.projects.size(); i++) { gstate.projects[i]->attached_via_acct_mgr = false; } return 0; } mf.init_file(p); XML_PARSER xp(&mf); if (!xp.parse_start("acct_mgr")) { // } while (!xp.get_tag()) { if (!xp.is_tag) { printf("unexpected text: %s\n", xp.parsed_tag); continue; } if (xp.match_tag("/acct_mgr")) break; else if (xp.parse_str("name", project_name, 256)) continue; else if (xp.parse_str("url", master_url, 256)) continue; else if (xp.parse_bool("send_gui_rpc_info", send_gui_rpc_info)) continue; else if (xp.match_tag("signing_key")) { retval = xp.element_contents("</signing_key>", signing_key, sizeof(signing_key)); if (retval) { msg_printf(NULL, MSG_INFO, "error parsing <signing_key> in acct_mgr_url.xml" ); } continue; } else if (xp.parse_bool("cookie_required", cookie_required)) continue; else if (xp.parse_str("cookie_failure_url", cookie_failure_url, 256)) continue; if (log_flags.unparsed_xml) { msg_printf(NULL, MSG_INFO, "[unparsed_xml] ACCT_MGR_INFO::init: unrecognized %s", xp.parsed_tag ); } xp.skip_unexpected(log_flags.unparsed_xml, "ACCT_MGR_INFO::init"); } fclose(p); p = fopen(ACCT_MGR_LOGIN_FILENAME, "r"); if (p) { parse_login_file(p); fclose(p); } if (using_am()) { msg_printf(NULL, MSG_INFO, "Using account manager %s", project_name); if (strlen(user_name)) { msg_printf(NULL, MSG_INFO, "Account manager login: %s", user_name); } } return 0; }