Fixed problems after merging

This commit is contained in:
Christian Basler 2016-04-12 17:27:19 +02:00
parent 6f4f51aef3
commit c31ec7a9e5
5 changed files with 16 additions and 16 deletions

View File

@ -165,8 +165,8 @@ class DefaultMessageListener implements NetworkHandler.MessageListener {
listener.receive(msg);
updatePubkey(msg.getFrom(), msg.getFrom().getPubkey());
if (msg.getType() == Type.MSG && identity.has(Pubkey.Feature.DOES_ACK)) {
ObjectMessage ack = plaintext.getAckMessage();
if (msg.getType() == Plaintext.Type.MSG && msg.getTo().has(Pubkey.Feature.DOES_ACK)) {
ObjectMessage ack = msg.getAckMessage();
if (ack != null) {
ctx.getInventory().storeObject(ack);
ctx.getNetworkHandler().offer(ack.getInventoryVector());

View File

@ -16,14 +16,10 @@
package ch.dissem.bitmessage;
import ch.dissem.bitmessage.entity.BitmessageAddress;
import ch.dissem.bitmessage.entity.Encrypted;
import ch.dissem.bitmessage.entity.ObjectMessage;
import ch.dissem.bitmessage.entity.payload.*;
import ch.dissem.bitmessage.exception.ApplicationException;
import ch.dissem.bitmessage.entity.*;
import ch.dissem.bitmessage.entity.payload.*;
import ch.dissem.bitmessage.entity.valueobject.Label;
import ch.dissem.bitmessage.exception.ApplicationException;
import ch.dissem.bitmessage.ports.*;
import ch.dissem.bitmessage.utils.Singleton;
import ch.dissem.bitmessage.utils.TTL;
@ -36,7 +32,6 @@ import java.util.Arrays;
import java.util.TreeSet;
import static ch.dissem.bitmessage.entity.Plaintext.Status.SENT;
import static ch.dissem.bitmessage.utils.UnixTime.DAY;
/**
* The internal context should normally only be used for port implementations. If you need it in your client
@ -182,11 +177,11 @@ public class InternalContext {
if (payload instanceof Msg && recipient.has(Pubkey.Feature.DOES_ACK)) {
ObjectMessage ackMessage = ((Msg) payload).getPlaintext().getAckMessage();
messageCallback.proofOfWorkStarted(payload);
security.doProofOfWork(ackMessage, networkNonceTrialsPerByte, networkExtraBytes, new ProofOfWorkEngine.Callback() {
cryptography.doProofOfWork(ackMessage, NETWORK_NONCE_TRIALS_PER_BYTE, NETWORK_EXTRA_BYTES, new ProofOfWorkEngine.Callback() {
@Override
public void onNonceCalculated(byte[] nonce) {
public void onNonceCalculated(byte[] initialHash, byte[] nonce) {
object.encrypt(recipient.getPubkey());
proofOfWorkService.doProofOfWork(to, object);
proofOfWorkService.doProofOfWork(recipient, object);
}
});
} else {
@ -318,7 +313,7 @@ public class InternalContext {
}
@Override
public void onNonceCalculated(byte[] nonce) {
public void onNonceCalculated(byte[] initialHash, byte[] nonce) {
object.setNonce(nonce);
messageCallback.proofOfWorkCompleted(payload);
if (payload instanceof PlaintextHolder) {

View File

@ -175,7 +175,7 @@ public class Plaintext implements Streamable {
if (type == Type.MSG) {
if (to.has(Pubkey.Feature.DOES_ACK)) {
ByteArrayOutputStream ack = new ByteArrayOutputStream();
ackMessage.write(ack);
getAckMessage().write(ack);
byte[] data = ack.toByteArray();
Encode.varInt(data.length, out);
out.write(data);

View File

@ -24,9 +24,7 @@ import ch.dissem.bitmessage.entity.payload.Broadcast;
import ch.dissem.bitmessage.entity.payload.GetPubkey;
import ch.dissem.bitmessage.entity.payload.Msg;
import ch.dissem.bitmessage.factory.Factory;
import ch.dissem.bitmessage.ports.AddressRepository;
import ch.dissem.bitmessage.ports.Labeler;
import ch.dissem.bitmessage.ports.MessageRepository;
import ch.dissem.bitmessage.ports.*;
import ch.dissem.bitmessage.utils.Singleton;
import ch.dissem.bitmessage.utils.TestBase;
import ch.dissem.bitmessage.utils.TestUtils;
@ -51,6 +49,10 @@ public class DefaultMessageListenerTest extends TestBase {
private AddressRepository addressRepo;
@Mock
private MessageRepository messageRepo;
@Mock
private Inventory inventory;
@Mock
private NetworkHandler networkHandler;
private InternalContext ctx;
private DefaultMessageListener listener;
@ -62,6 +64,8 @@ public class DefaultMessageListenerTest extends TestBase {
Singleton.initialize(new BouncyCryptography());
when(ctx.getAddressRepository()).thenReturn(addressRepo);
when(ctx.getMessageRepository()).thenReturn(messageRepo);
when(ctx.getInventory()).thenReturn(inventory);
when(ctx.getNetworkHandler()).thenReturn(networkHandler);
listener = new DefaultMessageListener(ctx, mock(Labeler.class), mock(BitmessageContext.Listener.class));
}
@ -104,6 +108,7 @@ public class DefaultMessageListenerTest extends TestBase {
public void ensureIncomingMessageIsSaved() throws Exception {
BitmessageAddress identity = TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8");
BitmessageAddress contact = new BitmessageAddress(identity.getAddress());
contact.setPubkey(identity.getPubkey());
when(addressRepo.getIdentities()).thenReturn(Collections.singletonList(identity));