use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class MetaSearchImpl method exportEngines.
@Override
public void exportEngines(File target) throws MetaSearchException {
Engine[] engines = getEngines(true, false);
VuzeFile vf = VuzeFileHandler.getSingleton().create();
for (Engine engine : engines) {
try {
vf.addComponent(VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE, engine.exportToBencodedMap());
} catch (IOException e) {
Debug.out(e);
}
}
try {
vf.write(target);
} catch (IOException e) {
throw (new MetaSearchException("Failed to write file", e));
}
}
use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class SubscriptionBodyImpl method writeVuzeFile.
protected void writeVuzeFile(SubscriptionImpl subs) throws SubscriptionException {
try {
File file = manager.getVuzeFile(subs);
Map details = (Map) map.get("details");
updateDetails(subs, details);
byte[] contents = BEncoder.encode(details);
byte[] new_hash = new SHA1Simple().calculateHash(contents);
byte[] old_hash = (byte[]) map.get("hash");
if (old_hash != null && !Arrays.equals(old_hash, new_hash)) {
Map details_copy = new HashMap(details);
details_copy.remove("az_version");
contents = BEncoder.encode(details_copy);
new_hash = new SHA1Simple().calculateHash(contents);
}
if (old_hash == null || !Arrays.equals(old_hash, new_hash)) {
byte[] private_key = subs.getPrivateKey();
if (private_key == null) {
throw (new SubscriptionException("Only the originator of a subscription can modify it"));
}
map.put("size", new Long(contents.length));
try {
map.put("hash", new_hash);
map.put("sig", sign(private_key, new_hash, version, contents.length));
} catch (Throwable e) {
throw (new SubscriptionException("Crypto failed: " + Debug.getNestedExceptionMessage(e)));
}
}
File backup_file = null;
if (file.exists()) {
backup_file = new File(file.getParent(), file.getName() + ".bak");
backup_file.delete();
if (!file.renameTo(backup_file)) {
throw (new SubscriptionException("Backup failed"));
}
}
try {
VuzeFile vf = VuzeFileHandler.getSingleton().create();
vf.addComponent(VuzeFileComponent.COMP_TYPE_SUBSCRIPTION, map);
vf.write(file);
hash = new_hash;
sig = (byte[]) map.get("sig");
sig_data_size = contents.length;
} catch (Throwable e) {
if (backup_file != null) {
backup_file.renameTo(file);
}
throw (new SubscriptionException("File write failed: " + Debug.getNestedExceptionMessage(e)));
}
} catch (Throwable e) {
rethrow(e);
}
}
use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class SubscriptionManagerImpl method updateSubscription.
protected void updateSubscription(final SubscriptionImpl subs, final int new_version) {
log("Subscription " + subs.getString() + " - higher version found: " + new_version);
if (!subs.canAutoUpgradeCheck()) {
log(" Checked too recently or not updateable, ignoring");
return;
}
if (subs.getHighestUserPromptedVersion() >= new_version) {
log(" User has already been prompted for version " + new_version + " so ignoring");
return;
}
byte[] sub_id = subs.getShortID();
if (!subs.isAnonymous()) {
try {
PlatformSubscriptionsMessenger.subscriptionDetails details = PlatformSubscriptionsMessenger.getSubscriptionBySID(sub_id, false);
if (!askIfCanUpgrade(subs, new_version)) {
return;
}
VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
VuzeFile vf = vfh.loadVuzeFile(Base64.decode(details.getContent()));
vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_SUBSCRIPTION);
return;
} catch (Throwable e) {
log("Failed to read subscription from platform, trying DHT");
}
}
log("Checking subscription '" + subs.getString() + "' upgrade to version " + new_version);
final String key = "subscription:publish:" + ByteFormatter.encodeString(sub_id) + ":" + new_version;
DHTPluginInterface dht_plugin = selectDHTPlugin(subs);
dht_plugin.get(getKeyBytes(key), "Subs update read: " + Base32.encode(sub_id) + ":" + new_version, DHTPlugin.FLAG_SINGLE_VALUE, 12, 60 * 1000 * (subs.isAnonymous() ? 2 : 1), false, false, new DHTPluginOperationListener() {
private byte[] verified_hash;
private int verified_size;
@Override
public boolean diversified() {
return (true);
}
@Override
public void starts(byte[] key) {
}
@Override
public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
byte[] data = value.getValue();
try {
Map details = decodeSubscriptionDetails(data);
if (verified_hash == null && subs.getVerifiedPublicationVersion(details) == new_version) {
verified_hash = SubscriptionImpl.getPublicationHash(details);
verified_size = SubscriptionImpl.getPublicationSize(details);
}
} catch (Throwable e) {
}
}
@Override
public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
}
@Override
public void complete(byte[] original_key, boolean timeout_occurred) {
if (verified_hash != null) {
log(" Subscription '" + subs.getString() + " upgrade verified as authentic");
updateSubscription(subs, new_version, verified_hash, verified_size);
} else {
log(" Subscription '" + subs.getString() + " upgrade not verified");
}
}
});
}
use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class SubscriptionManagerImpl method updateSubscription.
protected void updateSubscription(SubscriptionImpl subs, File data_location) {
log("Updating subscription '" + subs.getString() + " using '" + data_location + "'");
VuzeFileHandler vfh = VuzeFileHandler.getSingleton();
VuzeFile vf = vfh.loadVuzeFile(data_location.getAbsolutePath());
vfh.handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_SUBSCRIPTION);
}
use of com.biglybt.core.vuzefile.VuzeFile in project BiglyBT by BiglySoftware.
the class SubscriptionManagerImpl method isSearchTemplateImportable.
public boolean isSearchTemplateImportable(SubscriptionImpl sub) {
try {
String subs_url_str = ((RSSEngine) sub.getEngine()).getSearchUrl(true);
URL subs_url = new URL(subs_url_str);
final byte[] vf_bytes = FileUtil.readInputStreamAsByteArray(subs_url.openConnection().getInputStream());
VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(vf_bytes);
return (MetaSearchManagerFactory.getSingleton().isImportable(vf));
} catch (Throwable e) {
Debug.out(e);
}
return (false);
}
Aggregations