Multiple all ttl values by 1000 and stop dividing timestamp by 1000 so they are both milliseconds

pull/262/head
Beaudan 6 years ago
parent ff452cd7f0
commit db8f8ba36f

@ -14,7 +14,7 @@ class LokiMessageAPI {
} }
async sendMessage(pubKey, data, messageTimeStamp, ttl, isPing = false) { async sendMessage(pubKey, data, messageTimeStamp, ttl, isPing = false) {
const timestamp = Math.floor(Date.now() / 1000); const timestamp = Date.now();
// Data required to identify a message in a conversation // Data required to identify a message in a conversation
const messageEventData = { const messageEventData = {

@ -76,7 +76,8 @@ const pow = {
const nonceTrials = const nonceTrials =
_nonceTrials || (development ? DEV_NONCE_TRIALS : PROD_NONCE_TRIALS); _nonceTrials || (development ? DEV_NONCE_TRIALS : PROD_NONCE_TRIALS);
const target = pow.calcTarget(ttl, payload.length, nonceTrials); // ttl always calculated from hour values, so this floor is redundant
const target = pow.calcTarget(Math.floor(ttl/1000), payload.length, nonceTrials);
let nonce = new Uint8Array(NONCE_LEN); let nonce = new Uint8Array(NONCE_LEN);
nonce = pow.incrementNonce(nonce, startNonce); // initial value nonce = pow.incrementNonce(nonce, startNonce); // initial value

@ -25,7 +25,7 @@ async function run(messageLength, numWorkers = 1, nonceTrials = 100, ttl = 72) {
jobId, jobId,
'calcPoW', 'calcPoW',
timestamp, timestamp,
ttl * 60 * 60, ttl * 60 * 60 * 1000,
pubKey, pubKey,
data, data,
false, false,

@ -46,7 +46,7 @@ describe('Proof of Work', () => {
it('should calculate a correct difficulty target', () => { it('should calculate a correct difficulty target', () => {
// These values will need to be updated if we adjust the difficulty settings // These values will need to be updated if we adjust the difficulty settings
let payloadLen = 625; let payloadLen = 625;
const ttl = 86400; const ttl = 86400000;
let expectedTarget = new Uint8Array([0, 4, 119, 164, 35, 224, 222, 64]); let expectedTarget = new Uint8Array([0, 4, 119, 164, 35, 224, 222, 64]);
let actualTarget = calcTarget(ttl, payloadLen, 10); let actualTarget = calcTarget(ttl, payloadLen, 10);

@ -184,7 +184,7 @@ OutgoingMessage.prototype = {
}, },
// Default ttl to 24 hours if no value provided // Default ttl to 24 hours if no value provided
async transmitMessage(number, data, timestamp, ttl = 24 * 60 * 60) { async transmitMessage(number, data, timestamp, ttl = 24 * 60 * 60 * 1000) {
const pubKey = number; const pubKey = number;
try { try {
await lokiMessageAPI.sendMessage( await lokiMessageAPI.sendMessage(
@ -345,12 +345,12 @@ OutgoingMessage.prototype = {
} }
let ttl; let ttl;
if (this.messageType === 'friend-request') { if (this.messageType === 'friend-request') {
ttl = 4 * 24 * 60 * 60; // 4 days for friend request message ttl = 4 * 24 * 60 * 60 * 1000; // 4 days for friend request message
} else if (this.messageType === 'onlineBroadcast') { } else if (this.messageType === 'onlineBroadcast') {
ttl = 60; // 1 minute for online broadcast message ttl = 60 * 1000; // 1 minute for online broadcast message
} else { } else {
const hours = window.getMessageTTL() || 24; // 1 day default for any other message const hours = window.getMessageTTL() || 24; // 1 day default for any other message
ttl = hours * 60 * 60; ttl = hours * 60 * 60 * 1000;
} }
return { return {

Loading…
Cancel
Save