Added function for getting your loki IP and bind the local server

pull/196/head
Beaudan 6 years ago
parent 6426a5eb9b
commit 2fd746821a

@ -9,6 +9,17 @@ const dns = require('dns');
const MINIMUM_SWARM_NODES = 1;
const FAILURE_THRESHOLD = 3;
const resolve4 = url =>
new Promise((resolve, reject) => {
dns.resolve4(url, (err, ip) => {
if (err) {
reject(err);
} else {
resolve(ip);
}
});
});
const resolveCname = url =>
new Promise((resolve, reject) => {
dns.resolveCname(url, (err, address) => {
@ -33,7 +44,12 @@ class LokiSnodeAPI {
this.contactSwarmNodes = {};
}
async getMySnodeAddress() {
async getMyLokiIp() {
const address = await resolveCname(this.localUrl);
return resolve4(address);
}
async getMyLokiAddress() {
/* resolve our local loki address */
return resolveCname(this.localUrl);
}

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

@ -50,13 +50,13 @@ class LocalLokiServer extends EventEmitter {
});
}
async start(port) {
async start(port, ip) {
// Close the old server
await this.close();
// Start a listening on new server
return new Promise((res, rej) => {
this.server.listen(port, err => {
this.server.listen(port, ip, err => {
if (err) {
rej(err);
} else {

@ -83,11 +83,12 @@ MessageReceiver.prototype.extend({
this.onEmpty();
}
});
localLokiServer.start(localServerPort).then(port => {
window.log.info(`Local Server started at localhost:${port}`);
libloki.api.broadcastOnlineStatus();
localLokiServer.on('message', this.handleP2pMessage.bind(this));
window.lokiSnodeAPI.getMyLokiIp().then(myLokiIp => {
localLokiServer.start(localServerPort, myLokiIp).then(port => {
window.log.info(`Local Server started at localhost:${port}`);
libloki.api.broadcastOnlineStatus();
localLokiServer.on('message', this.handleP2pMessage.bind(this));
});
});
// TODO: Rework this socket stuff to work with online messaging

Loading…
Cancel
Save