mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Rename getOnionAddress() to getBaseUrl()
This can later include a version parameter as well.
This commit is contained in:
@@ -8,19 +8,19 @@ import javax.annotation.concurrent.Immutable;
|
|||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
public class MailboxProperties {
|
public class MailboxProperties {
|
||||||
|
|
||||||
private final String onionAddress;
|
private final String baseUrl;
|
||||||
private final MailboxAuthToken authToken;
|
private final MailboxAuthToken authToken;
|
||||||
private final boolean owner;
|
private final boolean owner;
|
||||||
|
|
||||||
public MailboxProperties(String onionAddress, MailboxAuthToken authToken,
|
public MailboxProperties(String baseUrl, MailboxAuthToken authToken,
|
||||||
boolean owner) {
|
boolean owner) {
|
||||||
this.onionAddress = onionAddress;
|
this.baseUrl = baseUrl;
|
||||||
this.authToken = authToken;
|
this.authToken = authToken;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOnionAddress() {
|
public String getBaseUrl() {
|
||||||
return onionAddress;
|
return baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MailboxAuthToken getAuthToken() {
|
public MailboxAuthToken getAuthToken() {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class MailboxApiImpl implements MailboxApi {
|
|||||||
throws IOException, ApiException {
|
throws IOException, ApiException {
|
||||||
if (!properties.isOwner()) throw new IllegalArgumentException();
|
if (!properties.isOwner()) throw new IllegalArgumentException();
|
||||||
Request request = getRequestBuilder(properties.getAuthToken())
|
Request request = getRequestBuilder(properties.getAuthToken())
|
||||||
.url(properties.getOnionAddress() + "/setup")
|
.url(properties.getBaseUrl() + "/setup")
|
||||||
.put(EMPTY_REQUEST)
|
.put(EMPTY_REQUEST)
|
||||||
.build();
|
.build();
|
||||||
OkHttpClient client = httpClientProvider.get();
|
OkHttpClient client = httpClientProvider.get();
|
||||||
@@ -108,7 +108,7 @@ class MailboxApiImpl implements MailboxApi {
|
|||||||
public void deleteContact(MailboxProperties properties, ContactId contactId)
|
public void deleteContact(MailboxProperties properties, ContactId contactId)
|
||||||
throws IOException, ApiException, TolerableFailureException {
|
throws IOException, ApiException, TolerableFailureException {
|
||||||
if (!properties.isOwner()) throw new IllegalArgumentException();
|
if (!properties.isOwner()) throw new IllegalArgumentException();
|
||||||
String url = properties.getOnionAddress() + "/contacts/" +
|
String url = properties.getBaseUrl() + "/contacts/" +
|
||||||
contactId.getInt();
|
contactId.getInt();
|
||||||
Request request = getRequestBuilder(properties.getAuthToken())
|
Request request = getRequestBuilder(properties.getAuthToken())
|
||||||
.delete()
|
.delete()
|
||||||
@@ -212,7 +212,7 @@ class MailboxApiImpl implements MailboxApi {
|
|||||||
String path = "/files/" + folderId + "/" + fileId;
|
String path = "/files/" + folderId + "/" + fileId;
|
||||||
Request request = getRequestBuilder(properties.getAuthToken())
|
Request request = getRequestBuilder(properties.getAuthToken())
|
||||||
.delete()
|
.delete()
|
||||||
.url(properties.getOnionAddress() + path)
|
.url(properties.getBaseUrl() + path)
|
||||||
.build();
|
.build();
|
||||||
OkHttpClient client = httpClientProvider.get();
|
OkHttpClient client = httpClientProvider.get();
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
@@ -254,7 +254,7 @@ class MailboxApiImpl implements MailboxApi {
|
|||||||
private Response sendGetRequest(MailboxProperties properties, String path)
|
private Response sendGetRequest(MailboxProperties properties, String path)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Request request = getRequestBuilder(properties.getAuthToken())
|
Request request = getRequestBuilder(properties.getAuthToken())
|
||||||
.url(properties.getOnionAddress() + path)
|
.url(properties.getBaseUrl() + path)
|
||||||
.build();
|
.build();
|
||||||
OkHttpClient client = httpClientProvider.get();
|
OkHttpClient client = httpClientProvider.get();
|
||||||
return client.newCall(request).execute();
|
return client.newCall(request).execute();
|
||||||
@@ -263,7 +263,7 @@ class MailboxApiImpl implements MailboxApi {
|
|||||||
private Response sendPostRequest(MailboxProperties properties, String path,
|
private Response sendPostRequest(MailboxProperties properties, String path,
|
||||||
RequestBody body) throws IOException {
|
RequestBody body) throws IOException {
|
||||||
Request request = getRequestBuilder(properties.getAuthToken())
|
Request request = getRequestBuilder(properties.getAuthToken())
|
||||||
.url(properties.getOnionAddress() + path)
|
.url(properties.getBaseUrl() + path)
|
||||||
.post(body)
|
.post(body)
|
||||||
.build();
|
.build();
|
||||||
OkHttpClient client = httpClientProvider.get();
|
OkHttpClient client = httpClientProvider.get();
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
|
|||||||
}
|
}
|
||||||
MailboxAuthToken ownerToken = api.setup(mailboxProperties);
|
MailboxAuthToken ownerToken = api.setup(mailboxProperties);
|
||||||
MailboxProperties ownerProperties = new MailboxProperties(
|
MailboxProperties ownerProperties = new MailboxProperties(
|
||||||
mailboxProperties.getOnionAddress(), ownerToken, true);
|
mailboxProperties.getBaseUrl(), ownerToken, true);
|
||||||
db.transaction(false, txn -> mailboxSettingsManager
|
db.transaction(false, txn -> mailboxSettingsManager
|
||||||
.setOwnMailboxProperties(txn, ownerProperties));
|
.setOwnMailboxProperties(txn, ownerProperties));
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
@@ -158,9 +158,10 @@ class MailboxPairingTaskImpl implements MailboxPairingTask {
|
|||||||
LOG.info("QR code is valid");
|
LOG.info("QR code is valid");
|
||||||
byte[] onionPubKey = Arrays.copyOfRange(bytes, 1, 33);
|
byte[] onionPubKey = Arrays.copyOfRange(bytes, 1, 33);
|
||||||
String onionAddress = crypto.encodeOnionAddress(onionPubKey);
|
String onionAddress = crypto.encodeOnionAddress(onionPubKey);
|
||||||
|
String baseUrl = "http://" + onionAddress + ".onion";
|
||||||
byte[] tokenBytes = Arrays.copyOfRange(bytes, 33, 65);
|
byte[] tokenBytes = Arrays.copyOfRange(bytes, 33, 65);
|
||||||
MailboxAuthToken setupToken = new MailboxAuthToken(tokenBytes);
|
MailboxAuthToken setupToken = new MailboxAuthToken(tokenBytes);
|
||||||
return new MailboxProperties(onionAddress, setupToken, true);
|
return new MailboxProperties(baseUrl, setupToken, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class MailboxSettingsManagerImpl implements MailboxSettingsManager {
|
|||||||
public void setOwnMailboxProperties(Transaction txn, MailboxProperties p)
|
public void setOwnMailboxProperties(Transaction txn, MailboxProperties p)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
Settings s = new Settings();
|
Settings s = new Settings();
|
||||||
s.put(SETTINGS_KEY_ONION, p.getOnionAddress());
|
s.put(SETTINGS_KEY_ONION, p.getBaseUrl());
|
||||||
s.put(SETTINGS_KEY_TOKEN, p.getAuthToken().toString());
|
s.put(SETTINGS_KEY_TOKEN, p.getAuthToken().toString());
|
||||||
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
settingsManager.mergeSettings(txn, s, SETTINGS_NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class MailboxIntegrationTest extends BrambleTestCase {
|
|||||||
ContactId contactId = new ContactId(1);
|
ContactId contactId = new ContactId(1);
|
||||||
MailboxContact contact = getMailboxContact(contactId);
|
MailboxContact contact = getMailboxContact(contactId);
|
||||||
MailboxProperties contactProperties = new MailboxProperties(
|
MailboxProperties contactProperties = new MailboxProperties(
|
||||||
ownerProperties.getOnionAddress(), contact.token, false);
|
ownerProperties.getBaseUrl(), contact.token, false);
|
||||||
api.addContact(ownerProperties, contact);
|
api.addContact(ownerProperties, contact);
|
||||||
|
|
||||||
// upload a file for our contact
|
// upload a file for our contact
|
||||||
|
|||||||
@@ -44,15 +44,16 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
private final String onion = getRandomString(64);
|
private final String onion = getRandomString(64);
|
||||||
private final byte[] onionBytes = getRandomBytes(32);
|
private final byte[] onionBytes = getRandomBytes(32);
|
||||||
|
private final String onionAddress = "http://" + onion + ".onion";
|
||||||
private final MailboxAuthToken setupToken =
|
private final MailboxAuthToken setupToken =
|
||||||
new MailboxAuthToken(getRandomId());
|
new MailboxAuthToken(getRandomId());
|
||||||
private final MailboxAuthToken ownerToken =
|
private final MailboxAuthToken ownerToken =
|
||||||
new MailboxAuthToken(getRandomId());
|
new MailboxAuthToken(getRandomId());
|
||||||
private final String validPayload = getValidPayload();
|
private final String validPayload = getValidPayload();
|
||||||
private final MailboxProperties setupProperties =
|
private final MailboxProperties setupProperties =
|
||||||
new MailboxProperties(onion, setupToken, true);
|
new MailboxProperties(onionAddress, setupToken, true);
|
||||||
private final MailboxProperties ownerProperties =
|
private final MailboxProperties ownerProperties =
|
||||||
new MailboxProperties(onion, ownerToken, true);
|
new MailboxProperties(onionAddress, ownerToken, true);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInitialQrCodeReceivedState() {
|
public void testInitialQrCodeReceivedState() {
|
||||||
@@ -180,7 +181,7 @@ public class MailboxPairingTaskImplTest extends BrambleMockTestCase {
|
|||||||
private PredicateMatcher<MailboxProperties> matches(MailboxProperties p2) {
|
private PredicateMatcher<MailboxProperties> matches(MailboxProperties p2) {
|
||||||
return new PredicateMatcher<>(MailboxProperties.class, p1 ->
|
return new PredicateMatcher<>(MailboxProperties.class, p1 ->
|
||||||
p1.getAuthToken().equals(p2.getAuthToken()) &&
|
p1.getAuthToken().equals(p2.getAuthToken()) &&
|
||||||
p1.getOnionAddress().equals(p2.getOnionAddress()) &&
|
p1.getBaseUrl().equals(p2.getBaseUrl()) &&
|
||||||
p1.isOwner() == p2.isOwner());
|
p1.isOwner() == p2.isOwner());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class MailboxSettingsManagerImplTest extends BrambleMockTestCase {
|
|||||||
|
|
||||||
MailboxProperties properties = manager.getOwnMailboxProperties(txn);
|
MailboxProperties properties = manager.getOwnMailboxProperties(txn);
|
||||||
assertNotNull(properties);
|
assertNotNull(properties);
|
||||||
assertEquals(onion, properties.getOnionAddress());
|
assertEquals(onion, properties.getBaseUrl());
|
||||||
assertEquals(token, properties.getAuthToken());
|
assertEquals(token, properties.getAuthToken());
|
||||||
assertTrue(properties.isOwner());
|
assertTrue(properties.isOwner());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user