Merge pull request #167 from BeaudanBrown/p2p-fixes

P2p logic fixes
pull/168/head
sachaaaaa 6 years ago committed by GitHub
commit 8462864373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,7 +8,7 @@ class LokiP2pAPI extends EventEmitter {
this.contactP2pDetails = {}; this.contactP2pDetails = {};
} }
addContactP2pDetails(pubKey, address, port, resetTimer = false) { updateContactP2pDetails(pubKey, address, port, fromP2p = false) {
// Stagger the timers so the friends don't ping each other at the same time // Stagger the timers so the friends don't ping each other at the same time
this.ourKey = this.ourKey || window.textsecure.storage.user.getNumber(); this.ourKey = this.ourKey || window.textsecure.storage.user.getNumber();
const timerDuration = const timerDuration =
@ -16,12 +16,10 @@ class LokiP2pAPI extends EventEmitter {
? 60 * 1000 // 1 minute ? 60 * 1000 // 1 minute
: 2 * 60 * 1000; // 2 minutes : 2 * 60 * 1000; // 2 minutes
if ( if (this.contactP2pDetails[pubKey]) {
this.contactP2pDetails[pubKey] &&
this.contactP2pDetails[pubKey].pingTimer
) {
clearTimeout(this.contactP2pDetails[pubKey].pingTimer); clearTimeout(this.contactP2pDetails[pubKey].pingTimer);
} }
this.contactP2pDetails[pubKey] = { this.contactP2pDetails[pubKey] = {
address, address,
port, port,
@ -29,16 +27,12 @@ class LokiP2pAPI extends EventEmitter {
isOnline: false, isOnline: false,
pingTimer: null, pingTimer: null,
}; };
if (resetTimer) {
// If this contact is simply sharing the same details with us if (fromP2p) {
// then we just reset our timer this.setContactOnline(pubKey);
this.contactP2pDetails[pubKey].pingTimer = setTimeout(
this.pingContact.bind(this),
this.contactP2pDetails[pubKey].timerDuration,
pubKey
);
return; return;
} }
this.pingContact(pubKey); this.pingContact(pubKey);
} }

@ -908,7 +908,7 @@ MessageReceiver.prototype.extend({
}, },
async handleLokiAddressMessage(envelope, lokiAddressMessage) { async handleLokiAddressMessage(envelope, lokiAddressMessage) {
const { p2pAddress, p2pPort } = lokiAddressMessage; const { p2pAddress, p2pPort } = lokiAddressMessage;
lokiP2pAPI.addContactP2pDetails( lokiP2pAPI.updateContactP2pDetails(
envelope.source, envelope.source,
p2pAddress, p2pAddress,
p2pPort, p2pPort,

Loading…
Cancel
Save