mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-21 15:19:53 +01:00
Offer IDs no longer need to be calculated or echoed in requests.
The initiator flag in the transport protocol makes this unnecessary by linking the two sides of a stream-mode connection, making it impossible for an attacker to replay the responder's side of a different connection.
This commit is contained in:
@@ -8,9 +8,6 @@ public interface Offer {
|
|||||||
/** The maximum number of message IDs per offer. */
|
/** The maximum number of message IDs per offer. */
|
||||||
static final int MAX_IDS_PER_OFFER = 29959;
|
static final int MAX_IDS_PER_OFFER = 29959;
|
||||||
|
|
||||||
/** Returns the offer's unique identifier. */
|
|
||||||
OfferId getId();
|
|
||||||
|
|
||||||
/** Returns the message IDs contained in the offer. */
|
/** Returns the message IDs contained in the offer. */
|
||||||
Collection<MessageId> getMessageIds();
|
Collection<MessageId> getMessageIds();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
package net.sf.briar.api.protocol;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import net.sf.briar.api.serial.Writer;
|
|
||||||
|
|
||||||
/** Type-safe wrapper for a byte array that uniquely identifies an offer. */
|
|
||||||
public class OfferId extends UniqueId {
|
|
||||||
|
|
||||||
public OfferId(byte[] id) {
|
|
||||||
super(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeTo(Writer w) throws IOException {
|
|
||||||
w.writeUserDefinedTag(Tags.OFFER_ID);
|
|
||||||
w.writeBytes(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if(o instanceof OfferId)
|
|
||||||
return Arrays.equals(id, ((OfferId) o).id);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,12 +5,6 @@ import java.util.BitSet;
|
|||||||
/** A packet requesting some or all of the messages from an offer. */
|
/** A packet requesting some or all of the messages from an offer. */
|
||||||
public interface Request {
|
public interface Request {
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the unique identifier of the offer to which this request
|
|
||||||
* responds.
|
|
||||||
*/
|
|
||||||
OfferId getOfferId();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a sequence of bits corresponding to the sequence of messages in
|
* Returns a sequence of bits corresponding to the sequence of messages in
|
||||||
* the offer, where the i^th bit is set if the i^th message should be sent.
|
* the offer, where the i^th bit is set if the i^th message should be sent.
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public interface Tags {
|
|||||||
static final int MESSAGE = 7;
|
static final int MESSAGE = 7;
|
||||||
static final int MESSAGE_ID = 8;
|
static final int MESSAGE_ID = 8;
|
||||||
static final int OFFER = 9;
|
static final int OFFER = 9;
|
||||||
static final int OFFER_ID = 10;
|
// FIXME: Renumber
|
||||||
static final int REQUEST = 11;
|
static final int REQUEST = 11;
|
||||||
static final int SUBSCRIPTION_UPDATE = 12;
|
static final int SUBSCRIPTION_UPDATE = 12;
|
||||||
static final int TRANSPORT_PROPERTIES = 13;
|
static final int TRANSPORT_PROPERTIES = 13;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.sf.briar.api.protocol.writers;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
|
|
||||||
/** An interface for creating an offer packet. */
|
/** An interface for creating an offer packet. */
|
||||||
public interface OfferWriter {
|
public interface OfferWriter {
|
||||||
@@ -14,6 +13,6 @@ public interface OfferWriter {
|
|||||||
*/
|
*/
|
||||||
boolean writeMessageId(MessageId m) throws IOException;
|
boolean writeMessageId(MessageId m) throws IOException;
|
||||||
|
|
||||||
/** Finishes writing the offer and returns its unique identifier. */
|
/** Finishes writing the offer. */
|
||||||
OfferId finish() throws IOException;
|
void finish() throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ package net.sf.briar.api.protocol.writers;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
|
|
||||||
/** An interface for creating a request packet. */
|
/** An interface for creating a request packet. */
|
||||||
public interface RequestWriter {
|
public interface RequestWriter {
|
||||||
|
|
||||||
/** Writes the contents of the request. */
|
/** Writes the contents of the request. */
|
||||||
void writeRequest(OfferId offerId, BitSet b, int length) throws IOException;
|
void writeRequest(BitSet b, int length) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -815,7 +815,7 @@ class ReadWriteLockDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> {
|
|||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
r.writeRequest(o.getId(), request, offered.size());
|
r.writeRequest(request, offered.size());
|
||||||
} finally {
|
} finally {
|
||||||
subscriptionLock.readLock().unlock();
|
subscriptionLock.readLock().unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ class SynchronizedDatabaseComponent<Txn> extends DatabaseComponentImpl<Txn> {
|
|||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
r.writeRequest(o.getId(), request, offered.size());
|
r.writeRequest(request, offered.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
|
|
||||||
interface OfferFactory {
|
interface OfferFactory {
|
||||||
|
|
||||||
Offer createOffer(OfferId id, Collection<MessageId> offered);
|
Offer createOffer(Collection<MessageId> offered);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
|
|
||||||
class OfferFactoryImpl implements OfferFactory {
|
class OfferFactoryImpl implements OfferFactory {
|
||||||
|
|
||||||
public Offer createOffer(OfferId id, Collection<MessageId> offered) {
|
public Offer createOffer(Collection<MessageId> offered) {
|
||||||
return new OfferImpl(id, offered);
|
return new OfferImpl(offered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
package net.sf.briar.protocol;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import net.sf.briar.api.FormatException;
|
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.Tags;
|
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
|
||||||
import net.sf.briar.api.serial.ObjectReader;
|
|
||||||
import net.sf.briar.api.serial.Reader;
|
|
||||||
|
|
||||||
class OfferIdReader implements ObjectReader<OfferId> {
|
|
||||||
|
|
||||||
public OfferId readObject(Reader r) throws IOException {
|
|
||||||
r.readUserDefinedTag(Tags.OFFER_ID);
|
|
||||||
byte[] b = r.readBytes(UniqueId.LENGTH);
|
|
||||||
if(b.length != UniqueId.LENGTH) throw new FormatException();
|
|
||||||
return new OfferId(b);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,22 +4,15 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
|
|
||||||
class OfferImpl implements Offer {
|
class OfferImpl implements Offer {
|
||||||
|
|
||||||
private final OfferId id;
|
|
||||||
private final Collection<MessageId> offered;
|
private final Collection<MessageId> offered;
|
||||||
|
|
||||||
OfferImpl(OfferId id, Collection<MessageId> offered) {
|
OfferImpl(Collection<MessageId> offered) {
|
||||||
this.id = id;
|
|
||||||
this.offered = offered;
|
this.offered = offered;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OfferId getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<MessageId> getMessageIds() {
|
public Collection<MessageId> getMessageIds() {
|
||||||
return offered;
|
return offered;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package net.sf.briar.protocol;
|
package net.sf.briar.protocol;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Tags;
|
||||||
import net.sf.briar.api.serial.Consumer;
|
import net.sf.briar.api.serial.Consumer;
|
||||||
@@ -17,36 +14,29 @@ import net.sf.briar.api.serial.Reader;
|
|||||||
|
|
||||||
class OfferReader implements ObjectReader<Offer> {
|
class OfferReader implements ObjectReader<Offer> {
|
||||||
|
|
||||||
private final MessageDigest messageDigest;
|
|
||||||
private final ObjectReader<MessageId> messageIdReader;
|
private final ObjectReader<MessageId> messageIdReader;
|
||||||
private final OfferFactory offerFactory;
|
private final OfferFactory offerFactory;
|
||||||
|
|
||||||
OfferReader(CryptoComponent crypto, ObjectReader<MessageId> messageIdReader,
|
OfferReader(ObjectReader<MessageId> messageIdReader,
|
||||||
OfferFactory offerFactory) {
|
OfferFactory offerFactory) {
|
||||||
messageDigest = crypto.getMessageDigest();
|
|
||||||
this.messageIdReader = messageIdReader;
|
this.messageIdReader = messageIdReader;
|
||||||
this.offerFactory = offerFactory;
|
this.offerFactory = offerFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Offer readObject(Reader r) throws IOException {
|
public Offer readObject(Reader r) throws IOException {
|
||||||
// Initialise the consumers
|
// Initialise the consumer
|
||||||
Consumer counting =
|
Consumer counting =
|
||||||
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
new CountingConsumer(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
DigestingConsumer digesting = new DigestingConsumer(messageDigest);
|
|
||||||
messageDigest.reset();
|
|
||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.addConsumer(digesting);
|
|
||||||
r.readUserDefinedTag(Tags.OFFER);
|
r.readUserDefinedTag(Tags.OFFER);
|
||||||
r.addObjectReader(Tags.MESSAGE_ID, messageIdReader);
|
r.addObjectReader(Tags.MESSAGE_ID, messageIdReader);
|
||||||
Collection<MessageId> messages = r.readList(MessageId.class);
|
Collection<MessageId> messages = r.readList(MessageId.class);
|
||||||
if(messages.size() > Offer.MAX_IDS_PER_OFFER)
|
if(messages.size() > Offer.MAX_IDS_PER_OFFER)
|
||||||
throw new FormatException();
|
throw new FormatException();
|
||||||
r.removeObjectReader(Tags.MESSAGE_ID);
|
r.removeObjectReader(Tags.MESSAGE_ID);
|
||||||
r.removeConsumer(digesting);
|
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Build and return the offer
|
// Build and return the offer
|
||||||
OfferId id = new OfferId(messageDigest.digest());
|
return offerFactory.createOffer(messages);
|
||||||
return offerFactory.createOffer(id, messages);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import net.sf.briar.api.protocol.Message;
|
|||||||
import net.sf.briar.api.protocol.MessageEncoder;
|
import net.sf.briar.api.protocol.MessageEncoder;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||||
@@ -82,21 +81,14 @@ public class ProtocolModule extends AbstractModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
ObjectReader<OfferId> getOfferIdReader() {
|
ObjectReader<Offer> getOfferReader(ObjectReader<MessageId> messageIdReader,
|
||||||
return new OfferIdReader();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
ObjectReader<Offer> getOfferReader(CryptoComponent crypto,
|
|
||||||
ObjectReader<MessageId> messageIdReader,
|
|
||||||
OfferFactory offerFactory) {
|
OfferFactory offerFactory) {
|
||||||
return new OfferReader(crypto, messageIdReader, offerFactory);
|
return new OfferReader(messageIdReader, offerFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
ObjectReader<Request> getRequestReader(ObjectReader<OfferId> offerIdReader,
|
ObjectReader<Request> getRequestReader(RequestFactory requestFactory) {
|
||||||
RequestFactory requestFactory) {
|
return new RequestReader(requestFactory);
|
||||||
return new RequestReader(offerIdReader, requestFactory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ package net.sf.briar.protocol;
|
|||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
|
|
||||||
interface RequestFactory {
|
interface RequestFactory {
|
||||||
|
|
||||||
Request createRequest(OfferId offerId, BitSet requested);
|
Request createRequest(BitSet requested);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ package net.sf.briar.protocol;
|
|||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
|
|
||||||
class RequestFactoryImpl implements RequestFactory {
|
class RequestFactoryImpl implements RequestFactory {
|
||||||
|
|
||||||
public Request createRequest(OfferId offerId, BitSet requested) {
|
public Request createRequest(BitSet requested) {
|
||||||
return new RequestImpl(offerId, requested);
|
return new RequestImpl(requested);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,23 +2,16 @@ package net.sf.briar.protocol;
|
|||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
|
|
||||||
class RequestImpl implements Request {
|
class RequestImpl implements Request {
|
||||||
|
|
||||||
private final OfferId offerId;
|
|
||||||
private final BitSet requested;
|
private final BitSet requested;
|
||||||
|
|
||||||
RequestImpl(OfferId offerId, BitSet requested) {
|
RequestImpl(BitSet requested) {
|
||||||
this.offerId = offerId;
|
|
||||||
this.requested = requested;
|
this.requested = requested;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OfferId getOfferId() {
|
|
||||||
return offerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BitSet getBitmap() {
|
public BitSet getBitmap() {
|
||||||
return requested;
|
return requested;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package net.sf.briar.protocol;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Tags;
|
||||||
@@ -13,12 +12,9 @@ import net.sf.briar.api.serial.Reader;
|
|||||||
|
|
||||||
class RequestReader implements ObjectReader<Request> {
|
class RequestReader implements ObjectReader<Request> {
|
||||||
|
|
||||||
private final ObjectReader<OfferId> offerIdReader;
|
|
||||||
private final RequestFactory requestFactory;
|
private final RequestFactory requestFactory;
|
||||||
|
|
||||||
RequestReader(ObjectReader<OfferId> offerIdReader,
|
RequestReader(RequestFactory requestFactory) {
|
||||||
RequestFactory requestFactory) {
|
|
||||||
this.offerIdReader = offerIdReader;
|
|
||||||
this.requestFactory = requestFactory;
|
this.requestFactory = requestFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,8 +25,6 @@ class RequestReader implements ObjectReader<Request> {
|
|||||||
// Read the data
|
// Read the data
|
||||||
r.addConsumer(counting);
|
r.addConsumer(counting);
|
||||||
r.readUserDefinedTag(Tags.REQUEST);
|
r.readUserDefinedTag(Tags.REQUEST);
|
||||||
r.addObjectReader(Tags.OFFER_ID, offerIdReader);
|
|
||||||
OfferId offerId = r.readUserDefined(Tags.OFFER_ID, OfferId.class);
|
|
||||||
byte[] bitmap = r.readBytes(ProtocolConstants.MAX_PACKET_LENGTH);
|
byte[] bitmap = r.readBytes(ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
r.removeConsumer(counting);
|
r.removeConsumer(counting);
|
||||||
// Convert the bitmap into a BitSet
|
// Convert the bitmap into a BitSet
|
||||||
@@ -41,6 +35,6 @@ class RequestReader implements ObjectReader<Request> {
|
|||||||
if((bitmap[i] & bit) != 0) b.set(i * 8 + j);
|
if((bitmap[i] & bit) != 0) b.set(i * 8 + j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return requestFactory.createRequest(offerId, b);
|
return requestFactory.createRequest(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,9 @@ package net.sf.briar.protocol.writers;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.security.DigestOutputStream;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Tags;
|
||||||
import net.sf.briar.api.protocol.writers.OfferWriter;
|
import net.sf.briar.api.protocol.writers.OfferWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
@@ -17,21 +14,17 @@ class OfferWriterImpl implements OfferWriter {
|
|||||||
|
|
||||||
private final OutputStream out;
|
private final OutputStream out;
|
||||||
private final Writer w;
|
private final Writer w;
|
||||||
private final MessageDigest messageDigest;
|
|
||||||
|
|
||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private int idsWritten = 0;
|
private int idsWritten = 0;
|
||||||
|
|
||||||
OfferWriterImpl(OutputStream out, WriterFactory writerFactory,
|
OfferWriterImpl(OutputStream out, WriterFactory writerFactory) {
|
||||||
MessageDigest messageDigest) {
|
this.out = out;
|
||||||
this.out = new DigestOutputStream(out, messageDigest);
|
|
||||||
w = writerFactory.createWriter(out);
|
w = writerFactory.createWriter(out);
|
||||||
this.messageDigest = messageDigest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean writeMessageId(MessageId m) throws IOException {
|
public boolean writeMessageId(MessageId m) throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
messageDigest.reset();
|
|
||||||
w.writeUserDefinedTag(Tags.OFFER);
|
w.writeUserDefinedTag(Tags.OFFER);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
started = true;
|
started = true;
|
||||||
@@ -42,9 +35,8 @@ class OfferWriterImpl implements OfferWriter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OfferId finish() throws IOException {
|
public void finish() throws IOException {
|
||||||
if(!started) {
|
if(!started) {
|
||||||
messageDigest.reset();
|
|
||||||
w.writeUserDefinedTag(Tags.OFFER);
|
w.writeUserDefinedTag(Tags.OFFER);
|
||||||
w.writeListStart();
|
w.writeListStart();
|
||||||
started = true;
|
started = true;
|
||||||
@@ -52,6 +44,5 @@ class OfferWriterImpl implements OfferWriter {
|
|||||||
w.writeListEnd();
|
w.writeListEnd();
|
||||||
out.flush();
|
out.flush();
|
||||||
started = false;
|
started = false;
|
||||||
return new OfferId(messageDigest.digest());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class ProtocolWriterFactoryImpl implements ProtocolWriterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public OfferWriter createOfferWriter(OutputStream out) {
|
public OfferWriter createOfferWriter(OutputStream out) {
|
||||||
return new OfferWriterImpl(out, writerFactory, messageDigest);
|
return new OfferWriterImpl(out, writerFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestWriter createRequestWriter(OutputStream out) {
|
public RequestWriter createRequestWriter(OutputStream out) {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Tags;
|
||||||
import net.sf.briar.api.protocol.writers.RequestWriter;
|
import net.sf.briar.api.protocol.writers.RequestWriter;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
@@ -20,11 +19,9 @@ class RequestWriterImpl implements RequestWriter {
|
|||||||
w = writerFactory.createWriter(out);
|
w = writerFactory.createWriter(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeRequest(OfferId offerId, BitSet b, int length)
|
public void writeRequest(BitSet b, int length)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
w.writeUserDefinedTag(Tags.REQUEST);
|
w.writeUserDefinedTag(Tags.REQUEST);
|
||||||
w.writeUserDefinedTag(Tags.OFFER_ID);
|
|
||||||
w.writeBytes(offerId.getBytes());
|
|
||||||
// If the number of bits isn't a multiple of 8, round up to a byte
|
// If the number of bits isn't a multiple of 8, round up to a byte
|
||||||
int bytes = length % 8 == 0 ? length / 8 : length / 8 + 1;
|
int bytes = length % 8 == 0 ? length / 8 : length / 8 + 1;
|
||||||
byte[] bitmap = new byte[bytes];
|
byte[] bitmap = new byte[bytes];
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import net.sf.briar.api.protocol.Message;
|
|||||||
import net.sf.briar.api.protocol.MessageEncoder;
|
import net.sf.briar.api.protocol.MessageEncoder;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.ProtocolReader;
|
import net.sf.briar.api.protocol.ProtocolReader;
|
||||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
@@ -79,7 +78,6 @@ public class FileReadWriteTest extends TestCase {
|
|||||||
private final Message message, message1, message2, message3;
|
private final Message message, message1, message2, message3;
|
||||||
private final String authorName = "Alice";
|
private final String authorName = "Alice";
|
||||||
private final String messageBody = "Hello world";
|
private final String messageBody = "Hello world";
|
||||||
private final OfferId offerId;
|
|
||||||
private final Map<String, Map<String, String>> transports;
|
private final Map<String, Map<String, String>> transports;
|
||||||
|
|
||||||
public FileReadWriteTest() throws Exception {
|
public FileReadWriteTest() throws Exception {
|
||||||
@@ -120,7 +118,6 @@ public class FileReadWriteTest extends TestCase {
|
|||||||
message3 = messageEncoder.encodeMessage(MessageId.NONE, group1,
|
message3 = messageEncoder.encodeMessage(MessageId.NONE, group1,
|
||||||
groupKeyPair.getPrivate(), author, authorKeyPair.getPrivate(),
|
groupKeyPair.getPrivate(), author, authorKeyPair.getPrivate(),
|
||||||
messageBody.getBytes("UTF-8"));
|
messageBody.getBytes("UTF-8"));
|
||||||
offerId = new OfferId(TestUtils.getRandomId());
|
|
||||||
transports = Collections.singletonMap("foo",
|
transports = Collections.singletonMap("foo",
|
||||||
Collections.singletonMap("bar", "baz"));
|
Collections.singletonMap("bar", "baz"));
|
||||||
}
|
}
|
||||||
@@ -160,7 +157,7 @@ public class FileReadWriteTest extends TestCase {
|
|||||||
BitSet requested = new BitSet(4);
|
BitSet requested = new BitSet(4);
|
||||||
requested.set(1);
|
requested.set(1);
|
||||||
requested.set(3);
|
requested.set(3);
|
||||||
r.writeRequest(offerId, requested, 4);
|
r.writeRequest(requested, 4);
|
||||||
|
|
||||||
SubscriptionWriter s =
|
SubscriptionWriter s =
|
||||||
protocolWriterFactory.createSubscriptionWriter(out);
|
protocolWriterFactory.createSubscriptionWriter(out);
|
||||||
@@ -229,7 +226,6 @@ public class FileReadWriteTest extends TestCase {
|
|||||||
// Read the request
|
// Read the request
|
||||||
assertTrue(protocolReader.hasRequest());
|
assertTrue(protocolReader.hasRequest());
|
||||||
Request req = protocolReader.readRequest();
|
Request req = protocolReader.readRequest();
|
||||||
assertEquals(offerId, req.getOfferId());
|
|
||||||
BitSet requested = req.getBitmap();
|
BitSet requested = req.getBitmap();
|
||||||
assertFalse(requested.get(0));
|
assertFalse(requested.get(0));
|
||||||
assertTrue(requested.get(1));
|
assertTrue(requested.get(1));
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import net.sf.briar.api.protocol.GroupId;
|
|||||||
import net.sf.briar.api.protocol.Message;
|
import net.sf.briar.api.protocol.Message;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
import net.sf.briar.api.protocol.SubscriptionUpdate;
|
||||||
import net.sf.briar.api.protocol.TransportUpdate;
|
import net.sf.briar.api.protocol.TransportUpdate;
|
||||||
import net.sf.briar.api.protocol.writers.AckWriter;
|
import net.sf.briar.api.protocol.writers.AckWriter;
|
||||||
@@ -50,7 +49,6 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
protected final ContactId contactId;
|
protected final ContactId contactId;
|
||||||
protected final GroupId groupId;
|
protected final GroupId groupId;
|
||||||
protected final MessageId messageId, parentId;
|
protected final MessageId messageId, parentId;
|
||||||
protected final OfferId offerId;
|
|
||||||
private final long timestamp;
|
private final long timestamp;
|
||||||
private final int size;
|
private final int size;
|
||||||
private final byte[] raw;
|
private final byte[] raw;
|
||||||
@@ -67,7 +65,6 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
groupId = new GroupId(TestUtils.getRandomId());
|
groupId = new GroupId(TestUtils.getRandomId());
|
||||||
messageId = new MessageId(TestUtils.getRandomId());
|
messageId = new MessageId(TestUtils.getRandomId());
|
||||||
parentId = new MessageId(TestUtils.getRandomId());
|
parentId = new MessageId(TestUtils.getRandomId());
|
||||||
offerId = new OfferId(TestUtils.getRandomId());
|
|
||||||
timestamp = System.currentTimeMillis();
|
timestamp = System.currentTimeMillis();
|
||||||
size = 1234;
|
size = 1234;
|
||||||
raw = new byte[size];
|
raw = new byte[size];
|
||||||
@@ -1036,9 +1033,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
will(returnValue(true)); // Visible - do not request message # 1
|
will(returnValue(true)); // Visible - do not request message # 1
|
||||||
oneOf(database).setStatusSeenIfVisible(txn, contactId, messageId2);
|
oneOf(database).setStatusSeenIfVisible(txn, contactId, messageId2);
|
||||||
will(returnValue(false)); // Not visible - request message # 2
|
will(returnValue(false)); // Not visible - request message # 2
|
||||||
oneOf(offer).getId();
|
oneOf(requestWriter).writeRequest(expectedRequest, 3);
|
||||||
will(returnValue(offerId));
|
|
||||||
oneOf(requestWriter).writeRequest(offerId, expectedRequest, 3);
|
|
||||||
}});
|
}});
|
||||||
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
DatabaseComponent db = createDatabaseComponent(database, cleaner);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import net.sf.briar.api.protocol.Message;
|
|||||||
import net.sf.briar.api.protocol.MessageEncoder;
|
import net.sf.briar.api.protocol.MessageEncoder;
|
||||||
import net.sf.briar.api.protocol.MessageId;
|
import net.sf.briar.api.protocol.MessageId;
|
||||||
import net.sf.briar.api.protocol.Offer;
|
import net.sf.briar.api.protocol.Offer;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.ProtocolReader;
|
import net.sf.briar.api.protocol.ProtocolReader;
|
||||||
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
import net.sf.briar.api.protocol.ProtocolReaderFactory;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
@@ -47,7 +46,6 @@ public class ProtocolReadWriteTest extends TestCase {
|
|||||||
private final Group group;
|
private final Group group;
|
||||||
private final Message message;
|
private final Message message;
|
||||||
private final String messageBody = "Hello world";
|
private final String messageBody = "Hello world";
|
||||||
private final OfferId offerId;
|
|
||||||
private final BitSet bitSet;
|
private final BitSet bitSet;
|
||||||
private final Map<Group, Long> subscriptions;
|
private final Map<Group, Long> subscriptions;
|
||||||
private final Map<String, Map<String, String>> transports;
|
private final Map<String, Map<String, String>> transports;
|
||||||
@@ -65,7 +63,6 @@ public class ProtocolReadWriteTest extends TestCase {
|
|||||||
MessageEncoder messageEncoder = i.getInstance(MessageEncoder.class);
|
MessageEncoder messageEncoder = i.getInstance(MessageEncoder.class);
|
||||||
message = messageEncoder.encodeMessage(MessageId.NONE, group,
|
message = messageEncoder.encodeMessage(MessageId.NONE, group,
|
||||||
messageBody.getBytes("UTF-8"));
|
messageBody.getBytes("UTF-8"));
|
||||||
offerId = new OfferId(TestUtils.getRandomId());
|
|
||||||
bitSet = new BitSet();
|
bitSet = new BitSet();
|
||||||
bitSet.set(3);
|
bitSet.set(3);
|
||||||
bitSet.set(7);
|
bitSet.set(7);
|
||||||
@@ -92,7 +89,7 @@ public class ProtocolReadWriteTest extends TestCase {
|
|||||||
o.finish();
|
o.finish();
|
||||||
|
|
||||||
RequestWriter r = writerFactory.createRequestWriter(out);
|
RequestWriter r = writerFactory.createRequestWriter(out);
|
||||||
r.writeRequest(offerId, bitSet, 10);
|
r.writeRequest(bitSet, 10);
|
||||||
|
|
||||||
SubscriptionWriter s = writerFactory.createSubscriptionWriter(out);
|
SubscriptionWriter s = writerFactory.createSubscriptionWriter(out);
|
||||||
s.writeSubscriptions(subscriptions, timestamp);
|
s.writeSubscriptions(subscriptions, timestamp);
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ import java.util.BitSet;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.api.FormatException;
|
import net.sf.briar.api.FormatException;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.ProtocolConstants;
|
import net.sf.briar.api.protocol.ProtocolConstants;
|
||||||
import net.sf.briar.api.protocol.Request;
|
import net.sf.briar.api.protocol.Request;
|
||||||
import net.sf.briar.api.protocol.Tags;
|
import net.sf.briar.api.protocol.Tags;
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
|
||||||
import net.sf.briar.api.serial.Reader;
|
import net.sf.briar.api.serial.Reader;
|
||||||
import net.sf.briar.api.serial.ReaderFactory;
|
import net.sf.briar.api.serial.ReaderFactory;
|
||||||
import net.sf.briar.api.serial.Writer;
|
import net.sf.briar.api.serial.Writer;
|
||||||
@@ -41,8 +39,7 @@ public class RequestReaderTest extends TestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
|
public void testFormatExceptionIfRequestIsTooLarge() throws Exception {
|
||||||
RequestFactory requestFactory = context.mock(RequestFactory.class);
|
RequestFactory requestFactory = context.mock(RequestFactory.class);
|
||||||
RequestReader requestReader =
|
RequestReader requestReader = new RequestReader(requestFactory);
|
||||||
new RequestReader(new OfferIdReader(), requestFactory);
|
|
||||||
|
|
||||||
byte[] b = createRequest(true);
|
byte[] b = createRequest(true);
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
@@ -60,12 +57,10 @@ public class RequestReaderTest extends TestCase {
|
|||||||
public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception {
|
public void testNoFormatExceptionIfRequestIsMaximumSize() throws Exception {
|
||||||
final RequestFactory requestFactory =
|
final RequestFactory requestFactory =
|
||||||
context.mock(RequestFactory.class);
|
context.mock(RequestFactory.class);
|
||||||
RequestReader requestReader =
|
RequestReader requestReader = new RequestReader(requestFactory);
|
||||||
new RequestReader(new OfferIdReader(), requestFactory);
|
|
||||||
final Request request = context.mock(Request.class);
|
final Request request = context.mock(Request.class);
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
oneOf(requestFactory).createRequest(with(any(OfferId.class)),
|
oneOf(requestFactory).createRequest(with(any(BitSet.class)));
|
||||||
with(any(BitSet.class)));
|
|
||||||
will(returnValue(request));
|
will(returnValue(request));
|
||||||
}});
|
}});
|
||||||
|
|
||||||
@@ -101,8 +96,8 @@ public class RequestReaderTest extends TestCase {
|
|||||||
// Deserialise the request
|
// Deserialise the request
|
||||||
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
ByteArrayInputStream in = new ByteArrayInputStream(b);
|
||||||
Reader reader = readerFactory.createReader(in);
|
Reader reader = readerFactory.createReader(in);
|
||||||
RequestReader requestReader = new RequestReader(new OfferIdReader(),
|
RequestReader requestReader =
|
||||||
new RequestFactoryImpl());
|
new RequestReader(new RequestFactoryImpl());
|
||||||
reader.addObjectReader(Tags.REQUEST, requestReader);
|
reader.addObjectReader(Tags.REQUEST, requestReader);
|
||||||
Request r = reader.readUserDefined(Tags.REQUEST, Request.class);
|
Request r = reader.readUserDefined(Tags.REQUEST, Request.class);
|
||||||
BitSet decoded = r.getBitmap();
|
BitSet decoded = r.getBitmap();
|
||||||
@@ -121,14 +116,9 @@ public class RequestReaderTest extends TestCase {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeUserDefinedTag(Tags.REQUEST);
|
w.writeUserDefinedTag(Tags.REQUEST);
|
||||||
w.writeUserDefinedTag(Tags.OFFER_ID);
|
// Allow one byte for the REQUEST tag, one byte for the BYTES tag,
|
||||||
w.writeBytes(new byte[UniqueId.LENGTH]);
|
|
||||||
// Allow one byte for the REQUEST tag, one byte for the OFFER_ID tag,
|
|
||||||
// one byte for the BYTES tag, one byte for the length as a uint7,
|
|
||||||
// UniqueID.LENGTH bytes for the offer ID, one byte for the BYTES tag,
|
|
||||||
// and five bytes for the length as an int32
|
// and five bytes for the length as an int32
|
||||||
int overhead = UniqueId.LENGTH + 10;
|
int size = ProtocolConstants.MAX_PACKET_LENGTH - 7;
|
||||||
int size = ProtocolConstants.MAX_PACKET_LENGTH - overhead;
|
|
||||||
if(tooBig) size++;
|
if(tooBig) size++;
|
||||||
w.writeBytes(new byte[size]);
|
w.writeBytes(new byte[size]);
|
||||||
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
|
assertEquals(tooBig, out.size() > ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
@@ -139,8 +129,6 @@ public class RequestReaderTest extends TestCase {
|
|||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Writer w = writerFactory.createWriter(out);
|
Writer w = writerFactory.createWriter(out);
|
||||||
w.writeUserDefinedTag(Tags.REQUEST);
|
w.writeUserDefinedTag(Tags.REQUEST);
|
||||||
w.writeUserDefinedTag(Tags.OFFER_ID);
|
|
||||||
w.writeBytes(new byte[UniqueId.LENGTH]);
|
|
||||||
w.writeBytes(bitmap);
|
w.writeBytes(bitmap);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,8 +108,7 @@ public class ConstantsTest extends TestCase {
|
|||||||
// Create an offer with the maximum number of message IDs
|
// Create an offer with the maximum number of message IDs
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream(
|
ByteArrayOutputStream out = new ByteArrayOutputStream(
|
||||||
ProtocolConstants.MAX_PACKET_LENGTH);
|
ProtocolConstants.MAX_PACKET_LENGTH);
|
||||||
OfferWriter o = new OfferWriterImpl(out, writerFactory,
|
OfferWriter o = new OfferWriterImpl(out, writerFactory);
|
||||||
crypto.getMessageDigest());
|
|
||||||
for(int i = 0; i < Offer.MAX_IDS_PER_OFFER; i++) {
|
for(int i = 0; i < Offer.MAX_IDS_PER_OFFER; i++) {
|
||||||
assertTrue(o.writeMessageId(new MessageId(
|
assertTrue(o.writeMessageId(new MessageId(
|
||||||
TestUtils.getRandomId())));
|
TestUtils.getRandomId())));
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import java.io.IOException;
|
|||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.api.protocol.OfferId;
|
|
||||||
import net.sf.briar.api.protocol.UniqueId;
|
|
||||||
import net.sf.briar.api.protocol.writers.RequestWriter;
|
import net.sf.briar.api.protocol.writers.RequestWriter;
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
import net.sf.briar.api.serial.WriterFactory;
|
||||||
import net.sf.briar.serial.SerialModule;
|
import net.sf.briar.serial.SerialModule;
|
||||||
@@ -20,13 +18,11 @@ import com.google.inject.Injector;
|
|||||||
public class RequestWriterImplTest extends TestCase {
|
public class RequestWriterImplTest extends TestCase {
|
||||||
|
|
||||||
private final WriterFactory writerFactory;
|
private final WriterFactory writerFactory;
|
||||||
private final OfferId offerId;
|
|
||||||
|
|
||||||
public RequestWriterImplTest() {
|
public RequestWriterImplTest() {
|
||||||
super();
|
super();
|
||||||
Injector i = Guice.createInjector(new SerialModule());
|
Injector i = Guice.createInjector(new SerialModule());
|
||||||
writerFactory = i.getInstance(WriterFactory.class);
|
writerFactory = i.getInstance(WriterFactory.class);
|
||||||
offerId = new OfferId(new byte[UniqueId.LENGTH]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -45,14 +41,10 @@ public class RequestWriterImplTest extends TestCase {
|
|||||||
b.set(11);
|
b.set(11);
|
||||||
b.set(12);
|
b.set(12);
|
||||||
b.set(15);
|
b.set(15);
|
||||||
r.writeRequest(offerId, b, 16);
|
r.writeRequest(b, 16);
|
||||||
// Short user tag 11, short user tag 10, bytes with length 32 as a
|
// Short user tag 11, short bytes with length 2, 0xD959
|
||||||
// uint7, 32 zero bytes, short bytes with length 2, 0xD959
|
|
||||||
byte[] output = out.toByteArray();
|
byte[] output = out.toByteArray();
|
||||||
assertEquals("CB" + "CA" + "F6" + "20"
|
assertEquals("CB" + "92" + "D959", StringUtils.toHexString(output));
|
||||||
+ "00000000000000000000000000000000"
|
|
||||||
+ "00000000000000000000000000000000"
|
|
||||||
+ "92" + "D959", StringUtils.toHexString(output));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -70,13 +62,9 @@ public class RequestWriterImplTest extends TestCase {
|
|||||||
b.set(9);
|
b.set(9);
|
||||||
b.set(11);
|
b.set(11);
|
||||||
b.set(12);
|
b.set(12);
|
||||||
r.writeRequest(offerId, b, 13);
|
r.writeRequest(b, 13);
|
||||||
// Short user tag 11, short user tag 10, bytes with length 32 as a
|
// Short user tag 11, short bytes with length 2, 0x59D8
|
||||||
// uint7, 32 zero bytes, short bytes with length 2, 0x59D8
|
|
||||||
byte[] output = out.toByteArray();
|
byte[] output = out.toByteArray();
|
||||||
assertEquals("CB" + "CA" + "F6" + "20"
|
assertEquals("CB" + "92" + "59D8", StringUtils.toHexString(output));
|
||||||
+ "00000000000000000000000000000000"
|
|
||||||
+ "00000000000000000000000000000000"
|
|
||||||
+ "92" + "59D8", StringUtils.toHexString(output));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user