Decoupled ProtocolReader (which belongs in the protocol component)

from PacketReader (which belongs in the transport component).
This commit is contained in:
akwizgran
2011-08-13 14:18:16 +02:00
parent 5b6fecfb43
commit 9d25a819d1
17 changed files with 591 additions and 221 deletions

View File

@@ -0,0 +1,24 @@
package net.sf.briar.api.protocol;
import java.io.IOException;
public interface ProtocolReader {
boolean hasAck() throws IOException;
Ack readAck() throws IOException;
boolean hasBatch() throws IOException;
Batch readBatch() throws IOException;
boolean hasOffer() throws IOException;
Offer readOffer() throws IOException;
boolean hasRequest() throws IOException;
Request readRequest() throws IOException;
boolean hasSubscriptionUpdate() throws IOException;
SubscriptionUpdate readSubscriptionUpdate() throws IOException;
boolean hasTransportUpdate() throws IOException;
TransportUpdate readTransportUpdate() throws IOException;
}

View File

@@ -0,0 +1,8 @@
package net.sf.briar.api.protocol;
import java.io.InputStream;
public interface ProtocolReaderFactory {
ProtocolReader createProtocolReader(InputStream in);
}

View File

@@ -1,13 +1,8 @@
package net.sf.briar.api.transport;
import java.io.IOException;
import net.sf.briar.api.protocol.Ack;
import net.sf.briar.api.protocol.Batch;
import net.sf.briar.api.protocol.Offer;
import net.sf.briar.api.protocol.Request;
import net.sf.briar.api.protocol.SubscriptionUpdate;
import net.sf.briar.api.protocol.TransportUpdate;
import java.io.InputStream;
import java.security.GeneralSecurityException;
/**
* Reads encrypted packets from an underlying input stream, decrypts and
@@ -15,21 +10,17 @@ import net.sf.briar.api.protocol.TransportUpdate;
*/
public interface PacketReader {
boolean hasAck() throws IOException;
Ack readAck() throws IOException;
/**
* Returns the input stream from which packets should be read. (Note that
* this is not the underlying input stream.)
*/
InputStream getInputStream();
boolean hasBatch() throws IOException;
Batch readBatch() throws IOException;
boolean hasOffer() throws IOException;
Offer readOffer() throws IOException;
boolean hasRequest() throws IOException;
Request readRequest() throws IOException;
boolean hasSubscriptionUpdate() throws IOException;
SubscriptionUpdate readSubscriptionUpdate() throws IOException;
boolean hasTransportUpdate() throws IOException;
TransportUpdate readTransportUpdate() throws IOException;
/**
* Finishes reading the current packet (if any), authenticates the packet
* and prepares to read the next packet. If this method is called twice in
* succession without any intervening reads, the underlying input stream
* will be unaffected.
*/
void finishPacket() throws IOException, GeneralSecurityException;
}

View File

@@ -20,5 +20,5 @@ public interface PacketWriter {
* next packet. If this method is called twice in succession without any
* intervening writes, the underlying output stream will be unaffected.
*/
void nextPacket() throws IOException;
void finishPacket() throws IOException;
}