Search in sources :

Example 1 with LightWeightSeedAdapter

use of com.biglybt.core.lws.LightWeightSeedAdapter in project BiglyBT by BiglySoftware.

the class SubscriptionImpl method checkPublish.

protected void checkPublish() {
    synchronized (this) {
        if (destroyed) {
            return;
        }
        if (isSingleton()) {
            return;
        }
        if (!isSubscribed()) {
            return;
        }
        if (popularity > 100) {
            if (lws_skip_check == 2) {
                return;
            } else if (lws_skip_check == 0) {
                if (RandomUtils.nextInt((int) ((popularity + 99) / 100)) == 0) {
                    lws_skip_check = 1;
                } else {
                    lws_skip_check = 2;
                    return;
                }
            }
        }
        if (hash != null) {
            boolean create = false;
            if (lws == null) {
                create = true;
            } else {
                if (!Arrays.equals(lws.getHash().getBytes(), hash)) {
                    lws.remove();
                    create = true;
                }
            }
            if (create) {
                try {
                    File original_data_location = manager.getVuzeFile(this);
                    if (original_data_location.exists()) {
                        // make a version based filename to avoid issues regarding multiple
                        // versions
                        final File versioned_data_location = new File(original_data_location.getParent(), original_data_location.getName() + "." + getVersion());
                        if (!versioned_data_location.exists()) {
                            if (!FileUtil.copyFile(original_data_location, versioned_data_location)) {
                                throw (new Exception("Failed to copy file to '" + versioned_data_location + "'"));
                            }
                        }
                        lws = LightWeightSeedManager.getSingleton().add(getName(), new HashWrapper(hash), TorrentUtils.getDecentralisedEmptyURL(), versioned_data_location, isAnonymous() ? AENetworkClassifier.AT_I2P : AENetworkClassifier.AT_PUBLIC, new LightWeightSeedAdapter() {

                            @Override
                            public TOTorrent getTorrent(byte[] hash, URL announce_url, File data_location) throws Exception {
                                log("Generating light-weight torrent: hash=" + ByteFormatter.encodeString(hash));
                                TOTorrentCreator creator = TOTorrentFactory.createFromFileOrDirWithFixedPieceLength(data_location, announce_url, 256 * 1024);
                                TOTorrent t = creator.create();
                                t.setHashOverride(hash);
                                return (t);
                            }
                        });
                    }
                } catch (Throwable e) {
                    log("Failed to create light-weight-seed", e);
                }
            }
        }
    }
}
Also used : LightWeightSeedAdapter(com.biglybt.core.lws.LightWeightSeedAdapter) TOTorrent(com.biglybt.core.torrent.TOTorrent) TOTorrentCreator(com.biglybt.core.torrent.TOTorrentCreator) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

LightWeightSeedAdapter (com.biglybt.core.lws.LightWeightSeedAdapter)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentCreator (com.biglybt.core.torrent.TOTorrentCreator)1 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1