Search in sources :

Example 1 with UPnPRootDevice

use of com.biglybt.net.upnp.UPnPRootDevice in project BiglyBT by BiglySoftware.

the class DeviceUPnPImpl method getDisplayProperties.

@Override
protected void getDisplayProperties(List<String[]> dp) {
    super.getDisplayProperties(dp);
    UPnPDevice device = device_may_be_null;
    if (device != null) {
        UPnPRootDevice root = device.getRootDevice();
        URL location = root.getLocation();
        addDP(dp, "dht.reseed.ip", location.getHost() + ":" + location.getPort());
        String model_details = device.getModelName();
        String model_url = device.getModelURL();
        if (model_url != null && model_url.length() > 0) {
            model_details += " (" + model_url + ")";
        }
        String manu_details = device.getManufacturer();
        String manu_url = device.getManufacturerURL();
        if (manu_url != null && manu_url.length() > 0) {
            manu_details += " (" + manu_url + ")";
        }
        addDP(dp, "device.model.desc", device.getModelDescription());
        addDP(dp, "device.model.name", model_details);
        addDP(dp, "device.model.num", device.getModelNumber());
        addDP(dp, "device.manu.desc", manu_details);
    } else {
        InetAddress ia = getAddress();
        if (ia != null) {
            addDP(dp, "dht.reseed.ip", ia.getHostAddress());
        }
    }
    addDP(dp, "!Is Liveness Detectable!", isLivenessDetectable());
    if (isManual()) {
        addDP(dp, "azbuddy.ui.table.online", isAlive());
        addDP(dp, "device.lastseen", getLastSeen() == 0 ? "" : new SimpleDateFormat().format(new Date(getLastSeen())));
    }
}
Also used : UPnPDevice(com.biglybt.net.upnp.UPnPDevice) InetAddress(java.net.InetAddress) SimpleDateFormat(java.text.SimpleDateFormat) URL(java.net.URL) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice)

Example 2 with UPnPRootDevice

use of com.biglybt.net.upnp.UPnPRootDevice 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 3 with UPnPRootDevice

use of com.biglybt.net.upnp.UPnPRootDevice in project BiglyBT by BiglySoftware.

the class DeviceUPnPImpl method getAddress.

@Override
public InetAddress getAddress() {
    try {
        UPnPDevice device = device_may_be_null;
        if (device != null) {
            UPnPRootDevice root = device.getRootDevice();
            URL location = root.getLocation();
            return (InetAddress.getByName(location.getHost()));
        } else {
            InetAddress address = (InetAddress) getTransientProperty(TP_IP_ADDRESS);
            if (address != null) {
                return (address);
            }
            String last = getPersistentStringProperty(PP_IP_ADDRESS);
            if (last != null && last.length() > 0) {
                return (InetAddress.getByName(last));
            }
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    return (null);
}
Also used : UPnPDevice(com.biglybt.net.upnp.UPnPDevice) InetAddress(java.net.InetAddress) URL(java.net.URL) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice)

Aggregations

UPnPRootDevice (com.biglybt.net.upnp.UPnPRootDevice)3 UPnPDevice (com.biglybt.net.upnp.UPnPDevice)2 InetAddress (java.net.InetAddress)2 URL (java.net.URL)2 SimpleDateFormat (java.text.SimpleDateFormat)2 PluginInterface (com.biglybt.pif.PluginInterface)1 UPnPPlugin (com.biglybt.plugin.upnp.UPnPPlugin)1 UPnPPluginService (com.biglybt.plugin.upnp.UPnPPluginService)1