Search in sources :

Example 26 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class SelectableSpeedMenu method invokeSlider.

/**
 * @param cClickedFrom
 * @since 3.0.1.7
 */
public static void invokeSlider(Control cClickedFrom, Core core, boolean isUpSpeed) {
    final String prefix = MessageText.getString(isUpSpeed ? "GeneralView.label.maxuploadspeed" : "GeneralView.label.maxdownloadspeed");
    GlobalManager gm = core.getGlobalManager();
    final String configAutoKey = TransferSpeedValidator.getActiveAutoUploadParameter(gm);
    boolean auto = COConfigurationManager.getBooleanParameter(configAutoKey);
    final String configKey = isUpSpeed ? TransferSpeedValidator.getActiveUploadParameter(gm) : "Max Download Speed KBs";
    int maxBandwidth = COConfigurationManager.getIntParameter(configKey);
    final boolean unlim = (maxBandwidth == 0);
    if (unlim && !isUpSpeed) {
        GlobalManagerStats stats = gm.getStats();
        int dataReceive = stats.getDataReceiveRate();
        if (dataReceive >= 1024) {
            maxBandwidth = dataReceive / 1024;
        }
    }
    SpeedScaleShell speedScale = new SpeedScaleShell() {

        @Override
        public String getStringValue(int value, String sValue) {
            if (sValue != null) {
                return prefix + ": " + sValue;
            }
            if (value == 0) {
                return MessageText.getString("MyTorrentsView.menu.setSpeed.unlimited");
            }
            if (value == -1) {
                return MessageText.getString("ConfigView.auto");
            }
            return prefix + ": " + DisplayFormatters.formatByteCountToKiBEtcPerSec(getValue() * 1024, true);
        }
    };
    int max = unlim ? (isUpSpeed ? 100 : 800) : maxBandwidth * 5;
    if (max < 50) {
        max = 50;
    }
    speedScale.setMaxValue(max);
    speedScale.setMaxTextValue(9999999);
    final String config_prefix = "config.ui.speed.partitions.manual." + (isUpSpeed ? "upload" : "download") + ".";
    int lastValue = COConfigurationManager.getIntParameter(config_prefix + "last", -10);
    Integer[] speed_limits;
    if (COConfigurationManager.getBooleanParameter(config_prefix + "enabled", false)) {
        speed_limits = parseSpeedPartitionString(COConfigurationManager.getStringParameter(config_prefix + "values", ""));
    } else {
        speed_limits = getGenericSpeedList(6, maxBandwidth);
    }
    if (speed_limits != null) {
        for (int i = 0; i < speed_limits.length; i++) {
            int value = speed_limits[i].intValue();
            if (value > 0) {
                speedScale.addOption(DisplayFormatters.formatByteCountToKiBEtcPerSec(value * 1024, true), value);
                if (value == lastValue) {
                    lastValue = -10;
                }
            }
        }
    }
    speedScale.addOption(MessageText.getString("MyTorrentsView.menu.setSpeed.unlimited"), 0);
    speedScale.addOption(MessageText.getString("ConfigView.auto"), -1);
    if (lastValue > 0) {
        speedScale.addOption(DisplayFormatters.formatByteCountToKiBEtcPerSec(lastValue * 1024, true), lastValue);
    }
    if (speedScale.open(cClickedFrom, auto ? -1 : maxBandwidth, true)) {
        int value = speedScale.getValue();
        if (!speedScale.wasMenuChosen() || lastValue == value) {
            COConfigurationManager.setParameter(config_prefix + "last", maxBandwidth);
        }
        if (value >= 0) {
            if (auto) {
                COConfigurationManager.setParameter(configAutoKey, false);
            }
            COConfigurationManager.setParameter(configKey, value);
            COConfigurationManager.save();
        } else {
            // autospeed
            COConfigurationManager.setParameter(configAutoKey, true);
            COConfigurationManager.save();
        }
    }
}
Also used : SpeedScaleShell(com.biglybt.ui.swt.shells.SpeedScaleShell) GlobalManager(com.biglybt.core.global.GlobalManager) GlobalManagerStats(com.biglybt.core.global.GlobalManagerStats)

Example 27 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class TorrentOpener method addTorrent.

/**
 * @param torrentOptions
 * @return
 * @since 5.0.0.1
 *
 * @TODO: Remove SWT UI parts (use UIFunctions) and move out of SWT tree
 */
public static final boolean addTorrent(final TorrentOpenOptions torrentOptions) {
    try {
        if (torrentOptions.getTorrent() == null) {
            return false;
        }
        final DownloadManagerInitialisationAdapter dmia = new DownloadManagerInitialisationAdapter() {

            @Override
            public int getActions() {
                return (ACT_ASSIGNS_TAGS);
            }

            @Override
            public void initialised(DownloadManager dm, boolean for_seeding) {
                DiskManagerFileInfoSet file_info_set = dm.getDiskManagerFileInfoSet();
                DiskManagerFileInfo[] fileInfos = file_info_set.getFiles();
                boolean reorder_mode = COConfigurationManager.getBooleanParameter("Enable reorder storage mode");
                int reorder_mode_min_mb = COConfigurationManager.getIntParameter("Reorder storage mode min MB");
                try {
                    dm.getDownloadState().suppressStateSave(true);
                    boolean[] toSkip = new boolean[fileInfos.length];
                    boolean[] toCompact = new boolean[fileInfos.length];
                    boolean[] toReorderCompact = new boolean[fileInfos.length];
                    int[] priorities = null;
                    int comp_num = 0;
                    int reorder_comp_num = 0;
                    final TorrentOpenFileOptions[] files = torrentOptions.getFiles();
                    for (int iIndex = 0; iIndex < fileInfos.length; iIndex++) {
                        DiskManagerFileInfo fileInfo = fileInfos[iIndex];
                        if (iIndex >= 0 && iIndex < files.length && files[iIndex].lSize == fileInfo.getLength()) {
                            // Always pull destination file from fileInfo and not from
                            // TorrentFileInfo because the destination may have changed
                            // by magic code elsewhere
                            File fDest = fileInfo.getFile(true);
                            if (files[iIndex].isLinked()) {
                                fDest = files[iIndex].getDestFileFullName();
                                // Can't use fileInfo.setLink(fDest) as it renames
                                // the existing file if there is one
                                dm.getDownloadState().setFileLink(iIndex, fileInfo.getFile(false), fDest);
                            }
                            if (files[iIndex].isToDownload()) {
                                int priority = files[iIndex].getPriority();
                                if (priority != 0) {
                                    if (priorities == null) {
                                        priorities = new int[fileInfos.length];
                                    }
                                    priorities[iIndex] = priority;
                                }
                            } else {
                                toSkip[iIndex] = true;
                                if (!fDest.exists()) {
                                    if (reorder_mode && (fileInfo.getLength() / (1024 * 1024)) >= reorder_mode_min_mb) {
                                        toReorderCompact[iIndex] = true;
                                        reorder_comp_num++;
                                    } else {
                                        toCompact[iIndex] = true;
                                        comp_num++;
                                    }
                                }
                            }
                        }
                    }
                    if (files.length == 1) {
                        TorrentOpenFileOptions file = files[0];
                        if (file.isManualRename()) {
                            String fileRename = file.getDestFileName();
                            if (fileRename != null && fileRename.length() > 0) {
                                dm.getDownloadState().setDisplayName(fileRename);
                            }
                        }
                    } else {
                        String folderRename = torrentOptions.getManualRename();
                        if (folderRename != null && folderRename.length() > 0) {
                            dm.getDownloadState().setDisplayName(folderRename);
                        }
                    }
                    if (comp_num > 0) {
                        file_info_set.setStorageTypes(toCompact, DiskManagerFileInfo.ST_COMPACT);
                    }
                    if (reorder_comp_num > 0) {
                        file_info_set.setStorageTypes(toReorderCompact, DiskManagerFileInfo.ST_REORDER_COMPACT);
                    }
                    file_info_set.setSkipped(toSkip, true);
                    if (priorities != null) {
                        file_info_set.setPriority(priorities);
                    }
                    int maxUp = torrentOptions.getMaxUploadSpeed();
                    int kInB = DisplayFormatters.getKinB();
                    if (maxUp > 0) {
                        dm.getStats().setUploadRateLimitBytesPerSecond(maxUp * kInB);
                    }
                    int maxDown = torrentOptions.getMaxDownloadSpeed();
                    if (maxDown > 0) {
                        dm.getStats().setDownloadRateLimitBytesPerSecond(maxDown * kInB);
                    }
                    DownloadManagerState dm_state = dm.getDownloadState();
                    if (torrentOptions.disableIPFilter) {
                        dm_state.setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER, true);
                    }
                    if (torrentOptions.peerSource != null) {
                        for (String peerSource : torrentOptions.peerSource.keySet()) {
                            boolean enable = torrentOptions.peerSource.get(peerSource);
                            dm_state.setPeerSourceEnabled(peerSource, enable);
                        }
                    }
                    Map<String, Boolean> enabledNetworks = torrentOptions.getEnabledNetworks();
                    if (enabledNetworks != null) {
                        if (!dm_state.getFlag(DownloadManagerState.FLAG_INITIAL_NETWORKS_SET)) {
                            for (String net : enabledNetworks.keySet()) {
                                boolean enable = enabledNetworks.get(net);
                                dm_state.setNetworkEnabled(net, enable);
                            }
                        }
                    }
                    List<Tag> initialTags = torrentOptions.getInitialTags();
                    for (Tag t : initialTags) {
                        t.addTaggable(dm);
                    }
                    List<List<String>> trackers = torrentOptions.getTrackers(true);
                    if (trackers != null) {
                        TOTorrent torrent = dm.getTorrent();
                        TorrentUtils.listToAnnounceGroups(trackers, torrent);
                        try {
                            TorrentUtils.writeToFile(torrent);
                        } catch (Throwable e2) {
                            Debug.printStackTrace(e2);
                        }
                    }
                    if (torrentOptions.bSequentialDownload) {
                        dm_state.setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD, true);
                    }
                    File moc = torrentOptions.getMoveOnComplete();
                    if (moc != null) {
                        dm_state.setAttribute(DownloadManagerState.AT_MOVE_ON_COMPLETE_DIR, moc.getAbsolutePath());
                    }
                } finally {
                    dm.getDownloadState().suppressStateSave(false);
                }
            }
        };
        CoreFactory.addCoreRunningListener(new CoreRunningListener() {

            @Override
            public void coreRunning(Core core) {
                TOTorrent torrent = torrentOptions.getTorrent();
                byte[] hash = null;
                try {
                    hash = torrent.getHash();
                } catch (TOTorrentException e1) {
                }
                int iStartState = (torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_STOPPED) ? DownloadManager.STATE_STOPPED : DownloadManager.STATE_QUEUED;
                GlobalManager gm = core.getGlobalManager();
                DownloadManager dm = gm.addDownloadManager(torrentOptions.sFileName, hash, torrentOptions.getParentDir(), torrentOptions.getSubDir(), iStartState, true, torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_SEEDING, dmia);
                // since gm.addDown.. will handle it.
                if (dm == null) {
                    return;
                }
                if (torrentOptions.iQueueLocation == TorrentOpenOptions.QUEUELOCATION_TOP) {
                    gm.moveTop(new DownloadManager[] { dm });
                }
                if (torrentOptions.getStartMode() == TorrentOpenOptions.STARTMODE_FORCESTARTED) {
                    dm.setForceStart(true);
                }
            }
        });
    } catch (Exception e) {
        UIFunctions uif = UIFunctionsManager.getUIFunctions();
        if (uif != null) {
            uif.showErrorMessage("OpenTorrentWindow.mb.openError", Debug.getStackTrace(e), new String[] { torrentOptions.sOriginatingLocation, e.getMessage() });
        }
        return false;
    }
    return true;
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) CoreRunningListener(com.biglybt.core.CoreRunningListener) ArrayList(java.util.ArrayList) List(java.util.List) Core(com.biglybt.core.Core) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TorrentOpenFileOptions(com.biglybt.core.torrent.impl.TorrentOpenFileOptions) DiskManagerFileInfoSet(com.biglybt.core.disk.DiskManagerFileInfoSet) DownloadManagerInitialisationAdapter(com.biglybt.core.download.DownloadManagerInitialisationAdapter) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TOTorrent(com.biglybt.core.torrent.TOTorrent) Tag(com.biglybt.core.tag.Tag) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Example 28 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class PeersViewBase method updateSwarmPeers.

private void updateSwarmPeers() {
    if (peers_changed) {
        Utils.execSWTThread(new Runnable() {

            public void run() {
                peers_changed = false;
                GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                List<PEPeer> peers = tv.getDataSources();
                swarm_peers = new HashSet<>(peers);
                final Map<PEPeerManager, int[]> done_pms = new HashMap<>();
                List<DownloadManager> dms = new ArrayList<>();
                for (PEPeer peer : peers) {
                    PEPeerManager pm = peer.getManager();
                    int[] count = done_pms.get(pm);
                    if (count == null) {
                        done_pms.put(pm, new int[] { 1 });
                        byte[] hash = pm.getHash();
                        DownloadManager dm = gm.getDownloadManager(new HashWrapper(hash));
                        if (dm != null) {
                            dms.add(dm);
                        }
                    } else {
                        count[0]++;
                    }
                }
                Collections.sort(dms, new Comparator<DownloadManager>() {

                    @Override
                    public int compare(DownloadManager o1, DownloadManager o2) {
                        PEPeerManager pm1 = o1.getPeerManager();
                        PEPeerManager pm2 = o2.getPeerManager();
                        int[] c1 = done_pms.get(pm1);
                        int[] c2 = done_pms.get(pm2);
                        int n1 = c1 == null ? 0 : c1[0];
                        int n2 = c2 == null ? 0 : c2[0];
                        return (n2 - n1);
                    }
                });
                swarm_view.dataSourceChanged(dms.toArray(new DownloadManager[dms.size()]));
            }
        });
    }
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) DownloadManager(com.biglybt.core.download.DownloadManager) Comparator(java.util.Comparator) GlobalManager(com.biglybt.core.global.GlobalManager) HashWrapper(com.biglybt.core.util.HashWrapper) ArrayList(java.util.ArrayList) List(java.util.List) PEPeerManager(com.biglybt.core.peer.PEPeerManager) Map(java.util.Map) HashMap(java.util.HashMap) IdentityHashSet(com.biglybt.core.util.IdentityHashSet) HashSet(java.util.HashSet)

Example 29 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class PeersViewBase method fillMenu.

private static void fillMenu(final Menu menu, final PEPeer[] peers, final Shell shell, DownloadManager download_specific) {
    boolean hasSelection = (peers.length > 0);
    boolean downSpeedDisabled = false;
    boolean downSpeedUnlimited = false;
    long totalDownSpeed = 0;
    long downSpeedSetMax = 0;
    long maxDown = 0;
    boolean upSpeedDisabled = false;
    boolean upSpeedUnlimited = false;
    long totalUpSpeed = 0;
    long upSpeedSetMax = 0;
    long maxUp = 0;
    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
    final IdentityHashSet<DownloadManager> download_managers = new IdentityHashSet<>();
    Map<PEPeer, DownloadManager> peer_dm_map = new HashMap<>();
    if (hasSelection) {
        for (int i = 0; i < peers.length; i++) {
            PEPeer peer = peers[i];
            PEPeerManager m = peer.getManager();
            if (m != null) {
                if (gm != null) {
                    DownloadManager dm = gm.getDownloadManager(new HashWrapper(m.getHash()));
                    if (dm != null) {
                        peer_dm_map.put(peer, dm);
                        download_managers.add(dm);
                    }
                }
            }
            try {
                int maxul = peer.getStats().getUploadRateLimitBytesPerSecond();
                maxUp += maxul * 4;
                if (maxul == 0) {
                    upSpeedUnlimited = true;
                } else {
                    if (maxul > upSpeedSetMax) {
                        upSpeedSetMax = maxul;
                    }
                }
                if (maxul == -1) {
                    maxul = 0;
                    upSpeedDisabled = true;
                }
                totalUpSpeed += maxul;
                int maxdl = peer.getStats().getDownloadRateLimitBytesPerSecond();
                maxDown += maxdl * 4;
                if (maxdl == 0) {
                    downSpeedUnlimited = true;
                } else {
                    if (maxdl > downSpeedSetMax) {
                        downSpeedSetMax = maxdl;
                    }
                }
                if (maxdl == -1) {
                    maxdl = 0;
                    downSpeedDisabled = true;
                }
                totalDownSpeed += maxdl;
            } catch (Exception ex) {
                Debug.printStackTrace(ex);
            }
        }
    }
    if (download_specific != null) {
        final MenuItem block_item = new MenuItem(menu, SWT.CHECK);
        PEPeer peer = peers.length == 0 ? null : peers[0];
        if (peer == null || peer.getManager().getDiskManager().getRemainingExcludingDND() > 0) {
            // disallow peer upload blocking when downloading
            block_item.setSelection(false);
            block_item.setEnabled(false);
        } else {
            block_item.setEnabled(true);
            block_item.setSelection(peer.isSnubbed());
        }
        if (peer != null) {
            final boolean newSnubbedValue = !peer.isSnubbed();
            Messages.setLanguageText(block_item, "PeersView.menu.blockupload");
            block_item.addListener(SWT.Selection, new PeersRunner(peers) {

                @Override
                public void run(PEPeer peer) {
                    peer.setSnubbed(newSnubbedValue);
                }
            });
        }
    } else {
        if (download_managers.size() > 0) {
            MenuItem itemDetails = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemDetails, "PeersView.menu.showdownload");
            Utils.setMenuItemImage(itemDetails, "details");
            itemDetails.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                    if (uiFunctions != null) {
                        for (DownloadManager dm : download_managers) {
                            uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                        }
                    }
                }
            });
            new MenuItem(menu, SWT.SEPARATOR);
        }
    }
    BuddyPlugin bp = BuddyPluginUtils.getPlugin();
    if (bp != null) {
        boolean has_pb = false;
        boolean has_public = false;
        for (PEPeer peer : peers) {
            if (AENetworkClassifier.categoriseAddress(peer.getIp()) == AENetworkClassifier.AT_PUBLIC) {
                has_public = true;
                DownloadManager dm = peer_dm_map.get(peer);
                if (dm != null && bp.isPartialBuddy(PluginCoreUtils.wrap(dm), PluginCoreUtils.wrap(peer))) {
                    has_pb = true;
                }
            }
        }
        MenuItem boost_item = new MenuItem(menu, SWT.CHECK);
        Messages.setLanguageText(boost_item, "PeersView.menu.boost");
        boost_item.setSelection(has_pb);
        boost_item.setEnabled(has_public);
        boost_item.addListener(SWT.Selection, new PeersRunner(peers) {

            @Override
            public void run(PEPeer peer) {
                boolean sel = boost_item.getSelection();
                if (AENetworkClassifier.categoriseAddress(peer.getIp()) == AENetworkClassifier.AT_PUBLIC) {
                    DownloadManager dm = peer_dm_map.get(peer);
                    if (dm != null) {
                        bp.setPartialBuddy(PluginCoreUtils.wrap(dm), PluginCoreUtils.wrap(peer), sel);
                    }
                }
            }
        });
    }
    final MenuItem kick_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(kick_item, "PeersView.menu.kick");
    kick_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public void run(PEPeer peer) {
            peer.getManager().removePeer(peer, "Peer kicked");
        }
    });
    final MenuItem ban_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(ban_item, "PeersView.menu.kickandban");
    ban_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public void run(PEPeer peer) {
            String msg = MessageText.getString("PeersView.menu.kickandban.reason");
            IpFilterManagerFactory.getSingleton().getIPFilter().ban(peer.getIp(), msg, true);
            peer.getManager().removePeer(peer, "Peer kicked and banned");
        }
    });
    final MenuItem ban_for_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(ban_for_item, "PeersView.menu.kickandbanfor");
    ban_for_item.addListener(SWT.Selection, new PeersRunner(peers) {

        @Override
        public boolean run(final PEPeer[] peers) {
            String text = MessageText.getString("dialog.ban.for.period.text");
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.ban.for.period.title", "!" + text + "!");
            int def = COConfigurationManager.getIntParameter("ban.for.period.default", 60);
            entryWindow.setPreenteredText(String.valueOf(def), false);
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (!entryWindow.hasSubmittedInput()) {
                        return;
                    }
                    String sReturn = entryWindow.getSubmittedInput();
                    if (sReturn == null) {
                        return;
                    }
                    int mins = -1;
                    try {
                        mins = Integer.valueOf(sReturn).intValue();
                    } catch (NumberFormatException er) {
                    // Ignore
                    }
                    if (mins <= 0) {
                        MessageBox mb = new MessageBox(Utils.findAnyShell(), SWT.ICON_ERROR | SWT.OK);
                        mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
                        mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
                        mb.open();
                        return;
                    }
                    COConfigurationManager.setParameter("ban.for.period.default", mins);
                    IpFilter filter = IpFilterManagerFactory.getSingleton().getIPFilter();
                    for (PEPeer peer : peers) {
                        String msg = MessageText.getString("PeersView.menu.kickandbanfor.reason", new String[] { String.valueOf(mins) });
                        filter.ban(peer.getIp(), msg, true, mins);
                        peer.getManager().removePeer(peer, "Peer kicked and banned");
                    }
                }
            });
            return (true);
        }
    });
    // === advanced menu ===
    final MenuItem itemAdvanced = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(itemAdvanced, "MyTorrentsView.menu.advancedmenu");
    itemAdvanced.setEnabled(hasSelection);
    final Menu menuAdvanced = new Menu(shell, SWT.DROP_DOWN);
    itemAdvanced.setMenu(menuAdvanced);
    // advanced > Download Speed Menu //
    Map<String, Object> menu_properties = new HashMap<>();
    menu_properties.put(ViewUtils.SM_PROP_PERMIT_UPLOAD_DISABLE, true);
    menu_properties.put(ViewUtils.SM_PROP_PERMIT_DOWNLOAD_DISABLE, true);
    ViewUtils.addSpeedMenu(shell, menuAdvanced, true, true, false, hasSelection, downSpeedDisabled, downSpeedUnlimited, totalDownSpeed, downSpeedSetMax, maxDown, upSpeedDisabled, upSpeedUnlimited, totalUpSpeed, upSpeedSetMax, maxUp, peers.length, menu_properties, new ViewUtils.SpeedAdapter() {

        @Override
        public void setDownSpeed(int speed) {
            if (peers.length > 0) {
                for (int i = 0; i < peers.length; i++) {
                    try {
                        PEPeer peer = (PEPeer) peers[i];
                        peer.getStats().setDownloadRateLimitBytesPerSecond(speed);
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }

        @Override
        public void setUpSpeed(int speed) {
            if (peers.length > 0) {
                for (int i = 0; i < peers.length; i++) {
                    try {
                        PEPeer peer = (PEPeer) peers[i];
                        peer.getStats().setUploadRateLimitBytesPerSecond(speed);
                    } catch (Exception e) {
                        Debug.printStackTrace(e);
                    }
                }
            }
        }
    });
    addPeersMenu(download_specific, "", menu);
}
Also used : IdentityHashSet(com.biglybt.core.util.IdentityHashSet) PEPeer(com.biglybt.core.peer.PEPeer) IpFilter(com.biglybt.core.ipfilter.IpFilter) SelectionListener(org.eclipse.swt.events.SelectionListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) Listener(org.eclipse.swt.widgets.Listener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) TableLifeCycleListener(com.biglybt.ui.common.table.TableLifeCycleListener) HashMap(java.util.HashMap) DownloadManager(com.biglybt.core.download.DownloadManager) BuddyPlugin(com.biglybt.plugin.net.buddy.BuddyPlugin) GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) Menu(org.eclipse.swt.widgets.Menu) MenuItem(org.eclipse.swt.widgets.MenuItem) MessageBox(org.eclipse.swt.widgets.MessageBox) HashWrapper(com.biglybt.core.util.HashWrapper) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 30 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class CoreImpl method announceAll.

protected void announceAll(boolean force) {
    Logger.log(new LogEvent(LOGID, "Updating trackers"));
    GlobalManager gm = getGlobalManager();
    if (gm != null) {
        List downloads = gm.getDownloadManagers();
        long now = SystemTime.getCurrentTime();
        for (int i = 0; i < downloads.size(); i++) {
            DownloadManager dm = (DownloadManager) downloads.get(i);
            Long last_announce_l = (Long) dm.getUserData(DM_ANNOUNCE_KEY);
            long last_announce = last_announce_l == null ? create_time : last_announce_l.longValue();
            TRTrackerAnnouncer an = dm.getTrackerClient();
            if (an != null) {
                TRTrackerAnnouncerResponse last_announce_response = an.getLastResponse();
                if (now - last_announce > 15 * 60 * 1000 || last_announce_response == null || last_announce_response.getStatus() == TRTrackerAnnouncerResponse.ST_OFFLINE || force) {
                    dm.setUserData(DM_ANNOUNCE_KEY, new Long(now));
                    Logger.log(new LogEvent(LOGID, "    updating tracker for " + dm.getDisplayName()));
                    dm.requestTrackerAnnounce(true);
                }
            }
        }
    }
    PluginInterface dht_tracker_pi = getPluginManager().getPluginInterfaceByClass(DHTTrackerPlugin.class);
    if (dht_tracker_pi != null) {
        ((DHTTrackerPlugin) dht_tracker_pi.getPlugin()).announceAll();
    }
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) LogEvent(com.biglybt.core.logging.LogEvent) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TRTrackerAnnouncerResponse(com.biglybt.core.tracker.client.TRTrackerAnnouncerResponse) AtomicLong(java.util.concurrent.atomic.AtomicLong) DHTTrackerPlugin(com.biglybt.plugin.tracker.dht.DHTTrackerPlugin) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

GlobalManager (com.biglybt.core.global.GlobalManager)48 DownloadManager (com.biglybt.core.download.DownloadManager)33 Core (com.biglybt.core.Core)10 TOTorrent (com.biglybt.core.torrent.TOTorrent)10 List (java.util.List)7 CoreRunningListener (com.biglybt.core.CoreRunningListener)6 File (java.io.File)6 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 UIFunctions (com.biglybt.ui.UIFunctions)5 GlobalManagerStats (com.biglybt.core.global.GlobalManagerStats)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 HashWrapper (com.biglybt.core.util.HashWrapper)4 PluginInterface (com.biglybt.pif.PluginInterface)4 Menu (org.eclipse.swt.widgets.Menu)4 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)3 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)3 PEPeer (com.biglybt.core.peer.PEPeer)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 PluginException (com.biglybt.pif.PluginException)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3