Merge pull request #326 from BeaudanBrown/check-ips

Run lint and check for ip or address when removing unreachable nodes
pull/328/head
Beaudan Campbell-Brown 6 years ago committed by GitHub
commit 0435050916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -322,7 +322,6 @@
},
shutdown: async () => {
await window.localLokiServer.close();
// Stop background processing

@ -94,7 +94,10 @@ class LokiSnodeAPI {
storage_port: true,
},
};
const seedNode = seedNodes.splice(Math.floor(Math.random() * seedNodes.length), 1)[0];
const seedNode = seedNodes.splice(
Math.floor(Math.random() * seedNodes.length),
1
)[0];
try {
const result = await rpc(
`http://${seedNode.ip}`,
@ -114,7 +117,9 @@ class LokiSnodeAPI {
}));
} catch (e) {
if (seedNodes.length === 0) {
throw new window.textsecure.SeedNodeError('Failed to contact seed node');
throw new window.textsecure.SeedNodeError(
'Failed to contact seed node'
);
}
this.initialiseRandomPool(seedNodes);
}
@ -123,7 +128,9 @@ class LokiSnodeAPI {
async unreachableNode(pubKey, nodeUrl) {
const conversation = ConversationController.get(pubKey);
const swarmNodes = [...conversation.get('swarmNodes')];
const filteredNodes = swarmNodes.filter(node => node.address !== nodeUrl);
const filteredNodes = swarmNodes.filter(
node => node.address !== nodeUrl && node.ip !== nodeUrl
);
await conversation.updateSwarmNodes(filteredNodes);
}

@ -31,8 +31,7 @@
if (!window.localLokiServer.isListening()) {
// Skip if server is not running AND we're not trying to ping a contact
if (!isPing)
return;
if (!isPing) return;
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE;
} else {

@ -88,7 +88,7 @@ class LocalLokiServer extends EventEmitter {
// Start a listening on new server
return new Promise((res, rej) => {
this.server.listen(port, ip, async (err) => {
this.server.listen(port, ip, async err => {
if (err) {
rej(err);
} else if (this.upnpClient) {
@ -117,14 +117,20 @@ class LocalLokiServer extends EventEmitter {
this.upnpClient.getMappings({ local: true }, (err, results) => {
if (err) {
// We assume an error here means upnp not enabled
reject(new textsecure.HolePunchingError('Could not get mapping from upnp. Upnp not available?', err));
}
else {
reject(
new textsecure.HolePunchingError(
'Could not get mapping from upnp. Upnp not available?',
err
)
);
} else {
// remove the current private port from the current mapping
// to allow reusing that port.
resolve(results
resolve(
results
.filter(entry => entry.private.port !== privatePort)
.map(entry => entry.public.port));
.map(entry => entry.public.port)
);
}
});
});
@ -135,16 +141,17 @@ class LocalLokiServer extends EventEmitter {
continue;
}
const p = new Promise((resolve, reject) => {
this.upnpClient.portMapping({
this.upnpClient.portMapping(
{
public: publicPort,
private: privatePort,
ttl,
}, (err) => {
if (err)
reject(err);
else
resolve();
});
},
err => {
if (err) reject(err);
else resolve();
}
);
});
try {
// eslint-disable-next-line no-await-in-loop
@ -159,11 +166,17 @@ class LocalLokiServer extends EventEmitter {
}, ttl * 1000);
return publicPort;
} catch (e) {
throw new textsecure.HolePunchingError('Could not punch hole. Disabled upnp?', e);
throw new textsecure.HolePunchingError(
'Could not punch hole. Disabled upnp?',
e
);
}
}
const e = new Error();
throw new textsecure.HolePunchingError(`Could not punch hole: no available port. Public ports: ${portStart}-${portEnd}`, e);
throw new textsecure.HolePunchingError(
`Could not punch hole: no available port. Public ports: ${portStart}-${portEnd}`,
e
);
}
// Async wrapper for http server close
close() {

@ -59,7 +59,9 @@ describe('LocalLokiServer', () => {
it('should return 404 and a string if invalid enpoint is provided', async () => {
try {
await this.axiosClient.post('https://localhost:8000/invalid', { name: 'Test' });
await this.axiosClient.post('https://localhost:8000/invalid', {
name: 'Test',
});
assert.fail('Got a successful response');
} catch (error) {
if (error.response) {
@ -95,7 +97,10 @@ describe('LocalLokiServer', () => {
});
try {
await this.axiosClient.post('https://localhost:8001/storage_rpc/v1', messageData);
await this.axiosClient.post(
'https://localhost:8001/storage_rpc/v1',
messageData
);
} catch (error) {
assert.isNotOk(error, 'Error occured');
}

@ -131,8 +131,7 @@ MessageReceiver.prototype.extend({
window.log.warn(e.message);
window.log.warn('Abdandoning starting p2p server.');
return;
}
else if (e instanceof textsecure.LokiIpError) {
} else if (e instanceof textsecure.LokiIpError) {
window.log.warn(
'Failed to get my loki address to bind server to, will retry in 30 seconds'
);

Loading…
Cancel
Save