Merge branch 'clearnet' into sender-keys

This commit is contained in:
Ryan Tharp 2020-05-13 23:47:49 -07:00 committed by GitHub
commit ead2f62b6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 128 additions and 37 deletions

View File

@ -6,20 +6,16 @@
"defaultPoWDifficulty": "1",
"seedNodeList": [
{
"ip": "public.loki.foundation",
"port": "22023"
"ip_url": "http://116.203.53.213/",
"url": "https://storage.seed1.loki.network/"
},
{
"ip": "storage.seed1.loki.network",
"port": "22023"
"ip_url": "http://212.199.114.66/",
"url": "https://storage.seed3.loki.network/"
},
{
"ip": "storage.seed2.loki.network",
"port": "38157"
},
{
"ip": "imaginary.stream",
"port": "38157"
"ip_url": "http://144.76.164.202/",
"url": "https://public.loki.foundation/"
}
],
"updatesEnabled": false,

View File

@ -1,8 +1,8 @@
{
"seedNodeList": [
{
"ip": "public.loki.foundation",
"port": "38157"
"url": "http://public.loki.foundation:38157/",
"ip_url": "http://144.76.164.202:38157/"
}
],
"openDevTools": true,

View File

@ -1,8 +1,8 @@
{
"seedNodeList": [
{
"ip": "127.0.0.1",
"port": "22129"
"ip_url": "http://127.0.0.1:22129/",
"url": "http://localhost:22129/"
}
],
"openDevTools": true,

View File

@ -1418,6 +1418,11 @@
});
Whisper.events.on('deviceUnpairingRequested', async (pubKey, callback) => {
const isSecondaryDevice = !!textsecure.storage.get('isSecondaryDevice');
if (isSecondaryDevice) {
return;
}
await libloki.storage.removePairingAuthorisationForSecondaryPubKey(
pubKey
);

View File

@ -607,6 +607,7 @@
hasSentFriendRequest: this.hasSentFriendRequest(),
isBlocked: this.isBlocked(),
isSecondary: !!this.get('secondaryStatus'),
primaryDevice: this.getPrimaryDevicePubKey(),
phoneNumber: format(this.id, {
ourRegionCode: regionCode,
}),

View File

@ -1,5 +1,5 @@
/* eslint-disable class-methods-use-this */
/* global window, textsecure, ConversationController, _, log, process, Buffer, StringView, dcodeIO */
/* global window, textsecure, ConversationController, _, log, process, Buffer, StringView, dcodeIO, URL */
const { lokiRpc } = require('./loki_rpc');
// not sure I like this name but it's been than util
@ -44,22 +44,33 @@ async function tryGetSnodeListFromLokidSeednode(
)[0];
let snodes = [];
try {
const response = await lokiRpc(
`http://${seedNode.ip}`,
seedNode.port,
'get_n_service_nodes',
params,
{}, // Options
'/json_rpc' // Seed request endpoint
);
// Filter 0.0.0.0 nodes which haven't submitted uptime proofs
snodes = response.result.service_node_states.filter(
snode => snode.public_ip !== '0.0.0.0'
);
const getSnodesFromSeedUrl = async urlObj => {
const response = await lokiRpc(
`${urlObj.protocol}//${urlObj.hostname}`,
urlObj.port,
'get_n_service_nodes',
params,
{}, // Options
'/json_rpc' // Seed request endpoint
);
// Filter 0.0.0.0 nodes which haven't submitted uptime proofs
return response.result.service_node_states.filter(
snode => snode.public_ip !== '0.0.0.0'
);
};
const tryUrl = new URL(seedNode.url);
snodes = getSnodesFromSeedUrl(tryUrl);
// throw before clearing the lock, so the retries can kick in
if (snodes.length === 0) {
// does this error message need to be exactly this?
throw new window.textsecure.SeedNodeError('Failed to contact seed node');
// fall back on ip_url
const tryIpUrl = new URL(seedNode.ip_url);
snodes = getSnodesFromSeedUrl(tryIpUrl);
if (snodes.length === 0) {
// does this error message need to be exactly this?
throw new window.textsecure.SeedNodeError(
'Failed to contact seed node'
);
}
}
return snodes;
} catch (e) {

View File

@ -1429,7 +1429,12 @@ MessageReceiver.prototype.extend({
);
return this.removeFromCache(envelope);
}
if (!friendRequest && this.isMessageEmpty(message)) {
window.log.warn(
`Message ${this.getEnvelopeId(envelope)} ignored; it was empty`
);
return this.removeFromCache(envelope);
}
const ev = new Event('message');
ev.confirm = this.removeFromCache.bind(this, envelope);
ev.data = {
@ -1443,6 +1448,27 @@ MessageReceiver.prototype.extend({
};
return this.dispatchAndWait(ev);
},
isMessageEmpty({
body,
attachments,
group,
flags,
quote,
contact,
preview,
groupInvitation,
}) {
return (
!flags &&
_.isEmpty(body) &&
_.isEmpty(attachments) &&
_.isEmpty(group) &&
_.isEmpty(quote) &&
_.isEmpty(contact) &&
_.isEmpty(preview) &&
_.isEmpty(groupInvitation)
);
},
handleLegacyMessage(envelope) {
return this.decrypt(envelope, envelope.legacyMessage).then(plaintext => {
if (!plaintext) {

View File

@ -175,6 +175,7 @@ function prepareURL(pathSegments, moreKeys) {
localUrl: config.get('localUrl'),
cdnUrl: config.get('cdnUrl'),
defaultPoWDifficulty: config.get('defaultPoWDifficulty'),
// one day explain why we need to do this - neuroscr
seedNodeList: JSON.stringify(config.get('seedNodeList')),
certificateAuthority: config.get('certificateAuthority'),
environment: config.environment,

View File

@ -2,7 +2,7 @@
"name": "session-messenger-desktop",
"productName": "Session",
"description": "Private messaging from your desktop",
"version": "1.0.7",
"version": "1.0.8",
"license": "GPL-3.0",
"author": {
"name": "Loki Project",

View File

@ -25,6 +25,7 @@ export type PropsData = {
isPublic?: boolean;
isRss?: boolean;
isClosable?: boolean;
primaryDevice?: string;
lastUpdated: number;
unreadCount: number;

View File

@ -321,8 +321,10 @@ export class LeftPaneContactSection extends React.Component<Props, State> {
private renderList() {
const { sentFriendsRequest } = this.props;
const friends = window.getFriendsFromContacts(this.props.friends);
const length = Number(sentFriendsRequest.length) + Number(friends.length);
const combined = [...sentFriendsRequest, ...friends];
const list = (

View File

@ -53,6 +53,8 @@ export type ConversationType = {
isSelected: boolean;
isTyping: boolean;
isFriend?: boolean;
isSecondary?: boolean;
primaryDevice: string;
hasReceivedFriendRequest?: boolean;
hasSentFriendRequest?: boolean;
};

View File

@ -107,9 +107,9 @@ export const _getLeftPaneLists = (
const conversations: Array<ConversationType> = [];
const archivedConversations: Array<ConversationType> = [];
const friends: Array<ConversationType> = [];
const receivedFriendsRequest: Array<ConversationListItemPropsType> = [];
const sentFriendsRequest: Array<ConversationListItemPropsType> = [];
const allFriends: Array<ConversationType> = [];
const allReceivedFriendsRequest: Array<ConversationListItemPropsType> = [];
const allSentFriendsRequest: Array<ConversationListItemPropsType> = [];
const max = sorted.length;
let unreadCount = 0;
@ -125,11 +125,11 @@ export const _getLeftPaneLists = (
}
if (conversation.isFriend && conversation.activeAt !== undefined) {
friends.push(conversation);
allFriends.push(conversation);
}
if (conversation.hasReceivedFriendRequest) {
receivedFriendsRequest.push(conversation);
allReceivedFriendsRequest.push(conversation);
} else if (
unreadCount < 9 &&
conversation.isFriend &&
@ -138,7 +138,9 @@ export const _getLeftPaneLists = (
unreadCount += conversation.unreadCount;
}
if (conversation.hasSentFriendRequest) {
sentFriendsRequest.push(conversation);
if (!conversation.isFriend) {
allSentFriendsRequest.push(conversation);
}
}
if (!conversation.activeAt) {
@ -152,6 +154,40 @@ export const _getLeftPaneLists = (
}
}
const filterToPrimary = <
T extends Array<ConversationType | ConversationListItemPropsType>
>(
group: Array<ConversationType | ConversationListItemPropsType>
): T => {
const secondariesToRemove: Array<string> = [];
group.forEach(device => {
if (!device.isSecondary) {
return;
}
const devicePrimary = group.find(c => c.id === device.primaryDevice);
// Remove secondary where primary already exists in group
if (group.some(c => c === devicePrimary)) {
secondariesToRemove.push(device.id);
}
});
// tslint:disable-next-line: no-unnecessary-local-variable
const filteredGroup = group.filter(
c => !secondariesToRemove.find(s => s === c.id)
);
return filteredGroup as T;
};
const friends: Array<ConversationType> = filterToPrimary(allFriends);
const receivedFriendsRequest: Array<
ConversationListItemPropsType
> = filterToPrimary(allReceivedFriendsRequest);
const sentFriendsRequest: Array<
ConversationListItemPropsType
> = filterToPrimary(allSentFriendsRequest);
return {
conversations,
archivedConversations,

View File

@ -19,6 +19,8 @@ describe('state/selectors/conversations', () => {
timestamp: 0,
phoneNumber: 'notused',
isArchived: false,
isSecondary: false,
primaryDevice: 'id1',
type: 'direct',
isMe: false,
@ -35,6 +37,8 @@ describe('state/selectors/conversations', () => {
timestamp: 20,
phoneNumber: 'notused',
isArchived: false,
isSecondary: false,
primaryDevice: 'id2',
type: 'direct',
isMe: false,
@ -51,6 +55,8 @@ describe('state/selectors/conversations', () => {
timestamp: 20,
phoneNumber: 'notused',
isArchived: false,
isSecondary: false,
primaryDevice: 'id3',
type: 'direct',
isMe: false,
@ -67,6 +73,8 @@ describe('state/selectors/conversations', () => {
timestamp: 20,
phoneNumber: 'notused',
isArchived: false,
isSecondary: false,
primaryDevice: 'id4',
type: 'direct',
isMe: false,
@ -83,6 +91,8 @@ describe('state/selectors/conversations', () => {
timestamp: 30,
phoneNumber: 'notused',
isArchived: false,
isSecondary: false,
primaryDevice: 'id5',
type: 'direct',
isMe: false,