Package freenet.keys

Examples of freenet.keys.ClientKey


       
        //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);
        } else {
          block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
          insertKey = fetchKey = block.getClientKey();
          testKey = insertKey.getURI();
        }
       
        System.err.println();
        System.err.println("Created random test key "+testKey+" = "+fetchKey.getNodeKey(false));
        System.err.println();
       
        byte[] data = dataString.getBytes("UTF-8");
        Logger.minor(RealNodeRequestInsertTest.class, "Decoded: "+new String(block.memoryDecode(), "UTF-8"));
        Logger.normal(RealNodeRequestInsertTest.class,"Insert Key: "+insertKey.getURI());
        Logger.normal(RealNodeRequestInsertTest.class,"Fetch Key: "+fetchKey.getURI());
    try {
      insertAttempts++;
      randomNode.clientCore.realPut(block.getBlock(), false, FORK_ON_CACHEABLE, false, false, REAL_TIME_FLAG);
      Logger.error(RealNodeRequestInsertTest.class, "Inserted to "+node1);
    } catch (freenet.node.LowLevelPutException putEx) {
View Full Code Here


  /** Get a numbered key to fetch. */
  public abstract ClientKey getKey(SendableRequestItem token);
 
  @Override
  public Key getNodeKey(SendableRequestItem token) {
    ClientKey key = getKey(token);
    if(key == null) return null;
    return key.getNodeKey(true);
  }
View Full Code Here

        byte[] buf = new byte[32];
        random.nextBytes(buf);
        String keyName = HexUtil.bytesToHex(buf);
       
        FreenetURI testKey;
        ClientKey insertKey;
        ClientKey fetchKey;
        ClientKeyBlock block;
       
        if(isSSK) {
          testKey = new FreenetURI("KSK", keyName);
         
          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);
        } else {
          block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
          insertKey = fetchKey = block.getClientKey();
          testKey = insertKey.getURI();
        }
        final Key nodeKey = fetchKey.getNodeKey(false);
       
        System.err.println();
        System.err.println("Created random test key "+testKey+" = "+nodeKey);
        System.err.println();
        Logger.error(RealNodeULPRTest.class, "Starting ULPR test #"+successfulTests+": "+testKey+" = "+fetchKey+" = "+nodeKey);
       
        waitForAllConnected(nodes);
       
        // Fetch the key from each node.
       
        // Only those nodes which have been asked by another node (not directly here) for the key will want it.
        // Further, only those nodes on the actual DNF path will learn from their mistakes: a RejectedLoop doesn't tell you much.
       
        // Lets track which nodes have been visited.
       
        final boolean[] visited = new boolean[nodes.length];
       
        NodeDispatcherCallback cb = new NodeDispatcherCallback() {

      @Override
      public void snoop(Message m, Node n) {
        if(((!isSSK) && m.getSpec() == DMT.FNPCHKDataRequest) ||
            (isSSK && m.getSpec() == DMT.FNPSSKDataRequest)) {
          Key key = (Key) m.getObject(DMT.FREENET_ROUTING_KEY);
          if(key.equals(nodeKey)) {
            visited[n.getDarknetPortNumber() - DARKNET_PORT_BASE] = true;
          }
        }
      }
         
        };
       
        for(Node node: nodes) {
          node.setDispatcherHook(cb);
        }
       
        for(int i=0;i<nodes.length;i++) {
          System.out.println("Searching from node "+i);
          try {
            nodes[i%nodes.length].clientCore.realGetKey(fetchKey, false, false, false, REAL_TIME_FLAG);
            System.err.println("TEST FAILED: KEY ALREADY PRESENT!!!"); // impossible!
            System.exit(EXIT_KEY_EXISTS);
          } catch (LowLevelGetException e) {
            switch(e.code) {
            case LowLevelGetException.DATA_NOT_FOUND:
            case LowLevelGetException.ROUTE_NOT_FOUND:
              // Expected
              System.err.println("Node "+i%nodes.length+" : key not found (expected behaviour)");
              continue;
            case LowLevelGetException.RECENTLY_FAILED:
               System.err.println("Node "+i%nodes.length+" : recently failed (expected behaviour on later tests)");
               continue;
            default:
              System.err.println("Node "+i%nodes.length+" : UNEXPECTED ERROR: "+e.toString());
              System.exit(EXIT_UNKNOWN_ERROR_CHECKING_KEY_NOT_EXIST);
            }
          }
        }
       
        // Now we should have a good web of subscriptions set up.
       
        int visitedCount = 0;
        StringBuilder sb = new StringBuilder(3*nodes.length+1);
        boolean first = true;
        for(int i=0;i<visited.length;i++) {
          if(!visited[i]) continue;
          visitedCount++;
          if(!first) sb.append(' ');
          first = false;
          sb.append(i);
        }
        System.err.println("Nodes which were asked for the key by another node: "+visitedCount+" : "+sb.toString());
       
        // Store the key to ONE node.
       
        Logger.normal(RealNodeULPRTest.class, "Inserting to node "+(nodes.length-1));
    long tStart = System.currentTimeMillis();
    nodes[nodes.length-1].store(block.getBlock(), false, false, true, false); // Write to datastore
        Logger.normal(RealNodeULPRTest.class, "Inserted to node "+(nodes.length-1));
   
    int x = -1;
    while(true) {
      x++;
      Thread.sleep(1000);
      int count = 0;
      for(Node node: nodes) {
        if(node.hasKey(fetchKey.getNodeKey(false), true, true))
          count++;
      }
      System.err.println("T="+x+" : "+count+'/'+nodes.length+" have the data on test "+successfulTests+".");
      Logger.normal(RealNodeULPRTest.class, "T="+x+" : "+count+'/'+nodes.length+" have the data on test "+successfulTests+".");
      if(x > 300) {
        System.err.println();
        System.err.println("TEST FAILED");
        System.exit(EXIT_TEST_FAILED);
      }
      if(count == nodes.length) {
        successfulTests++;
        long tEnd = System.currentTimeMillis();
        long propagationTime = tEnd-tStart;
        System.err.println("SUCCESSFUL TEST # "+successfulTests+" in "+propagationTime+"ms!!!");
        totalPropagationTime += propagationTime;
            System.err.println("Average propagation time: "+(totalPropagationTime / successfulTests)+"ms");
        System.err.println();
        break;
      }
      if(x % nodes.length == 0) {
        System.err.print("Nodes that do have the data: ");
        for(int i=0;i<nodes.length;i++)
          if(nodes[i].hasKey(fetchKey.getNodeKey(false), true, true)) {
            System.err.print(i+" ");
          }
        System.err.println();
      }
    }
View Full Code Here

    USKDateHint date = USKDateHint.now();
    ClientSSK[] ssks = date.getRequestURIs(this.origUSK);
    DBRAttempt[] atts = new DBRAttempt[ssks.length];
    int x = 0;
    for(int i=0;i<ssks.length;i++) {
      ClientKey key = ssks[i];
      DBRAttempt att = new DBRAttempt(key, context, USKDateHint.Type.values()[i]);
      this.dbrAttempts.add(att);
      atts[x++] = att;
    }
    dbrHintsStarted = atts.length;
View Full Code Here

        // Just create a new SingleFileFetcher
        // Which will then fetch the target URI, and call the rcd.success
        // Hopefully!
        FreenetURI newURI = metadata.getSingleTarget();
        if(logMINOR) Logger.minor(this, "Redirecting to "+newURI);
        ClientKey redirectedKey;
        try {
          BaseClientKey k = BaseClientKey.getBaseKey(newURI);
          if(k instanceof ClientKey)
            redirectedKey = (ClientKey) k;
          else
View Full Code Here

    if(token == null) {
      if(logMINOR) Logger.minor(this, "Choose key returned null: "+req);
      return null;
    } else {
      Key key;
      ClientKey ckey;
      if(isInsertScheduler) {
        key = null;
        ckey = null;
      } else {
        key = ((BaseSendableGet)req).getNodeKey(token);
View Full Code Here

    @Override
    public boolean send(NodeClientCore core, RequestScheduler sched, final ClientContext context, final ChosenBlock req) {
      // Ignore keyNum, key, since we're only sending one block.
      ClientKeyBlock encodedBlock;
      KeyBlock b;
      final ClientKey key;
      ClientKey k = null;
      if(SingleBlockInserter.logMINOR) Logger.minor(this, "Starting request");
      BlockItem block = (BlockItem) req.token;
      try {
        try {
          encodedBlock = innerEncode(context.random, block.uri, block.copyBucket, block.isMetadata, block.compressionCodec, block.sourceLength, compressorDescriptor, block.pre1254, block.cryptoAlgorithm, block.cryptoKey);
          b = encodedBlock.getBlock();
        } catch (CHKEncodeException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (SSKEncodeException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (MalformedURLException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (InsertException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (IOException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        } catch (InvalidCompressionCodecException e) {
          throw new LowLevelPutException(LowLevelPutException.INTERNAL_ERROR, e.toString() + ":" + e.getMessage(), e);
        }
        if (b==null) {
          Logger.error(this, "Asked to send empty block", new Exception("error"));
          return false;
        }
        key = encodedBlock.getClientKey();
        k = key;
        context.getJobRunner(block.persistent).queueNormalOrDrop(new PersistentJob() {
           
            @Override
            public boolean run(ClientContext context) {
                orig.onEncode(key, context);
                return true;
            }
           
        });
        if(req.localRequestOnly)
          try {
            core.node.store(b, false, req.canWriteClientCache, true, false);
          } catch (KeyCollisionException e) {
            LowLevelPutException failed = new LowLevelPutException(LowLevelPutException.COLLISION);
            KeyBlock collided = core.node.fetch(k.getNodeKey(), true, req.canWriteClientCache, false, false, null);
            if(collided == null) {
              Logger.error(this, "Collided but no key?!");
              // Could be a race condition.
              try {
                core.node.store(b, false, req.canWriteClientCache, true, false);
View Full Code Here

   * @return True if a request was executed. False if caller should try to find another request, and remove
   * this one from the queue. */
  @Override
  public boolean send(NodeClientCore core, final RequestScheduler sched, final ClientContext context, final ChosenBlock req) {
    Object keyNum = req.token;
    final ClientKey key = req.ckey;
    if(key == null) {
      Logger.error(SendableGet.class, "Key is null in send(): keyNum = "+keyNum+" for "+req);
      return false;
    }
    if(logMINOR)
      Logger.minor(SendableGet.class, "Sending get for key "+keyNum+" : "+key);
    if(req.isCancelled()) {
      if(logMINOR) Logger.minor(SendableGet.class, "Cancelled: "+req);
      req.onFailure(new LowLevelGetException(LowLevelGetException.CANCELLED), context);
      return false;
    }
    try {
      try {
        final Key k = key.getNodeKey();
        core.asyncGet(k, false, new RequestCompletionListener() {

          @Override
          public void onSucceeded() {
              req.onFetchSuccess(context);
View Full Code Here

TOP

Related Classes of freenet.keys.ClientKey

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.