Search in sources :

Example 1 with ClientInstanceManager

use of com.biglybt.core.instancemanager.ClientInstanceManager in project BiglyBT by BiglySoftware.

the class NetworkAdminImpl method runInitialChecks.

@Override
public void runInitialChecks(Core core) {
    ClientInstanceManager i_man = core.getInstanceManager();
    final ClientInstance my_instance = i_man.getMyInstance();
    i_man.addListener(new ClientInstanceManagerListener() {

        private InetAddress external_address;

        @Override
        public void instanceFound(ClientInstance instance) {
        }

        @Override
        public void instanceChanged(ClientInstance instance) {
            if (instance == my_instance) {
                InetAddress address = instance.getExternalAddress();
                if (external_address == null || !external_address.equals(address)) {
                    external_address = address;
                    try {
                        lookupCurrentASN(address);
                    } catch (Throwable e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }

        @Override
        public void instanceLost(ClientInstance instance) {
        }

        @Override
        public void instanceTracked(ClientInstanceTracked instance) {
        }
    });
    if (COConfigurationManager.getBooleanParameter("Proxy.Check.On.Start")) {
        NetworkAdminSocksProxy[] socks = getSocksProxies();
        for (int i = 0; i < socks.length; i++) {
            NetworkAdminSocksProxy sock = socks[i];
            try {
                sock.getVersionsSupported();
            } catch (Throwable e) {
                Debug.printStackTrace(e);
                Logger.log(new LogAlert(true, LogAlert.AT_WARNING, "Socks proxy " + sock.getName() + " check failed: " + Debug.getNestedExceptionMessage(e)));
            }
        }
        NetworkAdminHTTPProxy http_proxy = getHTTPProxy();
        if (http_proxy != null) {
            try {
                http_proxy.getDetails();
            } catch (Throwable e) {
                Debug.printStackTrace(e);
                Logger.log(new LogAlert(true, LogAlert.AT_WARNING, "HTTP proxy " + http_proxy.getName() + " check failed: " + Debug.getNestedExceptionMessage(e)));
            }
        }
    }
    if (COConfigurationManager.getBooleanParameter("Check Bind IP On Start")) {
        checkBindAddresses(true);
    }
    NetworkAdminSpeedTestScheduler nast = NetworkAdminSpeedTestSchedulerImpl.getInstance();
    nast.initialise();
}
Also used : ClientInstanceManagerListener(com.biglybt.core.instancemanager.ClientInstanceManagerListener) ClientInstanceTracked(com.biglybt.core.instancemanager.ClientInstanceTracked) ClientInstance(com.biglybt.core.instancemanager.ClientInstance) LogAlert(com.biglybt.core.logging.LogAlert) ClientInstanceManager(com.biglybt.core.instancemanager.ClientInstanceManager)

Example 2 with ClientInstanceManager

use of com.biglybt.core.instancemanager.ClientInstanceManager in project BiglyBT by BiglySoftware.

the class AddressUtils method getLANAddresses.

public static List<String> getLANAddresses(String address) {
    List<String> result = new ArrayList<>();
    result.add(address);
    try {
        InetAddress ad = InetAddress.getByName(address);
        if (isLANLocalAddress(address) != LAN_LOCAL_NO) {
            ClientInstanceManager im = getInstanceManager();
            if (im == null || !im.isInitialized()) {
                return (result);
            }
            ClientInstance[] instances = im.getOtherInstances();
            for (int i = 0; i < instances.length; i++) {
                ClientInstance instance = instances[i];
                List addresses = instance.getInternalAddresses();
                if (addresses.contains(ad)) {
                    for (int j = 0; j < addresses.size(); j++) {
                        InetAddress ia = (InetAddress) addresses.get(j);
                        String str = ia.getHostAddress();
                        if (!result.contains(str)) {
                            result.add(str);
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
    }
    return (result);
}
Also used : ClientInstance(com.biglybt.core.instancemanager.ClientInstance) ClientInstanceManager(com.biglybt.core.instancemanager.ClientInstanceManager)

Example 3 with ClientInstanceManager

use of com.biglybt.core.instancemanager.ClientInstanceManager in project BiglyBT by BiglySoftware.

the class AddressUtils method adjustAddress.

private static InetSocketAddress adjustAddress(InetSocketAddress address, boolean ext_to_lan, int port_type) {
    ClientInstanceManager im = getInstanceManager();
    if (im == null || !im.isInitialized()) {
        return (address);
    }
    InetSocketAddress adjusted_address;
    if (ext_to_lan) {
        adjusted_address = im.getLANAddress(address, port_type);
    } else {
        adjusted_address = im.getExternalAddress(address, port_type);
    }
    if (adjusted_address == null) {
        adjusted_address = address;
    } else {
    // System.out.println( "adj: " + address + "/" + ext_to_lan + " -> " + adjusted_address );
    }
    return (adjusted_address);
}
Also used : ClientInstanceManager(com.biglybt.core.instancemanager.ClientInstanceManager)

Example 4 with ClientInstanceManager

use of com.biglybt.core.instancemanager.ClientInstanceManager in project BiglyBT by BiglySoftware.

the class AddressUtils method addLANRateLimitAddress.

public static void addLANRateLimitAddress(InetAddress address) {
    synchronized (pending_addresses) {
        ClientInstanceManager im = getInstanceManager();
        if (im == null || !im.isInitialized()) {
            pending_addresses.add(address);
            if (pa_timer == null) {
                pa_timer = SimpleTimer.addPeriodicEvent("au:pa", 250, new TimerEventPerformer() {

                    @Override
                    public void perform(TimerEvent event) {
                        synchronized (pending_addresses) {
                            ClientInstanceManager im = getInstanceManager();
                            if (im != null && im.isInitialized()) {
                                for (InetAddress address : pending_addresses) {
                                    try {
                                        im.addLANAddress(address);
                                    } catch (Throwable e) {
                                    }
                                }
                                pending_addresses.clear();
                                pa_timer.cancel();
                                pa_timer = null;
                            }
                        }
                    }
                });
            }
        } else {
            im.addLANAddress(address);
        }
    }
}
Also used : ClientInstanceManager(com.biglybt.core.instancemanager.ClientInstanceManager)

Aggregations

ClientInstanceManager (com.biglybt.core.instancemanager.ClientInstanceManager)4 ClientInstance (com.biglybt.core.instancemanager.ClientInstance)2 ClientInstanceManagerListener (com.biglybt.core.instancemanager.ClientInstanceManagerListener)1 ClientInstanceTracked (com.biglybt.core.instancemanager.ClientInstanceTracked)1 LogAlert (com.biglybt.core.logging.LogAlert)1