mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 12:49:55 +01:00
Replaced PacketWriter methods with a constant.
This commit is contained in:
@@ -32,6 +32,7 @@ import java.util.logging.Logger;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_IDS;
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_PACKET_PAYLOAD_LENGTH;
|
||||
|
||||
/**
|
||||
@@ -176,9 +177,8 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
|
||||
|
||||
public void run() {
|
||||
if (interrupted) return;
|
||||
int maxMessages = packetWriter.getMaxMessagesForAck(Long.MAX_VALUE);
|
||||
try {
|
||||
Ack a = db.generateAck(contactId, maxMessages);
|
||||
Ack a = db.generateAck(contactId, MAX_MESSAGE_IDS);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Generated ack: " + (a != null));
|
||||
if (a != null) writerTasks.add(new WriteAck(a));
|
||||
@@ -246,10 +246,9 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
|
||||
|
||||
public void run() {
|
||||
if (interrupted) return;
|
||||
int maxMessages = packetWriter.getMaxMessagesForOffer(
|
||||
Long.MAX_VALUE);
|
||||
try {
|
||||
Offer o = db.generateOffer(contactId, maxMessages, maxLatency);
|
||||
Offer o = db.generateOffer(contactId, MAX_MESSAGE_IDS,
|
||||
maxLatency);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Generated offer: " + (o != null));
|
||||
if (o != null) writerTasks.add(new WriteOffer(o));
|
||||
@@ -282,10 +281,8 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
|
||||
|
||||
public void run() {
|
||||
if (interrupted) return;
|
||||
int maxMessages = packetWriter.getMaxMessagesForRequest(
|
||||
Long.MAX_VALUE);
|
||||
try {
|
||||
Request r = db.generateRequest(contactId, maxMessages);
|
||||
Request r = db.generateRequest(contactId, MAX_MESSAGE_IDS);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Generated request: " + (r != null));
|
||||
if (r != null) writerTasks.add(new WriteRequest(r));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.briarproject.sync;
|
||||
|
||||
import org.briarproject.api.UniqueId;
|
||||
import org.briarproject.api.sync.Ack;
|
||||
import org.briarproject.api.sync.MessageId;
|
||||
import org.briarproject.api.sync.Offer;
|
||||
@@ -34,24 +33,6 @@ class PacketWriterImpl implements PacketWriter {
|
||||
payload = new ByteArrayOutputStream(MAX_PACKET_PAYLOAD_LENGTH);
|
||||
}
|
||||
|
||||
public int getMaxMessagesForAck(long capacity) {
|
||||
return getMaxMessagesForPacket(capacity);
|
||||
}
|
||||
|
||||
public int getMaxMessagesForRequest(long capacity) {
|
||||
return getMaxMessagesForPacket(capacity);
|
||||
}
|
||||
|
||||
public int getMaxMessagesForOffer(long capacity) {
|
||||
return getMaxMessagesForPacket(capacity);
|
||||
}
|
||||
|
||||
private int getMaxMessagesForPacket(long capacity) {
|
||||
int payload = (int) Math.min(capacity - PACKET_HEADER_LENGTH,
|
||||
MAX_PACKET_PAYLOAD_LENGTH);
|
||||
return payload / UniqueId.LENGTH;
|
||||
}
|
||||
|
||||
private void writePacket(byte packetType) throws IOException {
|
||||
header[1] = packetType;
|
||||
ByteUtils.writeUint16(payload.size(), header, 2);
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_MESSAGE_IDS;
|
||||
import static org.briarproject.api.sync.SyncConstants.MAX_PACKET_PAYLOAD_LENGTH;
|
||||
|
||||
/**
|
||||
@@ -117,9 +118,8 @@ class SimplexOutgoingSession implements SyncSession, EventListener {
|
||||
|
||||
public void run() {
|
||||
if (interrupted) return;
|
||||
int maxMessages = packetWriter.getMaxMessagesForAck(Long.MAX_VALUE);
|
||||
try {
|
||||
Ack a = db.generateAck(contactId, maxMessages);
|
||||
Ack a = db.generateAck(contactId, MAX_MESSAGE_IDS);
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Generated ack: " + (a != null));
|
||||
if (a == null) decrementOutstandingQueries();
|
||||
|
||||
Reference in New Issue
Block a user