Merge pull request #1676 from Bilb/ons-resolve
ONS resolve on start conversation screenpull/1682/head
commit
d5c28c46f9
@ -1,51 +0,0 @@
|
|||||||
|
|
||||||
A TESTER
|
|
||||||
move mentions user to redux for opengroups
|
|
||||||
* MENTIONS opengroupv2
|
|
||||||
|
|
||||||
|
|
||||||
lokiPublicChatAPI
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DELETED
|
|
||||||
LokiPushNotificationServerApi
|
|
||||||
channelAPI.sendMessage
|
|
||||||
dot_net_api
|
|
||||||
loki_public_chat_api
|
|
||||||
tokenlessFileServerAdnAPI
|
|
||||||
channelId
|
|
||||||
publicChat with only a cahnnel of 1
|
|
||||||
loki_file_server_api
|
|
||||||
LokiAppDotNetApi
|
|
||||||
LokiPublicChatFactoryAPI
|
|
||||||
lastPublicMessage
|
|
||||||
getLastRetrievedMessage
|
|
||||||
setLastRetrievedMessage
|
|
||||||
attemptConnection
|
|
||||||
attemptConnectionOneAtATime
|
|
||||||
|
|
||||||
getPublicSendData
|
|
||||||
setPublicSource
|
|
||||||
getPublicSource
|
|
||||||
findOrCreateServer
|
|
||||||
initAPIs
|
|
||||||
OpenGroup.
|
|
||||||
findOrCreateChannel
|
|
||||||
initSpecialConversations
|
|
||||||
updateOpenGroupV1
|
|
||||||
partChannel
|
|
||||||
acceptOpenGroupInvitationV1
|
|
||||||
pollForChannelOnce
|
|
||||||
publicConversatio
|
|
||||||
handleOpenGroupJoinV1
|
|
||||||
setChannelName
|
|
||||||
setChannelAvatar
|
|
||||||
isOpenGroupV1
|
|
||||||
toOpenGroupV1
|
|
||||||
setListOfMembers
|
|
||||||
|
|
||||||
|
|
||||||
lokiFileServerAPI
|
|
||||||
lokiFileServerAPIFactory
|
|
@ -1,121 +0,0 @@
|
|||||||
/* eslint-disable class-methods-use-this */
|
|
||||||
/* global window, Buffer, StringView, dcodeIO */
|
|
||||||
|
|
||||||
class LokiSnodeAPI {
|
|
||||||
// ************** NOTE ***************
|
|
||||||
// This is not used by anything yet,
|
|
||||||
// but should be. Do not remove!!!
|
|
||||||
// ***********************************
|
|
||||||
async getLnsMapping(lnsName, timeout) {
|
|
||||||
// Returns { pubkey, error }
|
|
||||||
// pubkey is
|
|
||||||
// undefined when unconfirmed or no mapping found
|
|
||||||
// string when found
|
|
||||||
// timeout parameter optional (ms)
|
|
||||||
|
|
||||||
// How many nodes to fetch data from?
|
|
||||||
const numRequests = 5;
|
|
||||||
|
|
||||||
// How many nodes must have the same response value?
|
|
||||||
const numRequiredConfirms = 3;
|
|
||||||
|
|
||||||
let ciphertextHex;
|
|
||||||
let pubkey;
|
|
||||||
let error;
|
|
||||||
|
|
||||||
const _ = window.Lodash;
|
|
||||||
|
|
||||||
const input = Buffer.from(lnsName);
|
|
||||||
const output = await window.blake2b(input);
|
|
||||||
const nameHash = dcodeIO.ByteBuffer.wrap(output).toString('base64');
|
|
||||||
|
|
||||||
// Timeouts
|
|
||||||
const maxTimeoutVal = 2 ** 31 - 1;
|
|
||||||
const timeoutPromise = () =>
|
|
||||||
new Promise((_resolve, reject) => setTimeout(() => reject(), timeout || maxTimeoutVal));
|
|
||||||
|
|
||||||
// Get nodes capable of doing LNS
|
|
||||||
const lnsNodes = await window.SnodePool.getNodesMinVersion(
|
|
||||||
window.CONSTANTS.LNS_CAPABLE_NODES_VERSION
|
|
||||||
);
|
|
||||||
|
|
||||||
// Enough nodes?
|
|
||||||
if (lnsNodes.length < numRequiredConfirms) {
|
|
||||||
error = { lnsTooFewNodes: window.i18n('lnsTooFewNodes') };
|
|
||||||
return { pubkey, error };
|
|
||||||
}
|
|
||||||
|
|
||||||
const confirmedNodes = [];
|
|
||||||
|
|
||||||
// Promise is only resolved when a consensus is found
|
|
||||||
let cipherResolve;
|
|
||||||
const cipherPromise = () =>
|
|
||||||
new Promise(resolve => {
|
|
||||||
cipherResolve = resolve;
|
|
||||||
});
|
|
||||||
|
|
||||||
const decryptHex = async cipherHex => {
|
|
||||||
const ciphertext = new Uint8Array(StringView.hexToArrayBuffer(cipherHex));
|
|
||||||
|
|
||||||
const res = await window.decryptLnsEntry(lnsName, ciphertext);
|
|
||||||
const publicKey = StringView.arrayBufferToHex(res);
|
|
||||||
|
|
||||||
return publicKey;
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchFromNode = async node => {
|
|
||||||
const res = await window.NewSnodeAPI._requestLnsMapping(node, nameHash);
|
|
||||||
|
|
||||||
// Do validation
|
|
||||||
if (res && res.result && res.result.status === 'OK') {
|
|
||||||
const hasMapping = res.result.entries && res.result.entries.length > 0;
|
|
||||||
|
|
||||||
const resValue = hasMapping ? res.result.entries[0].encrypted_value : null;
|
|
||||||
|
|
||||||
confirmedNodes.push(resValue);
|
|
||||||
|
|
||||||
if (confirmedNodes.length >= numRequiredConfirms) {
|
|
||||||
if (ciphertextHex) {
|
|
||||||
// Result already found, dont worry
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [winner, count] = _.maxBy(_.entries(_.countBy(confirmedNodes)), x => x[1]);
|
|
||||||
|
|
||||||
if (count >= numRequiredConfirms) {
|
|
||||||
ciphertextHex = winner === String(null) ? null : winner;
|
|
||||||
|
|
||||||
// null represents no LNS mapping
|
|
||||||
if (ciphertextHex === null) {
|
|
||||||
error = { lnsMappingNotFound: window.i18n('lnsMappingNotFound') };
|
|
||||||
}
|
|
||||||
|
|
||||||
cipherResolve({ ciphertextHex });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const nodes = lnsNodes.splice(0, numRequests);
|
|
||||||
|
|
||||||
// Start fetching from nodes
|
|
||||||
nodes.forEach(node => fetchFromNode(node));
|
|
||||||
|
|
||||||
// Timeouts (optional parameter)
|
|
||||||
// Wait for cipher to be found; race against timeout
|
|
||||||
// eslint-disable-next-line more/no-then
|
|
||||||
await Promise.race([cipherPromise, timeoutPromise].map(f => f()))
|
|
||||||
.then(async () => {
|
|
||||||
if (ciphertextHex !== null) {
|
|
||||||
pubkey = await decryptHex(ciphertextHex);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
error = { lnsLookupTimeout: window.i18n('lnsLookupTimeout') };
|
|
||||||
});
|
|
||||||
|
|
||||||
return { pubkey, error };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = LokiSnodeAPI;
|
|
@ -1,10 +0,0 @@
|
|||||||
interface Promise<T> {
|
|
||||||
ignore(): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Types also correspond to messages.json keys
|
|
||||||
enum LnsLookupErrorType {
|
|
||||||
lnsTooFewNodes,
|
|
||||||
lnsLookupTimeout,
|
|
||||||
lnsMappingNotFound,
|
|
||||||
}
|
|
Loading…
Reference in New Issue