Search in sources :

Example 1 with TRHostException

use of com.biglybt.core.tracker.host.TRHostException in project BiglyBT by BiglySoftware.

the class TorrentPublish method performCommand.

@Override
protected boolean performCommand(ConsoleInput ci, DownloadManager dm, List args) {
    TOTorrent torrent = dm.getTorrent();
    if (torrent != null) {
        try {
            TRHost host = ci.core.getTrackerHost();
            TRHostTorrent existing = host.getHostTorrent(torrent);
            if (existing == null) {
                host.publishTorrent(torrent);
            } else {
                try {
                    existing.remove();
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        } catch (TRHostException e) {
            e.printStackTrace(ci.out);
            return false;
        }
        return true;
    }
    return false;
}
Also used : TRHostException(com.biglybt.core.tracker.host.TRHostException) TOTorrent(com.biglybt.core.torrent.TOTorrent) TRHost(com.biglybt.core.tracker.host.TRHost) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent)

Example 2 with TRHostException

use of com.biglybt.core.tracker.host.TRHostException in project BiglyBT by BiglySoftware.

the class ProgressPanel method makeTorrent.

public void makeTorrent() {
    int tracker_type = wizard.getTrackerType();
    if (tracker_type == NewTorrentWizard.TT_EXTERNAL) {
        TrackersUtil.getInstance().addTracker(wizard.trackerURL);
    }
    File f;
    if (wizard.create_mode == NewTorrentWizard.MODE_DIRECTORY) {
        f = new File(wizard.directoryPath);
    } else if (wizard.create_mode == NewTorrentWizard.MODE_SINGLE_FILE) {
        f = new File(wizard.singlePath);
    } else {
        f = wizard.byo_desc_file;
    }
    try {
        URL url = new URL(wizard.trackerURL);
        final TOTorrent torrent;
        if (wizard.getPieceSizeComputed()) {
            wizard.creator = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(f, url, wizard.getAddOtherHashes());
            wizard.creator.addListener(this);
            wizard.creator.setFileIsLayoutDescriptor(wizard.create_mode == NewTorrentWizard.MODE_BYO);
            torrent = wizard.creator.create();
        } else {
            wizard.creator = TOTorrentFactory.createFromFileOrDirWithFixedPieceLength(f, url, wizard.getAddOtherHashes(), wizard.getPieceSizeManual());
            wizard.creator.addListener(this);
            wizard.creator.setFileIsLayoutDescriptor(wizard.create_mode == NewTorrentWizard.MODE_BYO);
            torrent = wizard.creator.create();
        }
        if (tracker_type == NewTorrentWizard.TT_DECENTRAL) {
            TorrentUtils.setDecentralised(torrent);
        }
        torrent.setComment(wizard.getComment());
        TorrentUtils.setDHTBackupEnabled(torrent, wizard.permitDHT);
        TorrentUtils.setPrivate(torrent, wizard.getPrivateTorrent());
        LocaleTorrentUtil.setDefaultTorrentEncoding(torrent);
        // mark this newly created torrent as complete to avoid rechecking on open
        final File save_dir;
        if (wizard.create_mode == NewTorrentWizard.MODE_DIRECTORY) {
            save_dir = f;
        } else if (wizard.create_mode == NewTorrentWizard.MODE_SINGLE_FILE) {
            save_dir = f.getParentFile();
        } else {
            String save_path = COConfigurationManager.getStringParameter("Default save path");
            File f_save_path = new File(save_path);
            if (!f_save_path.canWrite()) {
                throw (new Exception("Default save path is not configured: See Tools->Options->File"));
            }
            save_dir = f_save_path;
        }
        if (wizard.useMultiTracker) {
            this.reportCurrentTask(MessageText.getString("wizard.addingmt"));
            TorrentUtils.listToAnnounceGroups(wizard.trackers, torrent);
        }
        if (wizard.useWebSeed && wizard.webseeds.size() > 0) {
            this.reportCurrentTask(MessageText.getString("wizard.webseed.adding"));
            Map ws = wizard.webseeds;
            List getright = (List) ws.get("getright");
            if (getright.size() > 0) {
                for (int i = 0; i < getright.size(); i++) {
                    reportCurrentTask("    GetRight: " + getright.get(i));
                }
                torrent.setAdditionalListProperty("url-list", new ArrayList(getright));
            }
            List webseed = (List) ws.get("webseed");
            if (webseed.size() > 0) {
                for (int i = 0; i < webseed.size(); i++) {
                    reportCurrentTask("    WebSeed: " + webseed.get(i));
                }
                torrent.setAdditionalListProperty("httpseeds", new ArrayList(webseed));
            }
        }
        // must do this last as it saves a copy of the torrent state for future opening...
        /*
       * actually, don't need to do this as the "open-for-seeding" option used when adding the download
       * does the job. Reason I stopped doing this is
       * https://sourceforge.net/tracker/index.php?func=detail&aid=1721917&group_id=84122&atid=575154
       *
	  DownloadManagerState	download_manager_state =
			DownloadManagerStateFactory.getDownloadState( torrent );

	  TorrentUtils.setResumeDataCompletelyValid( download_manager_state );

	  download_manager_state.save();
     */
        this.reportCurrentTask(MessageText.getString("wizard.maketorrent.savingfile"));
        final File torrent_file = new File(wizard.savePath);
        torrent.serialiseToBEncodedFile(torrent_file);
        this.reportCurrentTask(MessageText.getString("wizard.maketorrent.filesaved"));
        wizard.switchToClose(new Runnable() {

            @Override
            public void run() {
                show_torrent_file.setEnabled(true);
            }
        });
        if (wizard.autoOpen) {
            CoreWaiterSWT.waitForCore(TriggerInThread.NEW_THREAD, new CoreRunningListener() {

                @Override
                public void coreRunning(Core core) {
                    boolean start_stopped = COConfigurationManager.getBooleanParameter("Default Start Torrents Stopped");
                    byte[] hash = null;
                    try {
                        hash = torrent.getHash();
                    } catch (TOTorrentException e1) {
                    }
                    if (wizard.forceStart || wizard.superseed) {
                        // superseeding can only be set for an active download...
                        start_stopped = false;
                    }
                    DownloadManagerInitialisationAdapter dmia;
                    final String initialTags = wizard.getInitialTags(true);
                    if (initialTags.length() > 0) {
                        dmia = new DownloadManagerInitialisationAdapter() {

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

                            @Override
                            public void initialised(DownloadManager dm, boolean for_seeding) {
                                TagManager tm = TagManagerFactory.getTagManager();
                                TagType tag_type = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                String[] bits = initialTags.replace(';', ',').split(",");
                                for (String tag : bits) {
                                    tag = tag.trim();
                                    if (tag.length() > 0) {
                                        try {
                                            Tag t = tag_type.getTag(tag, true);
                                            if (t == null) {
                                                t = tag_type.createTag(tag, true);
                                            }
                                            t.addTaggable(dm);
                                        } catch (Throwable e) {
                                            Debug.out(e);
                                        }
                                    }
                                }
                            }
                        };
                    } else {
                        dmia = null;
                    }
                    final DownloadManager dm = core.getGlobalManager().addDownloadManager(torrent_file.toString(), hash, save_dir.toString(), start_stopped ? DownloadManager.STATE_STOPPED : // persistent
                    DownloadManager.STATE_QUEUED, // persistent
                    true, // for seeding
                    true, dmia);
                    if (!start_stopped && dm != null) {
                        // We want this to move to seeding ASAP, so move it to the top
                        // of the download list, where it will do the quick check and
                        // move to the seeding list
                        // (the for seeding flag should really be smarter and verify
                        // it's a seeding torrent and set appropriately)
                        dm.getGlobalManager().moveTop(new DownloadManager[] { dm });
                    }
                    if (wizard.autoHost && wizard.getTrackerType() != NewTorrentWizard.TT_EXTERNAL) {
                        try {
                            core.getTrackerHost().hostTorrent(torrent, true, false);
                        } catch (TRHostException e) {
                            Logger.log(new LogAlert(LogAlert.REPEATABLE, "Host operation fails", e));
                        }
                    }
                    if (dm != null) {
                        if (wizard.forceStart) {
                            dm.setForceStart(true);
                        }
                        if (wizard.superseed) {
                            new AEThread2("startwait") {

                                @Override
                                public void run() {
                                    long start = SystemTime.getMonotonousTime();
                                    while (true) {
                                        if (dm.isDestroyed()) {
                                            break;
                                        }
                                        long elapsed = SystemTime.getMonotonousTime() - start;
                                        if (elapsed > 60 * 1000) {
                                            int state = dm.getState();
                                            if (state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED) {
                                                break;
                                            }
                                        }
                                        if (elapsed > 5 * 60 * 1000) {
                                            break;
                                        }
                                        PEPeerManager pm = dm.getPeerManager();
                                        if (pm != null) {
                                            pm.setSuperSeedMode(true);
                                            break;
                                        }
                                        try {
                                            Thread.sleep(1000);
                                        } catch (Throwable e) {
                                            break;
                                        }
                                    }
                                }
                            }.start();
                        }
                    }
                }
            });
        }
    } catch (Exception e) {
        if (e instanceof TOTorrentException) {
            TOTorrentException te = (TOTorrentException) e;
            if (te.getReason() == TOTorrentException.RT_CANCELLED) {
            // expected failure, don't log exception
            } else {
                reportCurrentTask(MessageText.getString("wizard.operationfailed"));
                reportCurrentTask(TorrentUtils.exceptionToText(te));
            }
        } else {
            Debug.printStackTrace(e);
            reportCurrentTask(MessageText.getString("wizard.operationfailed"));
            reportCurrentTask(Debug.getStackTrace(e));
        }
        wizard.switchToClose();
    }
}
Also used : TRHostException(com.biglybt.core.tracker.host.TRHostException) ArrayList(java.util.ArrayList) DownloadManager(com.biglybt.core.download.DownloadManager) URL(java.net.URL) CoreRunningListener(com.biglybt.core.CoreRunningListener) ArrayList(java.util.ArrayList) List(java.util.List) Core(com.biglybt.core.Core) DownloadManagerInitialisationAdapter(com.biglybt.core.download.DownloadManagerInitialisationAdapter) TRHostException(com.biglybt.core.tracker.host.TRHostException) LogAlert(com.biglybt.core.logging.LogAlert) TagType(com.biglybt.core.tag.TagType) TagManager(com.biglybt.core.tag.TagManager) PEPeerManager(com.biglybt.core.peer.PEPeerManager) Tag(com.biglybt.core.tag.Tag) File(java.io.File) Map(java.util.Map)

Example 3 with TRHostException

use of com.biglybt.core.tracker.host.TRHostException in project BiglyBT by BiglySoftware.

the class TorrentHost method performCommand.

@Override
protected boolean performCommand(ConsoleInput ci, DownloadManager dm, List args) {
    TOTorrent torrent = dm.getTorrent();
    if (torrent != null) {
        try {
            TRHost host = ci.core.getTrackerHost();
            TRHostTorrent existing = host.getHostTorrent(torrent);
            if (existing == null) {
                ci.core.getTrackerHost().hostTorrent(torrent, true, false);
            } else {
                try {
                    existing.remove();
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        } catch (TRHostException e) {
            e.printStackTrace(ci.out);
            return false;
        }
        return true;
    }
    return false;
}
Also used : TRHostException(com.biglybt.core.tracker.host.TRHostException) TOTorrent(com.biglybt.core.torrent.TOTorrent) TRHost(com.biglybt.core.tracker.host.TRHost) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent)

Aggregations

TRHostException (com.biglybt.core.tracker.host.TRHostException)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 TRHost (com.biglybt.core.tracker.host.TRHost)2 TRHostTorrent (com.biglybt.core.tracker.host.TRHostTorrent)2 Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)1 LogAlert (com.biglybt.core.logging.LogAlert)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 Tag (com.biglybt.core.tag.Tag)1 TagManager (com.biglybt.core.tag.TagManager)1 TagType (com.biglybt.core.tag.TagType)1 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1