Search in sources :

Example 1 with ClientInstance

use of com.biglybt.core.instancemanager.ClientInstance 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 ClientInstance

use of com.biglybt.core.instancemanager.ClientInstance 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 ClientInstance

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

the class LocalTrackerPlugin method handleTrackResult.

protected int handleTrackResult(ClientInstanceTracked tracked_inst) {
    ClientInstance inst = tracked_inst.getInstance();
    Download download = (Download) tracked_inst.getTarget().getTarget();
    boolean is_seed = tracked_inst.isSeed();
    long now = plugin_interface.getUtilities().getCurrentSystemTime();
    boolean skip = false;
    try {
        mon.enter();
        Map<String, Long> map = track_times.get(inst.getID());
        if (map == null) {
            map = new HashMap<>();
            track_times.put(inst.getID(), map);
        }
        String dl_key = plugin_interface.getUtilities().getFormatters().encodeBytesToString(download.getTorrent().getHash());
        Long last_track = map.get(dl_key);
        if (last_track != null) {
            long lt = last_track.longValue();
            if (now - lt < 30 * 1000) {
                skip = true;
            }
        }
        map.put(dl_key, new Long(now));
    } finally {
        mon.exit();
    }
    if (skip) {
        return (-1);
    }
    log.log("Tracked: " + inst.getString() + ": " + download.getName() + ", seed = " + is_seed);
    if (download.isComplete() && is_seed) {
        return (1);
    }
    PeerManager peer_manager = download.getPeerManager();
    if (peer_manager != null) {
        String peer_ip = inst.getInternalAddress().getHostAddress();
        int peer_tcp_port = inst.getTCPListenPort();
        int peer_udp_port = inst.getUDPListenPort();
        log.log("    " + download.getName() + ": Injecting peer " + peer_ip + ":" + peer_tcp_port + "/" + peer_udp_port);
        peer_manager.addPeer(peer_ip, peer_tcp_port, peer_udp_port, false);
    }
    return (is_seed ? 3 : 2);
}
Also used : PeerManager(com.biglybt.pif.peers.PeerManager) ClientInstance(com.biglybt.core.instancemanager.ClientInstance) Download(com.biglybt.pif.download.Download)

Aggregations

ClientInstance (com.biglybt.core.instancemanager.ClientInstance)3 ClientInstanceManager (com.biglybt.core.instancemanager.ClientInstanceManager)2 ClientInstanceManagerListener (com.biglybt.core.instancemanager.ClientInstanceManagerListener)1 ClientInstanceTracked (com.biglybt.core.instancemanager.ClientInstanceTracked)1 LogAlert (com.biglybt.core.logging.LogAlert)1 Download (com.biglybt.pif.download.Download)1 PeerManager (com.biglybt.pif.peers.PeerManager)1