Added ability to look up our .loki address and now send that with our LokiAddress messages

pull/196/head
Beaudan 6 years ago
parent 92ff7a1995
commit 6426a5eb9b

@ -1,5 +1,6 @@
{
"serverUrl": "random.snode",
"localUrl": "localhost.loki",
"cdnUrl": "random.snode",
"localServerPort": "8081",
"messageServerPort": "8080",

@ -9,29 +9,38 @@ const dns = require('dns');
const MINIMUM_SWARM_NODES = 1;
const FAILURE_THRESHOLD = 3;
const resolveCname = url =>
new Promise((resolve, reject) => {
dns.resolveCname(url, (err, address) => {
if (err) {
reject(err);
} else {
resolve(address[0]);
}
});
});
class LokiSnodeAPI {
constructor({ url, swarmServerPort }) {
if (!is.string(url)) {
constructor({ serverUrl, localUrl, swarmServerPort }) {
if (!is.string(serverUrl)) {
throw new Error('WebAPI.initialize: Invalid server url');
}
this.url = url;
this.serverUrl = serverUrl;
this.localUrl = localUrl;
this.swarmServerPort = swarmServerPort ? `:${swarmServerPort}` : '';
this.swarmsPendingReplenish = {};
this.ourSwarmNodes = {};
this.contactSwarmNodes = {};
}
async getMySnodeAddress() {
/* resolve our local loki address */
return resolveCname(this.localUrl);
}
getRandomSnodeAddress() {
/* resolve random snode */
return new Promise((resolve, reject) => {
dns.resolveCname(this.url, (err, address) => {
if (err) {
reject(err);
} else {
resolve(address[0]);
}
});
});
return resolveCname(this.serverUrl);
}
async unreachableNode(pubKey, nodeUrl) {

@ -24,8 +24,9 @@
}
async function sendOnlineBroadcastMessage(pubKey, forceP2p = false) {
const myLokiAddress = await window.lokiSnodeAPI.getMySnodeAddress();
const lokiAddressMessage = new textsecure.protobuf.LokiAddressMessage({
p2pAddress: 'http://localhost',
p2pAddress: `http://${myLokiAddress}`,
p2pPort: parseInt(window.localServerPort, 10),
});
const content = new textsecure.protobuf.Content({

@ -144,6 +144,7 @@ function prepareURL(pathSegments, moreKeys) {
version: app.getVersion(),
buildExpiration: config.get('buildExpiration'),
serverUrl: config.get('serverUrl'),
localUrl: config.get('localUrl'),
cdnUrl: config.get('cdnUrl'),
messageServerPort: config.get('messageServerPort'),
swarmServerPort: config.get('swarmServerPort'),

@ -289,7 +289,8 @@ window.WebAPI = initializeWebAPI({
const LokiSnodeAPI = require('./js/modules/loki_snode_api');
window.lokiSnodeAPI = new LokiSnodeAPI({
url: config.serverUrl,
serverUrl: config.serverUrl,
localUrl: config.localUrl,
swarmServerPort: config.swarmServerPort,
});

Loading…
Cancel
Save