Whitespace-only code formatting changes.

This commit is contained in:
akwizgran
2015-11-30 09:38:25 +00:00
parent 1950c13ffb
commit 027ae8340f
202 changed files with 2993 additions and 2993 deletions

View File

@@ -47,7 +47,7 @@ class AuthorFactoryImpl implements AuthorFactory {
w.writeString(name);
w.writeRaw(publicKey);
w.writeListEnd();
} catch(IOException e) {
} catch (IOException e) {
// Shouldn't happen with ByteArrayOutputStream
throw new RuntimeException();
}

View File

@@ -28,7 +28,7 @@ class AuthorReader implements ObjectReader<Author> {
// Read and digest the data
r.readListStart();
String name = r.readString(MAX_AUTHOR_NAME_LENGTH);
if(name.length() == 0) throw new FormatException();
if (name.length() == 0) throw new FormatException();
byte[] publicKey = r.readRaw(MAX_PUBLIC_KEY_LENGTH);
r.readListEnd();
// Reset the reader

View File

@@ -24,11 +24,11 @@ class CountingConsumer implements Consumer {
public void write(byte b) throws IOException {
count++;
if(count > limit) throw new FormatException();
if (count > limit) throw new FormatException();
}
public void write(byte[] b, int off, int len) throws IOException {
count += len;
if(count > limit) throw new FormatException();
if (count > limit) throw new FormatException();
}
}

View File

@@ -114,13 +114,13 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
nextRetxQuery = now + RETX_QUERY_INTERVAL;
// Write packets until interrupted
try {
while(!interrupted) {
while (!interrupted) {
// Work out how long we should wait for a packet
now = clock.currentTimeMillis();
long wait = Math.min(nextKeepalive, nextRetxQuery) - now;
if(wait < 0) wait = 0;
if (wait < 0) wait = 0;
// Flush any unflushed data if we're going to wait
if(wait > 0 && dataToFlush && writerTasks.isEmpty()) {
if (wait > 0 && dataToFlush && writerTasks.isEmpty()) {
packetWriter.flush();
dataToFlush = false;
nextKeepalive = now + maxIdleTime;
@@ -128,9 +128,9 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
// Wait for a packet
ThrowingRunnable<IOException> task = writerTasks.poll(wait,
MILLISECONDS);
if(task == null) {
if (task == null) {
now = clock.currentTimeMillis();
if(now >= nextRetxQuery) {
if (now >= nextRetxQuery) {
// Check for retransmittable packets
dbExecutor.execute(new GenerateTransportUpdates());
dbExecutor.execute(new GenerateSubscriptionUpdate());
@@ -139,21 +139,21 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
dbExecutor.execute(new GenerateOffer());
nextRetxQuery = now + RETX_QUERY_INTERVAL;
}
if(now >= nextKeepalive) {
if (now >= nextKeepalive) {
// Flush the stream to keep it alive
packetWriter.flush();
dataToFlush = false;
nextKeepalive = now + maxIdleTime;
}
} else if(task == CLOSE) {
} else if (task == CLOSE) {
break;
} else {
task.run();
dataToFlush = true;
}
}
if(dataToFlush) packetWriter.flush();
} catch(InterruptedException e) {
if (dataToFlush) packetWriter.flush();
} catch (InterruptedException e) {
LOG.info("Interrupted while waiting for a packet to write");
Thread.currentThread().interrupt();
}
@@ -168,53 +168,53 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void eventOccurred(Event e) {
if(e instanceof ContactRemovedEvent) {
if (e instanceof ContactRemovedEvent) {
ContactRemovedEvent c = (ContactRemovedEvent) e;
if(c.getContactId().equals(contactId)) interrupt();
} else if(e instanceof MessageAddedEvent) {
if (c.getContactId().equals(contactId)) interrupt();
} else if (e instanceof MessageAddedEvent) {
dbExecutor.execute(new GenerateOffer());
} else if(e instanceof MessageExpiredEvent) {
} else if (e instanceof MessageExpiredEvent) {
dbExecutor.execute(new GenerateRetentionUpdate());
} else if(e instanceof LocalSubscriptionsUpdatedEvent) {
} else if (e instanceof LocalSubscriptionsUpdatedEvent) {
LocalSubscriptionsUpdatedEvent l =
(LocalSubscriptionsUpdatedEvent) e;
if(l.getAffectedContacts().contains(contactId)) {
if (l.getAffectedContacts().contains(contactId)) {
dbExecutor.execute(new GenerateSubscriptionUpdate());
dbExecutor.execute(new GenerateOffer());
}
} else if(e instanceof LocalTransportsUpdatedEvent) {
} else if (e instanceof LocalTransportsUpdatedEvent) {
dbExecutor.execute(new GenerateTransportUpdates());
} else if(e instanceof MessageRequestedEvent) {
if(((MessageRequestedEvent) e).getContactId().equals(contactId))
} else if (e instanceof MessageRequestedEvent) {
if (((MessageRequestedEvent) e).getContactId().equals(contactId))
dbExecutor.execute(new GenerateBatch());
} else if(e instanceof MessageToAckEvent) {
if(((MessageToAckEvent) e).getContactId().equals(contactId))
} else if (e instanceof MessageToAckEvent) {
if (((MessageToAckEvent) e).getContactId().equals(contactId))
dbExecutor.execute(new GenerateAck());
} else if(e instanceof MessageToRequestEvent) {
if(((MessageToRequestEvent) e).getContactId().equals(contactId))
} else if (e instanceof MessageToRequestEvent) {
if (((MessageToRequestEvent) e).getContactId().equals(contactId))
dbExecutor.execute(new GenerateRequest());
} else if(e instanceof RemoteRetentionTimeUpdatedEvent) {
} else if (e instanceof RemoteRetentionTimeUpdatedEvent) {
RemoteRetentionTimeUpdatedEvent r =
(RemoteRetentionTimeUpdatedEvent) e;
if(r.getContactId().equals(contactId))
if (r.getContactId().equals(contactId))
dbExecutor.execute(new GenerateRetentionAck());
} else if(e instanceof RemoteSubscriptionsUpdatedEvent) {
} else if (e instanceof RemoteSubscriptionsUpdatedEvent) {
RemoteSubscriptionsUpdatedEvent r =
(RemoteSubscriptionsUpdatedEvent) e;
if(r.getContactId().equals(contactId)) {
if (r.getContactId().equals(contactId)) {
dbExecutor.execute(new GenerateSubscriptionAck());
dbExecutor.execute(new GenerateOffer());
}
} else if(e instanceof RemoteTransportsUpdatedEvent) {
} else if (e instanceof RemoteTransportsUpdatedEvent) {
RemoteTransportsUpdatedEvent r =
(RemoteTransportsUpdatedEvent) e;
if(r.getContactId().equals(contactId))
if (r.getContactId().equals(contactId))
dbExecutor.execute(new GenerateTransportAcks());
} else if(e instanceof ShutdownEvent) {
} else if (e instanceof ShutdownEvent) {
interrupt();
} else if(e instanceof TransportRemovedEvent) {
} else if (e instanceof TransportRemovedEvent) {
TransportRemovedEvent t = (TransportRemovedEvent) e;
if(t.getTransportId().equals(transportId)) interrupt();
if (t.getTransportId().equals(transportId)) interrupt();
}
}
@@ -222,15 +222,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateAck implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
int maxMessages = packetWriter.getMaxMessagesForAck(Long.MAX_VALUE);
try {
Ack a = db.generateAck(contactId, maxMessages);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated ack: " + (a != null));
if(a != null) writerTasks.add(new WriteAck(a));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (a != null) writerTasks.add(new WriteAck(a));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -246,7 +246,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeAck(ack);
LOG.info("Sent ack");
dbExecutor.execute(new GenerateAck());
@@ -257,15 +257,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateBatch implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
Collection<byte[]> b = db.generateRequestedBatch(contactId,
MAX_PAYLOAD_LENGTH, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated batch: " + (b != null));
if(b != null) writerTasks.add(new WriteBatch(b));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (b != null) writerTasks.add(new WriteBatch(b));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -281,8 +281,8 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
for(byte[] raw : batch) packetWriter.writeMessage(raw);
if (interrupted) return;
for (byte[] raw : batch) packetWriter.writeMessage(raw);
LOG.info("Sent batch");
dbExecutor.execute(new GenerateBatch());
}
@@ -292,16 +292,16 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateOffer implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
int maxMessages = packetWriter.getMaxMessagesForOffer(
Long.MAX_VALUE);
try {
Offer o = db.generateOffer(contactId, maxMessages, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated offer: " + (o != null));
if(o != null) writerTasks.add(new WriteOffer(o));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (o != null) writerTasks.add(new WriteOffer(o));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -317,7 +317,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeOffer(offer);
LOG.info("Sent offer");
dbExecutor.execute(new GenerateOffer());
@@ -328,16 +328,16 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateRequest implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
int maxMessages = packetWriter.getMaxMessagesForRequest(
Long.MAX_VALUE);
try {
Request r = db.generateRequest(contactId, maxMessages);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated request: " + (r != null));
if(r != null) writerTasks.add(new WriteRequest(r));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (r != null) writerTasks.add(new WriteRequest(r));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -353,7 +353,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeRequest(request);
LOG.info("Sent request");
dbExecutor.execute(new GenerateRequest());
@@ -364,14 +364,14 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateRetentionAck implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
RetentionAck a = db.generateRetentionAck(contactId);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated retention ack: " + (a != null));
if(a != null) writerTasks.add(new WriteRetentionAck(a));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (a != null) writerTasks.add(new WriteRetentionAck(a));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -388,7 +388,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeRetentionAck(ack);
LOG.info("Sent retention ack");
dbExecutor.execute(new GenerateRetentionAck());
@@ -399,15 +399,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateRetentionUpdate implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
RetentionUpdate u =
db.generateRetentionUpdate(contactId, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated retention update: " + (u != null));
if(u != null) writerTasks.add(new WriteRetentionUpdate(u));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (u != null) writerTasks.add(new WriteRetentionUpdate(u));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -424,7 +424,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeRetentionUpdate(update);
LOG.info("Sent retention update");
dbExecutor.execute(new GenerateRetentionUpdate());
@@ -435,14 +435,14 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateSubscriptionAck implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
SubscriptionAck a = db.generateSubscriptionAck(contactId);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated subscription ack: " + (a != null));
if(a != null) writerTasks.add(new WriteSubscriptionAck(a));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (a != null) writerTasks.add(new WriteSubscriptionAck(a));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -459,7 +459,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeSubscriptionAck(ack);
LOG.info("Sent subscription ack");
dbExecutor.execute(new GenerateSubscriptionAck());
@@ -470,15 +470,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateSubscriptionUpdate implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
SubscriptionUpdate u =
db.generateSubscriptionUpdate(contactId, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated subscription update: " + (u != null));
if(u != null) writerTasks.add(new WriteSubscriptionUpdate(u));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (u != null) writerTasks.add(new WriteSubscriptionUpdate(u));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -495,7 +495,7 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeSubscriptionUpdate(update);
LOG.info("Sent subscription update");
dbExecutor.execute(new GenerateSubscriptionUpdate());
@@ -506,15 +506,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateTransportAcks implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
Collection<TransportAck> acks =
db.generateTransportAcks(contactId);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated transport acks: " + (acks != null));
if(acks != null) writerTasks.add(new WriteTransportAcks(acks));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (acks != null) writerTasks.add(new WriteTransportAcks(acks));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -530,8 +530,8 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
for(TransportAck a : acks) packetWriter.writeTransportAck(a);
if (interrupted) return;
for (TransportAck a : acks) packetWriter.writeTransportAck(a);
LOG.info("Sent transport acks");
dbExecutor.execute(new GenerateTransportAcks());
}
@@ -541,15 +541,15 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateTransportUpdates implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
Collection<TransportUpdate> t =
db.generateTransportUpdates(contactId, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated transport updates: " + (t != null));
if(t != null) writerTasks.add(new WriteTransportUpdates(t));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
if (t != null) writerTasks.add(new WriteTransportUpdates(t));
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -566,8 +566,8 @@ class DuplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
for(TransportUpdate u : updates)
if (interrupted) return;
for (TransportUpdate u : updates)
packetWriter.writeTransportUpdate(u);
LOG.info("Sent transport updates");
dbExecutor.execute(new GenerateTransportUpdates());

View File

@@ -40,7 +40,7 @@ class GroupFactoryImpl implements GroupFactory {
w.writeString(name);
w.writeRaw(salt);
w.writeListEnd();
} catch(IOException e) {
} catch (IOException e) {
// Shouldn't happen with ByteArrayOutputStream
throw new RuntimeException();
}

View File

@@ -27,9 +27,9 @@ class GroupReader implements ObjectReader<Group> {
r.addConsumer(digesting);
r.readListStart();
String name = r.readString(MAX_GROUP_NAME_LENGTH);
if(name.length() == 0) throw new FormatException();
if (name.length() == 0) throw new FormatException();
byte[] salt = r.readRaw(GROUP_SALT_LENGTH);
if(salt.length != GROUP_SALT_LENGTH) throw new FormatException();
if (salt.length != GROUP_SALT_LENGTH) throw new FormatException();
r.readListEnd();
r.removeConsumer(digesting);
// Build and return the group

View File

@@ -70,35 +70,35 @@ class IncomingSession implements MessagingSession, EventListener {
eventBus.addListener(this);
try {
// Read packets until interrupted or EOF
while(!interrupted && !packetReader.eof()) {
if(packetReader.hasAck()) {
while (!interrupted && !packetReader.eof()) {
if (packetReader.hasAck()) {
Ack a = packetReader.readAck();
dbExecutor.execute(new ReceiveAck(a));
} else if(packetReader.hasMessage()) {
} else if (packetReader.hasMessage()) {
UnverifiedMessage m = packetReader.readMessage();
cryptoExecutor.execute(new VerifyMessage(m));
} else if(packetReader.hasOffer()) {
} else if (packetReader.hasOffer()) {
Offer o = packetReader.readOffer();
dbExecutor.execute(new ReceiveOffer(o));
} else if(packetReader.hasRequest()) {
} else if (packetReader.hasRequest()) {
Request r = packetReader.readRequest();
dbExecutor.execute(new ReceiveRequest(r));
} else if(packetReader.hasRetentionAck()) {
} else if (packetReader.hasRetentionAck()) {
RetentionAck a = packetReader.readRetentionAck();
dbExecutor.execute(new ReceiveRetentionAck(a));
} else if(packetReader.hasRetentionUpdate()) {
} else if (packetReader.hasRetentionUpdate()) {
RetentionUpdate u = packetReader.readRetentionUpdate();
dbExecutor.execute(new ReceiveRetentionUpdate(u));
} else if(packetReader.hasSubscriptionAck()) {
} else if (packetReader.hasSubscriptionAck()) {
SubscriptionAck a = packetReader.readSubscriptionAck();
dbExecutor.execute(new ReceiveSubscriptionAck(a));
} else if(packetReader.hasSubscriptionUpdate()) {
} else if (packetReader.hasSubscriptionUpdate()) {
SubscriptionUpdate u = packetReader.readSubscriptionUpdate();
dbExecutor.execute(new ReceiveSubscriptionUpdate(u));
} else if(packetReader.hasTransportAck()) {
} else if (packetReader.hasTransportAck()) {
TransportAck a = packetReader.readTransportAck();
dbExecutor.execute(new ReceiveTransportAck(a));
} else if(packetReader.hasTransportUpdate()) {
} else if (packetReader.hasTransportUpdate()) {
TransportUpdate u = packetReader.readTransportUpdate();
dbExecutor.execute(new ReceiveTransportUpdate(u));
} else {
@@ -116,14 +116,14 @@ class IncomingSession implements MessagingSession, EventListener {
}
public void eventOccurred(Event e) {
if(e instanceof ContactRemovedEvent) {
if (e instanceof ContactRemovedEvent) {
ContactRemovedEvent c = (ContactRemovedEvent) e;
if(c.getContactId().equals(contactId)) interrupt();
} else if(e instanceof ShutdownEvent) {
if (c.getContactId().equals(contactId)) interrupt();
} else if (e instanceof ShutdownEvent) {
interrupt();
} else if(e instanceof TransportRemovedEvent) {
} else if (e instanceof TransportRemovedEvent) {
TransportRemovedEvent t = (TransportRemovedEvent) e;
if(t.getTransportId().equals(transportId)) interrupt();
if (t.getTransportId().equals(transportId)) interrupt();
}
}
@@ -138,8 +138,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveAck(contactId, ack);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -157,8 +157,8 @@ class IncomingSession implements MessagingSession, EventListener {
try {
Message m = messageVerifier.verifyMessage(message);
dbExecutor.execute(new ReceiveMessage(m));
} catch(GeneralSecurityException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (GeneralSecurityException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -175,8 +175,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveMessage(contactId, message);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -193,8 +193,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveOffer(contactId, offer);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -211,8 +211,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveRequest(contactId, request);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -229,8 +229,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveRetentionAck(contactId, ack);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -247,8 +247,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveRetentionUpdate(contactId, update);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -265,8 +265,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveSubscriptionAck(contactId, ack);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -283,8 +283,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveSubscriptionUpdate(contactId, update);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -301,8 +301,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveTransportAck(contactId, ack);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -319,8 +319,8 @@ class IncomingSession implements MessagingSession, EventListener {
public void run() {
try {
db.receiveTransportUpdate(contactId, update);
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}

View File

@@ -61,11 +61,11 @@ class MessageFactoryImpl implements MessageFactory {
PrivateKey privateKey, String contentType, long timestamp,
byte[] body) throws IOException, GeneralSecurityException {
// Validate the arguments
if((author == null) != (privateKey == null))
if ((author == null) != (privateKey == null))
throw new IllegalArgumentException();
if(StringUtils.toUtf8(contentType).length > MAX_CONTENT_TYPE_LENGTH)
if (StringUtils.toUtf8(contentType).length > MAX_CONTENT_TYPE_LENGTH)
throw new IllegalArgumentException();
if(body.length > MAX_BODY_LENGTH)
if (body.length > MAX_BODY_LENGTH)
throw new IllegalArgumentException();
// Serialise the message to a buffer
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -76,17 +76,17 @@ class MessageFactoryImpl implements MessageFactory {
Consumer digestingConsumer = new DigestingConsumer(messageDigest);
w.addConsumer(digestingConsumer);
Consumer signingConsumer = null;
if(privateKey != null) {
if (privateKey != null) {
signature.initSign(privateKey);
signingConsumer = new SigningConsumer(signature);
w.addConsumer(signingConsumer);
}
// Write the message
w.writeListStart();
if(parent == null) w.writeNull();
if (parent == null) w.writeNull();
else w.writeRaw(parent.getBytes());
writeGroup(w, group);
if(author == null) w.writeNull();
if (author == null) w.writeNull();
else writeAuthor(w, author);
w.writeString(contentType);
w.writeInteger(timestamp);
@@ -96,12 +96,12 @@ class MessageFactoryImpl implements MessageFactory {
w.writeRaw(body);
int bodyStart = (int) counting.getCount() - body.length;
// Sign the message with the author's private key, if there is one
if(privateKey == null) {
if (privateKey == null) {
w.writeNull();
} else {
w.removeConsumer(signingConsumer);
byte[] sig = signature.sign();
if(sig.length > MAX_SIGNATURE_LENGTH)
if (sig.length > MAX_SIGNATURE_LENGTH)
throw new IllegalArgumentException();
w.writeRaw(sig);
}

View File

@@ -21,9 +21,9 @@ class MessageImpl implements Message {
public MessageImpl(MessageId id, MessageId parent, Group group,
Author author, String contentType, long timestamp,
byte[] raw, int bodyStart, int bodyLength) {
if(bodyStart + bodyLength > raw.length)
if (bodyStart + bodyLength > raw.length)
throw new IllegalArgumentException();
if(bodyLength > MAX_BODY_LENGTH)
if (bodyLength > MAX_BODY_LENGTH)
throw new IllegalArgumentException();
this.id = id;
this.parent = parent;

View File

@@ -37,27 +37,27 @@ class MessageReader implements ObjectReader<UnverifiedMessage> {
r.readListStart();
// Read the parent's message ID, if there is one
MessageId parent = null;
if(r.hasNull()) {
if (r.hasNull()) {
r.readNull();
} else {
byte[] b = r.readRaw(UniqueId.LENGTH);
if(b.length < UniqueId.LENGTH) throw new FormatException();
if (b.length < UniqueId.LENGTH) throw new FormatException();
parent = new MessageId(b);
}
// Read the group
Group group = groupReader.readObject(r);
// Read the author, if there is one
Author author = null;
if(r.hasNull()) r.readNull();
if (r.hasNull()) r.readNull();
else author = authorReader.readObject(r);
// Read the content type
String contentType = r.readString(MAX_CONTENT_TYPE_LENGTH);
// Read the timestamp
long timestamp = r.readInteger();
if(timestamp < 0) throw new FormatException();
if (timestamp < 0) throw new FormatException();
// Read the salt
byte[] salt = r.readRaw(MESSAGE_SALT_LENGTH);
if(salt.length < MESSAGE_SALT_LENGTH) throw new FormatException();
if (salt.length < MESSAGE_SALT_LENGTH) throw new FormatException();
// Read the message body
byte[] body = r.readRaw(MAX_BODY_LENGTH);
// Record the offset of the body within the message
@@ -66,7 +66,7 @@ class MessageReader implements ObjectReader<UnverifiedMessage> {
int signedLength = (int) counting.getCount();
// Read the author's signature, if there is one
byte[] signature = null;
if(author == null) r.readNull();
if (author == null) r.readNull();
else signature = r.readRaw(MAX_SIGNATURE_LENGTH);
// Read the end of the message
r.readListEnd();

View File

@@ -42,7 +42,7 @@ class MessageVerifierImpl implements MessageVerifier {
MessageDigest messageDigest = crypto.getMessageDigest();
Signature signature = crypto.getSignature();
// Reject the message if it's too far in the future
if(m.getTimestamp() > clock.currentTimeMillis() + MAX_CLOCK_DIFFERENCE)
if (m.getTimestamp() > clock.currentTimeMillis() + MAX_CLOCK_DIFFERENCE)
throw new GeneralSecurityException();
// Hash the message to get the message ID
byte[] raw = m.getSerialised();
@@ -50,18 +50,18 @@ class MessageVerifierImpl implements MessageVerifier {
MessageId id = new MessageId(messageDigest.digest());
// Verify the author's signature, if there is one
Author author = m.getAuthor();
if(author != null) {
if (author != null) {
PublicKey k = keyParser.parsePublicKey(author.getPublicKey());
signature.initVerify(k);
signature.update(raw, 0, m.getSignedLength());
if(!signature.verify(m.getSignature()))
if (!signature.verify(m.getSignature()))
throw new GeneralSecurityException();
}
Message verified = new MessageImpl(id, m.getParent(), m.getGroup(),
author, m.getContentType(), m.getTimestamp(), raw,
m.getBodyStart(), m.getBodyLength());
long duration = System.currentTimeMillis() - now;
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Verifying message took " + duration + " ms");
return verified;
}

View File

@@ -77,32 +77,32 @@ class PacketReaderImpl implements PacketReader {
assert state == State.BUFFER_EMPTY;
// Read the header
int offset = 0;
while(offset < HEADER_LENGTH) {
while (offset < HEADER_LENGTH) {
int read = in.read(header, offset, HEADER_LENGTH - offset);
if(read == -1) {
if(offset > 0) throw new FormatException();
if (read == -1) {
if (offset > 0) throw new FormatException();
state = State.EOF;
return;
}
offset += read;
}
// Check the protocol version
if(header[0] != PROTOCOL_VERSION) throw new FormatException();
if (header[0] != PROTOCOL_VERSION) throw new FormatException();
// Read the payload length
payloadLength = ByteUtils.readUint16(header, 2);
if(payloadLength > MAX_PAYLOAD_LENGTH) throw new FormatException();
if (payloadLength > MAX_PAYLOAD_LENGTH) throw new FormatException();
// Read the payload
offset = 0;
while(offset < payloadLength) {
while (offset < payloadLength) {
int read = in.read(payload, offset, payloadLength - offset);
if(read == -1) throw new FormatException();
if (read == -1) throw new FormatException();
offset += read;
}
state = State.BUFFER_FULL;
}
public boolean eof() throws IOException {
if(state == State.BUFFER_EMPTY) readPacket();
if (state == State.BUFFER_EMPTY) readPacket();
assert state != State.BUFFER_EMPTY;
return state == State.EOF;
}
@@ -112,7 +112,7 @@ class PacketReaderImpl implements PacketReader {
}
public Ack readAck() throws IOException {
if(!hasAck()) throw new FormatException();
if (!hasAck()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
@@ -121,17 +121,17 @@ class PacketReaderImpl implements PacketReader {
// Read the message IDs
List<MessageId> acked = new ArrayList<MessageId>();
r.readListStart();
while(!r.hasListEnd()) {
while (!r.hasListEnd()) {
byte[] b = r.readRaw(UniqueId.LENGTH);
if(b.length != UniqueId.LENGTH)
if (b.length != UniqueId.LENGTH)
throw new FormatException();
acked.add(new MessageId(b));
}
if(acked.isEmpty()) throw new FormatException();
if (acked.isEmpty()) throw new FormatException();
r.readListEnd();
// Read the end of the payload
r.readListEnd();
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
// Build and return the ack
return new Ack(Collections.unmodifiableList(acked));
@@ -142,13 +142,13 @@ class PacketReaderImpl implements PacketReader {
}
public UnverifiedMessage readMessage() throws IOException {
if(!hasMessage()) throw new FormatException();
if (!hasMessage()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
// Read and build the message
UnverifiedMessage m = messageReader.readObject(r);
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
return m;
}
@@ -158,7 +158,7 @@ class PacketReaderImpl implements PacketReader {
}
public Offer readOffer() throws IOException {
if(!hasOffer()) throw new FormatException();
if (!hasOffer()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
@@ -167,17 +167,17 @@ class PacketReaderImpl implements PacketReader {
// Read the message IDs
List<MessageId> offered = new ArrayList<MessageId>();
r.readListStart();
while(!r.hasListEnd()) {
while (!r.hasListEnd()) {
byte[] b = r.readRaw(UniqueId.LENGTH);
if(b.length != UniqueId.LENGTH)
if (b.length != UniqueId.LENGTH)
throw new FormatException();
offered.add(new MessageId(b));
}
if(offered.isEmpty()) throw new FormatException();
if (offered.isEmpty()) throw new FormatException();
r.readListEnd();
// Read the end of the payload
r.readListEnd();
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
// Build and return the offer
return new Offer(Collections.unmodifiableList(offered));
@@ -188,7 +188,7 @@ class PacketReaderImpl implements PacketReader {
}
public Request readRequest() throws IOException {
if(!hasRequest()) throw new FormatException();
if (!hasRequest()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
@@ -197,17 +197,17 @@ class PacketReaderImpl implements PacketReader {
// Read the message IDs
r.readListStart();
List<MessageId> requested = new ArrayList<MessageId>();
while(!r.hasListEnd()) {
while (!r.hasListEnd()) {
byte[] b = r.readRaw(UniqueId.LENGTH);
if(b.length != UniqueId.LENGTH)
if (b.length != UniqueId.LENGTH)
throw new FormatException();
requested.add(new MessageId(b));
}
if(requested.isEmpty()) throw new FormatException();
if (requested.isEmpty()) throw new FormatException();
r.readListEnd();
// Read the end of the payload
r.readListEnd();
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
// Build and return the request
return new Request(Collections.unmodifiableList(requested));
@@ -218,7 +218,7 @@ class PacketReaderImpl implements PacketReader {
}
public RetentionAck readRetentionAck() throws IOException {
if(!hasRetentionAck()) throw new FormatException();
if (!hasRetentionAck()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
@@ -226,10 +226,10 @@ class PacketReaderImpl implements PacketReader {
r.readListStart();
// Read the version
long version = r.readInteger();
if(version < 0) throw new FormatException();
if (version < 0) throw new FormatException();
// Read the end of the payload
r.readListEnd();
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
// Build and return the retention ack
return new RetentionAck(version);
@@ -240,7 +240,7 @@ class PacketReaderImpl implements PacketReader {
}
public RetentionUpdate readRetentionUpdate() throws IOException {
if(!hasRetentionUpdate()) throw new FormatException();
if (!hasRetentionUpdate()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
@@ -248,12 +248,12 @@ class PacketReaderImpl implements PacketReader {
r.readListStart();
// Read the retention time and version
long retention = r.readInteger();
if(retention < 0) throw new FormatException();
if (retention < 0) throw new FormatException();
long version = r.readInteger();
if(version < 0) throw new FormatException();
if (version < 0) throw new FormatException();
// Read the end of the payload
r.readListEnd();
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
// Build and return the retention update
return new RetentionUpdate(retention, version);
@@ -264,7 +264,7 @@ class PacketReaderImpl implements PacketReader {
}
public SubscriptionAck readSubscriptionAck() throws IOException {
if(!hasSubscriptionAck()) throw new FormatException();
if (!hasSubscriptionAck()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
@@ -272,10 +272,10 @@ class PacketReaderImpl implements PacketReader {
r.readListStart();
// Read the version
long version = r.readInteger();
if(version < 0) throw new FormatException();
if (version < 0) throw new FormatException();
// Read the end of the payload
r.readListEnd();
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
// Build and return the subscription ack
return new SubscriptionAck(version);
@@ -286,13 +286,13 @@ class PacketReaderImpl implements PacketReader {
}
public SubscriptionUpdate readSubscriptionUpdate() throws IOException {
if(!hasSubscriptionUpdate()) throw new FormatException();
if (!hasSubscriptionUpdate()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
// Read and build the subscription update
SubscriptionUpdate u = subscriptionUpdateReader.readObject(r);
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
return u;
}
@@ -302,7 +302,7 @@ class PacketReaderImpl implements PacketReader {
}
public TransportAck readTransportAck() throws IOException {
if(!hasTransportAck()) throw new FormatException();
if (!hasTransportAck()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
@@ -310,13 +310,13 @@ class PacketReaderImpl implements PacketReader {
r.readListStart();
// Read the transport ID and version
String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
if(idString.length() == 0) throw new FormatException();
if (idString.length() == 0) throw new FormatException();
TransportId id = new TransportId(idString);
long version = r.readInteger();
if(version < 0) throw new FormatException();
if (version < 0) throw new FormatException();
// Read the end of the payload
r.readListEnd();
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
// Build and return the transport ack
return new TransportAck(id, version);
@@ -327,7 +327,7 @@ class PacketReaderImpl implements PacketReader {
}
public TransportUpdate readTransportUpdate() throws IOException {
if(!hasTransportUpdate()) throw new FormatException();
if (!hasTransportUpdate()) throw new FormatException();
// Set up the reader
InputStream bais = new ByteArrayInputStream(payload, 0, payloadLength);
Reader r = readerFactory.createReader(bais);
@@ -335,13 +335,13 @@ class PacketReaderImpl implements PacketReader {
r.readListStart();
// Read the transport ID
String idString = r.readString(MAX_TRANSPORT_ID_LENGTH);
if(idString.length() == 0) throw new FormatException();
if (idString.length() == 0) throw new FormatException();
TransportId id = new TransportId(idString);
// Read the transport properties
Map<String, String> p = new HashMap<String, String>();
r.readMapStart();
for(int i = 0; !r.hasMapEnd(); i++) {
if(i == MAX_PROPERTIES_PER_TRANSPORT)
for (int i = 0; !r.hasMapEnd(); i++) {
if (i == MAX_PROPERTIES_PER_TRANSPORT)
throw new FormatException();
String key = r.readString(MAX_PROPERTY_LENGTH);
String value = r.readString(MAX_PROPERTY_LENGTH);
@@ -350,10 +350,10 @@ class PacketReaderImpl implements PacketReader {
r.readMapEnd();
// Read the version number
long version = r.readInteger();
if(version < 0) throw new FormatException();
if (version < 0) throw new FormatException();
// Read the end of the payload
r.readListEnd();
if(!r.eof()) throw new FormatException();
if (!r.eof()) throw new FormatException();
state = State.BUFFER_EMPTY;
// Build and return the transport update
return new TransportUpdate(id, new TransportProperties(p), version);

View File

@@ -85,7 +85,7 @@ class PacketWriterImpl implements PacketWriter {
Writer w = writerFactory.createWriter(payload);
w.writeListStart();
w.writeListStart();
for(MessageId m : a.getMessageIds()) w.writeRaw(m.getBytes());
for (MessageId m : a.getMessageIds()) w.writeRaw(m.getBytes());
w.writeListEnd();
w.writeListEnd();
writePacket(ACK);
@@ -103,7 +103,7 @@ class PacketWriterImpl implements PacketWriter {
Writer w = writerFactory.createWriter(payload);
w.writeListStart();
w.writeListStart();
for(MessageId m : o.getMessageIds()) w.writeRaw(m.getBytes());
for (MessageId m : o.getMessageIds()) w.writeRaw(m.getBytes());
w.writeListEnd();
w.writeListEnd();
writePacket(OFFER);
@@ -114,7 +114,7 @@ class PacketWriterImpl implements PacketWriter {
Writer w = writerFactory.createWriter(payload);
w.writeListStart();
w.writeListStart();
for(MessageId m : r.getMessageIds()) w.writeRaw(m.getBytes());
for (MessageId m : r.getMessageIds()) w.writeRaw(m.getBytes());
w.writeListEnd();
w.writeListEnd();
writePacket(REQUEST);
@@ -154,7 +154,7 @@ class PacketWriterImpl implements PacketWriter {
Writer w = writerFactory.createWriter(payload);
w.writeListStart();
w.writeListStart();
for(Group g : u.getGroups()) {
for (Group g : u.getGroups()) {
w.writeListStart();
w.writeString(g.getName());
w.writeRaw(g.getSalt());

View File

@@ -88,13 +88,13 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
dbExecutor.execute(new GenerateBatch());
// Write packets until interrupted or no more packets to write
try {
while(!interrupted) {
while (!interrupted) {
ThrowingRunnable<IOException> task = writerTasks.take();
if(task == CLOSE) break;
if (task == CLOSE) break;
task.run();
}
packetWriter.flush();
} catch(InterruptedException e) {
} catch (InterruptedException e) {
LOG.info("Interrupted while waiting for a packet to write");
Thread.currentThread().interrupt();
}
@@ -109,18 +109,18 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
}
private void decrementOutstandingQueries() {
if(outstandingQueries.decrementAndGet() == 0) writerTasks.add(CLOSE);
if (outstandingQueries.decrementAndGet() == 0) writerTasks.add(CLOSE);
}
public void eventOccurred(Event e) {
if(e instanceof ContactRemovedEvent) {
if (e instanceof ContactRemovedEvent) {
ContactRemovedEvent c = (ContactRemovedEvent) e;
if(c.getContactId().equals(contactId)) interrupt();
} else if(e instanceof ShutdownEvent) {
if (c.getContactId().equals(contactId)) interrupt();
} else if (e instanceof ShutdownEvent) {
interrupt();
} else if(e instanceof TransportRemovedEvent) {
} else if (e instanceof TransportRemovedEvent) {
TransportRemovedEvent t = (TransportRemovedEvent) e;
if(t.getTransportId().equals(transportId)) interrupt();
if (t.getTransportId().equals(transportId)) interrupt();
}
}
@@ -128,16 +128,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateAck implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
int maxMessages = packetWriter.getMaxMessagesForAck(Long.MAX_VALUE);
try {
Ack a = db.generateAck(contactId, maxMessages);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated ack: " + (a != null));
if(a == null) decrementOutstandingQueries();
if (a == null) decrementOutstandingQueries();
else writerTasks.add(new WriteAck(a));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -153,7 +153,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeAck(ack);
LOG.info("Sent ack");
dbExecutor.execute(new GenerateAck());
@@ -164,16 +164,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateBatch implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
Collection<byte[]> b = db.generateBatch(contactId,
MAX_PAYLOAD_LENGTH, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated batch: " + (b != null));
if(b == null) decrementOutstandingQueries();
if (b == null) decrementOutstandingQueries();
else writerTasks.add(new WriteBatch(b));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -189,8 +189,8 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
for(byte[] raw : batch) packetWriter.writeMessage(raw);
if (interrupted) return;
for (byte[] raw : batch) packetWriter.writeMessage(raw);
LOG.info("Sent batch");
dbExecutor.execute(new GenerateBatch());
}
@@ -200,15 +200,15 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateRetentionAck implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
RetentionAck a = db.generateRetentionAck(contactId);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated retention ack: " + (a != null));
if(a == null) decrementOutstandingQueries();
if (a == null) decrementOutstandingQueries();
else writerTasks.add(new WriteRetentionAck(a));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -225,7 +225,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeRetentionAck(ack);
LOG.info("Sent retention ack");
dbExecutor.execute(new GenerateRetentionAck());
@@ -236,16 +236,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateRetentionUpdate implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
RetentionUpdate u =
db.generateRetentionUpdate(contactId, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated retention update: " + (u != null));
if(u == null) decrementOutstandingQueries();
if (u == null) decrementOutstandingQueries();
else writerTasks.add(new WriteRetentionUpdate(u));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -262,7 +262,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeRetentionUpdate(update);
LOG.info("Sent retention update");
dbExecutor.execute(new GenerateRetentionUpdate());
@@ -273,15 +273,15 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateSubscriptionAck implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
SubscriptionAck a = db.generateSubscriptionAck(contactId);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated subscription ack: " + (a != null));
if(a == null) decrementOutstandingQueries();
if (a == null) decrementOutstandingQueries();
else writerTasks.add(new WriteSubscriptionAck(a));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -298,7 +298,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeSubscriptionAck(ack);
LOG.info("Sent subscription ack");
dbExecutor.execute(new GenerateSubscriptionAck());
@@ -309,16 +309,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateSubscriptionUpdate implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
SubscriptionUpdate u =
db.generateSubscriptionUpdate(contactId, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated subscription update: " + (u != null));
if(u == null) decrementOutstandingQueries();
if (u == null) decrementOutstandingQueries();
else writerTasks.add(new WriteSubscriptionUpdate(u));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -335,7 +335,7 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
if (interrupted) return;
packetWriter.writeSubscriptionUpdate(update);
LOG.info("Sent subscription update");
dbExecutor.execute(new GenerateSubscriptionUpdate());
@@ -346,16 +346,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateTransportAcks implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
Collection<TransportAck> acks =
db.generateTransportAcks(contactId);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated transport acks: " + (acks != null));
if(acks == null) decrementOutstandingQueries();
if (acks == null) decrementOutstandingQueries();
else writerTasks.add(new WriteTransportAcks(acks));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -371,8 +371,8 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
for(TransportAck a : acks) packetWriter.writeTransportAck(a);
if (interrupted) return;
for (TransportAck a : acks) packetWriter.writeTransportAck(a);
LOG.info("Sent transport acks");
dbExecutor.execute(new GenerateTransportAcks());
}
@@ -382,16 +382,16 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
private class GenerateTransportUpdates implements Runnable {
public void run() {
if(interrupted) return;
if (interrupted) return;
try {
Collection<TransportUpdate> t =
db.generateTransportUpdates(contactId, maxLatency);
if(LOG.isLoggable(INFO))
if (LOG.isLoggable(INFO))
LOG.info("Generated transport updates: " + (t != null));
if(t == null) decrementOutstandingQueries();
if (t == null) decrementOutstandingQueries();
else writerTasks.add(new WriteTransportUpdates(t));
} catch(DbException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch (DbException e) {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
interrupt();
}
}
@@ -408,8 +408,8 @@ class SimplexOutgoingSession implements MessagingSession, EventListener {
}
public void run() throws IOException {
if(interrupted) return;
for(TransportUpdate u : updates)
if (interrupted) return;
for (TransportUpdate u : updates)
packetWriter.writeTransportUpdate(u);
LOG.info("Sent transport updates");
dbExecutor.execute(new GenerateTransportUpdates());

View File

@@ -36,15 +36,15 @@ class SubscriptionUpdateReader implements ObjectReader<SubscriptionUpdate> {
List<Group> groups = new ArrayList<Group>();
Set<GroupId> ids = new HashSet<GroupId>();
r.readListStart();
for(int i = 0; i < MAX_SUBSCRIPTIONS && !r.hasListEnd(); i++) {
for (int i = 0; i < MAX_SUBSCRIPTIONS && !r.hasListEnd(); i++) {
Group g = groupReader.readObject(r);
if(!ids.add(g.getId())) throw new FormatException(); // Duplicate
if (!ids.add(g.getId())) throw new FormatException(); // Duplicate
groups.add(g);
}
r.readListEnd();
// Read the version number
long version = r.readInteger();
if(version < 0) throw new FormatException();
if (version < 0) throw new FormatException();
// Read the end of the update
r.readListEnd();
// Reset the reader