Merge branch '346-smaller-qr-codes' into 'master'

Encode transport properties more compactly in QR codes

The [original BQP spec](https://code.briarproject.org/akwizgran/briar/wikis/BQP) described a compact encoding for transport properties, with the goal of making the QR code as small as possible. At some point during the implementation, I asked @str4d to use TransportIds and TransportProperties instead, as described in the [current spec](https://code.briarproject.org/akwizgran/briar-spec/blob/master/protocols/BQP.md). That was a mistake.

Using the original format reduces the payload from 60 to 34 bytes (43% smaller) for Bluetooth only, and from 96 to 49 bytes (49% smaller) for Bluetooth and LAN. This makes it easier to scan codes from low-resolution screens using fixed-focus and/or low-resolution cameras. Using this branch I can exchange codes between the Sony Xperia Tipo (320x480 screen, fixed focus, 640x480 preview size) and the Huawei Ascend Y300 (480x800 screen, infinity focus, 1280x720 preview size).

This also removes an obstacle to implementing #558, as TransportIds are no longer included in QR codes.

Closes #346.

See merge request !394
This commit is contained in:
akwizgran
2016-11-08 17:32:26 +00:00
27 changed files with 441 additions and 202 deletions

View File

@@ -4,7 +4,7 @@ package org.briarproject.api.keyagreement;
public interface KeyAgreementConstants {
/** The current version of the BQP protocol. */
byte PROTOCOL_VERSION = 1;
byte PROTOCOL_VERSION = 2;
/** The length of the record header in bytes. */
int RECORD_HEADER_LENGTH = 4;
@@ -16,4 +16,10 @@ public interface KeyAgreementConstants {
int COMMIT_LENGTH = 16;
long CONNECTION_TIMEOUT = 20 * 1000; // Milliseconds
/** The transport identifier for Bluetooth. */
int TRANSPORT_ID_BLUETOOTH = 0;
/** The transport identifier for LAN. */
int TRANSPORT_ID_LAN = 1;
}

View File

@@ -1,5 +1,7 @@
package org.briarproject.api.keyagreement;
import org.briarproject.api.data.BdfList;
import java.util.concurrent.Callable;
/**
@@ -7,9 +9,9 @@ import java.util.concurrent.Callable;
*/
public abstract class KeyAgreementListener {
private final TransportDescriptor descriptor;
private final BdfList descriptor;
public KeyAgreementListener(TransportDescriptor descriptor) {
public KeyAgreementListener(BdfList descriptor) {
this.descriptor = descriptor;
}
@@ -17,7 +19,7 @@ public abstract class KeyAgreementListener {
* Returns the descriptor that a remote peer can use to connect to this
* listener.
*/
public TransportDescriptor getDescriptor() {
public BdfList getDescriptor() {
return descriptor;
}

View File

@@ -1,29 +1,40 @@
package org.briarproject.api.keyagreement;
import org.briarproject.api.Bytes;
import org.briarproject.api.TransportId;
import org.briarproject.api.data.BdfList;
import org.briarproject.api.nullsafety.NotNullByDefault;
import java.util.List;
import java.util.Map;
import javax.annotation.concurrent.Immutable;
/**
* A BQP payload.
*/
@Immutable
@NotNullByDefault
public class Payload implements Comparable<Payload> {
private final Bytes commitment;
private final List<TransportDescriptor> descriptors;
private final Map<TransportId, BdfList> descriptors;
public Payload(byte[] commitment, List<TransportDescriptor> descriptors) {
public Payload(byte[] commitment, Map<TransportId, BdfList> descriptors) {
this.commitment = new Bytes(commitment);
this.descriptors = descriptors;
}
/** Returns the commitment contained in this payload. */
/**
* Returns the commitment contained in this payload.
*/
public byte[] getCommitment() {
return commitment.getBytes();
}
/** Returns the transport descriptors contained in this payload. */
public List<TransportDescriptor> getTransportDescriptors() {
/**
* Returns the transport descriptors contained in this payload.
*/
public Map<TransportId, BdfList> getTransportDescriptors() {
return descriptors;
}

View File

@@ -1,7 +1,10 @@
package org.briarproject.api.keyagreement;
import org.briarproject.api.nullsafety.NotNullByDefault;
import java.io.IOException;
@NotNullByDefault
public interface PayloadParser {
Payload parse(byte[] raw) throws IOException;

View File

@@ -1,28 +0,0 @@
package org.briarproject.api.keyagreement;
import org.briarproject.api.TransportId;
import org.briarproject.api.properties.TransportProperties;
/**
* Describes how to connect to a device over a short-range transport.
*/
public class TransportDescriptor {
private final TransportId id;
private final TransportProperties properties;
public TransportDescriptor(TransportId id, TransportProperties properties) {
this.id = id;
this.properties = properties;
}
/** Returns the transport identifier. */
public TransportId getIdentifier() {
return id;
}
/** Returns the transport properties. */
public TransportProperties getProperties() {
return properties;
}
}

View File

@@ -2,28 +2,42 @@ package org.briarproject.api.plugins;
import org.briarproject.api.TransportId;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.nullsafety.NotNullByDefault;
import java.io.IOException;
import java.util.Collection;
@NotNullByDefault
public interface Plugin {
/** Returns the plugin's transport identifier. */
/**
* Returns the plugin's transport identifier.
*/
TransportId getId();
/** Returns the transport's maximum latency in milliseconds. */
/**
* Returns the transport's maximum latency in milliseconds.
*/
int getMaxLatency();
/** Returns the transport's maximum idle time in milliseconds. */
/**
* Returns the transport's maximum idle time in milliseconds.
*/
int getMaxIdleTime();
/** Starts the plugin and returns true if it started successfully. */
/**
* Starts the plugin and returns true if it started successfully.
*/
boolean start() throws IOException;
/** Stops the plugin. */
/**
* Stops the plugin.
*/
void stop() throws IOException;
/** Returns true if the plugin is running. */
/**
* Returns true if the plugin is running.
*/
boolean isRunning();
/**

View File

@@ -1,21 +1,26 @@
package org.briarproject.api.plugins;
import org.briarproject.api.TransportId;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.plugins.duplex.DuplexPlugin;
import org.briarproject.api.plugins.simplex.SimplexPlugin;
import java.util.Collection;
import javax.annotation.Nullable;
/**
* Responsible for starting transport plugins at startup and stopping them at
* shutdown.
*/
@NotNullByDefault
public interface PluginManager {
/**
* Returns the plugin for the given transport, or null if no such plugin
* has been created.
*/
@Nullable
Plugin getPlugin(TransportId t);
/**

View File

@@ -2,21 +2,30 @@ package org.briarproject.api.plugins.duplex;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.crypto.PseudoRandom;
import org.briarproject.api.data.BdfList;
import org.briarproject.api.keyagreement.KeyAgreementListener;
import org.briarproject.api.keyagreement.TransportDescriptor;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.plugins.Plugin;
/** An interface for transport plugins that support duplex communication. */
import javax.annotation.Nullable;
/**
* An interface for transport plugins that support duplex communication.
*/
@NotNullByDefault
public interface DuplexPlugin extends Plugin {
/**
* Attempts to create and return a connection to the given contact using
* the current transport and configuration properties. Returns null if a
* connection could not be created.
* connection cannot be created.
*/
@Nullable
DuplexTransportConnection createConnection(ContactId c);
/** Returns true if the plugin supports exchanging invitations. */
/**
* Returns true if the plugin supports exchanging invitations.
*/
boolean supportsInvitations();
/**
@@ -24,21 +33,27 @@ public interface DuplexPlugin extends Plugin {
* peer. Returns null if no connection can be established within the given
* time.
*/
@Nullable
DuplexTransportConnection createInvitationConnection(PseudoRandom r,
long timeout, boolean alice);
/** Returns true if the plugin supports short-range key agreement. */
/**
* Returns true if the plugin supports short-range key agreement.
*/
boolean supportsKeyAgreement();
/**
* Returns a listener that can be used to perform key agreement.
* Attempts to create and return a listener that can be used to perform key
* agreement. Returns null if a listener cannot be created.
*/
@Nullable
KeyAgreementListener createKeyAgreementListener(byte[] localCommitment);
/**
* Attempts to connect to the remote peer specified in the given descriptor.
* Returns null if no connection can be established within the given time.
*/
@Nullable
DuplexTransportConnection createKeyAgreementConnection(
byte[] remoteCommitment, TransportDescriptor d, long timeout);
byte[] remoteCommitment, BdfList descriptor, long timeout);
}

View File

@@ -1,24 +1,32 @@
package org.briarproject.api.plugins.simplex;
import org.briarproject.api.contact.ContactId;
import org.briarproject.api.nullsafety.NotNullByDefault;
import org.briarproject.api.plugins.Plugin;
import org.briarproject.api.plugins.TransportConnectionReader;
import org.briarproject.api.plugins.TransportConnectionWriter;
/** An interface for transport plugins that support simplex communication. */
import javax.annotation.Nullable;
/**
* An interface for transport plugins that support simplex communication.
*/
@NotNullByDefault
public interface SimplexPlugin extends Plugin {
/**
* Attempts to create and return a reader for the given contact using the
* current transport and configuration properties. Returns null if a reader
* could not be created.
* cannot be created.
*/
@Nullable
TransportConnectionReader createReader(ContactId c);
/**
* Attempts to create and return a writer for the given contact using the
* current transport and configuration properties. Returns null if a writer
* could not be created.
* cannot be created.
*/
@Nullable
TransportConnectionWriter createWriter(ContactId c);
}