mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Add public key to pending contacts.
This commit is contained in:
@@ -77,7 +77,8 @@ public interface ContactManager {
|
||||
Collection<PendingContact> getPendingContacts();
|
||||
|
||||
/**
|
||||
* Removes a {@link PendingContact} that is in state {@link FAILED}.
|
||||
* Removes a {@link PendingContact} that is in state
|
||||
* {@link PendingContactState FAILED}.
|
||||
*/
|
||||
void removePendingContact(PendingContact pendingContact);
|
||||
|
||||
|
||||
@@ -9,13 +9,15 @@ import javax.annotation.concurrent.Immutable;
|
||||
public class PendingContact {
|
||||
|
||||
private final PendingContactId id;
|
||||
private final byte[] publicKey;
|
||||
private final String alias;
|
||||
private final PendingContactState state;
|
||||
private final long timestamp;
|
||||
|
||||
public PendingContact(PendingContactId id, String alias,
|
||||
PendingContactState state, long timestamp) {
|
||||
public PendingContact(PendingContactId id, byte[] publicKey,
|
||||
String alias, PendingContactState state, long timestamp) {
|
||||
this.id = id;
|
||||
this.publicKey = publicKey;
|
||||
this.alias = alias;
|
||||
this.state = state;
|
||||
this.timestamp = timestamp;
|
||||
@@ -25,6 +27,10 @@ public class PendingContact {
|
||||
return id;
|
||||
}
|
||||
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
@@ -47,5 +53,4 @@ public class PendingContact {
|
||||
return o instanceof PendingContact &&
|
||||
id.equals(((PendingContact) o).id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -149,8 +149,10 @@ public class TestUtils {
|
||||
|
||||
public static PendingContact getPendingContact(int nameLength) {
|
||||
PendingContactId id = new PendingContactId(getRandomId());
|
||||
byte[] publicKey = getRandomBytes(MAX_PUBLIC_KEY_LENGTH);
|
||||
String alias = getRandomString(nameLength);
|
||||
return new PendingContact(id, alias, WAITING_FOR_CONNECTION, timestamp);
|
||||
return new PendingContact(id, publicKey, alias, WAITING_FOR_CONNECTION,
|
||||
timestamp);
|
||||
}
|
||||
|
||||
public static double getMedian(Collection<? extends Number> samples) {
|
||||
|
||||
@@ -32,6 +32,7 @@ import javax.inject.Inject;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.briarproject.bramble.api.contact.PendingContactState.WAITING_FOR_CONNECTION;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_AUTHOR_NAME_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorConstants.MAX_PUBLIC_KEY_LENGTH;
|
||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.OURSELVES;
|
||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNKNOWN;
|
||||
import static org.briarproject.bramble.api.identity.AuthorInfo.Status.UNVERIFIED;
|
||||
@@ -123,8 +124,8 @@ class ContactManagerImpl implements ContactManager {
|
||||
public PendingContact addRemoteContactRequest(String link, String alias) {
|
||||
// TODO replace with real implementation
|
||||
PendingContactId id = new PendingContactId(link.getBytes());
|
||||
return new PendingContact(id, alias, WAITING_FOR_CONNECTION,
|
||||
System.currentTimeMillis());
|
||||
return new PendingContact(id, new byte[MAX_PUBLIC_KEY_LENGTH], alias,
|
||||
WAITING_FOR_CONNECTION, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -291,6 +291,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
private static final String CREATE_PENDING_CONTACTS =
|
||||
"CREATE TABLE pendingContacts"
|
||||
+ " (pendingContactId _HASH NOT NULL,"
|
||||
+ " publicKey _BINARY NOT NULL,"
|
||||
+ " alias _STRING NOT NULL,"
|
||||
+ " state INT NOT NULL,"
|
||||
+ " timestamp BIGINT NOT NULL,"
|
||||
@@ -1057,13 +1058,14 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
String sql = "INSERT INTO pendingContacts (pendingContactId,"
|
||||
+ " alias, state, timestamp)"
|
||||
+ " VALUES (?, ?, ?, ?)";
|
||||
+ " publicKey, alias, state, timestamp)"
|
||||
+ " VALUES (?, ?, ?, ?, ?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, p.getId().getBytes());
|
||||
ps.setString(2, p.getAlias());
|
||||
ps.setInt(3, p.getState().getValue());
|
||||
ps.setLong(4, p.getTimestamp());
|
||||
ps.setBytes(2, p.getPublicKey());
|
||||
ps.setString(3, p.getAlias());
|
||||
ps.setInt(4, p.getState().getValue());
|
||||
ps.setLong(5, p.getTimestamp());
|
||||
int affected = ps.executeUpdate();
|
||||
if (affected != 1) throw new DbStateException();
|
||||
ps.close();
|
||||
@@ -2372,19 +2374,21 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
Statement s = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT pendingContactId, alias, state, timestamp"
|
||||
String sql = "SELECT pendingContactId, publicKey, alias, state,"
|
||||
+ " timestamp"
|
||||
+ " FROM pendingContacts";
|
||||
s = txn.createStatement();
|
||||
rs = s.executeQuery(sql);
|
||||
List<PendingContact> pendingContacts = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
PendingContactId id = new PendingContactId(rs.getBytes(1));
|
||||
String alias = rs.getString(2);
|
||||
byte[] publicKey = rs.getBytes(2);
|
||||
String alias = rs.getString(3);
|
||||
PendingContactState state =
|
||||
PendingContactState.fromValue(rs.getInt(3));
|
||||
long timestamp = rs.getLong(4);
|
||||
pendingContacts.add(new PendingContact(id, alias, state,
|
||||
timestamp));
|
||||
PendingContactState.fromValue(rs.getInt(4));
|
||||
long timestamp = rs.getLong(5);
|
||||
pendingContacts.add(new PendingContact(id, publicKey, alias,
|
||||
state, timestamp));
|
||||
}
|
||||
rs.close();
|
||||
s.close();
|
||||
|
||||
@@ -46,6 +46,7 @@ class Migration41_42 implements Migration<Connection> {
|
||||
+ " DROP COLUMN contactId");
|
||||
s.execute(dbTypes.replaceTypes("CREATE TABLE pendingContacts"
|
||||
+ " (pendingContactId _HASH NOT NULL,"
|
||||
+ " publicKey _BINARY NOT NULL,"
|
||||
+ " alias _STRING NOT NULL,"
|
||||
+ " state INT NOT NULL,"
|
||||
+ " timestamp BIGINT NOT NULL,"
|
||||
|
||||
Reference in New Issue
Block a user