Esempio n. 1
0
  /**
   * Utility method for converting the non-firewalled elements of an AlternateLocationCollection to
   * a smaller set of endpoints.
   */
  private static Set getAsEndpoints(AlternateLocationCollection col) {
    if (col == null || !col.hasAlternateLocations()) return Collections.EMPTY_SET;

    long now = System.currentTimeMillis();
    synchronized (col) {
      Set endpoints = null;
      int i = 0;
      for (Iterator iter = col.iterator(); iter.hasNext() && i < MAX_LOCATIONS; ) {
        Object o = iter.next();
        if (!(o instanceof DirectAltLoc)) continue;
        DirectAltLoc al = (DirectAltLoc) o;
        if (al.canBeSent(AlternateLocation.MESH_RESPONSE)) {
          IpPort host = al.getHost();
          if (!NetworkUtils.isMe(host)) {
            if (endpoints == null) endpoints = new HashSet();

            if (!(host instanceof Endpoint)) host = new Endpoint(host.getAddress(), host.getPort());

            endpoints.add(host);
            i++;
            al.send(now, AlternateLocation.MESH_RESPONSE);
          }
        } else if (!al.canBeSentAny()) iter.remove();
      }
      return endpoints == null ? Collections.EMPTY_SET : endpoints;
    }
  }
Esempio n. 2
0
 /**
  * Constructs a new RemoteFileDesc exactly like the other one, but with a different remote host.
  *
  * <p>It is okay to use the same internal structures for URNs because the Set is immutable.
  */
 public RemoteFileDesc(RemoteFileDesc rfd, IpPort ep) {
   this(
       ep.getAddress(), // host
       ep.getPort(), // port
       COPY_INDEX, // index (unknown)
       rfd.getFileName(), // filename
       rfd.getSize(), // filesize
       DataUtils.EMPTY_GUID, // client GUID
       0, // speed
       false, // chat capable
       2, // quality
       false, // browse hostable
       rfd.getUrns(), // urns
       false, // reply to MCast
       false, // is firewalled
       AlternateLocation.ALT_VENDOR, // vendor
       System.currentTimeMillis(), // timestamp
       Collections.EMPTY_SET, // push proxies
       rfd.getCreationTime(), // creation time
       0); // firewalled transfer
 }