// LICENSE_CODE ZON
'use strict'; /*jslint node:true*/
process.env.NODE_EMBEDDED = '1';
require('../util/config.js');
const conf = require('../util/conf.js');
const agent_proxy = require('./unblocker/agent_proxy.js');
const unblocker_lib = require('./pub/unblocker_lib.js');
const smart_proxy = require('./unblocker/smart_proxy.js');
const transparent = require('./unblocker/transparent.js');
const wget = require('../util/wget.js');
const zerr = require('../util/zerr.js');
const client = require('./peer/client.js');
const E = exports;

if (process.env.ZNODE_DEP_SCAN)
{
    let dep_scan = require('../util/dep_scan.js');
    process.stdout.write(JSON.stringify(dep_scan()));
    process.exit(0);
}

process.zon.init();
conf.app = 'android';

E.proxy_get_port = function(country, force_port){
    return smart_proxy.get(country, force_port).port; };

E.set_auth_info = agent_proxy.set_auth_info;
E.should_redirect_outgoing_tcp = transparent.should_redirect_outgoing_tcp;
E.enable_app_unblocker = transparent.enable;
E.disable_app_unblocker = transparent.disable;
E.set_app_country = transparent.set_app_country;
E.set_apkid = client.set_apkid;
E.set_appid = client.set_appid;
E.set_idle = client.set_idle;
E.set_confdir = client.set_confdir;
E.zid_update = client.zid_update;
E.set_mobile_enable = client.set_mobile_enable;
E.usage_update = client.usage_update;

E.unblocker_json_set = function(json, opt){
    unblocker_lib.unblocker_json_set(json, opt);
    transparent.unblocker_json_set(json, opt);
};

let last_gw;
E.gw_change_notify = function(gw){
    if (gw==last_gw)
        return;
    zerr.notice('Gateway IP changed from '+last_gw+' to '+gw);
    last_gw = gw;
    smart_proxy.purge_stats();
    unblocker_lib.cache_purge();
    client.connect();
};
