Merge pull request #262 from BeaudanBrown/millisecond-times

Ttl and timestamp milliseconds
This commit is contained in:
Beaudan Campbell-Brown 2019-04-11 13:05:14 +10:00 committed by GitHub
commit 495ddcabab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 8 deletions

View File

@ -14,7 +14,7 @@ class LokiMessageAPI {
}
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
const messageEventData = {

View File

@ -106,8 +106,10 @@ const pow = {
calcTarget(ttl, payloadLen, nonceTrials = PROD_NONCE_TRIALS) {
// payloadLength + NONCE_LEN
const totalLen = JSBI.add(JSBI.BigInt(payloadLen), JSBI.BigInt(NONCE_LEN));
// ttl converted to seconds
const ttlSeconds = JSBI.divide(JSBI.BigInt(ttl), JSBI.BigInt(1000));
// ttl * totalLen
const ttlMult = JSBI.multiply(JSBI.BigInt(ttl), JSBI.BigInt(totalLen));
const ttlMult = JSBI.multiply(ttlSeconds, JSBI.BigInt(totalLen));
// 2^16 - 1
const two16 = JSBI.subtract(
JSBI.exponentiate(JSBI.BigInt(2), JSBI.BigInt(16)), // 2^16

View File

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

View File

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

View File

@ -184,7 +184,7 @@ OutgoingMessage.prototype = {
},
// 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;
try {
await lokiMessageAPI.sendMessage(
@ -345,12 +345,12 @@ OutgoingMessage.prototype = {
}
let ttl;
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') {
ttl = 60; // 1 minute for online broadcast message
ttl = 60 * 1000; // 1 minute for online broadcast message
} else {
const hours = window.getMessageTTL() || 24; // 1 day default for any other message
ttl = hours * 60 * 60;
ttl = hours * 60 * 60 * 1000;
}
return {