Search in sources :

Example 66 with PluginInterface

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

the class NATTraverser method syncTraverse.

protected void syncTraverse(NATTraversalHandler handler, InetSocketAddress target, Map request, NATTraversalObserver listener) {
    try {
        int type = handler.getType();
        synchronized (this) {
            if (puncher == null) {
                if (!PluginCoreUtils.isInitialisationComplete()) {
                    listener.failed(new Exception("NAT traversal failed, initialisation not complete"));
                    return;
                }
                PluginInterface dht_pi = core.getPluginManager().getPluginInterfaceByClass(DHTPlugin.class);
                if (dht_pi != null) {
                    DHTPlugin dht_plugin = (DHTPlugin) dht_pi.getPlugin();
                    if (dht_plugin.isEnabled()) {
                        DHT dht = dht_plugin.getDHT(DHT.NW_AZ_MAIN);
                        if (dht == null) {
                            dht = dht_plugin.getDHT(DHT.NW_AZ_CVS);
                        }
                        if (dht != null) {
                            puncher = dht.getNATPuncher();
                        }
                    }
                }
            }
            if (puncher == null) {
                listener.disabled();
                return;
            }
        }
        if (request == null) {
            request = new HashMap();
        }
        request.put("_travreas", new Long(type));
        InetSocketAddress[] target_a = { target };
        DHTTransportContact[] rendezvous_used = { null };
        Map reply = puncher.punch(handler.getName(), target_a, rendezvous_used, request);
        if (reply == null) {
            if (rendezvous_used[0] == null) {
                listener.failed(NATTraversalObserver.FT_NO_RENDEZVOUS);
            } else {
                listener.failed(new Exception("NAT traversal failed"));
            }
        } else {
            listener.succeeded(rendezvous_used[0].getAddress(), target_a[0], reply);
        }
    } catch (Throwable e) {
        listener.failed(e);
    }
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) PluginInterface(com.biglybt.pif.PluginInterface) DHT(com.biglybt.core.dht.DHT) DHTTransportContact(com.biglybt.core.dht.transport.DHTTransportContact) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) HashMap(java.util.HashMap) Map(java.util.Map)

Example 67 with PluginInterface

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

the class SubscriptionManagerImpl method getKnownSubscriptionCount.

@Override
public int getKnownSubscriptionCount() {
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    Download[] downloads = pi.getDownloadManager().getDownloads();
    ByteArrayHashMap<String> results = new ByteArrayHashMap<>(Math.max(16, downloads.length * 2));
    try {
        for (Download download : downloads) {
            Map m = download.getMapAttribute(ta_subscription_info);
            if (m != null) {
                List s = (List) m.get("s");
                if (s != null && s.size() > 0) {
                    for (int i = 0; i < s.size(); i++) {
                        byte[] sid = (byte[]) s.get(i);
                        results.put(sid, "");
                    }
                }
            }
        }
    } catch (Throwable e) {
        log("Failed to get known subscriptions", e);
    }
    return (results.size());
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface)

Example 68 with PluginInterface

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

the class OverallStatsImpl method updateStats.

private void updateStats(boolean force) {
    try {
        this_mon.enter();
        long current_time = SystemTime.getCurrentTime() / 1000;
        if (current_time < lastUptime) {
            // time went backwards
            lastUptime = current_time;
            return;
        }
        long current_total_d_received = gm_stats.getTotalDataBytesReceived();
        long current_total_p_received = gm_stats.getTotalProtocolBytesReceived();
        long current_total_d_sent = gm_stats.getTotalDataBytesSent();
        long current_total_p_sent = gm_stats.getTotalProtocolBytesSent();
        long current_total_received = current_total_d_received + current_total_p_received;
        long current_total_sent = current_total_d_sent + current_total_p_sent;
        // overall totals
        totalDownloaded += current_total_received - lastDownloaded;
        lastDownloaded = current_total_received;
        if (totalDownloaded < 0)
            totalDownloaded = 0;
        totalUploaded += current_total_sent - lastUploaded;
        lastUploaded = current_total_sent;
        if (totalUploaded < 0)
            totalUploaded = 0;
        // split totals
        totalDataDownloaded += current_total_d_received - lastDataDownloaded;
        lastDataDownloaded = current_total_d_received;
        if (totalDataDownloaded < 0)
            totalDataDownloaded = 0;
        totalProtocolDownloaded += current_total_p_received - lastProtocolDownloaded;
        lastProtocolDownloaded = current_total_p_received;
        if (totalProtocolDownloaded < 0)
            totalProtocolDownloaded = 0;
        totalDataUploaded += current_total_d_sent - lastDataUploaded;
        lastDataUploaded = current_total_d_sent;
        if (totalDataUploaded < 0)
            totalDataUploaded = 0;
        totalProtocolUploaded += current_total_p_sent - lastProtocolUploaded;
        lastProtocolUploaded = current_total_p_sent;
        if (totalProtocolUploaded < 0)
            totalProtocolUploaded = 0;
        if (dhts == null) {
            try {
                PluginManager pm = core.getPluginManager();
                if (pm.isInitialized()) {
                    PluginInterface dht_pi = pm.getPluginInterfaceByClass(DHTPlugin.class);
                    if (dht_pi == null) {
                        dhts = new DHT[0];
                    } else {
                        DHTPlugin plugin = (DHTPlugin) dht_pi.getPlugin();
                        if (!plugin.isInitialising()) {
                            if (plugin.isEnabled()) {
                                dhts = ((DHTPlugin) dht_pi.getPlugin()).getDHTs();
                            } else {
                                dhts = new DHT[0];
                            }
                        }
                    }
                }
            } catch (Throwable e) {
                dhts = new DHT[0];
            }
        }
        long current_total_dht_up = 0;
        long current_total_dht_down = 0;
        if (dhts != null) {
            for (DHT dht : dhts) {
                DHTTransportStats stats = dht.getTransport().getStats();
                current_total_dht_up += stats.getBytesSent();
                current_total_dht_down += stats.getBytesReceived();
            }
        }
        totalDHTUploaded += current_total_dht_up - lastDHTUploaded;
        lastDHTUploaded = current_total_dht_up;
        if (totalDHTUploaded < 0)
            totalDHTUploaded = 0;
        totalDHTDownloaded += current_total_dht_down - lastDHTDownloaded;
        lastDHTDownloaded = current_total_dht_down;
        if (totalDHTDownloaded < 0)
            totalDHTDownloaded = 0;
        // TIME
        long delta = current_time - lastUptime;
        if (delta > 100 || delta < 0) {
            // make sure the time diff isn't borked
            lastUptime = current_time;
            return;
        }
        if (totalUptime < 0)
            totalUptime = 0;
        totalUptime += delta;
        lastUptime = current_time;
        lastSnapshot = new long[] { totalProtocolUploaded, totalDataUploaded, totalProtocolDownloaded, totalDataDownloaded, totalDHTUploaded, totalDHTDownloaded, current_total_p_sent, current_total_d_sent, current_total_p_received, current_total_d_received, current_total_dht_up, current_total_dht_down };
        HashMap overallMap = new HashMap();
        overallMap.put("downloaded", new Long(totalDownloaded));
        overallMap.put("uploaded", new Long(totalUploaded));
        overallMap.put("uptime", new Long(totalUptime));
        overallMap.put("mark_time", new Long(markTime));
        overallMap.put("mark_downloaded", new Long(markTotalDownloaded));
        overallMap.put("mark_uploaded", new Long(markTotalUploaded));
        overallMap.put("mark_uptime", new Long(markTotalUptime));
        overallMap.put("dht_down", new Long(totalDHTDownloaded));
        overallMap.put("dht_up", new Long(totalDHTUploaded));
        overallMap.put("p_uploaded", new Long(totalProtocolUploaded));
        overallMap.put("d_uploaded", new Long(totalDataUploaded));
        overallMap.put("p_downloaded", new Long(totalProtocolDownloaded));
        overallMap.put("d_downloaded", new Long(totalDataDownloaded));
        Map map = new HashMap();
        map.put("all", overallMap);
        tick_count++;
        if (force || tick_count % SAVE_TICKS == 0) {
            save(map);
        }
    } finally {
        this_mon.exit();
    }
}
Also used : PluginManager(com.biglybt.pif.PluginManager) DHT(com.biglybt.core.dht.DHT) HashMap(java.util.HashMap) PluginInterface(com.biglybt.pif.PluginInterface) DHTPlugin(com.biglybt.plugin.dht.DHTPlugin) HashMap(java.util.HashMap) Map(java.util.Map) DHTTransportStats(com.biglybt.core.dht.transport.DHTTransportStats)

Example 69 with PluginInterface

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

the class UtilitiesImpl method callWithPluginThreadContext.

public static void callWithPluginThreadContext(PluginInterface pi, Runnable target) {
    PluginInterface existing = tls.get();
    try {
        tls.set(pi);
        target.run();
    } finally {
        tls.set(existing);
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface)

Example 70 with PluginInterface

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

the class UIManagerImpl method attachUI.

public void attachUI(UIInstanceFactory factory, IUIIntializer init) {
    List<Object[]> to_fire = new ArrayList<>();
    try {
        class_mon.enter();
        ui_factories.add(factory);
        if (initialisation_complete) {
            Iterator<Object[]> it = ui_listeners.iterator();
            while (it.hasNext()) {
                Object[] entry = (Object[]) it.next();
                List<UIInstanceFactory> fired = (List<UIInstanceFactory>) entry[2];
                fired.add(factory);
                to_fire.add(new Object[] { entry[0], entry[1], factory.getInstance((PluginInterface) entry[1]) });
            }
        }
    } finally {
        class_mon.exit();
    }
    for (Object[] entry : to_fire) {
        PluginInterface pi = (PluginInterface) entry[1];
        String name = pi.getPluginName();
        if (init != null) {
            init.reportCurrentTask(MessageText.getString("splash.plugin.UIinit", new String[] { name }));
            init.increaseProgress();
        }
        try {
            ((UIManagerListener) entry[0]).UIAttached((UIInstance) entry[2]);
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
    for (Object[] entry : to_fire) {
        try {
            if (entry[0] instanceof UIManagerListener2) {
                ((UIManagerListener2) entry[0]).UIAttachedComplete((UIInstance) entry[2]);
            }
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) CopyOnWriteList(com.biglybt.core.util.CopyOnWriteList)

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