Skip to content
Snippets Groups Projects
Commit 47541e5a authored by bontric's avatar bontric
Browse files

add contact Id to TAKE request

parent 690e3d17
No related branches found
No related tags found
No related merge requests found
......@@ -4,11 +4,21 @@ import org.briarproject.bramble.api.FormatException;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.data.BdfList;
import javax.annotation.Nullable;
public class MailboxRequestTake extends MailboxRequest {
private byte[] encryptedSyncStream;
private final ContactId contactId;
private final byte[] encryptedSyncStream;
public MailboxRequestTake(byte[] encryptedSyncStream) {
super(TYPE.TAKE);
this.contactId = null;
this.encryptedSyncStream = encryptedSyncStream;
}
public MailboxRequestTake(ContactId contactId, byte[] encryptedSyncStream) {
super(TYPE.TAKE);
this.contactId = contactId;
this.encryptedSyncStream = encryptedSyncStream;
}
......@@ -16,14 +26,26 @@ public class MailboxRequestTake extends MailboxRequest {
super(TYPE.TAKE, msg.getLong(1));
BdfList body = msg.getList(2);
if(body.size() != 1)
if (body.size() != 2)
throw new FormatException();
this.encryptedSyncStream = body.getRaw(0);
Long cId = body.getOptionalLong(0);
if (cId != null) {
if (cId > Integer.MAX_VALUE || cId < Integer.MIN_VALUE)
throw new FormatException();
contactId = new ContactId(cId.intValue());
} else
contactId = null;
encryptedSyncStream = body.getRaw(1);
}
@Override
protected BdfList getRequestBody() {
return BdfList.of(encryptedSyncStream);
if (contactId == null)
return BdfList.of(null, encryptedSyncStream);
return BdfList.of(contactId.getInt(), encryptedSyncStream);
}
@Override
......@@ -35,5 +57,12 @@ public class MailboxRequestTake extends MailboxRequest {
return encryptedSyncStream;
}
@Nullable
public ContactId getContactId() {
return contactId;
}
public boolean hasContactId() {
return contactId != null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment