@peers-app/peers-sdk 0.7.15 → 0.7.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -38,6 +38,7 @@ export declare class Connection {
|
|
|
38
38
|
completeHandshake(boxedHandshake: IDataBox): Promise<IDeviceHandshake>;
|
|
39
39
|
doHandshake(remoteAddress: string): Promise<IDeviceHandshake>;
|
|
40
40
|
private closeLocal;
|
|
41
|
+
private closed;
|
|
41
42
|
close(): Promise<void>;
|
|
42
43
|
}
|
|
43
44
|
export declare function normalizeAddress(address: string): string;
|
|
@@ -260,9 +260,15 @@ class Connection {
|
|
|
260
260
|
this.removeAllListeners();
|
|
261
261
|
this.socket.disconnect(true);
|
|
262
262
|
}
|
|
263
|
+
closed = false;
|
|
263
264
|
async close() {
|
|
265
|
+
if (this.closed)
|
|
266
|
+
return;
|
|
267
|
+
this.closed = true;
|
|
264
268
|
await Promise.race([
|
|
265
|
-
this.emit('close')
|
|
269
|
+
this.emit('close').catch(err => {
|
|
270
|
+
console.error('Error sending close event to remote device', err);
|
|
271
|
+
}),
|
|
266
272
|
(0, utils_1.sleep)(100),
|
|
267
273
|
]);
|
|
268
274
|
this.closeLocal();
|
|
@@ -18,14 +18,6 @@ export interface ISortConnectionsArgs {
|
|
|
18
18
|
unconnectedDeviceIds: Set<string>;
|
|
19
19
|
connections: ISortableConnection[];
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Sort connections from most preferred to least preferred
|
|
23
|
-
* The most preferred connections are ones that link us to the most new devices
|
|
24
|
-
* (i.e. not already connected to by other preferred connections).
|
|
25
|
-
* Ties go to connections that are most preferred by other devices.
|
|
26
|
-
* Further ties go to connections with the lowest latency * error rate
|
|
27
|
-
*/
|
|
28
|
-
export declare function sortConnections({ myDeviceId, connections, unconnectedDeviceIds }: ISortConnectionsArgs): ISortableConnection[];
|
|
29
21
|
export interface IGetLeastPreferredConnectionArgs {
|
|
30
22
|
connections: (IDeviceConnection & {
|
|
31
23
|
groups: string[];
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.electDevices = electDevices;
|
|
4
|
-
exports.sortConnections = sortConnections;
|
|
5
4
|
exports.getLeastPreferredConnection = getLeastPreferredConnection;
|
|
6
5
|
const lodash_1 = require("lodash");
|
|
7
|
-
const peer_device_1 = require("../types/peer-device");
|
|
8
6
|
function electDevices({ deviceId, myConnections, allNetworkInfo, }) {
|
|
9
7
|
const allDeviceIdsSet = new Set();
|
|
10
8
|
const _preferredByDeviceIdsSet = new Set();
|
|
@@ -78,13 +76,8 @@ function sortConnections({ myDeviceId, connections, unconnectedDeviceIds }) {
|
|
|
78
76
|
//=============================================
|
|
79
77
|
// Edge Cases - these should _usually_ return 0
|
|
80
78
|
//=============================================
|
|
81
|
-
const MAX_CONNECTIONS = peer_device_1.PeerDeviceConsts.MAX_CONNECTIONS;
|
|
82
79
|
// deprioritize devices that are close to max connections
|
|
83
80
|
connections.sort((a, b) => {
|
|
84
|
-
// const aConnCnt = a.preferredByDeviceIds.length + a.preferredDeviceIds.length;
|
|
85
|
-
// const bConnCnt = b.preferredByDeviceIds.length + b.preferredDeviceIds.length;
|
|
86
|
-
// const nearingMaxA = aConnCnt >= MAX_CONNECTIONS * 0.9;
|
|
87
|
-
// const nearingMaxB = bConnCnt >= MAX_CONNECTIONS * 0.9;
|
|
88
81
|
const nearingMaxA = a.connectionSlotsAvailable <= 3;
|
|
89
82
|
const nearingMaxB = b.connectionSlotsAvailable <= 3;
|
|
90
83
|
if (nearingMaxA && !nearingMaxB)
|
|
@@ -16,8 +16,8 @@ export interface IDeviceMessage {
|
|
|
16
16
|
dataContextId: string;
|
|
17
17
|
ttl: number;
|
|
18
18
|
payload: any;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
hops: string[];
|
|
20
|
+
suggestedPath?: string[];
|
|
21
21
|
}
|
|
22
22
|
export interface INetworkInfo {
|
|
23
23
|
deviceId: string;
|
|
@@ -38,12 +38,12 @@ export interface IDeviceConnection {
|
|
|
38
38
|
}
|
|
39
39
|
export declare const PeerDeviceConsts: Readonly<{
|
|
40
40
|
MAX_CONNECTIONS: 30;
|
|
41
|
-
RESYNC_INTERVAL:
|
|
41
|
+
RESYNC_INTERVAL: 60000;
|
|
42
42
|
NOTIFY_CHANGE_DELAY: 100;
|
|
43
43
|
CHANGES_PAGE_SIZE: 100;
|
|
44
44
|
RETRY_COUNT: 2;
|
|
45
|
-
TIMEOUT_MIN:
|
|
46
|
-
TIMEOUT_MAX:
|
|
45
|
+
TIMEOUT_MIN: 3000;
|
|
46
|
+
TIMEOUT_MAX: 30000;
|
|
47
47
|
NETWORK_INFO_CACHE_TIME: 1000;
|
|
48
48
|
}>;
|
|
49
49
|
export type IFileChunkInfo = {
|
|
@@ -4,11 +4,11 @@ exports.PeerDeviceConsts = void 0;
|
|
|
4
4
|
exports.PeerDeviceConsts = Object.freeze({
|
|
5
5
|
// TODO set this based on device type (desktops and servers should be able to handle 100 connections)
|
|
6
6
|
MAX_CONNECTIONS: 30,
|
|
7
|
-
RESYNC_INTERVAL:
|
|
7
|
+
RESYNC_INTERVAL: 60_000, // play with this to find the right balance
|
|
8
8
|
NOTIFY_CHANGE_DELAY: 100,
|
|
9
9
|
CHANGES_PAGE_SIZE: 100,
|
|
10
10
|
RETRY_COUNT: 2,
|
|
11
|
-
TIMEOUT_MIN:
|
|
12
|
-
TIMEOUT_MAX:
|
|
11
|
+
TIMEOUT_MIN: 3_000,
|
|
12
|
+
TIMEOUT_MAX: 30_000,
|
|
13
13
|
NETWORK_INFO_CACHE_TIME: 1000,
|
|
14
14
|
});
|