mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Readers, writers and factories for subscription and transport updates.
This commit is contained in:
@@ -19,10 +19,10 @@ class AckWriterImpl implements AckWriter {
|
||||
|
||||
AckWriterImpl(OutputStream out, WriterFactory writerFactory) {
|
||||
this.out = out;
|
||||
this.w = writerFactory.createWriter(out);
|
||||
w = writerFactory.createWriter(out);
|
||||
}
|
||||
|
||||
public boolean addBatchId(BatchId b) throws IOException {
|
||||
public boolean writeBatchId(BatchId b) throws IOException {
|
||||
if(finished) throw new IllegalStateException();
|
||||
if(!started) {
|
||||
w.writeUserDefinedTag(Tags.ACK);
|
||||
|
||||
@@ -31,7 +31,7 @@ class BatchWriterImpl implements BatchWriter {
|
||||
return Batch.MAX_SIZE - 3;
|
||||
}
|
||||
|
||||
public boolean addMessage(byte[] message) throws IOException {
|
||||
public boolean writeMessage(byte[] message) throws IOException {
|
||||
if(finished) throw new IllegalStateException();
|
||||
if(!started) {
|
||||
messageDigest.reset();
|
||||
|
||||
@@ -33,12 +33,10 @@ class PacketWriterFactoryImpl implements PacketWriterFactory {
|
||||
}
|
||||
|
||||
public SubscriptionWriter createSubscriptionWriter(OutputStream out) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return new SubscriptionWriterImpl(out, writerFactory);
|
||||
}
|
||||
|
||||
public TransportWriter createTransportWriter(OutputStream out) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return new TransportWriterImpl(out, writerFactory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.sf.briar.protocol.writers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.sf.briar.api.protocol.Group;
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.writers.SubscriptionWriter;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
|
||||
class SubscriptionWriterImpl implements SubscriptionWriter {
|
||||
|
||||
private final OutputStream out;
|
||||
private final Writer w;
|
||||
|
||||
private boolean used = false;
|
||||
|
||||
SubscriptionWriterImpl(OutputStream out, WriterFactory writerFactory) {
|
||||
this.out = out;
|
||||
w = writerFactory.createWriter(out);
|
||||
}
|
||||
|
||||
public void writeSubscriptions(Collection<Group> subs) throws IOException {
|
||||
if(used) throw new IllegalStateException();
|
||||
w.writeUserDefinedTag(Tags.SUBSCRIPTIONS);
|
||||
w.writeList(subs);
|
||||
w.writeInt64(System.currentTimeMillis());
|
||||
out.flush();
|
||||
used = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.sf.briar.protocol.writers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import net.sf.briar.api.protocol.Tags;
|
||||
import net.sf.briar.api.protocol.writers.TransportWriter;
|
||||
import net.sf.briar.api.serial.Writer;
|
||||
import net.sf.briar.api.serial.WriterFactory;
|
||||
|
||||
class TransportWriterImpl implements TransportWriter {
|
||||
|
||||
private final OutputStream out;
|
||||
private final Writer w;
|
||||
|
||||
private boolean used = false;
|
||||
|
||||
TransportWriterImpl(OutputStream out, WriterFactory writerFactory) {
|
||||
this.out = out;
|
||||
w = writerFactory.createWriter(out);
|
||||
}
|
||||
|
||||
public void writeTransports(Map<String, String> transports)
|
||||
throws IOException {
|
||||
if(used) throw new IllegalStateException();
|
||||
w.writeUserDefinedTag(Tags.TRANSPORTS);
|
||||
w.writeMap(transports);
|
||||
w.writeInt64(System.currentTimeMillis());
|
||||
out.flush();
|
||||
used = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user