Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.MetaChunk


    KeyPair protectionKeysOld = EncryptionUtil.generateRSAKeyPair();
    KeyPair protectionKeysNew = EncryptionUtil.generateRSAKeyPair();

    // generate a fake meta file
    List<MetaChunk> metaChunks1 = new ArrayList<MetaChunk>();
    metaChunks1.add(new MetaChunk(NetworkTestUtil.randomString(), NetworkTestUtil.randomString()
        .getBytes(), 0));
    metaChunks1.add(new MetaChunk(NetworkTestUtil.randomString(), NetworkTestUtil.randomString()
        .getBytes(), 1));
    List<MetaChunk> metaChunks2 = new ArrayList<MetaChunk>();
    metaChunks2.add(new MetaChunk(NetworkTestUtil.randomString(), NetworkTestUtil.randomString()
        .getBytes(), 2));
    List<FileVersion> fileVersions = new ArrayList<FileVersion>();
    fileVersions.add(new FileVersion(0, 123, System.currentTimeMillis(), metaChunks1));
    fileVersions.add(new FileVersion(1, 123, System.currentTimeMillis(), metaChunks2));
    MetaFileSmall metaFileSmall = new MetaFileSmall(metaFileEncryptionKeys.getPublic(), fileVersions,
View Full Code Here


        parameters.setHashFlag(true);
        // put the encrypted chunk into the network
        put(parameters);

        // store the hash in the index of the meta file
        context.getMetaChunks().add(new MetaChunk(chunkId, parameters.getHash(), index));
      } catch (IOException | DataLengthException | InvalidKeyException | IllegalStateException
          | InvalidCipherTextException | IllegalBlockSizeException | BadPaddingException
          | PutFailedException e) {
        logger.error("Could not encrypt and put the chunk.", e);
        throw new ProcessExecutionException("Could not encrypt and put the chunk.", e);
View Full Code Here

      receiverPublicKey = keyManager.getPublicKey(context.getUserName());
    } catch (GetFailedException e) {
      throw new ProcessExecutionException("Cannot get public key of user " + context.getUserName());
    }

    MetaChunk metaChunk = context.getMetaChunk();
    RequestChunkMessage request = new RequestChunkMessage(context.getSelectedPeer(), context.getTask()
        .getFileKey(), metaChunk.getIndex(), config.getChunkSize(), metaChunk.getChunkHash());
    try {
      logger.debug("Requesting chunk {} from peer {}", metaChunk.getIndex(), context.getSelectedPeer());
      sendDirect(request, receiverPublicKey);
      responseLatch.await(H2HConstants.DIRECT_DOWNLOAD_AWAIT_MS, TimeUnit.MILLISECONDS);
    } catch (SendFailedException e) {
      logger.error("Cannot send message to {}", context.getSelectedPeer(), e);
      rerunProcess();
View Full Code Here

    }
  }

  @Override
  public void handleResponseMessage(ResponseMessage responseMessage) {
    MetaChunk metaChunk = context.getMetaChunk();

    // check the response
    if (responseMessage.getContent() == null) {
      logger.error("Peer {} did not send the chunk {}", context.getSelectedPeer(), metaChunk.getIndex());
      rerunProcess();
      return;
    }

    Chunk chunk = (Chunk) responseMessage.getContent();

    // verify the md5 hash
    byte[] respondedHash = EncryptionUtil.generateMD5Hash(chunk.getData());
    if (H2HEncryptionUtil.compareMD5(respondedHash, metaChunk.getChunkHash())) {
      logger.debug("Peer {} sent a valid content for chunk {}. MD5 verified.",
          context.getSelectedPeer(), metaChunk.getIndex());
    } else {
      logger.error("Peer {} sent an invalid content for chunk {}.", context.getSelectedPeer(),
          metaChunk.getIndex());
      rerunProcess();
      return;
    }

    // hash is ok, write it to the file
View Full Code Here

      } catch (IOException e) {
        throw new ProcessExecutionException("Cannot read the large file", e);
      }

      byte[] md5Hash = EncryptionUtil.generateMD5Hash(chunk.getData());
      context.getMetaChunks().add(new MetaChunk(chunkId, md5Hash, i));
    }
  }
View Full Code Here

TOP

Related Classes of org.hive2hive.core.model.MetaChunk

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.