@Override
protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
File file = context.getFile();
Chunk chunk;
try {
chunk = FileChunkUtil.getChunk(file, config.getChunkSize(), index, chunkId);
} catch (IOException e) {
logger.error("File {}: Could not read the file.", file.getAbsolutePath());
throw new ProcessExecutionException("File " + file.getAbsolutePath()
+ ": Could not read the file", e);
}
if (chunk != null) {
try {
// encrypt the chunk prior to put such that nobody can read it
HybridEncryptedContent encryptedContent = H2HEncryptionUtil.encryptHybrid(chunk, context
.consumeChunkKeys().getPublic());
logger.debug("Uploading chunk {} of file {}.", chunk.getOrder(), file.getName());
Parameters parameters = new Parameters().setLocationKey(chunk.getId())
.setContentKey(H2HConstants.FILE_CHUNK).setData(encryptedContent)
.setProtectionKeys(context.consumeProtectionKeys()).setTTL(chunk.getTimeToLive());
// data manager has to produce the hash, which gets used for signing
parameters.setHashFlag(true);
// put the encrypted chunk into the network
put(parameters);