Package freenet.keys

Examples of freenet.keys.ClientKeyBlock


        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) {
      Logger.error(RealNodeRequestInsertTest.class, "Insert failed: "+ putEx);
      System.err.println("Insert failed: "+ putEx);
      return EXIT_INSERT_FAILED;
    }
        // Pick random node to request from
        int node2;
        do {
            node2 = random.nextInt(NUMBER_OF_NODES);
        } while(node2 == node1);
        Node fetchNode = nodes[node2];
        try {
          block = fetchNode.clientCore.realGetKey(fetchKey, false, false, false, REAL_TIME_FLAG);
        } catch (LowLevelGetException e) {
          block = null;
        }
        if(block == null) {
      int percentSuccess=100*fetchSuccesses/insertAttempts;
            Logger.error(RealNodeRequestInsertTest.class, "Fetch #"+requestNumber+" FAILED ("+percentSuccess+"%); from "+node2);
            System.err.println("Fetch #"+requestNumber+" FAILED ("+percentSuccess+"%); from "+node2);
            requestsAvg.report(0.0);
        } else {
            byte[] results = block.memoryDecode();
            requestsAvg.report(1.0);
            if(Arrays.equals(results, data)) {
        fetchSuccesses++;
        int percentSuccess=100*fetchSuccesses/insertAttempts;
                Logger.error(RealNodeRequestInsertTest.class, "Fetch #"+requestNumber+" from node "+node2+" succeeded ("+percentSuccess+"%): "+new String(results));
View Full Code Here


    unregister(context, getPriorityClass()); // Key has already been removed from pendingKeys
    onSuccess(block, false, null, context);
  }
 
  public void onSuccess(KeyBlock lowLevelBlock, boolean fromStore, SendableRequestItem token, ClientContext context) {
    ClientKeyBlock block;
    try {
      block = Key.createKeyBlock(this.key, lowLevelBlock);
      onSuccess(block, fromStore, token, context);
    } catch (KeyVerifyException e) {
      onBlockDecodeError(token, context);
View Full Code Here

        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++;
View Full Code Here

        });
    }
  }
 
  protected ClientKeyBlock encode(ClientContext context, boolean calledByCB) throws InsertException {
    ClientKeyBlock block;
    boolean shouldSend;
    synchronized(this) {
      if(finished) return null;
      if(sourceData == null) {
        Logger.error(this, "Source data is null on "+this+" but not finished!");
        return null;
      }
      block = innerEncode(context.random);
      shouldSend = (resultingKey == null);
      resultingKey = block.getClientKey();
    }
    if(logMINOR)
      Logger.minor(this, "Encoded "+resultingKey.getURI()+" for "+this+" shouldSend="+shouldSend+" dontSendEncoded="+dontSendEncoded);
    if(shouldSend && !dontSendEncoded)
      cb.onEncode(block.getClientKey(), this, context);
    return block;
  }
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) {
View Full Code Here

TOP

Related Classes of freenet.keys.ClientKeyBlock

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.