public FileDesc getFileDescForUrn(URN urn) {

    if (urn.toString().equals(FileDescStub.DEFAULT_URN)) return fdStub;
    else if (urn.equals(_notHave)) return null;
    else if (_urns.containsKey(urn)) return (FileDesc) _urns.get(urn);
    else return new FileDescStub("other.txt");
  }
  public HUGEExtension(byte[] extsBytes) {
    int currIndex = 0;
    // while we don't encounter a null....
    while ((currIndex < extsBytes.length) && (extsBytes[currIndex] != (byte) 0x00)) {

      // HANDLE GGEP STUFF
      if (extsBytes[currIndex] == GGEP.GGEP_PREFIX_MAGIC_NUMBER) {
        int start = currIndex;
        int[] endIndex = new int[1];
        endIndex[0] = currIndex + 1;
        try {
          GGEP ggep = new GGEP(extsBytes, currIndex, endIndex);
          if (_ggep == null) {
            _ggep = new GGEP();
          }
          _ggep.merge(ggep);
          if (_ggepBlocks == null) {
            _ggepBlocks = new ArrayList<GGEPBlock>(2);
          }
          _ggepBlocks.add(new GGEPBlock(ggep, start, endIndex[0]));
        } catch (BadGGEPBlockException ignored) {
        }
        currIndex = endIndex[0];
      } else { // HANDLE HUGE STUFF
        int delimIndex = currIndex;
        while ((delimIndex < extsBytes.length) && (extsBytes[delimIndex] != (byte) 0x1c))
          delimIndex++;
        if (delimIndex <= extsBytes.length) {
          try {
            // another GEM extension
            String curExtStr = new String(extsBytes, currIndex, delimIndex - currIndex, "UTF-8");
            if (URN.isUrn(curExtStr)) {
              // it's an URN to match, of form "urn:namespace:etc"
              URN urn = URN.createSHA1Urn(curExtStr);
              if (_urns == null) _urns = new UrnSet();
              _urns.add(urn);
            } else if (URN.Type.isSupportedUrnType(curExtStr)) {
              if (_urnTypes == null) _urnTypes = EnumSet.noneOf(URN.Type.class);
              _urnTypes.add(URN.Type.createUrnType(curExtStr));
            } else {
              // miscellaneous, but in the case of queries, xml
              if (_miscBlocks == null) _miscBlocks = new HashSet<String>(1);
              _miscBlocks.add(curExtStr);
            }
          } catch (IOException bad) {
          }
        } // else we've overflown and not encounted a 0x1c - discard
        currIndex = delimIndex + 1;
      }
    }
  }
예제 #3
0
    @Override
    public void handle(HttpRequest request, HttpResponse response, HttpContext context)
        throws HttpException, IOException {

      AbstractHttpEntity entity;
      String uri = request.getRequestLine().getUri();
      int i = uri.indexOf(LIBRARY_URL);
      String sha1 = uri.substring(i + LIBRARY_URL.length());
      if (sha1.indexOf("?") != -1) {
        sha1 = sha1.substring(0, sha1.indexOf("?"));
      }
      System.out.println("sha1:" + sha1);

      URN urn = new URNImpl(com.limegroup.gnutella.URN.createSHA1Urn(sha1));
      if (libraryManager.getLibraryManagedList().contains(urn)) {
        FileDesc fileDesc = libraryManager.getLibraryManagedList().getFileDescsByURN(urn).get(0);
        entity = new NFileEntity(fileDesc.getFile(), "application/binary");
        entity.setContentType("application/binary");
        response.setHeader(
            "Content-disposition", "attachment; filename=\"" + fileDesc.getFileName() + "\";");
      } else {
        entity = new NStringEntity("File not found: " + sha1);
        entity.setContentType("text/plain");
      }
      response.setEntity(entity);
    }
예제 #4
0
 static {
   try {
     DEFAULT_URN = URN.createSHA1Urn("urn:sha1:PLSTHIPQGSSZTS5FJUPAKUZZZZZZZZZZ");
   } catch (IOException ignored) {
     throw new RuntimeException(ignored);
   }
 }
예제 #5
0
 public synchronized void addTorrentEntry(URN urn) {
   String torrentDirPath =
       SharingSettings.INCOMPLETE_DIRECTORY.get().getAbsolutePath()
           + File.separator
           + Base32.encode(urn.getBytes());
   File torrentDir = new File(torrentDirPath);
   hashes.put(urn, torrentDir);
 }
예제 #6
0
 @Override
 public URN getUrn() {
   if (urn == null) {
     synchronized (this) {
       if (urn == null) {
         try {
           urn = URN.createSha1UrnFromHex(torrent.getSha1());
         } catch (IOException e) {
           throw new RuntimeException(e);
         }
       }
     }
   }
   return urn;
 }
 static {
   try {
     _notHave = URN.createSHA1Urn("urn:sha1:PLSTHIPQGSSZTS5FJUPAKUZZZZZZZZZZ");
   } catch (IOException ignored) {
   }
 }
예제 #8
0
 /** @see similar(RemoteFileDesc, RemoteFileDesc) */
 static boolean same(String name1, long size1, URN hash1, String name2, long size2, URN hash2) {
   // Either they have the same hashes...
   if (hash1 != null && hash2 != null) return hash1.equals(hash2);
   // ..or same name and size and no conflicting hashes.
   else return size1 == size2 && name1.equals(name2);
 }