Search in sources :

Example 21 with VuzeFile

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));
    }
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) IOException(java.io.IOException) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) RSSEngine(com.biglybt.core.metasearch.impl.web.rss.RSSEngine) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine)

Example 22 with VuzeFile

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);
    }
}
Also used : SubscriptionException(com.biglybt.core.subs.SubscriptionException) HashMap(java.util.HashMap) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) HashMap(java.util.HashMap) Map(java.util.Map) SHA1Simple(com.biglybt.core.util.SHA1Simple)

Example 23 with VuzeFile

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");
            }
        }
    });
}
Also used : PlatformSubscriptionsMessenger(com.biglybt.core.messenger.config.PlatformSubscriptionsMessenger) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 24 with VuzeFile

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);
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFileHandler(com.biglybt.core.vuzefile.VuzeFileHandler)

Example 25 with VuzeFile

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);
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) RSSEngine(com.biglybt.core.metasearch.impl.web.rss.RSSEngine) URL(java.net.URL)

Aggregations

VuzeFile (com.biglybt.core.vuzefile.VuzeFile)36 File (java.io.File)12 VuzeFileHandler (com.biglybt.core.vuzefile.VuzeFileHandler)10 VuzeFileComponent (com.biglybt.core.vuzefile.VuzeFileComponent)9 URL (java.net.URL)9 RSSEngine (com.biglybt.core.metasearch.impl.web.rss.RSSEngine)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 IOException (java.io.IOException)5 PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)4 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4 Subscription (com.biglybt.core.subs.Subscription)3 VuzeFileProcessor (com.biglybt.core.vuzefile.VuzeFileProcessor)3 UIManager (com.biglybt.pif.ui.UIManager)3 Engine (com.biglybt.core.metasearch.Engine)2 SubscriptionException (com.biglybt.core.subs.SubscriptionException)2 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)2 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)2 InputStream (java.io.InputStream)2