mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Partial implementation of the invitation protocol (untested).
This commit is contained in:
@@ -29,7 +29,7 @@ public abstract class DuplexClientTest extends DuplexTest {
|
||||
}
|
||||
// Try to send an invitation
|
||||
System.out.println("Sending invitation");
|
||||
d = plugin.sendInvitation(123, INVITATION_TIMEOUT);
|
||||
d = plugin.sendInvitation(getPseudoRandom(123), INVITATION_TIMEOUT);
|
||||
if(d == null) {
|
||||
System.out.println("Connection failed");
|
||||
} else {
|
||||
@@ -38,7 +38,7 @@ public abstract class DuplexClientTest extends DuplexTest {
|
||||
}
|
||||
// Try to accept an invitation
|
||||
System.out.println("Accepting invitation");
|
||||
d = plugin.acceptInvitation(456, INVITATION_TIMEOUT);
|
||||
d = plugin.acceptInvitation(getPseudoRandom(456), INVITATION_TIMEOUT);
|
||||
if(d == null) {
|
||||
System.out.println("Connection failed");
|
||||
} else {
|
||||
|
||||
@@ -24,8 +24,8 @@ public abstract class DuplexServerTest extends DuplexTest {
|
||||
callback.latch.await();
|
||||
// Try to accept an invitation
|
||||
System.out.println("Accepting invitation");
|
||||
DuplexTransportConnection d = plugin.acceptInvitation(123,
|
||||
INVITATION_TIMEOUT);
|
||||
DuplexTransportConnection d = plugin.acceptInvitation(
|
||||
getPseudoRandom(123), INVITATION_TIMEOUT);
|
||||
if(d == null) {
|
||||
System.out.println("Connection failed");
|
||||
} else {
|
||||
@@ -34,7 +34,7 @@ public abstract class DuplexServerTest extends DuplexTest {
|
||||
}
|
||||
// Try to send an invitation
|
||||
System.out.println("Sending invitation");
|
||||
d = plugin.sendInvitation(456, INVITATION_TIMEOUT);
|
||||
d = plugin.sendInvitation(getPseudoRandom(456), INVITATION_TIMEOUT);
|
||||
if(d == null) {
|
||||
System.out.println("Connection failed");
|
||||
} else {
|
||||
|
||||
@@ -2,9 +2,11 @@ package net.sf.briar.plugins;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.crypto.PseudoRandom;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexPlugin;
|
||||
import net.sf.briar.api.plugins.duplex.DuplexTransportConnection;
|
||||
|
||||
@@ -66,4 +68,23 @@ abstract class DuplexTest {
|
||||
d.dispose(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
protected PseudoRandom getPseudoRandom(int seed) {
|
||||
return new TestPseudoRandom(seed);
|
||||
}
|
||||
|
||||
private static class TestPseudoRandom implements PseudoRandom {
|
||||
|
||||
private final Random r;
|
||||
|
||||
private TestPseudoRandom(int seed) {
|
||||
r = new Random(seed);
|
||||
}
|
||||
|
||||
public byte[] nextBytes(int bytes) {
|
||||
byte[] b = new byte[bytes];
|
||||
r.nextBytes(b);
|
||||
return b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,19 @@ public class ByteUtilsTest extends BriarTestCase {
|
||||
ByteUtils.writeUint32(4294967295L, b, 1);
|
||||
assertEquals("00FFFFFFFF", StringUtils.toHexString(b));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadUint() {
|
||||
byte[] b = new byte[1];
|
||||
b[0] = (byte) 128;
|
||||
for(int i = 0; i < 8; i++) {
|
||||
assertEquals(1 << i, ByteUtils.readUint(b, i + 1));
|
||||
}
|
||||
b = new byte[2];
|
||||
for(int i = 0; i < 65535; i++) {
|
||||
ByteUtils.writeUint16(i, b, 0);
|
||||
assertEquals(i, ByteUtils.readUint(b, 16));
|
||||
assertEquals(i >> 1, ByteUtils.readUint(b, 15));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user