Search in sources :

Example 41 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class PairingManagerImpl method initialise.

protected void initialise(Core _core) {
    synchronized (this) {
        core = _core;
    }
    try {
        tunnel_handler = new PairingManagerTunnelHandler(this, core);
        PluginInterface default_pi = PluginInitializer.getDefaultInterface();
        DelayedTask dt = default_pi.getUtilities().createDelayedTask(new Runnable() {

            @Override
            public void run() {
                new DelayedEvent("PM:delayinit", 10 * 1000, new AERunnable() {

                    @Override
                    public void runSupport() {
                        enableUpdates();
                    }
                });
            }
        });
        dt.queue();
        if (ui != null) {
            try {
                ui.initialise(default_pi, param_icon_enable);
            } catch (Throwable e) {
            // ignore com.biglybt.ui.swt errors console UI users get here
            }
        }
    } finally {
        init_sem.releaseForever();
        updateSRPState();
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) DelayedTask(com.biglybt.pif.utils.DelayedTask)

Example 42 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class PairingManagerImpl method doUpdate.

protected void doUpdate() {
    long now = SystemTime.getMonotonousTime();
    synchronized (this) {
        if (deferred_update_event != null) {
            return;
        }
        long time_since_last_update = now - last_update_time;
        if (last_update_time > 0 && time_since_last_update < min_update_period) {
            deferUpdate(min_update_period - time_since_last_update);
            return;
        }
        update_in_progress = true;
    }
    try {
        Map<String, Object> payload = new HashMap<>();
        boolean is_enabled = param_enable.getValue();
        boolean has_services = false;
        synchronized (this) {
            List<Map<String, String>> list = new ArrayList<>();
            payload.put("s", list);
            if (services.size() > 0 && is_enabled) {
                if (global_update_event == null) {
                    global_update_event = SimpleTimer.addPeriodicEvent("PM:updater", GLOBAL_UPDATE_PERIOD, new TimerEventPerformer() {

                        private int tick_count;

                        @Override
                        public void perform(TimerEvent event) {
                            tick_count++;
                            updateGlobals(false);
                            if (tick_count % CD_REFRESH_TICKS == 0) {
                                updateNeeded();
                            }
                        }
                    });
                    updateGlobals(true);
                }
                boolean enable_nets = param_net_enable.getValue();
                for (PairedServiceImpl service : services.values()) {
                    list.add(service.toMap(enable_nets));
                }
                has_services = list.size() > 0;
            } else {
                if (global_update_event == null) {
                    if (consec_update_fails == 0 && !must_update_once) {
                        update_in_progress = false;
                        setStatus(MessageText.getString(is_enabled ? "pairing.status.noservices" : "label.disabled"));
                        return;
                    }
                } else {
                    global_update_event.cancel();
                    global_update_event = null;
                }
            }
            last_update_time = now;
        }
        // we need a valid access code here!
        String ac = readAccessCode();
        if (ac.length() == 0) {
            ac = allocateAccessCode(true);
        }
        payload.put("ac", ac);
        String gc = getGroup();
        if (gc != null && gc.length() > 0) {
            payload.put("gc", gc);
        }
        if (is_enabled && has_services && param_srp_enable.getValue()) {
            tunnel_handler.setActive(true);
            tunnel_handler.updateRegistrationData(payload);
        } else {
            tunnel_handler.setActive(false);
        }
        synchronized (this) {
            if (current_v4 != null) {
                payload.put("c_v4", current_v4.getHostAddress());
            }
            if (current_v6 != null) {
                payload.put("c_v6", current_v6.getHostAddress());
            }
            if (local_v4.length() > 0) {
                payload.put("l_v4", local_v4);
            }
            if (local_v6.length() > 0) {
                payload.put("l_v6", local_v6);
            }
            if (param_e_enable.getValue()) {
                String host = param_host.getValue().trim();
                if (host.length() > 0) {
                    payload.put("e_h", host);
                }
                String v4 = param_public_ipv4.getValue().trim();
                if (v4.length() > 0) {
                    payload.put("e_v4", v4);
                }
                String v6 = param_public_ipv6.getValue().trim();
                if (v6.length() > 0) {
                    payload.put("e_v6", v6);
                }
                String l_v4 = param_local_ipv4.getValue().trim();
                if (l_v4.length() > 0) {
                    payload.put("e_l_v4", l_v4);
                }
                String l_v6 = param_local_ipv6.getValue().trim();
                if (l_v6.length() > 0) {
                    payload.put("e_l_v6", l_v6);
                }
            }
            try {
                PluginInterface pi_upnp = core.getPluginManager().getPluginInterfaceByClass(UPnPPlugin.class);
                if (pi_upnp != null) {
                    UPnPPlugin upnp = (UPnPPlugin) pi_upnp.getPlugin();
                    if (upnp.isEnabled()) {
                        List<Map<String, String>> upnp_list = new ArrayList<>();
                        payload.put("upnp", upnp_list);
                        UPnPPluginService[] services = upnp.getServices();
                        Set<UPnPRootDevice> devices = new HashSet<>();
                        for (UPnPPluginService service : services) {
                            if (upnp_list.size() > 10) {
                                break;
                            }
                            UPnPRootDevice root_device = service.getService().getGenericService().getDevice().getRootDevice();
                            if (!devices.contains(root_device)) {
                                devices.add(root_device);
                                Map<String, String> map = new HashMap<>();
                                upnp_list.add(map);
                                map.put("i", root_device.getInfo());
                            }
                        }
                    }
                }
            } catch (Throwable e) {
            }
            try {
                NetworkAdmin admin = NetworkAdmin.getSingleton();
                NetworkAdminHTTPProxy http_proxy = admin.getHTTPProxy();
                if (http_proxy != null) {
                    payload.put("hp", http_proxy.getName());
                }
                NetworkAdminSocksProxy[] socks_proxies = admin.getSocksProxies();
                if (socks_proxies.length > 0) {
                    payload.put("sp", socks_proxies[0].getName());
                }
            } catch (Throwable e) {
            }
            payload.put("_enabled", is_enabled ? 1L : 0L);
        }
        if (DEBUG) {
            System.out.println("PS: doUpdate: " + payload);
        }
        sendRequest("update", payload);
        synchronized (this) {
            consec_update_fails = 0;
            must_update_once = false;
            if (deferred_update_event == null) {
                COConfigurationManager.setParameter("pairing.updateoutstanding", false);
            }
            update_in_progress = false;
            if (global_update_event == null) {
                setStatus(MessageText.getString(is_enabled ? "pairing.status.noservices" : "label.disabled"));
            } else {
                setStatus(MessageText.getString("pairing.status.registered", new String[] { new SimpleDateFormat().format(new Date(SystemTime.getCurrentTime())) }));
            }
        }
    } catch (Throwable e) {
        synchronized (this) {
            try {
                consec_update_fails++;
                long back_off = min_update_period;
                for (int i = 0; i < consec_update_fails; i++) {
                    back_off *= 2;
                    if (back_off > max_update_period) {
                        back_off = max_update_period;
                        break;
                    }
                }
                deferUpdate(back_off);
            } finally {
                update_in_progress = false;
            }
        }
    } finally {
        synchronized (this) {
            if (update_in_progress) {
                Debug.out("Something didn't clear update_in_progress!!!!");
                update_in_progress = false;
            }
        }
    }
}
Also used : UPnPPluginService(com.biglybt.plugin.upnp.UPnPPluginService) PluginInterface(com.biglybt.pif.PluginInterface) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) UPnPPlugin(com.biglybt.plugin.upnp.UPnPPlugin) SimpleDateFormat(java.text.SimpleDateFormat)

Example 43 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class AEPluginProxyHandler method getPluginProxy.

public static PluginProxyImpl getPluginProxy(String reason, URL target, Map<String, Object> properties, boolean can_wait) {
    if (isEnabled()) {
        checkPluginInstallation(null, reason);
        String url_protocol = target.getProtocol().toLowerCase();
        if (url_protocol.startsWith("http") || url_protocol.equals("ftp")) {
            if (can_wait) {
                waitForPlugins(0);
            }
            if (properties == null) {
                properties = new HashMap<>();
            }
            for (PluginInterface pi : plugins) {
                try {
                    IPCInterface ipc = pi.getIPC();
                    Object[] proxy_details;
                    if (ipc.canInvoke("getProxy", new Object[] { reason, target, properties })) {
                        proxy_details = (Object[]) ipc.invoke("getProxy", new Object[] { reason, target, properties });
                    } else {
                        proxy_details = (Object[]) ipc.invoke("getProxy", new Object[] { reason, target });
                    }
                    if (proxy_details != null) {
                        if (proxy_details.length == 2) {
                            // support old plugins
                            proxy_details = new Object[] { proxy_details[0], proxy_details[1], target.getHost() };
                        }
                        return (new PluginProxyImpl(target.toExternalForm(), reason, ipc, properties, proxy_details));
                    }
                } catch (Throwable e) {
                }
            }
        }
    }
    return (null);
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) DHTPluginInterface(com.biglybt.plugin.dht.DHTPluginInterface) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Example 44 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class AEPluginProxyHandler method getPluginServerProxy.

public static Map<String, Object> getPluginServerProxy(String reason, String network, String server_uid, Map<String, Object> options) {
    waitForPlugins(plugin_init_max_wait);
    checkPluginInstallation(network, reason);
    PluginInterface pi = getPluginProxyForNetwork(network, false);
    if (pi == null) {
        return (null);
    }
    options = new HashMap<>(options);
    options.put("id", server_uid);
    try {
        IPCInterface ipc = pi.getIPC();
        Map<String, Object> reply = (Map<String, Object>) ipc.invoke("getProxyServer", new Object[] { reason, options });
        return (reply);
    } catch (Throwable e) {
    }
    return (null);
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) DHTPluginInterface(com.biglybt.plugin.dht.DHTPluginInterface) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Example 45 with PluginInterface

use of com.biglybt.pif.PluginInterface in project BiglyBT by BiglySoftware.

the class AEPluginProxyHandler method getPluginDHTProxy.

public static DHTPluginInterface getPluginDHTProxy(String reason, String network, Map<String, Object> options) {
    waitForPlugins(plugin_init_max_wait);
    checkPluginInstallation(network, reason);
    PluginInterface pi = getPluginProxyForNetwork(network, false);
    if (pi == null) {
        return (null);
    }
    try {
        IPCInterface ipc = pi.getIPC();
        DHTPluginInterface reply = (DHTPluginInterface) ipc.invoke("getProxyDHT", new Object[] { reason, options });
        return (reply);
    } catch (Throwable e) {
    }
    return (null);
}
Also used : DHTPluginInterface(com.biglybt.plugin.dht.DHTPluginInterface) PluginInterface(com.biglybt.pif.PluginInterface) DHTPluginInterface(com.biglybt.plugin.dht.DHTPluginInterface) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Aggregations

PluginInterface (com.biglybt.pif.PluginInterface)120 URL (java.net.URL)15 IPCInterface (com.biglybt.pif.ipc.IPCInterface)14 UIManager (com.biglybt.pif.ui.UIManager)13 PluginManager (com.biglybt.pif.PluginManager)12 HashMap (java.util.HashMap)12 List (java.util.List)12 Download (com.biglybt.pif.download.Download)10 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)10 File (java.io.File)10 Map (java.util.Map)10 DownloadManager (com.biglybt.core.download.DownloadManager)9 UIFunctions (com.biglybt.ui.UIFunctions)9 ArrayList (java.util.ArrayList)9 PluginException (com.biglybt.pif.PluginException)8 MenuItem (com.biglybt.pif.ui.menus.MenuItem)8 MenuManager (com.biglybt.pif.ui.menus.MenuManager)8 DHTPlugin (com.biglybt.plugin.dht.DHTPlugin)8 DHT (com.biglybt.core.dht.DHT)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7