Removing IV of received objects from requested objects list (I forgot that one)
This commit is contained in:
parent
2c4d95af2f
commit
7f4c67f43e
@ -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,21 +162,17 @@ 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()
|
.stream(stream)
|
||||||
.stream(stream)
|
.expiresTime(expires)
|
||||||
.expiresTime(expires)
|
.payload(payload)
|
||||||
.payload(payload)
|
.build();
|
||||||
.build();
|
Security.doProofOfWork(object, ctx.getProofOfWorkEngine(),
|
||||||
Security.doProofOfWork(object, ctx.getProofOfWorkEngine(),
|
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) {
|
||||||
|
@ -199,20 +199,16 @@ 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()
|
.stream(contact.getStream())
|
||||||
.stream(contact.getStream())
|
.expiresTime(expires)
|
||||||
.expiresTime(expires)
|
.payload(new GetPubkey(contact))
|
||||||
.payload(new GetPubkey(contact))
|
.build();
|
||||||
.build();
|
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() {
|
||||||
|
@ -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,14 +163,18 @@ public class ObjectMessage implements MessagePayload {
|
|||||||
Encode.varInt(stream, out);
|
Encode.varInt(stream, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getPayloadBytesWithoutNonce() throws IOException {
|
public byte[] getPayloadBytesWithoutNonce() {
|
||||||
if (payloadBytes == null) {
|
try {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
if (payloadBytes == null) {
|
||||||
writeHeaderWithoutNonce(out);
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
payload.write(out);
|
writeHeaderWithoutNonce(out);
|
||||||
payloadBytes = out.toByteArray();
|
payload.write(out);
|
||||||
|
payloadBytes = out.toByteArray();
|
||||||
|
}
|
||||||
|
return payloadBytes;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return payloadBytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user