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);
}
}
}
}
}
Aggregations