Removing IV of received objects from requested objects list (I forgot that one)

This commit is contained in:
Christian Basler 2015-07-03 07:56:18 +02:00
parent 2c4d95af2f
commit 7f4c67f43e
4 changed files with 38 additions and 45 deletions

View File

@ -32,10 +32,7 @@ import ch.dissem.bitmessage.utils.UnixTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.TreeSet;
import static ch.dissem.bitmessage.entity.Plaintext.Status.*;
import static ch.dissem.bitmessage.entity.Plaintext.Type.BROADCAST;
@ -43,8 +40,7 @@ import static ch.dissem.bitmessage.entity.Plaintext.Type.MSG;
import static ch.dissem.bitmessage.utils.UnixTime.DAY;
/**
* Use this class if you want to create a Bitmessage client.
* <p>
* <p>Use this class if you want to create a Bitmessage client.</p>
* You'll need the Builder to create a BitmessageContext, and set the following properties:
* <ul>
* <li>addressRepo</li>
@ -54,9 +50,8 @@ import static ch.dissem.bitmessage.utils.UnixTime.DAY;
* <li>messageRepo</li>
* <li>streams</li>
* </ul>
* The default implementations in the different module builds can be used.
* <p>
* The port defaults to 8444 (the default Bitmessage port)
* <p>The default implementations in the different module builds can be used.</p>
* <p>The port defaults to 8444 (the default Bitmessage port)</p>
*/
public class BitmessageContext {
public static final int CURRENT_VERSION = 3;
@ -167,21 +162,17 @@ public class BitmessageContext {
}
private void send(long stream, ObjectPayload payload, long timeToLive) {
try {
long expires = UnixTime.now(+timeToLive);
LOG.info("Expires at " + expires);
ObjectMessage object = new ObjectMessage.Builder()
.stream(stream)
.expiresTime(expires)
.payload(payload)
.build();
Security.doProofOfWork(object, ctx.getProofOfWorkEngine(),
ctx.getNetworkNonceTrialsPerByte(), ctx.getNetworkExtraBytes());
ctx.getInventory().storeObject(object);
ctx.getNetworkHandler().offer(object.getInventoryVector());
} catch (IOException e) {
throw new RuntimeException(e);
}
long expires = UnixTime.now(+timeToLive);
LOG.info("Expires at " + expires);
ObjectMessage object = new ObjectMessage.Builder()
.stream(stream)
.expiresTime(expires)
.payload(payload)
.build();
Security.doProofOfWork(object, ctx.getProofOfWorkEngine(),
ctx.getNetworkNonceTrialsPerByte(), ctx.getNetworkExtraBytes());
ctx.getInventory().storeObject(object);
ctx.getNetworkHandler().offer(object.getInventoryVector());
}
public void startup(Listener listener) {

View File

@ -199,20 +199,16 @@ public class InternalContext {
}
public void requestPubkey(BitmessageAddress contact) {
try {
long expires = UnixTime.now(+2 * DAY);
LOG.info("Expires at " + expires);
ObjectMessage response = new ObjectMessage.Builder()
.stream(contact.getStream())
.expiresTime(expires)
.payload(new GetPubkey(contact))
.build();
Security.doProofOfWork(response, proofOfWorkEngine, networkNonceTrialsPerByte, networkExtraBytes);
inventory.storeObject(response);
networkHandler.offer(response.getInventoryVector());
} catch (IOException e) {
throw new RuntimeException(e);
}
long expires = UnixTime.now(+2 * DAY);
LOG.info("Expires at " + expires);
ObjectMessage response = new ObjectMessage.Builder()
.stream(contact.getStream())
.expiresTime(expires)
.payload(new GetPubkey(contact))
.build();
Security.doProofOfWork(response, proofOfWorkEngine, networkNonceTrialsPerByte, networkExtraBytes);
inventory.storeObject(response);
networkHandler.offer(response.getInventoryVector());
}
public long getClientNonce() {

View File

@ -88,7 +88,7 @@ public class ObjectMessage implements MessagePayload {
return stream;
}
public InventoryVector getInventoryVector() throws IOException {
public InventoryVector getInventoryVector() {
return new InventoryVector(Bytes.truncate(Security.doubleSha512(nonce, getPayloadBytesWithoutNonce()), 32));
}
@ -163,14 +163,18 @@ public class ObjectMessage implements MessagePayload {
Encode.varInt(stream, out);
}
public byte[] getPayloadBytesWithoutNonce() throws IOException {
if (payloadBytes == null) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeHeaderWithoutNonce(out);
payload.write(out);
payloadBytes = out.toByteArray();
public byte[] getPayloadBytesWithoutNonce() {
try {
if (payloadBytes == null) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
writeHeaderWithoutNonce(out);
payload.write(out);
payloadBytes = out.toByteArray();
}
return payloadBytes;
} catch (IOException e) {
throw new RuntimeException(e);
}
return payloadBytes;
}
public static final class Builder {

View File

@ -287,6 +287,8 @@ public class Connection implements Runnable {
} catch (IOException e) {
LOG.error("Stream " + objectMessage.getStream() + ", object type " + objectMessage.getType() + ": " + e.getMessage(), e);
DebugUtils.saveToFile(objectMessage);
} finally {
requestedObjects.remove(objectMessage.getInventoryVector());
}
break;
case ADDR: