send "unreachable" ping to allow half-p2p
This commit is contained in:
parent
c53633e367
commit
beac7a02bb
|
@ -26,16 +26,29 @@
|
|||
}
|
||||
|
||||
async function sendOnlineBroadcastMessage(pubKey, isPing = false) {
|
||||
if (!window.localLokiServer.isListening())
|
||||
return;
|
||||
// clearnet change: getMyLokiAddress -> getMyClearIP
|
||||
// const myLokiAddress = await window.lokiSnodeAPI.getMyLokiAddress();
|
||||
const myLokiAddress = await window.lokiSnodeAPI.getMyClearIp();
|
||||
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;
|
||||
|
||||
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE;
|
||||
} else {
|
||||
// clearnet change: getMyLokiAddress -> getMyClearIP
|
||||
// const myLokiAddress = await window.lokiSnodeAPI.getMyLokiAddress();
|
||||
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({
|
||||
// clearnet change: http -> https
|
||||
p2pAddress: `https://${myLokiAddress}`,
|
||||
p2pPort: window.localLokiServer.getPublicPort(),
|
||||
p2pAddress,
|
||||
p2pPort,
|
||||
type,
|
||||
});
|
||||
const content = new textsecure.protobuf.Content({
|
||||
lokiAddressMessage,
|
||||
|
|
|
@ -90,12 +90,12 @@ class LocalLokiServer extends EventEmitter {
|
|||
if (err) {
|
||||
rej(err);
|
||||
} else {
|
||||
try{
|
||||
try {
|
||||
const publicPort = await this.punchHole();
|
||||
res(publicPort);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
if (e instanceof textsecure.HolePunchingError)
|
||||
await this.close();
|
||||
await this.close();
|
||||
rej(e);
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ class LocalLokiServer extends EventEmitter {
|
|||
await p;
|
||||
this.publicPort = publicPort;
|
||||
return publicPort;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
// continue
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1002,13 +1002,15 @@ MessageReceiver.prototype.extend({
|
|||
);
|
||||
},
|
||||
async handleLokiAddressMessage(envelope, lokiAddressMessage) {
|
||||
const { p2pAddress, p2pPort } = lokiAddressMessage;
|
||||
lokiP2pAPI.updateContactP2pDetails(
|
||||
envelope.source,
|
||||
p2pAddress,
|
||||
p2pPort,
|
||||
envelope.isP2p
|
||||
);
|
||||
const { p2pAddress, p2pPort, type } = lokiAddressMessage;
|
||||
if (type === textsecure.protobuf.LokiAddressMessage.Type.HOST_REACHABLE) {
|
||||
lokiP2pAPI.updateContactP2pDetails(
|
||||
envelope.source,
|
||||
p2pAddress,
|
||||
p2pPort,
|
||||
envelope.isP2p
|
||||
);
|
||||
}
|
||||
return this.removeFromCache(envelope);
|
||||
},
|
||||
handleDataMessage(envelope, msg) {
|
||||
|
|
|
@ -39,8 +39,13 @@ message Content {
|
|||
}
|
||||
|
||||
message LokiAddressMessage {
|
||||
enum Type {
|
||||
HOST_REACHABLE = 0;
|
||||
HOST_UNREACHABLE = 1;
|
||||
}
|
||||
optional string p2pAddress = 1;
|
||||
optional uint32 p2pPort = 2;
|
||||
optional Type type = 3;
|
||||
}
|
||||
|
||||
message PreKeyBundleMessage {
|
||||
|
|
Loading…
Reference in New Issue