mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Connection readers and writers don't need the connection context.
This commit is contained in:
@@ -6,15 +6,15 @@ public interface ConnectionReaderFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection reader for a batch-mode connection or the
|
* Creates a connection reader for a batch-mode connection or the
|
||||||
* initiator's side of a stream-mode connection.
|
* initiator's side of a stream-mode connection. The secret is erased
|
||||||
|
* before this method returns.
|
||||||
*/
|
*/
|
||||||
ConnectionReader createConnectionReader(InputStream in,
|
ConnectionReader createConnectionReader(InputStream in, byte[] secret,
|
||||||
ConnectionContext ctx, byte[] tag);
|
byte[] tag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection reader for the responder's side of a stream-mode
|
* Creates a connection reader for the responder's side of a stream-mode
|
||||||
* connection.
|
* connection. The secret is erased before this method returns.
|
||||||
*/
|
*/
|
||||||
ConnectionReader createConnectionReader(InputStream in,
|
ConnectionReader createConnectionReader(InputStream in, byte[] secret);
|
||||||
ConnectionContext ctx);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,16 @@ public interface ConnectionWriterFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection writer for a batch-mode connection or the
|
* Creates a connection writer for a batch-mode connection or the
|
||||||
* initiator's side of a stream-mode connection.
|
* initiator's side of a stream-mode connection. The secret is erased
|
||||||
|
* before this method returns.
|
||||||
*/
|
*/
|
||||||
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
||||||
ConnectionContext ctx);
|
byte[] secret);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a connection writer for the responder's side of a stream-mode
|
* Creates a connection writer for the responder's side of a stream-mode
|
||||||
* connection.
|
* connection. The secret is erased before this method returns.
|
||||||
*/
|
*/
|
||||||
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
ConnectionWriter createConnectionWriter(OutputStream out, long capacity,
|
||||||
ConnectionContext ctx, byte[] tag);
|
byte[] secret, byte[] tag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import javax.crypto.Mac;
|
|||||||
|
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.crypto.ErasableKey;
|
import net.sf.briar.api.crypto.ErasableKey;
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
|
||||||
import net.sf.briar.api.transport.ConnectionReader;
|
import net.sf.briar.api.transport.ConnectionReader;
|
||||||
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
||||||
import net.sf.briar.util.ByteUtils;
|
import net.sf.briar.util.ByteUtils;
|
||||||
@@ -24,25 +23,24 @@ class ConnectionReaderFactoryImpl implements ConnectionReaderFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionReader createConnectionReader(InputStream in,
|
public ConnectionReader createConnectionReader(InputStream in,
|
||||||
ConnectionContext ctx, byte[] tag) {
|
byte[] secret, byte[] tag) {
|
||||||
// Validate the tag
|
// Validate the tag
|
||||||
Cipher tagCipher = crypto.getTagCipher();
|
Cipher tagCipher = crypto.getTagCipher();
|
||||||
ErasableKey tagKey = crypto.deriveTagKey(ctx.getSecret(), true);
|
ErasableKey tagKey = crypto.deriveTagKey(secret, true);
|
||||||
boolean valid = TagEncoder.validateTag(tag, 0, tagCipher, tagKey);
|
boolean valid = TagEncoder.validateTag(tag, 0, tagCipher, tagKey);
|
||||||
tagKey.erase();
|
tagKey.erase();
|
||||||
if(!valid) throw new IllegalArgumentException();
|
if(!valid) throw new IllegalArgumentException();
|
||||||
return createConnectionReader(in, true, ctx);
|
return createConnectionReader(in, true, secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionReader createConnectionReader(InputStream in,
|
public ConnectionReader createConnectionReader(InputStream in,
|
||||||
ConnectionContext ctx) {
|
byte[] secret) {
|
||||||
return createConnectionReader(in, false, ctx);
|
return createConnectionReader(in, false, secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConnectionReader createConnectionReader(InputStream in,
|
private ConnectionReader createConnectionReader(InputStream in,
|
||||||
boolean initiator, ConnectionContext ctx) {
|
boolean initiator, byte[] secret) {
|
||||||
// Derive the keys and erase the secret
|
// Derive the keys and erase the secret
|
||||||
byte[] secret = ctx.getSecret();
|
|
||||||
ErasableKey frameKey = crypto.deriveFrameKey(secret, initiator);
|
ErasableKey frameKey = crypto.deriveFrameKey(secret, initiator);
|
||||||
ErasableKey macKey = crypto.deriveMacKey(secret, initiator);
|
ErasableKey macKey = crypto.deriveMacKey(secret, initiator);
|
||||||
ByteUtils.erase(secret);
|
ByteUtils.erase(secret);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import javax.crypto.Mac;
|
|||||||
|
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.crypto.ErasableKey;
|
import net.sf.briar.api.crypto.ErasableKey;
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
import net.sf.briar.util.ByteUtils;
|
import net.sf.briar.util.ByteUtils;
|
||||||
@@ -24,25 +23,24 @@ class ConnectionWriterFactoryImpl implements ConnectionWriterFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionWriter createConnectionWriter(OutputStream out,
|
public ConnectionWriter createConnectionWriter(OutputStream out,
|
||||||
long capacity, ConnectionContext ctx) {
|
long capacity, byte[] secret) {
|
||||||
return createConnectionWriter(out, capacity, true, ctx);
|
return createConnectionWriter(out, capacity, true, secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionWriter createConnectionWriter(OutputStream out,
|
public ConnectionWriter createConnectionWriter(OutputStream out,
|
||||||
long capacity, ConnectionContext ctx, byte[] tag) {
|
long capacity, byte[] secret, byte[] tag) {
|
||||||
// Decrypt the tag
|
// Decrypt the tag
|
||||||
Cipher tagCipher = crypto.getTagCipher();
|
Cipher tagCipher = crypto.getTagCipher();
|
||||||
ErasableKey tagKey = crypto.deriveTagKey(ctx.getSecret(), true);
|
ErasableKey tagKey = crypto.deriveTagKey(secret, true);
|
||||||
boolean valid = TagEncoder.validateTag(tag, 0, tagCipher, tagKey);
|
boolean valid = TagEncoder.validateTag(tag, 0, tagCipher, tagKey);
|
||||||
tagKey.erase();
|
tagKey.erase();
|
||||||
if(!valid) throw new IllegalArgumentException();
|
if(!valid) throw new IllegalArgumentException();
|
||||||
return createConnectionWriter(out, capacity, false, ctx);
|
return createConnectionWriter(out, capacity, false, secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConnectionWriter createConnectionWriter(OutputStream out,
|
private ConnectionWriter createConnectionWriter(OutputStream out,
|
||||||
long capacity, boolean initiator, ConnectionContext ctx) {
|
long capacity, boolean initiator, byte[] secret) {
|
||||||
// Derive the keys and erase the secret
|
// Derive the keys and erase the secret
|
||||||
byte[] secret = ctx.getSecret();
|
|
||||||
ErasableKey tagKey = crypto.deriveTagKey(secret, initiator);
|
ErasableKey tagKey = crypto.deriveTagKey(secret, initiator);
|
||||||
ErasableKey frameKey = crypto.deriveFrameKey(secret, initiator);
|
ErasableKey frameKey = crypto.deriveFrameKey(secret, initiator);
|
||||||
ErasableKey macKey = crypto.deriveMacKey(secret, initiator);
|
ErasableKey macKey = crypto.deriveMacKey(secret, initiator);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class IncomingBatchConnection {
|
|||||||
void read() {
|
void read() {
|
||||||
try {
|
try {
|
||||||
ConnectionReader conn = connFactory.createConnectionReader(
|
ConnectionReader conn = connFactory.createConnectionReader(
|
||||||
reader.getInputStream(), ctx, tag);
|
reader.getInputStream(), ctx.getSecret(), tag);
|
||||||
ProtocolReader proto = protoFactory.createProtocolReader(
|
ProtocolReader proto = protoFactory.createProtocolReader(
|
||||||
conn.getInputStream());
|
conn.getInputStream());
|
||||||
ContactId c = ctx.getContactId();
|
ContactId c = ctx.getContactId();
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ class OutgoingBatchConnection {
|
|||||||
ConnectionContext ctx = db.getConnectionContext(contactId,
|
ConnectionContext ctx = db.getConnectionContext(contactId,
|
||||||
transportIndex);
|
transportIndex);
|
||||||
ConnectionWriter conn = connFactory.createConnectionWriter(
|
ConnectionWriter conn = connFactory.createConnectionWriter(
|
||||||
writer.getOutputStream(), writer.getCapacity(), ctx);
|
writer.getOutputStream(), writer.getCapacity(),
|
||||||
|
ctx.getSecret());
|
||||||
OutputStream out = conn.getOutputStream();
|
OutputStream out = conn.getOutputStream();
|
||||||
// There should be enough space for a packet
|
// There should be enough space for a packet
|
||||||
long capacity = conn.getRemainingCapacity();
|
long capacity = conn.getRemainingCapacity();
|
||||||
|
|||||||
@@ -34,13 +34,14 @@ class IncomingStreamConnection extends StreamConnection {
|
|||||||
protected ConnectionReader createConnectionReader() throws DbException,
|
protected ConnectionReader createConnectionReader() throws DbException,
|
||||||
IOException {
|
IOException {
|
||||||
return connReaderFactory.createConnectionReader(
|
return connReaderFactory.createConnectionReader(
|
||||||
connection.getInputStream(), ctx, tag);
|
connection.getInputStream(), ctx.getSecret(), tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionWriter createConnectionWriter() throws DbException,
|
protected ConnectionWriter createConnectionWriter() throws DbException,
|
||||||
IOException {
|
IOException {
|
||||||
return connWriterFactory.createConnectionWriter(
|
return connWriterFactory.createConnectionWriter(
|
||||||
connection.getOutputStream(), Long.MAX_VALUE, ctx, tag);
|
connection.getOutputStream(), Long.MAX_VALUE, ctx.getSecret(),
|
||||||
|
tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class OutgoingStreamConnection extends StreamConnection {
|
|||||||
ctx = db.getConnectionContext(contactId, transportIndex);
|
ctx = db.getConnectionContext(contactId, transportIndex);
|
||||||
}
|
}
|
||||||
return connReaderFactory.createConnectionReader(
|
return connReaderFactory.createConnectionReader(
|
||||||
connection.getInputStream(), ctx);
|
connection.getInputStream(), ctx.getSecret());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -51,6 +51,6 @@ class OutgoingStreamConnection extends StreamConnection {
|
|||||||
ctx = db.getConnectionContext(contactId, transportIndex);
|
ctx = db.getConnectionContext(contactId, transportIndex);
|
||||||
}
|
}
|
||||||
return connWriterFactory.createConnectionWriter(
|
return connWriterFactory.createConnectionWriter(
|
||||||
connection.getOutputStream(), Long.MAX_VALUE, ctx);
|
connection.getOutputStream(), Long.MAX_VALUE, ctx.getSecret());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.sf.briar;
|
package net.sf.briar;
|
||||||
|
|
||||||
|
import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@@ -18,7 +19,6 @@ import java.util.concurrent.Executor;
|
|||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.api.ContactId;
|
|
||||||
import net.sf.briar.api.crypto.CryptoComponent;
|
import net.sf.briar.api.crypto.CryptoComponent;
|
||||||
import net.sf.briar.api.protocol.Ack;
|
import net.sf.briar.api.protocol.Ack;
|
||||||
import net.sf.briar.api.protocol.Author;
|
import net.sf.briar.api.protocol.Author;
|
||||||
@@ -46,13 +46,10 @@ import net.sf.briar.api.protocol.writers.ProtocolWriterFactory;
|
|||||||
import net.sf.briar.api.protocol.writers.RequestWriter;
|
import net.sf.briar.api.protocol.writers.RequestWriter;
|
||||||
import net.sf.briar.api.protocol.writers.SubscriptionUpdateWriter;
|
import net.sf.briar.api.protocol.writers.SubscriptionUpdateWriter;
|
||||||
import net.sf.briar.api.protocol.writers.TransportUpdateWriter;
|
import net.sf.briar.api.protocol.writers.TransportUpdateWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
|
||||||
import net.sf.briar.api.transport.ConnectionContextFactory;
|
|
||||||
import net.sf.briar.api.transport.ConnectionReader;
|
import net.sf.briar.api.transport.ConnectionReader;
|
||||||
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
import net.sf.briar.api.transport.ConnectionReaderFactory;
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
import static net.sf.briar.api.transport.TransportConstants.TAG_LENGTH;
|
|
||||||
import net.sf.briar.crypto.CryptoModule;
|
import net.sf.briar.crypto.CryptoModule;
|
||||||
import net.sf.briar.db.DatabaseModule;
|
import net.sf.briar.db.DatabaseModule;
|
||||||
import net.sf.briar.lifecycle.LifecycleModule;
|
import net.sf.briar.lifecycle.LifecycleModule;
|
||||||
@@ -63,7 +60,6 @@ import net.sf.briar.transport.TransportModule;
|
|||||||
import net.sf.briar.transport.batch.TransportBatchModule;
|
import net.sf.briar.transport.batch.TransportBatchModule;
|
||||||
import net.sf.briar.transport.stream.TransportStreamModule;
|
import net.sf.briar.transport.stream.TransportStreamModule;
|
||||||
|
|
||||||
import org.bouncycastle.util.Arrays;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
@@ -76,16 +72,13 @@ public class ProtocolIntegrationTest extends TestCase {
|
|||||||
private final BatchId ack = new BatchId(TestUtils.getRandomId());
|
private final BatchId ack = new BatchId(TestUtils.getRandomId());
|
||||||
private final long timestamp = System.currentTimeMillis();
|
private final long timestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
private final ConnectionContextFactory connectionContextFactory;
|
|
||||||
private final ConnectionReaderFactory connectionReaderFactory;
|
private final ConnectionReaderFactory connectionReaderFactory;
|
||||||
private final ConnectionWriterFactory connectionWriterFactory;
|
private final ConnectionWriterFactory connectionWriterFactory;
|
||||||
private final ProtocolReaderFactory protocolReaderFactory;
|
private final ProtocolReaderFactory protocolReaderFactory;
|
||||||
private final ProtocolWriterFactory protocolWriterFactory;
|
private final ProtocolWriterFactory protocolWriterFactory;
|
||||||
private final CryptoComponent crypto;
|
private final CryptoComponent crypto;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
private final ContactId contactId = new ContactId(13);
|
|
||||||
private final TransportIndex transportIndex = new TransportIndex(13);
|
private final TransportIndex transportIndex = new TransportIndex(13);
|
||||||
private final long connection = 12345L;
|
|
||||||
private final Author author;
|
private final Author author;
|
||||||
private final Group group, group1;
|
private final Group group, group1;
|
||||||
private final Message message, message1, message2, message3;
|
private final Message message, message1, message2, message3;
|
||||||
@@ -109,8 +102,6 @@ public class ProtocolIntegrationTest extends TestCase {
|
|||||||
new SerialModule(), new TestDatabaseModule(),
|
new SerialModule(), new TestDatabaseModule(),
|
||||||
new TransportBatchModule(), new TransportModule(),
|
new TransportBatchModule(), new TransportModule(),
|
||||||
new TransportStreamModule());
|
new TransportStreamModule());
|
||||||
connectionContextFactory =
|
|
||||||
i.getInstance(ConnectionContextFactory.class);
|
|
||||||
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
connectionReaderFactory = i.getInstance(ConnectionReaderFactory.class);
|
||||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||||
protocolReaderFactory = i.getInstance(ProtocolReaderFactory.class);
|
protocolReaderFactory = i.getInstance(ProtocolReaderFactory.class);
|
||||||
@@ -158,11 +149,8 @@ public class ProtocolIntegrationTest extends TestCase {
|
|||||||
|
|
||||||
private byte[] write() throws Exception {
|
private byte[] write() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ConnectionContext ctx =
|
|
||||||
connectionContextFactory.createConnectionContext(contactId,
|
|
||||||
transportIndex, connection, Arrays.clone(secret));
|
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||||
Long.MAX_VALUE, ctx);
|
Long.MAX_VALUE, secret.clone());
|
||||||
OutputStream out1 = w.getOutputStream();
|
OutputStream out1 = w.getOutputStream();
|
||||||
|
|
||||||
AckWriter a = protocolWriterFactory.createAckWriter(out1);
|
AckWriter a = protocolWriterFactory.createAckWriter(out1);
|
||||||
@@ -209,11 +197,8 @@ public class ProtocolIntegrationTest extends TestCase {
|
|||||||
InputStream in = new ByteArrayInputStream(connectionData);
|
InputStream in = new ByteArrayInputStream(connectionData);
|
||||||
byte[] tag = new byte[TAG_LENGTH];
|
byte[] tag = new byte[TAG_LENGTH];
|
||||||
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
assertEquals(TAG_LENGTH, in.read(tag, 0, TAG_LENGTH));
|
||||||
ConnectionContext ctx =
|
|
||||||
connectionContextFactory.createConnectionContext(contactId,
|
|
||||||
transportIndex, connection, Arrays.clone(secret));
|
|
||||||
ConnectionReader r = connectionReaderFactory.createConnectionReader(in,
|
ConnectionReader r = connectionReaderFactory.createConnectionReader(in,
|
||||||
ctx, tag);
|
secret.clone(), tag);
|
||||||
in = r.getInputStream();
|
in = r.getInputStream();
|
||||||
ProtocolReader protocolReader =
|
ProtocolReader protocolReader =
|
||||||
protocolReaderFactory.createProtocolReader(in);
|
protocolReaderFactory.createProtocolReader(in);
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import net.sf.briar.TestDatabaseModule;
|
import net.sf.briar.TestDatabaseModule;
|
||||||
import net.sf.briar.api.ContactId;
|
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
|
||||||
import net.sf.briar.api.transport.ConnectionContext;
|
|
||||||
import net.sf.briar.api.transport.ConnectionContextFactory;
|
|
||||||
import net.sf.briar.api.transport.ConnectionWriter;
|
import net.sf.briar.api.transport.ConnectionWriter;
|
||||||
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
import net.sf.briar.api.transport.ConnectionWriterFactory;
|
||||||
import net.sf.briar.crypto.CryptoModule;
|
import net.sf.briar.crypto.CryptoModule;
|
||||||
@@ -34,12 +30,8 @@ import com.google.inject.Module;
|
|||||||
|
|
||||||
public class ConnectionWriterTest extends TestCase {
|
public class ConnectionWriterTest extends TestCase {
|
||||||
|
|
||||||
private final ConnectionContextFactory connectionContextFactory;
|
|
||||||
private final ConnectionWriterFactory connectionWriterFactory;
|
private final ConnectionWriterFactory connectionWriterFactory;
|
||||||
private final byte[] secret;
|
private final byte[] secret;
|
||||||
private final ContactId contactId = new ContactId(13);
|
|
||||||
private final TransportIndex transportIndex = new TransportIndex(13);
|
|
||||||
private final long connection = 12345L;
|
|
||||||
|
|
||||||
public ConnectionWriterTest() throws Exception {
|
public ConnectionWriterTest() throws Exception {
|
||||||
super();
|
super();
|
||||||
@@ -56,8 +48,6 @@ public class ConnectionWriterTest extends TestCase {
|
|||||||
new SerialModule(), new TestDatabaseModule(),
|
new SerialModule(), new TestDatabaseModule(),
|
||||||
new TransportBatchModule(), new TransportModule(),
|
new TransportBatchModule(), new TransportModule(),
|
||||||
new TransportStreamModule());
|
new TransportStreamModule());
|
||||||
connectionContextFactory =
|
|
||||||
i.getInstance(ConnectionContextFactory.class);
|
|
||||||
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
connectionWriterFactory = i.getInstance(ConnectionWriterFactory.class);
|
||||||
secret = new byte[32];
|
secret = new byte[32];
|
||||||
new Random().nextBytes(secret);
|
new Random().nextBytes(secret);
|
||||||
@@ -67,11 +57,8 @@ public class ConnectionWriterTest extends TestCase {
|
|||||||
public void testOverhead() throws Exception {
|
public void testOverhead() throws Exception {
|
||||||
ByteArrayOutputStream out =
|
ByteArrayOutputStream out =
|
||||||
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
new ByteArrayOutputStream(MIN_CONNECTION_LENGTH);
|
||||||
ConnectionContext ctx =
|
|
||||||
connectionContextFactory.createConnectionContext(contactId,
|
|
||||||
transportIndex, connection, secret);
|
|
||||||
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
ConnectionWriter w = connectionWriterFactory.createConnectionWriter(out,
|
||||||
MIN_CONNECTION_LENGTH, ctx);
|
MIN_CONNECTION_LENGTH, secret);
|
||||||
// Check that the connection writer thinks there's room for a packet
|
// Check that the connection writer thinks there's room for a packet
|
||||||
long capacity = w.getRemainingCapacity();
|
long capacity = w.getRemainingCapacity();
|
||||||
assertTrue(capacity >= MAX_PACKET_LENGTH);
|
assertTrue(capacity >= MAX_PACKET_LENGTH);
|
||||||
|
|||||||
Reference in New Issue
Block a user