mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
SLIP classes don't need to depend on SLTP classes.
This commit is contained in:
@@ -45,7 +45,7 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
|
||||
SlipEncoder encoder = new SlipEncoder(this);
|
||||
final Sender sender = new Sender(clock, encoder);
|
||||
receiver = new Receiver(clock, sender);
|
||||
decoder = new SlipDecoder(receiver);
|
||||
decoder = new SlipDecoder(receiver, Data.MAX_LENGTH);
|
||||
inputStream = new ReceiverInputStream(receiver);
|
||||
outputStream = new SenderOutputStream(sender);
|
||||
running = true;
|
||||
@@ -97,12 +97,12 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
|
||||
return outputStream;
|
||||
}
|
||||
|
||||
// The transport calls this method to pass data up to the SLIP decoder
|
||||
// The lower layer calls this method to pass data up to the SLIP decoder
|
||||
public void handleRead(byte[] b) throws IOException {
|
||||
if(running) decoder.handleRead(b);
|
||||
}
|
||||
|
||||
// The SLIP encoder calls this method to pass data down to the transport
|
||||
// The SLIP encoder calls this method to pass data down to the lower layer
|
||||
public void handleWrite(byte[] b) {
|
||||
if(running && b.length > 0) writes.add(b);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,14 @@ class SlipDecoder implements ReadHandler {
|
||||
private static final byte TEND = (byte) 220, TESC = (byte) 221;
|
||||
|
||||
private final ReadHandler readHandler;
|
||||
private final byte[] buf;
|
||||
|
||||
private byte[] buf = new byte[Data.MAX_LENGTH];
|
||||
private int decodedLength = 0;
|
||||
private boolean escape = false;
|
||||
|
||||
SlipDecoder(ReadHandler readHandler) {
|
||||
SlipDecoder(ReadHandler readHandler, int maxDecodedLength) {
|
||||
this.readHandler = readHandler;
|
||||
buf = new byte[maxDecodedLength];
|
||||
}
|
||||
|
||||
public void handleRead(byte[] b) throws IOException {
|
||||
|
||||
@@ -17,7 +17,6 @@ class SlipEncoder implements WriteHandler {
|
||||
}
|
||||
|
||||
public void handleWrite(byte[] b) throws IOException {
|
||||
if(b.length > Data.MAX_LENGTH) throw new IllegalArgumentException();
|
||||
int encodedLength = b.length + 2;
|
||||
for(int i = 0; i < b.length; i++)
|
||||
if(b[i] == END || b[i] == ESC) encodedLength++;
|
||||
|
||||
Reference in New Issue
Block a user