Package net.yacy.peers

Examples of net.yacy.peers.Seed


            prop.put("localremotepeer", "0");
            prop.putHTML("success_peername", sb.peers.mySeed().getName());
            prop.put("success_peerhash", sb.peers.mySeed().hash);
        } else {
            // read the profile from remote peer
            Seed seed = sb.peers.getConnected(hash);
            if (seed == null) seed = sb.peers.getDisconnected(hash);
            if (seed == null) {
                prop.put("success", "1"); // peer unknown
            } else {
                // process news if existent
                try {
                    final NewsDB.Record record = sb.peers.newsPool.getByOriginator(NewsPool.INCOMING_DB, NewsPool.CATEGORY_PROFILE_UPDATE, seed.hash);
                    if (record != null) sb.peers.newsPool.moveOff(NewsPool.INCOMING_DB, record.id());
                } catch (final Exception e) {
                    Log.logException(e);
                }
               
                // try to get the profile from remote peer
                if (sb.clusterhashes != null) seed.setAlternativeAddress(sb.clusterhashes.get(seed.hash.getBytes()));
                profile = Protocol.getProfile(seed);
               
                // if profile did not arrive, say that peer is disconnected
                if (profile == null) {
                    prop.put("success", "2"); // peer known, but disconnected
                } else {
                    Network.log.logInfo("fetched profile:" + profile);
                    prop.put("success", "3"); // everything ok
                }
                prop.putHTML("success_peername", seed.getName());
                prop.put("success_peerhash", seed.hash);
            }
            prop.put("localremotepeer", "1");
        }
        Iterator<Map.Entry<String, String>> i;
View Full Code Here


        int j = 0;
        String url = "", urlhash;
        Row.Entry entry;
        int score = 0;
        Integer vote;
        Seed seed;
        while ((recordIterator.hasNext()) && (j++ < maxCount)) {
            record = recordIterator.next();
            if (record == null) continue;

            entry = null;
            if ((record.category().equals(NewsPool.CATEGORY_PROFILE_UPDATE)) &&
                ((seed = sb.peers.getConnected(record.originator())) != null)) {
                url = record.attribute("homepage", "");
                if (url.length() < 12) continue;
                entry = rowdef.newEntry(new byte[][]{
                                url.getBytes(),
                                url.getBytes(),
                                UTF8.getBytes(("Home Page of " + seed.getName())),
                                record.id().getBytes()
                        });
                score = 1 + timeFactor(record.created());
            }

            if ((record.category().equals(NewsPool.CATEGORY_PROFILE_BROADCAST)) &&
                ((seed = sb.peers.getConnected(record.originator())) != null)) {
                url = record.attribute("homepage", "");
                if (url.length() < 12) continue;
                entry = rowdef.newEntry(new byte[][]{
                                url.getBytes(),
                                url.getBytes(),
                                UTF8.getBytes(("Home Page of " + seed.getName())),
                                record.id().getBytes()
                        });
                score = 1 + timeFactor(record.created());
            }
View Full Code Here

                prop.put("rejected_only-latest", "0");
            }
            dark = true;
            DigestURI url;
            byte[] initiatorHash, executorHash;
            Seed initiatorSeed, executorSeed;
            int j=0;
            ArrayList<ZURL.Entry> l = sb.crawlQueues.errorURL.list(showRejectedCount);
            ZURL.Entry entry;
            for (int i = l.size() - 1; i >= 0; i--) {
                entry = l.get(i);
                if (entry == null) continue;
                url = entry.url();
                if (url == null) continue;
               
                initiatorHash = entry.initiator();
                executorHash = entry.executor();
                initiatorSeed = (initiatorHash == null) ? null : sb.peers.getConnected(ASCII.String(initiatorHash));
                executorSeed = (executorHash == null) ? null : sb.peers.getConnected(ASCII.String(executorHash));
                prop.putHTML("rejected_list_"+j+"_initiator", ((initiatorSeed == null) ? "proxy" : initiatorSeed.getName()));
                prop.putHTML("rejected_list_"+j+"_executor", ((executorSeed == null) ? "proxy" : executorSeed.getName()));
                prop.putHTML("rejected_list_"+j+"_url", url.toNormalform(false, true));
                prop.putHTML("rejected_list_"+j+"_failreason", entry.anycause());
                prop.put("rejected_list_"+j+"_dark", dark ? "1" : "0");
                dark = !dark;
View Full Code Here

            // clean up seed-dbs
            if (getConfigBool("routing.deleteOldSeeds.permission",true)) {
                final long deleteOldSeedsTime = getConfigLong("routing.deleteOldSeeds.time",7)*24*3600000;
                Iterator<Seed> e = this.peers.seedsSortedDisconnected(true,Seed.LASTSEEN);
                Seed seed = null;
                final List<String> deleteQueue = new ArrayList<String>();
                checkInterruption();
                // clean passive seeds
                while (e.hasNext()) {
                    seed = e.next();
                    if (seed != null) {
                        //list is sorted -> break when peers are too young to delete
                        if (!seed.isLastSeenTimeout(deleteOldSeedsTime)) break;
                        deleteQueue.add(seed.hash);
                    }
                }
                for (int i = 0; i < deleteQueue.size(); ++i) this.peers.removeDisconnected(deleteQueue.get(i));
                deleteQueue.clear();
                e = this.peers.seedsSortedPotential(true,Seed.LASTSEEN);
                checkInterruption();
                // clean potential seeds
                while (e.hasNext()) {
                    seed = e.next();
                    if (seed != null) {
                        //list is sorted -> break when peers are too young to delete
                        if (!seed.isLastSeenTimeout(deleteOldSeedsTime)) break;
                        deleteQueue.add(seed.hash);
                    }
                }
                for (int i = 0; i < deleteQueue.size(); ++i) this.peers.removePotential(deleteQueue.get(i));
            }
View Full Code Here

        }
        EventTracker.update(EventTracker.EClass.INDEX, url.toNormalform(true, false), false);

        // if this was performed for a remote crawl request, notify requester
        if ((processCase == EventOrigin.GLOBAL_CRAWLING) && (queueEntry.initiator() != null)) {
            final Seed initiatorPeer = this.peers.get(ASCII.String(queueEntry.initiator()));
            if (initiatorPeer != null) {
                if (this.clusterhashes != null) {
                    initiatorPeer.setAlternativeAddress(this.clusterhashes.get(queueEntry.initiator()));
                }
                // start a thread for receipt sending to avoid a blocking here
                new Thread(new receiptSending(initiatorPeer, newEntry), "sending receipt to " + ASCII.String(queueEntry.initiator())).start();
            }
        }
View Full Code Here

    }

    public void loadSeedLists() {
        // uses the superseed to initialize the database with known seeds

        Seed           ys;
        String             seedListFileURL;
        DigestURI          url;
        Iterator<String>   enu;
        int                lc;
        final int          sc = this.peers.sizeConnected();
        ResponseHeader header;

        final RequestHeader reqHeader = new RequestHeader();
        reqHeader.put(HeaderFramework.PRAGMA, "no-cache");
        reqHeader.put(HeaderFramework.CACHE_CONTROL, "no-cache");
        reqHeader.put(HeaderFramework.USER_AGENT, ClientIdentification.getUserAgent());
        final HTTPClient client = new HTTPClient();
        client.setHeader(reqHeader.entrySet());
        client.setTimout((int) getConfigLong("bootstrapLoadTimeout", 20000));

        Network.log.logInfo("BOOTSTRAP: " + sc + " seeds known from previous run");

        // - use the superseed to further fill up the seedDB
        int ssc = 0, c = 0;
        while (true) {
            if (Thread.currentThread().isInterrupted()) {
                break;
            }
            seedListFileURL = sb.getConfig("network.unit.bootstrap.seedlist" + c, "");
            if (seedListFileURL.length() == 0) {
                break;
            }
            c++;
            if (
                    seedListFileURL.startsWith("http://") ||
                    seedListFileURL.startsWith("https://")
            ) {
                // load the seed list
                try {

                    url = new DigestURI(seedListFileURL);
                    //final long start = System.currentTimeMillis();
                    client.HEADResponse(url.toString());
                    header = new ResponseHeader(client.getHttpResponse().getAllHeaders());
                    //final long loadtime = System.currentTimeMillis() - start;
                    /*if (header == null) {
                        if (loadtime > getConfigLong("bootstrapLoadTimeout", 6000)) {
                            yacyCore.log.logWarning("BOOTSTRAP: seed-list URL " + seedListFileURL + " not available, time-out after " + loadtime + " milliseconds");
                        } else {
                            yacyCore.log.logWarning("BOOTSTRAP: seed-list URL " + seedListFileURL + " not available, no content");
                        }
                    } else*/ if (header.lastModified() == null) {
                        Network.log.logWarning("BOOTSTRAP: seed-list URL " + seedListFileURL + " not usable, last-modified is missing");
                    } else if ((header.age() > 86400000) && (ssc > 0)) {
                        Network.log.logInfo("BOOTSTRAP: seed-list URL " + seedListFileURL + " too old (" + (header.age() / 86400000) + " days)");
                    } else {
                        ssc++;
                        final byte[] content = client.GETbytes(url);
                        enu = FileUtils.strings(content);
                        lc = 0;
                        while (enu.hasNext()) {
                            try {
                                ys = Seed.genRemoteSeed(enu.next(), null, false, null);
                                if ((ys != null) &&
                                    (!this.peers.mySeedIsDefined() || !this.peers.mySeed().hash.equals(ys.hash))) {
                                        final long lastseen = Math.abs((System.currentTimeMillis() - ys.getLastSeenUTC()) / 1000 / 60);
                                        if (lastseen < 240) {
                                            if (this.peers.peerActions.connectPeer(ys, false)) {
                                                lc++;
                                            }
                                        }
View Full Code Here

                    prop.put("keystring", "&lt;not possible to compute word from hash&gt;");
                }

                // find host & peer
                String host = post.get("host", ""); // get host from input field
                Seed seed = null;
                if (host.length() != 0) {
                    if (host.length() == 12) {
                        // the host string is a peer hash
                        seed = sb.peers.getConnected(host);
                    } else {
View Full Code Here

        return b;
    }

    public static void listHosts(final serverObjects prop, final byte[] startHash, final Switchboard sb) {
        // list known hosts
        Seed seed;
        int hc = 0;
        prop.put("searchresult_keyhash", startHash);
        final Iterator<Seed> e = PeerSelection.getAcceptRemoteIndexSeeds(sb.peers, startHash, sb.peers.sizeConnected(), true);
        while (e.hasNext()) {
            seed = e.next();
            if (seed != null) {
                prop.put("searchresult_hosts_" + hc + "_hosthash", seed.hash);
                prop.putHTML("searchresult_hosts_" + hc + "_hostname", seed.hash + " " + seed.get(Seed.NAME, "nameless"));
                hc++;
            }
        }
        prop.put("searchresult_hosts", hc);
    }
View Full Code Here

                final String hash = post.get("hash");

                // generate the download URL
                String downloadURLOld = null;
                if( sb.peers != null ){ //no nullpointer error..
                    final Seed seed = sb.peers.getConnected(hash);
                    if (seed != null) {
                        final String IP = seed.getIP();
                        final String Port = seed.get(Seed.PORT, "8090");
                        final String peerName = seed.get(Seed.NAME, "<" + IP + ":" + Port + ">");
                        prop.putHTML("page_source", peerName);
                        downloadURLOld = "http://" + IP + ":" + Port + "/yacy/list.html?col=black";
                    } else {
                        prop.put("status", STATUS_PEER_UNKNOWN);//YaCy-Peer not found
                        prop.putHTML("status_name", hash);
View Full Code Here

    public static Seed[] selectClusterPeers(final SeedDB seedDB, final SortedMap<byte[], String> peerhashes) {
        final Iterator<Map.Entry<byte[], String>> i = peerhashes.entrySet().iterator();
        final List<Seed> l = new ArrayList<Seed>();
        Map.Entry<byte[], String> entry;
        Seed s;
        while (i.hasNext()) {
            entry = i.next();
            s = seedDB.get(ASCII.String(entry.getKey())); // should be getConnected; get only during testing time
            if (s != null) {
                s.setAlternativeAddress(entry.getValue());
                l.add(s);
            }
        }
        return l.toArray(new Seed[l.size()]);
    }
View Full Code Here

TOP

Related Classes of net.yacy.peers.Seed

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.