send "unreachable" ping to allow half-p2p

pull/317/head
sachaaaaa 6 years ago
parent c53633e367
commit beac7a02bb

@ -26,16 +26,29 @@
} }
async function sendOnlineBroadcastMessage(pubKey, isPing = false) { async function sendOnlineBroadcastMessage(pubKey, isPing = false) {
if (!window.localLokiServer.isListening()) let p2pAddress = null;
let p2pPort = null;
let type;
if (!window.localLokiServer.isListening()) {
// Skip if server is not running AND we're not trying to ping a contact
if (!isPing)
return; return;
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE;
} else {
// clearnet change: getMyLokiAddress -> getMyClearIP // clearnet change: getMyLokiAddress -> getMyClearIP
// const myLokiAddress = await window.lokiSnodeAPI.getMyLokiAddress(); // const myLokiAddress = await window.lokiSnodeAPI.getMyLokiAddress();
const myLokiAddress = await window.lokiSnodeAPI.getMyClearIp(); const myIp = await window.lokiSnodeAPI.getMyClearIp();
p2pAddress = `https://${myIp}`;
p2pPort = window.localLokiServer.getPublicPort();
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_REACHABLE;
}
const lokiAddressMessage = new textsecure.protobuf.LokiAddressMessage({ const lokiAddressMessage = new textsecure.protobuf.LokiAddressMessage({
// clearnet change: http -> https p2pAddress,
p2pAddress: `https://${myLokiAddress}`, p2pPort,
p2pPort: window.localLokiServer.getPublicPort(), type,
}); });
const content = new textsecure.protobuf.Content({ const content = new textsecure.protobuf.Content({
lokiAddressMessage, lokiAddressMessage,

@ -90,10 +90,10 @@ class LocalLokiServer extends EventEmitter {
if (err) { if (err) {
rej(err); rej(err);
} else { } else {
try{ try {
const publicPort = await this.punchHole(); const publicPort = await this.punchHole();
res(publicPort); res(publicPort);
} catch(e) { } catch (e) {
if (e instanceof textsecure.HolePunchingError) if (e instanceof textsecure.HolePunchingError)
await this.close(); await this.close();
rej(e); rej(e);
@ -139,7 +139,7 @@ class LocalLokiServer extends EventEmitter {
await p; await p;
this.publicPort = publicPort; this.publicPort = publicPort;
return publicPort; return publicPort;
} catch(e) { } catch (e) {
// continue // continue
} }
} }

@ -1002,13 +1002,15 @@ MessageReceiver.prototype.extend({
); );
}, },
async handleLokiAddressMessage(envelope, lokiAddressMessage) { async handleLokiAddressMessage(envelope, lokiAddressMessage) {
const { p2pAddress, p2pPort } = lokiAddressMessage; const { p2pAddress, p2pPort, type } = lokiAddressMessage;
if (type === textsecure.protobuf.LokiAddressMessage.Type.HOST_REACHABLE) {
lokiP2pAPI.updateContactP2pDetails( lokiP2pAPI.updateContactP2pDetails(
envelope.source, envelope.source,
p2pAddress, p2pAddress,
p2pPort, p2pPort,
envelope.isP2p envelope.isP2p
); );
}
return this.removeFromCache(envelope); return this.removeFromCache(envelope);
}, },
handleDataMessage(envelope, msg) { handleDataMessage(envelope, msg) {

@ -39,8 +39,13 @@ message Content {
} }
message LokiAddressMessage { message LokiAddressMessage {
enum Type {
HOST_REACHABLE = 0;
HOST_UNREACHABLE = 1;
}
optional string p2pAddress = 1; optional string p2pAddress = 1;
optional uint32 p2pPort = 2; optional uint32 p2pPort = 2;
optional Type type = 3;
} }
message PreKeyBundleMessage { message PreKeyBundleMessage {

Loading…
Cancel
Save