Examples of FreenetURI


Examples of freenet.keys.FreenetURI

  @Override
  public void run(FCPConnectionHandler handler, Node node)
      throws MessageInvalidException {
      InsertableClientSSK key = InsertableClientSSK.createRandom(node.random, "");
      FreenetURI insertURI = key.getInsertURI();
      FreenetURI requestURI = key.getURI();
      SSKKeypairMessage msg = new SSKKeypairMessage(insertURI, requestURI, identifier);
      handler.outputHandler.queue(msg);
  }
View Full Code Here

Examples of freenet.keys.FreenetURI

      name = fs.get("Name");
      if (name == null)
        throw new MessageInvalidException(
            ProtocolErrorMessage.MISSING_FIELD, "No name",
            identifier, false);
      uri = new FreenetURI(fs.get("URI"));
      hasAnAnActiveLink = fs.getBoolean("HasAnActivelink", false);
    } catch (MalformedURLException e) {
      throw new MessageInvalidException(
          ProtocolErrorMessage.FREENET_URI_PARSE_ERROR, e
              .getMessage(), identifier, false);
View Full Code Here

Examples of freenet.keys.FreenetURI

    filterData = fs.getBoolean("FilterData", false);
    charset = fs.get("Charset");
    if(identifier == null)
      throw new MessageInvalidException(ProtocolErrorMessage.MISSING_FIELD, "No Identifier", null, global);
    try {
      uri = new FreenetURI(fs.get("URI"));
    } catch (MalformedURLException e) {
      throw new MessageInvalidException(ProtocolErrorMessage.FREENET_URI_PARSE_ERROR, e.getMessage(), identifier, global);
    }
    String verbosityString = fs.get("Verbosity");
    if(verbosityString == null)
View Full Code Here

Examples of freenet.keys.FreenetURI

  }

  @Override
  public FreenetURI checkSource(String source) throws PluginNotFoundException {
    try {
      return new FreenetURI(source);
    } catch (MalformedURLException e) {
      Logger.error(this, "not a valid freenet key: " + source, e);
      throw new PluginNotFoundException("not a valid freenet key: " + source, e);
    }
  }
View Full Code Here

Examples of freenet.keys.FreenetURI

    }
  }

  @Override
  InputStream getInputStream(final PluginProgress progress) throws IOException, PluginNotFoundException {
    FreenetURI uri = getSource();
    System.out.println("Downloading plugin from Freenet: "+uri);
    while (true) {
      try {
        progress.setDownloading();
        hlsc.addEventHook(new ClientEventListener() {
View Full Code Here

Examples of freenet.keys.FreenetURI

        //Logger.error(RealNodeRequestInsertTest.class,"Inserting: \""+dataString+"\" to "+node1);
       
        //boolean isSSK = requestNumber % 2 == 1;
        boolean isSSK = true;
       
        FreenetURI testKey;
        ClientKey insertKey;
        ClientKey fetchKey;
        ClientKeyBlock block;
       
      byte[] buf = dataString.getBytes("UTF-8");
        if(isSSK) {
          testKey = new FreenetURI("KSK", dataString);
         
          insertKey = InsertableClientSSK.create(testKey);
          fetchKey = ClientKSK.create(testKey);
         
          block = ((InsertableClientSSK)insertKey).encode(new ArrayBucket(buf), false, false, (short)-1, buf.length, random, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
View Full Code Here

Examples of freenet.keys.FreenetURI

    }

    if (ks.equals("/")) {
      if (httprequest.isParameterSet("key")) {
        String k = httprequest.getParam("key");
        FreenetURI newURI;
        try {
          newURI = new FreenetURI(k);
        } catch (MalformedURLException e) {
          Logger.normal(this, "Invalid key: "+e+" for "+k, e);
          sendErrorPage(ctx, 404, l10n("notFoundTitle"), NodeL10n.getBase().getString("FProxyToadlet.invalidKeyWithReason", new String[] { "reason" }, new String[] { e.toString() }));
          return;
        }

        if(logMINOR) Logger.minor(this, "Redirecting to FreenetURI: "+newURI);
        String requestedMimeType = httprequest.getParam("type");
        String location = getLink(newURI, requestedMimeType, maxSize, httprequest.getParam("force", null), httprequest.isParameterSet("forcedownload"), maxRetries, overrideSize);
        writeTemporaryRedirect(ctx, null, location);
        return;
      }

      /*
       * Redirect to the welcome page because no key was specified.
       */
      try {
        throw new RedirectException(new URI(null, null, null, -1, welcome.getPath(), uri.getQuery(), uri.getFragment()));
      } catch (URISyntaxException e) {
        /*
         * This shouldn't happen because all the inputs to the URI constructor come from getters
         * of existing URIs.
         */
        Logger.error(FProxyToadlet.class, "Unexpected syntax error in URI: " + e);
        writeTemporaryRedirect(ctx, "Internal error. Please check logs and report.", WelcomeToadlet.PATH);
        return;
      }
    }else if(ks.equals("/favicon.ico")){
        try {
                throw new RedirectException(StaticToadlet.ROOT_URL+"favicon.ico");
            } catch (URISyntaxException e) {
                throw new Error(e);
            }
    } else if(ks.startsWith("/feed/") || ks.equals("/feed")) {
      //TODO Better way to find the host. Find if https is used?
      String host = ctx.getHeaders().get("host");
      String atom = ctx.getAlertManager().getAtom("http://" + host);
      byte[] buf = atom.getBytes("UTF-8");
      ctx.sendReplyHeadersFProxy(200, "OK", null, "application/atom+xml", buf.length);
      ctx.writeData(buf, 0, buf.length);
      return;
    }else if(ks.equals("/robots.txt") && ctx.doRobots()){
      this.writeTextReply(ctx, 200, "Ok", "User-agent: *\nDisallow: /");
      return;
    }else if(ks.startsWith("/darknet/") || ks.equals("/darknet")) { //TODO (pre-build 1045 url format) remove when obsolete
      writePermanentRedirect(ctx, "obsoleted", "/friends/");
      return;
    }else if(ks.startsWith("/opennet/") || ks.equals("/opennet")) { //TODO (pre-build 1045 url format) remove when obsolete
      writePermanentRedirect(ctx, "obsoleted", "/strangers/");
      return;
    } else if(ks.startsWith("/queue/")) {
      writePermanentRedirect(ctx, "obsoleted", "/downloads/");
      return;
    } else if(ks.startsWith("/config/")) {
      writePermanentRedirect(ctx, "obsoleted", "/config/node");
      return;
    }

    if(ks.startsWith("/"))
      ks = ks.substring(1);

    //first check of httprange before get
    // only valid number format is checked here
    String rangeStr = ctx.getHeaders().get("range");
    if (rangeStr != null) {
      try {
        parseRange(rangeStr);
      } catch (HTTPRangeException e) {
        Logger.normal(this, "Invalid Range Header: "+rangeStr, e);
        ctx.sendReplyHeaders(416, "Requested Range Not Satisfiable", null, null, 0);
        return;
      }
    }

    FreenetURI key;
    try {
      key = new FreenetURI(ks);
    } catch (MalformedURLException e) {
      PageNode page = ctx.getPageMaker().getPageNode(l10n("invalidKeyTitle"), ctx);
      HTMLNode pageNode = page.outer;
      HTMLNode contentNode = page.content;

      HTMLNode errorInfobox = contentNode.addChild("div", "class", "infobox infobox-error");
      errorInfobox.addChild("div", "class", "infobox-header", NodeL10n.getBase().getString("FProxyToadlet.invalidKeyWithReason", new String[] { "reason" }, new String[] { e.toString() }));
      HTMLNode errorContent = errorInfobox.addChild("div", "class", "infobox-content");
      errorContent.addChild("#", l10n("expectedKeyButGot"));
      errorContent.addChild("code", ks);
      errorContent.addChild("br");
      errorContent.addChild(ctx.getPageMaker().createBackLink(ctx, l10n("goBack")));
      errorContent.addChild("br");
      addHomepageLink(errorContent);

      this.writeHTMLReply(ctx, 400, l10n("invalidKeyTitle"), pageNode.generate());
      return;
    }

    FetchContext fctx = getFetchContext(maxSize);
    // max-size=-1 => use default
    maxSize = fctx.maxOutputLength;

    //We should run the ContentFilter by default
    String forceString = httprequest.getParam("force");
    long now = System.currentTimeMillis();
    boolean force = false;
    if(forceString != null) {
      if(forceString.equals(getForceValue(key, now)) ||
          forceString.equals(getForceValue(key, now-FORCE_GRAIN_INTERVAL)))
        force = true;
    }
    if(restricted)
      maxRetries = -2;
    if(maxRetries >= -1) {
      fctx.maxNonSplitfileRetries = maxRetries;
      fctx.maxSplitfileBlockRetries = maxRetries;
    }
    if (!force && !httprequest.isParameterSet("forcedownload")) fctx.filterData = true;
    else if(logMINOR) Logger.minor(this, "Content filter disabled via request parameter");
    //Load the fetch context with the callbacks needed for web-pushing, if enabled
    if(container.enableInlinePrefetch()) {
      fctx.prefetchHook = new FoundURICallback() {

        List<FreenetURI> uris = new ArrayList<FreenetURI>();
       
        @Override
        public void foundURI(FreenetURI uri) {
          // Ignore
        }

        @Override
        public void foundURI(FreenetURI uri, boolean inline) {
          if(!inline) return;
          if(logMINOR) Logger.minor(this, "Prefetching "+uri);
          synchronized(this) {
            if(uris.size() < MAX_PREFETCH)
              // FIXME Maybe we should do this randomly, but since it's a DoS protection (in an obscure feature), if so we should do it in constant space!
              uris.add(uri);
          }
        }

        @Override
        public void onText(String text, String type, URI baseURI) {
          // Ignore
        }

        @Override
        public void onFinishedPage() {
          core.node.executor.execute(new Runnable() {

            @Override
            public void run() {
              for(FreenetURI uri : uris) {
                client.prefetch(uri, SECONDS.toMillis(60), 512*1024, prefetchAllowedTypes);
              }
            }
           
          });
        }

      };

    }
    if(container.isFProxyWebPushingEnabled()) fctx.tagReplacer = new PushingTagReplacerCallback(core.getFProxy().fetchTracker, defaultMaxSize, ctx);

    String requestedMimeType = httprequest.getParam("type", null);
    fctx.overrideMIME = requestedMimeType;
    String override = (requestedMimeType == null) ? "" : "?type="+URLEncoder.encode(requestedMimeType,true);
    String maybeCharset = httprequest.isParameterSet("maybecharset") ? httprequest.getParam("maybecharset", null) : null;
    fctx.charset = maybeCharset;
    if(override.equals("") && maybeCharset != null)
      override = "?maybecharset="+URLEncoder.encode(maybeCharset, true);
    // No point passing ?force= across a redirect, since the key will change.
    // However, there is every point in passing ?forcedownload.
    if(httprequest.isParameterSet("forcedownload")) {
      if(override.length() == 0) override = "?forcedownload";
      else override = override+"&forcedownload";
    }

    Bucket data = null;
    String mimeType = null;
    String referer = sanitizeReferer(ctx);
    FetchException fe = null;


    FProxyFetchResult fr = null;

      FProxyFetchWaiter fetch = null;
      try {
        fetch = fetchTracker.makeFetcher(key, maxSize, fctx, ctx.getReFilterPolicy());
      } catch (FetchException e) {
            fe = e;
      }
      if(fetch != null)
      while(true) {
      fr = fetch.getResult(!canSendProgress);
      if(fr.hasData()) {

        if(fr.getFetchCount() > 1 && !fr.hasWaited() && fr.getFetchCount() > 1 && key.isUSK() && context.uskManager.lookupKnownGood(USK.create(key)) > key.getSuggestedEdition()) {
          Logger.normal(this, "Loading later edition...");
          fetch.progress.requestImmediateCancel();
          fr = null;
          fetch = null;
          try {
            fetch = fetchTracker.makeFetcher(key, maxSize, fctx, ctx.getReFilterPolicy());
          } catch (FetchException e) {
                            fe = e;
          }
          if(fetch == null) break;
          continue;
        }

        if(logMINOR) Logger.minor(this, "Found data");
        data = new NoFreeBucket(fr.data);
        mimeType = fr.mimeType;
        fetch.close(); // Not waiting any more, but still locked the results until sent
        break;
      } else if(fr.failed != null) {
        if(logMINOR) Logger.minor(this, "Request failed");
        fe = fr.failed;
        fetch.close(); // Not waiting any more, but still locked the results until sent
        break;
      } else if(canSendProgress) {
        if(logMINOR) Logger.minor(this, "Still in progress");
        // Still in progress
        boolean isJsEnabled=ctx.getContainer().isFProxyJavascriptEnabled() && ua != null && !ua.contains("AppleWebKit/");
        boolean isWebPushingEnabled = false;
        PageNode page = ctx.getPageMaker().getPageNode(l10n("fetchingPageTitle"), ctx);
        HTMLNode pageNode = page.outer;
        String location = getLink(key, requestedMimeType, maxSize, httprequest.getParam("force", null), httprequest.isParameterSet("forcedownload"), maxRetries, overrideSize);
        HTMLNode headNode=page.headNode;
        if(isJsEnabled){
          //If the user has enabled javascript, we add a <noscript> http refresh(if he has disabled it in the browser)
          headNode.addChild("noscript").addChild("meta", "http-equiv", "Refresh").addAttribute("content", "2;URL=" + location);
            // If pushing is disabled, but js is enabled, then we add the original progresspage.js
            if ((isWebPushingEnabled = ctx.getContainer().isFProxyWebPushingEnabled()) == false) {
              HTMLNode scriptNode = headNode.addChild("script", "//abc");
              scriptNode.addAttribute("type", "text/javascript");
              scriptNode.addAttribute("src", "/static/js/progresspage.js");
            }
        }else{
          //If he disabled it, we just put the http refresh meta, without the noscript
          headNode.addChild("meta", "http-equiv", "Refresh").addAttribute("content", "2;URL=" + location);
        }
        HTMLNode contentNode = page.content;
        HTMLNode infobox = contentNode.addChild("div", "class", "infobox infobox-information");
        infobox.addChild("div", "class", "infobox-header", l10n("fetchingPageBox"));
        HTMLNode infoboxContent = infobox.addChild("div", "class", "infobox-content");
        infoboxContent.addAttribute("id", "infoContent");
        infoboxContent.addChild(new ProgressInfoElement(fetchTracker, key, fctx, maxSize, ctx.isAdvancedModeEnabled(), ctx, isWebPushingEnabled));


        HTMLNode table = infoboxContent.addChild("table", "border", "0");
        HTMLNode progressCell = table.addChild("tr").addChild("td", "class", "request-progress");
        if(fr.totalBlocks <= 0)
          progressCell.addChild("#", NodeL10n.getBase().getString("QueueToadlet.unknown"));
        else {
          progressCell.addChild(new ProgressBarElement(fetchTracker,key,fctx,maxSize,ctx, isWebPushingEnabled));
        }

        infobox = contentNode.addChild("div", "class", "infobox infobox-information");
        infobox.addChild("div", "class", "infobox-header", l10n("fetchingPageOptions"));
        infoboxContent = infobox.addChild("div", "class", "infobox-content");

        HTMLNode optionList = infoboxContent.addChild("ul");
        optionList.addChild("li").addChild("p", l10n("progressOptionZero"));

        addDownloadOptions(ctx, optionList, key, mimeType, false, false, core);

        optionList.addChild("li").addChild(ctx.getPageMaker().createBackLink(ctx, l10n("goBackToPrev")));
        optionList.addChild("li").addChild("a", new String[] { "href", "title" },
            new String[] { "/", NodeL10n.getBase().getString("Toadlet.homepage") }, l10n("abortToHomepage"));

        MultiValueTable<String, String> retHeaders = new MultiValueTable<String, String>();
        //retHeaders.put("Refresh", "2; url="+location);
        writeHTMLReply(ctx, 200, "OK", retHeaders, pageNode.generate());
        fr.close();
        fetch.close();
        return;
      } else if(fr != null)
        fr.close();
      }

    try {
      if(logMINOR)
        Logger.minor(this, "FProxy fetching "+key+" ("+maxSize+ ')');
      if(data == null && fe == null) {
        boolean needsFetch=true;
        //If we don't have the data, then check if an FProxyFetchInProgress has. It can happen when one FetchInProgress downloaded an image
        //asynchronously, then loads it. This way a FetchInprogress will have the full image, and no need to block.
        FProxyFetchInProgress progress=fetchTracker.getFetchInProgress(key, maxSize, fctx);
        if(progress!=null){
          FProxyFetchWaiter waiter=null;
          FProxyFetchResult result=null;
          try{
            waiter=progress.getWaiter();
            result=waiter.getResult(false);
            if(result.failed==null && result.data!=null){
              mimeType=result.mimeType;
              data=result.data;
              data=ctx.getBucketFactory().makeBucket(result.data.size());
              BucketTools.copy(result.data, data);
              needsFetch=false;
            }
          }finally{
            if(waiter!=null){
              progress.close(waiter);
            }
            if(result!=null){
              progress.close(result);
            }
          }
        }
        if(needsFetch){
          //If we don't have the data, then we need to fetch it and block until it is available
          FetchResult result = fetch(key, maxSize, new RequestClient() {
            @Override
            public boolean persistent() {
              return false;
            }
            @Override
            public boolean realTimeFlag() {
              return true;
            } }, fctx);

          // Now, is it safe?

          data = result.asBucket();
          mimeType = result.getMimeType();
        }
      } else if(fe != null) throw fe;

      handleDownload(ctx, data, ctx.getBucketFactory(), mimeType, requestedMimeType, forceString, httprequest.isParameterSet("forcedownload"), "/", key, "&max-size="+maxSizeDownload, referer, true, ctx, core, fr != null, maybeCharset);
    } catch (FetchException e) {
      //Handle exceptions thrown from the ContentFilter
      String msg = e.getMessage();
      if(logMINOR) {
        Logger.minor(this, "Failed to fetch "+uri+" : "+e);
      }
      if(e.newURI != null) {
        if(accept != null && (accept.startsWith("text/css") || accept.startsWith("image/")) && recursion++ < MAX_RECURSION) {
          // If it's an image or a CSS fetch, auto-follow the redirect, up to a limit.
          String link = getLink(e.newURI, requestedMimeType, maxSize, httprequest.getParam("force", null), httprequest.isParameterSet("forcedownload"), maxRetries, overrideSize);
          try {
            uri = new URI(link);
            innerHandleMethodGET(uri, httprequest, ctx, recursion);
            return;
          } catch (URISyntaxException e1) {
            Logger.error(this, "Caught "+e1+" parsing new link "+link, e1);
          }
        }
        Toadlet.writePermanentRedirect(ctx, msg,
          getLink(e.newURI, requestedMimeType, maxSize, httprequest.getParam("force", null), httprequest.isParameterSet("forcedownload"), maxRetries, overrideSize));
      } else if(e.mode == FetchExceptionMode.TOO_BIG) {
        PageNode page = ctx.getPageMaker().getPageNode(l10n("fileInformationTitle"), ctx);
        HTMLNode pageNode = page.outer;
        HTMLNode contentNode = page.content;

        HTMLNode infobox = contentNode.addChild("div", "class", "infobox infobox-information");
        infobox.addChild("div", "class", "infobox-header", l10n("largeFile"));
        HTMLNode infoboxContent = infobox.addChild("div", "class", "infobox-content");
        HTMLNode fileInformationList = infoboxContent.addChild("ul");
        HTMLNode option = fileInformationList.addChild("li");
        option.addChild("#", (l10n("filenameLabel") + ' '));
        option.addChild("a", "href", '/' + key.toString(), getFilename(key, e.getExpectedMimeType()));

        String mime = writeSizeAndMIME(fileInformationList, e);

        infobox = contentNode.addChild("div", "class", "infobox infobox-information");
        infobox.addChild("div", "class", "infobox-header", l10n("explanationTitle"));
        infoboxContent = infobox.addChild("div", "class", "infobox-content");
        infoboxContent.addChild("#", l10n("largeFileExplanationAndOptions"));
        HTMLNode optionList = infoboxContent.addChild("ul");
        //HTMLNode optionTable = infoboxContent.addChild("table", "border", "0");
        if(!restricted) {
          option = optionList.addChild("li");
          HTMLNode optionForm = option.addChild("form", new String[] { "action", "method" }, new String[] {'/' + key.toString(), "get" });
          optionForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "max-size", String.valueOf(e.expectedSize == -1 ? Long.MAX_VALUE : e.expectedSize*2) });
          if (requestedMimeType != null)
            optionForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "type", requestedMimeType });
          if(maxRetries >= -1)
            optionForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "max-retries", Integer.toString(maxRetries) });
          optionForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "fetch", l10n("fetchLargeFileAnywayAndDisplayButton") });
          optionForm.addChild("#", " - " + l10n("fetchLargeFileAnywayAndDisplay"));
          addDownloadOptions(ctx, optionList, key, mime, false, false, core);
        }


        //optionTable.addChild("tr").addChild("td", "colspan", "2").addChild("a", new String[] { "href", "title" }, new String[] { "/", NodeL10n.getBase().getString("Toadlet.homepage") }, l10n("abortToHomepage"));
        optionList.addChild("li").addChild("a", new String[] { "href", "title" }, new String[] { "/", NodeL10n.getBase().getString("Toadlet.homepage") }, l10n("abortToHomepage"));

        //option = optionTable.addChild("tr").addChild("td", "colspan", "2");
        optionList.addChild("li").addChild(ctx.getPageMaker().createBackLink(ctx, l10n("goBackToPrev")));

        writeHTMLReply(ctx, 200, "OK", pageNode.generate());
      } else {
        PageNode page = ctx.getPageMaker().getPageNode(e.getShortMessage(), ctx);
        HTMLNode pageNode = page.outer;
        HTMLNode contentNode = page.content;

        HTMLNode infobox = contentNode.addChild("div", "class", "infobox infobox-error");
        infobox.addChild("div", "class", "infobox-header", l10n("errorWithReason", "error", e.getShortMessage()));
        HTMLNode infoboxContent = infobox.addChild("div", "class", "infobox-content");
        HTMLNode fileInformationList = infoboxContent.addChild("ul");
        HTMLNode option = fileInformationList.addChild("li");
        option.addChild("#", (l10n("filenameLabel") + ' '));
        option.addChild("a", "href", '/' + key.toString(), getFilename(key, e.getExpectedMimeType()));

        String mime = writeSizeAndMIME(fileInformationList, e);
        infobox = contentNode.addChild("div", "class", "infobox infobox-error");
        infobox.addChild("div", "class", "infobox-header", l10n("explanationTitle"));
        UnsafeContentTypeException filterException = null;
        if(e.getCause() != null && e.getCause() instanceof UnsafeContentTypeException) {
          filterException = (UnsafeContentTypeException)e.getCause();
        }
        infoboxContent = infobox.addChild("div", "class", "infobox-content");
        if(filterException == null)
          infoboxContent.addChild("p", l10n("unableToRetrieve"));
        else
          infoboxContent.addChild("p", l10n("unableToSafelyDisplay"));
        if(e.isFatal() && filterException == null)
          infoboxContent.addChild("p", l10n("errorIsFatal"));
        infoboxContent.addChild("p", msg);
        if(filterException != null) {
          if(filterException.details() != null) {
            HTMLNode detailList = infoboxContent.addChild("ul");
            for(String detail : filterException.details()) {
              detailList.addChild("li", detail);
            }
          }
        }
        if(e.errorCodes != null) {
          infoboxContent.addChild("p").addChild("pre").addChild("#", e.errorCodes.toVerboseString());
        }

        infobox = contentNode.addChild("div", "class", "infobox infobox-error");
        infobox.addChild("div", "class", "infobox-header", l10n("options"));
        infoboxContent = infobox.addChild("div", "class", "infobox-content");

        HTMLNode optionList = infoboxContent.addChild("ul");

        PluginInfoWrapper keyUtil;
        if((e.mode == FetchExceptionMode.NOT_IN_ARCHIVE || e.mode == FetchExceptionMode.NOT_ENOUGH_PATH_COMPONENTS)) {
          // first look for the newest version
          if ((keyUtil = core.node.pluginManager.getPluginInfo("plugins.KeyUtils.KeyUtilsPlugin")) != null) {
            option = optionList.addChild("li");
            if (keyUtil.getPluginLongVersion() < 5010)
              NodeL10n.getBase().addL10nSubstitution(option, "FProxyToadlet.openWithKeyExplorer", new String[] { "link" }, new HTMLNode[] { HTMLNode.link("/KeyUtils/?automf=true&key=" + key.toString()) });
            else {
              NodeL10n.getBase().addL10nSubstitution(option, "FProxyToadlet.openWithKeyExplorer", new String[] { "link" }, new HTMLNode[] { HTMLNode.link("/KeyUtils/?key=" + key.toString()) });
              option = optionList.addChild("li");
              NodeL10n.getBase().addL10nSubstitution(option, "FProxyToadlet.openWithSiteExplorer", new String[] { "link" }, new HTMLNode[] { HTMLNode.link("/KeyUtils/Site?key=" + key.toString()) });
            }
          } else if ((keyUtil = core.node.pluginManager.getPluginInfo("plugins.KeyExplorer.KeyExplorer")) != null) {
            option = optionList.addChild("li");
            if (keyUtil.getPluginLongVersion() > 4999)
              NodeL10n.getBase().addL10nSubstitution(option, "FProxyToadlet.openWithKeyExplorer", new String[] { "link" }, new HTMLNode[] { HTMLNode.link("/KeyExplorer/?automf=true&key=" + key.toString())});
            else
              NodeL10n.getBase().addL10nSubstitution(option, "FProxyToadlet.openWithKeyExplorer", new String[] { "link" }, new HTMLNode[] { HTMLNode.link("/plugins/plugins.KeyExplorer.KeyExplorer/?key=" + key.toString())});
          }
        }
        if(filterException != null) {
          if((mime.equals("application/x-freenet-index")) && (core.node.pluginManager.isPluginLoaded("plugins.ThawIndexBrowser.ThawIndexBrowser"))) {
            option = optionList.addChild("li");
            NodeL10n.getBase().addL10nSubstitution(option, "FProxyToadlet.openAsThawIndex", new String[] { "link" }, new HTMLNode[] { HTMLNode.link("/plugins/plugins.ThawIndexBrowser.ThawIndexBrowser/?key=" + key.toString()).addChild("b") });
          }
          option = optionList.addChild("li");
          // FIXME: is this safe? See bug #131
          MediaType textMediaType = new MediaType("text/plain");
          textMediaType.setParameter("charset", (e.getExpectedMimeType() != null) ? MediaType.getCharsetRobust(e.getExpectedMimeType()) : null);
View Full Code Here

Examples of freenet.keys.FreenetURI

      try {
        URI refererURI = new URI(URIPreEncoder.encode(referer));
        String path = refererURI.getPath();
        while(path.startsWith("/")) path = path.substring(1);
        if("".equals(path)) return "/";
        FreenetURI furi = new FreenetURI(path);
        HTTPRequest req = new HTTPRequestImpl(refererURI, "GET");
        String type = req.getParam("type");
        referer = "/" + furi.toString();
        if(type != null && type.length() > 0)
          referer += "?type=" + type;
      } catch (MalformedURLException e) {
        referer = "/";
        Logger.normal(this, "Caught MalformedURLException on the referer : "+e.getMessage());
View Full Code Here

Examples of freenet.keys.FreenetURI

      // Push one block only.
     
      RandomAccessBucket data = randomData(node);
      HighLevelSimpleClient client = node.clientCore.makeClient((short) 0, false, false);
      FreenetURI uri = new FreenetURI("KSK@" + uid + "-" + dateFormat.format(today.getTime()));
      System.out.println("PUSHING " + uri);
     
      try {
        InsertBlock block = new InsertBlock(data, new ClientMetadata(), uri);
        t1 = System.currentTimeMillis();
        client.insert(block, false, null);
        t2 = System.currentTimeMillis();
       
        System.out.println("PUSH-TIME-" + ":" + (t2 - t1));
        csvLine.add(String.valueOf(t2 - t1));
      } catch (InsertException e) {
        e.printStackTrace();
        csvLine.add("N/A");
      }

      data.free();

      node.park();

      // Node 2
      File innerDir2 = new File(dir, Integer.toString(DARKNET_PORT2));
      innerDir2.mkdir();
      fis = new FileInputStream(seednodes);
      FileUtil.writeTo(fis, new File(innerDir2, "seednodes.fref"));
      fis.close();
      node2 = NodeStarter.createTestNode(DARKNET_PORT2, OPENNET_PORT2, dir.getPath(), false,
              Node.DEFAULT_MAX_HTL, 0, random, new PooledExecutor(), 1000, 5 * 1024 * 1024, true, true, true,
              true, true, true, true, 12 * 1024, false, true, false, false, null);
      node2.start(true);

      t1 = System.currentTimeMillis();
      if (!TestUtil.waitForNodes(node2)) {
        exitCode = EXIT_FAILED_TARGET;
        return;
      }
      t2 = System.currentTimeMillis();
      System.out.println("SEED-TIME:" + (t2 - t1));
      csvLine.add(String.valueOf(t2 - t1));

      // PULL N+1 BLOCKS
      for (int i = 0; i <= MAX_N; i++) {
        client = node2.clientCore.makeClient((short) 0, false, false);
        Calendar targetDate = (Calendar) today.clone();
        targetDate.add(Calendar.DAY_OF_MONTH, -((1 << i) - 1));

        uri = new FreenetURI("KSK@" + uid + "-" + dateFormat.format(targetDate.getTime()));
        System.out.println("PULLING " + uri);

        try {
          t1 = System.currentTimeMillis();
          client.fetch(uri);
View Full Code Here

Examples of freenet.keys.FreenetURI

      System.err.println("Inserting single block 3 times");
     
      InsertBlock block = new InsertBlock(single, new ClientMetadata(), FreenetURI.EMPTY_CHK_URI);
     
      FreenetURI uri = null;
     
      int successes = 0;
     
      for(int i=0;i<3;i++) {
        System.err.println("Inserting single block, try #"+i);
        try {
          t1 = System.currentTimeMillis();
          FreenetURI thisURI = client.insert(block, false, null);
          if(uri != null && !thisURI.equals(uri)) {
            System.err.println("URI "+i+" is "+thisURI+" but previous is "+uri);
            System.exit(EXIT_DIFFERENT_URI);
          }
          uri = thisURI;
          t2 = System.currentTimeMillis();
         
          System.out.println("PUSH-TIME-" + i + ":" + (t2 - t1)+" for "+uri+" for single block");
          csvLine.add(String.valueOf(t2 - t1));
          csvLine.add(uri.toASCIIString());
          successes++;
        } catch (InsertException e) {
          e.printStackTrace();
          csvLine.add(InsertException.getShortMessage(e.getMode()));
          csvLine.add("N/A");
          System.out.println("INSERT FAILED: "+e+" for insert "+i+" for single block");
        }
      }
     
      if(successes == 3)
        System.err.println("All inserts succeeded for single block: "+successes);
      else if(successes != 0)
        System.err.println("Some inserts succeeded for single block: "+successes);
      else
        System.err.println("NO INSERTS SUCCEEDED FOR SINGLE BLOCK: "+successes);
     
      uri = null;
     
      // Insert 3 blocks
     
      for(int i=0;i<3;i++) {
        System.err.println("Inserting MHK #"+i);
        uri = null;
        block = new InsertBlock(mhks[i], new ClientMetadata(), FreenetURI.EMPTY_CHK_URI);
        try {
          t1 = System.currentTimeMillis();
          FreenetURI thisURI = client.insert(block, false, null);
          uri = thisURI;
          t2 = System.currentTimeMillis();
         
          System.out.println("PUSH-TIME-" + i + ":" + (t2 - t1)+" for "+uri+" for MHK #"+i);
          csvLine.add(String.valueOf(t2 - t1));
          csvLine.add(uri.toASCIIString());
          successes++;
        } catch (InsertException e) {
          e.printStackTrace();
          csvLine.add(InsertException.getShortMessage(e.getMode()));
          csvLine.add("N/A");
          System.out.println("INSERT FAILED: "+e+" for MHK #"+i);
        }
      }
     
      if(successes == 3)
        System.err.println("All inserts succeeded for MHK: "+successes);
      else if(successes != 0)
        System.err.println("Some inserts succeeded for MHK: "+successes);
      else
        System.err.println("NO INSERTS SUCCEEDED FOR MHK: "+successes);
     
      uri = null;
      }
     
      // PARSE FILE AND FETCH OLD STUFF IF APPROPRIATE
     
      boolean match = false;
     
      FreenetURI singleURI = null;
      FreenetURI[] mhkURIs = new FreenetURI[3];
      fis = new FileInputStream(file);
      BufferedReader br = new BufferedReader(new InputStreamReader(fis, ENCODING));
      String line = null;
      int linesTooShort = 0, linesBroken = 0, linesNoNumber = 0, linesNoURL = 0, linesNoFetch = 0;
      int total = 0, singleKeysSucceeded = 0, mhkSucceeded = 0;
      int totalSingleKeyFetches = 0, totalSingleKeySuccesses = 0;
      while((line = br.readLine()) != null) {
       
        singleURI = null;
        for(int i=0;i<mhkURIs.length;i++) mhkURIs[i] = null;
        //System.out.println("LINE: "+line);
        String[] split = line.split("!");
        Date date = dateFormat.parse(split[0]);
        GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        calendar.setTime(date);
        System.out.println("Date: "+dateFormat.format(calendar.getTime()));
        GregorianCalendar target = (GregorianCalendar) today.clone();
        target.set(Calendar.HOUR_OF_DAY, 0);
        target.set(Calendar.MINUTE, 0);
        target.set(Calendar.MILLISECOND, 0);
        target.set(Calendar.SECOND, 0);
        target.add(Calendar.DAY_OF_MONTH, -DELTA);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.getTime();
        target.getTime();
        try {
          if(split.length < 3) {
            linesTooShort++;
            continue;
          }
          int seedTime = Integer.parseInt(split[2]);
          System.out.println("Seed time: "+seedTime);
         
          int token = 3;
          if(split.length < 4) {
            linesTooShort++;
            continue;
          }
         
          for(int i=0;i<3;i++) {
            int insertTime = Integer.parseInt(split[token]);
            System.out.println("Single key insert "+i+" : "+insertTime);
            token++;
            FreenetURI thisURI = new FreenetURI(split[token]);
            if(singleURI == null)
              singleURI = thisURI;
            else {
              if(!singleURI.equals(thisURI)) {
                System.err.println("URI is not the same for all 3 inserts: was "+singleURI+" but "+i+" is "+thisURI);
                linesBroken++;
                continue;
              }
            }
            token++;
          }
          System.out.println("Single key URI: "+singleURI);
         
          for(int i=0;i<3;i++) {
            int insertTime = Integer.parseInt(split[token]);
            token++;
            mhkURIs[i] = new FreenetURI(split[token]);
            token++;
            System.out.println("MHK #"+i+" URI: "+mhkURIs[i]+" insert time "+insertTime);
          }
         
        } catch (NumberFormatException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.