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

View File

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

View File

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

View File

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