Ejemplo n.º 1
0
 private static void listHosts(final Switchboard sb, final serverObjects prop) {
   // list known hosts
   yacySeed seed;
   int hc = 0;
   if (sb.peers != null && sb.peers.sizeConnected() > 0) {
     final Iterator<yacySeed> e = PeerSelection.getProvidesRemoteCrawlURLs(sb.peers);
     while (e.hasNext()) {
       seed = e.next();
       if (seed != null) {
         prop.put("hosts_" + hc + "_hosthash", seed.hash);
         prop.putHTML(
             "hosts_" + hc + "_hostname",
             seed.hash
                 + " "
                 + seed.get(yacySeed.NAME, "nameless")
                 + " ("
                 + seed.getLong(yacySeed.RCOUNT, 0)
                 + ")");
         hc++;
       }
     }
     prop.put("hosts", hc);
   } else {
     prop.put("hosts", "0");
   }
 }
Ejemplo n.º 2
0
  private static void accumulateSupporter(
      final Switchboard sb,
      final HashMap<String, Entry> Supporter,
      final ScoreMap<String> ranking,
      final Row rowdef,
      final HashMap<String, Integer> negativeHashes,
      final HashMap<String, Integer> positiveHashes,
      final int dbtype) {
    final int maxCount = Math.min(1000, sb.peers.newsPool.size(dbtype));
    yacyNewsDB.Record record;
    final Iterator<yacyNewsDB.Record> recordIterator =
        sb.peers.newsPool.recordIterator(dbtype, true);
    int j = 0;
    String url = "", urlhash;
    Row.Entry entry;
    int score = 0;
    Integer vote;
    yacySeed seed;
    while ((recordIterator.hasNext()) && (j++ < maxCount)) {
      record = recordIterator.next();
      if (record == null) continue;

      entry = null;
      if ((record.category().equals(yacyNewsPool.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(yacyNewsPool.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());
      }

      // add/subtract votes and write record
      if (entry != null) {
        try {
          urlhash = UTF8.String((new DigestURI(url)).hash());
        } catch (final MalformedURLException e) {
          urlhash = null;
        }
        if (urlhash == null)
          try {
            urlhash = UTF8.String((new DigestURI("http://" + url)).hash());
          } catch (final MalformedURLException e) {
            urlhash = null;
          }
        if (urlhash == null) {
          System.out.println(
              "Supporter: bad url '" + url + "' from news record " + record.toString());
          continue;
        }
        if ((vote = negativeHashes.get(urlhash)) != null) {
          score = Math.max(0, score - vote.intValue()); // do not go below zero
        }
        if ((vote = positiveHashes.get(urlhash)) != null) {
          score += 2 * vote.intValue();
        }
        // consider double-entries
        if (Supporter.containsKey(urlhash)) {
          ranking.inc(urlhash, score);
        } else {
          ranking.set(urlhash, score);
          Supporter.put(urlhash, entry);
        }
      }
    }
  }