@dxos/network-manager 2.33.9-dev.e605934d → 2.33.9-dev.eb69ac10
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.
- package/dist/browser-mocha/bundle.js +5420 -1612
- package/dist/src/network-manager.d.ts.map +1 -1
- package/dist/src/network-manager.js +7 -6
- package/dist/src/network-manager.js.map +1 -1
- package/dist/src/proto/gen/dxos/credentials.d.ts +39 -0
- package/dist/src/proto/gen/dxos/credentials.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.d.ts +44 -2
- package/dist/src/proto/gen/dxos/halo/keys.d.ts.map +1 -1
- package/dist/src/proto/gen/dxos/halo/keys.js +4 -0
- package/dist/src/proto/gen/dxos/halo/keys.js.map +1 -1
- package/dist/src/proto/gen/dxos/mesh/signal.d.ts +58 -7
- package/dist/src/proto/gen/dxos/mesh/signal.d.ts.map +1 -1
- package/dist/src/proto/gen/google/protobuf.d.ts +2 -2
- package/dist/src/proto/gen/google/protobuf.d.ts.map +1 -1
- package/dist/src/proto/gen/index.d.ts +1 -0
- package/dist/src/proto/gen/index.d.ts.map +1 -1
- package/dist/src/proto/gen/index.js +1 -1
- package/dist/src/proto/gen/index.js.map +1 -1
- package/dist/src/protocol-factory.js +3 -3
- package/dist/src/protocol-factory.js.map +1 -1
- package/dist/src/signal/in-memory-signal-manager.js +5 -5
- package/dist/src/signal/in-memory-signal-manager.js.map +1 -1
- package/dist/src/signal/message-router.d.ts +16 -4
- package/dist/src/signal/message-router.d.ts.map +1 -1
- package/dist/src/signal/message-router.js +91 -17
- package/dist/src/signal/message-router.js.map +1 -1
- package/dist/src/signal/message-router.test.js +120 -13
- package/dist/src/signal/message-router.test.js.map +1 -1
- package/dist/src/signal/signal-client.d.ts +2 -1
- package/dist/src/signal/signal-client.d.ts.map +1 -1
- package/dist/src/signal/signal-client.js +26 -16
- package/dist/src/signal/signal-client.js.map +1 -1
- package/dist/src/signal/signal-client.test.js +4 -2
- package/dist/src/signal/signal-client.test.js.map +1 -1
- package/dist/src/signal/websocket-rpc.js +3 -3
- package/dist/src/signal/websocket-rpc.js.map +1 -1
- package/dist/src/signal/websocket-signal-manager.js +2 -2
- package/dist/src/signal/websocket-signal-manager.js.map +1 -1
- package/dist/src/swarm/connection.js +8 -8
- package/dist/src/swarm/connection.js.map +1 -1
- package/dist/src/swarm/swarm.js +10 -10
- package/dist/src/swarm/swarm.js.map +1 -1
- package/dist/src/swarm/swarm.test.js +2 -0
- package/dist/src/swarm/swarm.test.js.map +1 -1
- package/dist/src/testing/test-protocol.d.ts.map +1 -1
- package/dist/src/testing/test-protocol.js +3 -3
- package/dist/src/testing/test-protocol.js.map +1 -1
- package/dist/src/topology/fully-connected-topology.js +3 -3
- package/dist/src/topology/fully-connected-topology.js.map +1 -1
- package/dist/src/topology/mmst-topology.js +5 -5
- package/dist/src/topology/mmst-topology.js.map +1 -1
- package/dist/src/topology/star-topology.js +4 -4
- package/dist/src/topology/star-topology.js.map +1 -1
- package/dist/src/transport/in-memory-transport.js +2 -2
- package/dist/src/transport/in-memory-transport.js.map +1 -1
- package/dist/src/transport/webrtc-transport.js +3 -3
- package/dist/src/transport/webrtc-transport.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -11
- package/src/network-manager.ts +2 -1
- package/src/proto/defs/dxos/mesh/signal.proto +13 -0
- package/src/proto/gen/dxos/credentials.ts +39 -0
- package/src/proto/gen/dxos/halo/keys.ts +44 -2
- package/src/proto/gen/dxos/mesh/signal.ts +58 -7
- package/src/proto/gen/google/protobuf.ts +2 -2
- package/src/proto/gen/index.ts +2 -1
- package/src/protocol-factory.ts +1 -1
- package/src/signal/in-memory-signal-manager.ts +1 -1
- package/src/signal/message-router.test.ts +154 -38
- package/src/signal/message-router.ts +107 -18
- package/src/signal/signal-client.test.ts +4 -2
- package/src/signal/signal-client.ts +42 -15
- package/src/signal/websocket-rpc.ts +1 -1
- package/src/signal/websocket-signal-manager.ts +1 -1
- package/src/swarm/connection.ts +1 -1
- package/src/swarm/swarm.test.ts +2 -0
- package/src/swarm/swarm.ts +2 -2
- package/src/testing/test-protocol.ts +1 -1
- package/src/topology/fully-connected-topology.ts +1 -1
- package/src/topology/mmst-topology.ts +1 -1
- package/src/topology/star-topology.ts +1 -1
- package/src/transport/in-memory-transport.ts +1 -1
- package/src/transport/webrtc-transport.ts +1 -1
|
@@ -13,9 +13,14 @@ message Message {
|
|
|
13
13
|
PubKey id = 1;
|
|
14
14
|
/// Receiver`s public key.
|
|
15
15
|
PubKey remoteId = 2;
|
|
16
|
+
/// Swarm identefier.
|
|
16
17
|
PubKey topic = 3;
|
|
18
|
+
/// Unique connection identifier.
|
|
17
19
|
PubKey sessionId = 4;
|
|
20
|
+
/// Message payload.
|
|
18
21
|
MessageData data = 5;
|
|
22
|
+
/// Unique message identifier. Used for Acknolegment and matching Anwers to Offers.
|
|
23
|
+
optional PubKey messageId = 6;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
message MessageData {
|
|
@@ -23,6 +28,7 @@ message MessageData {
|
|
|
23
28
|
Offer offer = 1;
|
|
24
29
|
Answer answer = 2;
|
|
25
30
|
Signal signal = 3;
|
|
31
|
+
Acknowledgement ack = 4;
|
|
26
32
|
}
|
|
27
33
|
}
|
|
28
34
|
|
|
@@ -31,8 +37,15 @@ message Offer {
|
|
|
31
37
|
|
|
32
38
|
message Answer {
|
|
33
39
|
bool accept = 1;
|
|
40
|
+
/// MessageId of the Offer being answered.
|
|
41
|
+
optional PubKey offerMessageId = 2;
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
message Signal {
|
|
37
45
|
string json = 1;
|
|
38
46
|
}
|
|
47
|
+
|
|
48
|
+
message Acknowledgement {
|
|
49
|
+
// MessageId of the Message being acknowledged.
|
|
50
|
+
PubKey messageId = 1;
|
|
51
|
+
}
|
|
@@ -3,25 +3,64 @@ import substitutions from "../../substitutions";
|
|
|
3
3
|
import * as dxos_halo_keys from "./halo/keys";
|
|
4
4
|
import * as dxos_mesh_signal from "./mesh/signal";
|
|
5
5
|
import * as google_protobuf from "../google/protobuf";
|
|
6
|
+
/**
|
|
7
|
+
* Defined in:
|
|
8
|
+
* {@link file://./../../../../../../common/protocols/src/proto/dxos/halo/signed.proto}
|
|
9
|
+
*/
|
|
6
10
|
export interface Message {
|
|
7
11
|
payload: google_protobuf.Any;
|
|
8
12
|
}
|
|
9
13
|
/**
|
|
10
14
|
* A generic container message used whenever messages are signed (e.g. PartyCredential)
|
|
15
|
+
*
|
|
16
|
+
* Defined in:
|
|
17
|
+
* {@link file://./../../../../../../common/protocols/src/proto/dxos/halo/signed.proto}
|
|
11
18
|
*/
|
|
12
19
|
export interface SignedMessage {
|
|
20
|
+
/**
|
|
21
|
+
* The signed message contents.
|
|
22
|
+
*/
|
|
13
23
|
signed: SignedMessage.Signed;
|
|
24
|
+
/**
|
|
25
|
+
* An array of Signatures, one for each key that signed the message.
|
|
26
|
+
*/
|
|
14
27
|
signatures?: SignedMessage.Signature[];
|
|
15
28
|
}
|
|
16
29
|
export namespace SignedMessage {
|
|
30
|
+
/**
|
|
31
|
+
* Defined in:
|
|
32
|
+
* {@link file://./../../../../../../common/protocols/src/proto/dxos/halo/signed.proto}
|
|
33
|
+
*/
|
|
17
34
|
export interface Signed {
|
|
35
|
+
/**
|
|
36
|
+
* RFC-3339 datetime string.
|
|
37
|
+
*/
|
|
18
38
|
created: string;
|
|
19
39
|
nonce: Uint8Array;
|
|
40
|
+
/**
|
|
41
|
+
* The payload to be signed.
|
|
42
|
+
*/
|
|
20
43
|
payload: google_protobuf.Any;
|
|
21
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Defined in:
|
|
47
|
+
* {@link file://./../../../../../../common/protocols/src/proto/dxos/halo/signed.proto}
|
|
48
|
+
*/
|
|
22
49
|
export interface Signature {
|
|
50
|
+
/**
|
|
51
|
+
* The publicKey of the keypair that made this signature.
|
|
52
|
+
*/
|
|
23
53
|
key: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
54
|
+
/**
|
|
55
|
+
* The bytes of the signature.
|
|
56
|
+
*/
|
|
24
57
|
signature: Uint8Array;
|
|
58
|
+
/**
|
|
59
|
+
* The certification chain of SignedMessages for this key.
|
|
60
|
+
*
|
|
61
|
+
* Options:
|
|
62
|
+
* - proto3_optional = true
|
|
63
|
+
*/
|
|
25
64
|
keyChain?: dxos_halo_keys.KeyChain;
|
|
26
65
|
}
|
|
27
66
|
}
|
|
@@ -3,6 +3,10 @@ import substitutions from "../../../substitutions";
|
|
|
3
3
|
import * as dxos_credentials from "../credentials";
|
|
4
4
|
import * as dxos_mesh_signal from "../mesh/signal";
|
|
5
5
|
import * as google_protobuf from "../../google/protobuf";
|
|
6
|
+
/**
|
|
7
|
+
* Defined in:
|
|
8
|
+
* {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
|
|
9
|
+
*/
|
|
6
10
|
export enum KeyType {
|
|
7
11
|
UNKNOWN = 0,
|
|
8
12
|
IDENTITY = 1,
|
|
@@ -11,12 +15,24 @@ export enum KeyType {
|
|
|
11
15
|
FEED = 4,
|
|
12
16
|
DXNS_ADDRESS = 5
|
|
13
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Defined in:
|
|
20
|
+
* {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
|
|
21
|
+
*/
|
|
14
22
|
export interface PubKey {
|
|
15
|
-
data
|
|
23
|
+
data: Uint8Array;
|
|
16
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Defined in:
|
|
27
|
+
* {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
|
|
28
|
+
*/
|
|
17
29
|
export interface PrivKey {
|
|
18
|
-
data
|
|
30
|
+
data: Uint8Array;
|
|
19
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Defined in:
|
|
34
|
+
* {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
|
|
35
|
+
*/
|
|
20
36
|
export interface KeyRecord {
|
|
21
37
|
/**
|
|
22
38
|
* The `KeyType` type of the key. This is often unknown for keys from other sources.
|
|
@@ -28,33 +44,59 @@ export interface KeyRecord {
|
|
|
28
44
|
publicKey: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
29
45
|
/**
|
|
30
46
|
* The secret key as a Buffer (this will never be visible outside the Keyring).
|
|
47
|
+
*
|
|
48
|
+
* Options:
|
|
49
|
+
* - proto3_optional = true
|
|
31
50
|
*/
|
|
32
51
|
secretKey?: ReturnType<(typeof substitutions)["dxos.halo.keys.PrivKey"]["decode"]>;
|
|
33
52
|
/**
|
|
34
53
|
* Is this key from a Greeting "hint"?
|
|
54
|
+
*
|
|
55
|
+
* Options:
|
|
56
|
+
* - proto3_optional = true
|
|
35
57
|
*/
|
|
36
58
|
hint?: boolean;
|
|
37
59
|
/**
|
|
38
60
|
* Determines if this is our key?
|
|
39
61
|
* Usually true if `secretKey` is present; may be false for "inception keys" such as the Party key.
|
|
62
|
+
*
|
|
63
|
+
* Options:
|
|
64
|
+
* - proto3_optional = true
|
|
40
65
|
*/
|
|
41
66
|
own?: boolean;
|
|
42
67
|
/**
|
|
43
68
|
* Is this key to be trusted?
|
|
69
|
+
*
|
|
70
|
+
* Options:
|
|
71
|
+
* - proto3_optional = true
|
|
44
72
|
*/
|
|
45
73
|
trusted?: boolean;
|
|
46
74
|
/**
|
|
47
75
|
* An RFC-3339 date/time string for when the key was added to the Keyring.
|
|
76
|
+
*
|
|
77
|
+
* Options:
|
|
78
|
+
* - proto3_optional = true
|
|
48
79
|
*/
|
|
49
80
|
added?: string;
|
|
50
81
|
/**
|
|
51
82
|
* An RFC-3339 date/time string for when the key was created.
|
|
83
|
+
*
|
|
84
|
+
* Options:
|
|
85
|
+
* - proto3_optional = true
|
|
52
86
|
*/
|
|
53
87
|
created?: string;
|
|
54
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Defined in:
|
|
91
|
+
* {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
|
|
92
|
+
*/
|
|
55
93
|
export interface KeyRecordList {
|
|
56
94
|
keys?: KeyRecord[];
|
|
57
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Defined in:
|
|
98
|
+
* {@link file://./../../../../../../../common/protocols/src/proto/dxos/halo/keys.proto}
|
|
99
|
+
*/
|
|
58
100
|
export interface KeyChain {
|
|
59
101
|
publicKey: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
60
102
|
message: dxos_credentials.SignedMessage;
|
|
@@ -3,29 +3,80 @@ import substitutions from "../../../substitutions";
|
|
|
3
3
|
import * as dxos_credentials from "../credentials";
|
|
4
4
|
import * as dxos_halo_keys from "../halo/keys";
|
|
5
5
|
import * as google_protobuf from "../../google/protobuf";
|
|
6
|
+
/**
|
|
7
|
+
* Defined in:
|
|
8
|
+
* {@link file://./../../../defs/dxos/mesh/signal.proto}
|
|
9
|
+
*/
|
|
6
10
|
export interface Message {
|
|
7
11
|
/**
|
|
8
12
|
* Sender's public key.
|
|
9
13
|
*/
|
|
10
|
-
id
|
|
14
|
+
id: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
11
15
|
/**
|
|
12
16
|
* Receiver`s public key.
|
|
13
17
|
*/
|
|
14
|
-
remoteId
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
remoteId: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
19
|
+
/**
|
|
20
|
+
* Swarm identefier.
|
|
21
|
+
*/
|
|
22
|
+
topic: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
23
|
+
/**
|
|
24
|
+
* Unique connection identifier.
|
|
25
|
+
*/
|
|
26
|
+
sessionId: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
27
|
+
/**
|
|
28
|
+
* Message payload.
|
|
29
|
+
*/
|
|
30
|
+
data: MessageData;
|
|
31
|
+
/**
|
|
32
|
+
* Unique message identifier. Used for Acknolegment and matching Anwers to Offers.
|
|
33
|
+
*
|
|
34
|
+
* Options:
|
|
35
|
+
* - proto3_optional = true
|
|
36
|
+
*/
|
|
37
|
+
messageId?: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
18
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Defined in:
|
|
41
|
+
* {@link file://./../../../defs/dxos/mesh/signal.proto}
|
|
42
|
+
*/
|
|
19
43
|
export interface MessageData {
|
|
20
44
|
offer?: Offer;
|
|
21
45
|
answer?: Answer;
|
|
22
46
|
signal?: Signal;
|
|
47
|
+
ack?: Acknowledgement;
|
|
23
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Defined in:
|
|
51
|
+
* {@link file://./../../../defs/dxos/mesh/signal.proto}
|
|
52
|
+
*/
|
|
24
53
|
export interface Offer {
|
|
25
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Defined in:
|
|
57
|
+
* {@link file://./../../../defs/dxos/mesh/signal.proto}
|
|
58
|
+
*/
|
|
26
59
|
export interface Answer {
|
|
27
|
-
accept
|
|
60
|
+
accept: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* MessageId of the Offer being answered.
|
|
63
|
+
*
|
|
64
|
+
* Options:
|
|
65
|
+
* - proto3_optional = true
|
|
66
|
+
*/
|
|
67
|
+
offerMessageId?: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
28
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Defined in:
|
|
71
|
+
* {@link file://./../../../defs/dxos/mesh/signal.proto}
|
|
72
|
+
*/
|
|
29
73
|
export interface Signal {
|
|
30
|
-
json
|
|
74
|
+
json: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Defined in:
|
|
78
|
+
* {@link file://./../../../defs/dxos/mesh/signal.proto}
|
|
79
|
+
*/
|
|
80
|
+
export interface Acknowledgement {
|
|
81
|
+
messageId: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
31
82
|
}
|
|
@@ -4,6 +4,6 @@ import * as dxos_credentials from "../dxos/credentials";
|
|
|
4
4
|
import * as dxos_halo_keys from "../dxos/halo/keys";
|
|
5
5
|
import * as dxos_mesh_signal from "../dxos/mesh/signal";
|
|
6
6
|
export interface Any {
|
|
7
|
-
type_url
|
|
8
|
-
value
|
|
7
|
+
type_url: string;
|
|
8
|
+
value: Uint8Array;
|
|
9
9
|
}
|
package/src/proto/gen/index.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface TYPES {
|
|
|
15
15
|
"dxos.halo.keys.KeyType": dxos_halo_keys.KeyType;
|
|
16
16
|
"dxos.halo.keys.PrivKey": dxos_halo_keys.PrivKey;
|
|
17
17
|
"dxos.halo.keys.PubKey": dxos_halo_keys.PubKey;
|
|
18
|
+
"dxos.mesh.signal.Acknowledgement": dxos_mesh_signal.Acknowledgement;
|
|
18
19
|
"dxos.mesh.signal.Answer": dxos_mesh_signal.Answer;
|
|
19
20
|
"dxos.mesh.signal.Message": dxos_mesh_signal.Message;
|
|
20
21
|
"dxos.mesh.signal.MessageData": dxos_mesh_signal.MessageData;
|
|
@@ -24,5 +25,5 @@ export interface TYPES {
|
|
|
24
25
|
}
|
|
25
26
|
export interface SERVICES {
|
|
26
27
|
}
|
|
27
|
-
export const schemaJson = JSON.parse("{\"nested\":{\"dxos\":{\"nested\":{\"credentials\":{\"nested\":{\"Message\":{\"fields\":{\"payload\":{\"rule\":\"required\",\"type\":\"google.protobuf.Any\",\"id\":1,\"comment\":null}},\"comment\":null},\"SignedMessage\":{\"fields\":{\"signed\":{\"rule\":\"required\",\"type\":\"Signed\",\"id\":1,\"comment\"
|
|
28
|
+
export const schemaJson = JSON.parse("{\"nested\":{\"dxos\":{\"nested\":{\"credentials\":{\"nested\":{\"Message\":{\"fields\":{\"payload\":{\"rule\":\"required\",\"type\":\"google.protobuf.Any\",\"id\":1,\"comment\":null}},\"comment\":null},\"SignedMessage\":{\"fields\":{\"signed\":{\"rule\":\"required\",\"type\":\"Signed\",\"id\":1,\"comment\":\"The signed message contents.\"},\"signatures\":{\"rule\":\"repeated\",\"type\":\"Signature\",\"id\":2,\"comment\":\"An array of Signatures, one for each key that signed the message.\"}},\"nested\":{\"Signature\":{\"oneofs\":{\"_keyChain\":{\"oneof\":[\"keyChain\"]}},\"fields\":{\"key\":{\"rule\":\"required\",\"type\":\"PubKey\",\"id\":1,\"comment\":\"The publicKey of the keypair that made this signature.\"},\"signature\":{\"rule\":\"required\",\"type\":\"bytes\",\"id\":2,\"comment\":\"The bytes of the signature.\"},\"keyChain\":{\"type\":\"KeyChain\",\"id\":3,\"options\":{\"proto3_optional\":true},\"comment\":\"The certification chain of SignedMessages for this key.\"}},\"comment\":null},\"Signed\":{\"fields\":{\"created\":{\"rule\":\"required\",\"type\":\"string\",\"id\":1,\"comment\":\"RFC-3339 datetime string.\"},\"nonce\":{\"rule\":\"required\",\"type\":\"bytes\",\"id\":2,\"comment\":null},\"payload\":{\"rule\":\"required\",\"type\":\"google.protobuf.Any\",\"id\":10,\"comment\":\"The payload to be signed.\"}},\"comment\":null}},\"comment\":\"A generic container message used whenever messages are signed (e.g. PartyCredential)\"}}},\"halo\":{\"nested\":{\"keys\":{\"nested\":{\"KeyChain\":{\"fields\":{\"publicKey\":{\"rule\":\"required\",\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"message\":{\"rule\":\"required\",\"type\":\"SignedMessage\",\"id\":2,\"comment\":null},\"parents\":{\"rule\":\"repeated\",\"type\":\"KeyChain\",\"id\":3,\"comment\":null}},\"comment\":null},\"KeyRecord\":{\"oneofs\":{\"_secretKey\":{\"oneof\":[\"secretKey\"]},\"_hint\":{\"oneof\":[\"hint\"]},\"_own\":{\"oneof\":[\"own\"]},\"_trusted\":{\"oneof\":[\"trusted\"]},\"_added\":{\"oneof\":[\"added\"]},\"_created\":{\"oneof\":[\"created\"]}},\"fields\":{\"type\":{\"rule\":\"required\",\"type\":\"KeyType\",\"id\":1,\"comment\":\"The `KeyType` type of the key. This is often unknown for keys from other sources.\"},\"publicKey\":{\"rule\":\"required\",\"type\":\"PubKey\",\"id\":2,\"comment\":\"The public key as a Buffer (required).\"},\"secretKey\":{\"type\":\"PrivKey\",\"id\":3,\"options\":{\"proto3_optional\":true},\"comment\":\"The secret key as a Buffer (this will never be visible outside the Keyring).\"},\"hint\":{\"type\":\"bool\",\"id\":4,\"options\":{\"proto3_optional\":true},\"comment\":\"Is this key from a Greeting \\\"hint\\\"?\"},\"own\":{\"type\":\"bool\",\"id\":5,\"options\":{\"proto3_optional\":true},\"comment\":\"Determines if this is our key?\\nUsually true if `secretKey` is present; may be false for \\\"inception keys\\\" such as the Party key.\"},\"trusted\":{\"type\":\"bool\",\"id\":6,\"options\":{\"proto3_optional\":true},\"comment\":\"Is this key to be trusted?\"},\"added\":{\"type\":\"string\",\"id\":7,\"options\":{\"proto3_optional\":true},\"comment\":\"An RFC-3339 date/time string for when the key was added to the Keyring.\"},\"created\":{\"type\":\"string\",\"id\":8,\"options\":{\"proto3_optional\":true},\"comment\":\"An RFC-3339 date/time string for when the key was created.\"}},\"comment\":null},\"KeyRecordList\":{\"fields\":{\"keys\":{\"rule\":\"repeated\",\"type\":\"KeyRecord\",\"id\":1,\"comment\":null}},\"comment\":null},\"KeyType\":{\"values\":{\"UNKNOWN\":0,\"IDENTITY\":1,\"DEVICE\":2,\"PARTY\":3,\"FEED\":4,\"DXNS_ADDRESS\":5},\"comment\":null,\"comments\":{\"UNKNOWN\":null,\"IDENTITY\":null,\"DEVICE\":null,\"PARTY\":null,\"FEED\":null,\"DXNS_ADDRESS\":null}},\"PrivKey\":{\"fields\":{\"data\":{\"type\":\"bytes\",\"id\":1,\"comment\":null}},\"comment\":null},\"PubKey\":{\"fields\":{\"data\":{\"type\":\"bytes\",\"id\":1,\"comment\":null}},\"comment\":null}}}}},\"mesh\":{\"nested\":{\"signal\":{\"nested\":{\"Acknowledgement\":{\"fields\":{\"messageId\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null}},\"comment\":null},\"Answer\":{\"oneofs\":{\"_offerMessageId\":{\"oneof\":[\"offerMessageId\"]}},\"fields\":{\"accept\":{\"type\":\"bool\",\"id\":1,\"comment\":null},\"offerMessageId\":{\"type\":\"PubKey\",\"id\":2,\"options\":{\"proto3_optional\":true},\"comment\":\"MessageId of the Offer being answered.\"}},\"comment\":null},\"Message\":{\"oneofs\":{\"_messageId\":{\"oneof\":[\"messageId\"]}},\"fields\":{\"id\":{\"type\":\"PubKey\",\"id\":1,\"comment\":\"Sender's public key.\"},\"remoteId\":{\"type\":\"PubKey\",\"id\":2,\"comment\":\"Receiver`s public key.\"},\"topic\":{\"type\":\"PubKey\",\"id\":3,\"comment\":\"Swarm identefier.\"},\"sessionId\":{\"type\":\"PubKey\",\"id\":4,\"comment\":\"Unique connection identifier.\"},\"data\":{\"type\":\"MessageData\",\"id\":5,\"comment\":\"Message payload.\"},\"messageId\":{\"type\":\"PubKey\",\"id\":6,\"options\":{\"proto3_optional\":true},\"comment\":\"Unique message identifier. Used for Acknolegment and matching Anwers to Offers.\"}},\"comment\":null},\"MessageData\":{\"oneofs\":{\"payload\":{\"oneof\":[\"offer\",\"answer\",\"signal\",\"ack\"],\"comment\":null}},\"fields\":{\"offer\":{\"type\":\"Offer\",\"id\":1,\"comment\":null},\"answer\":{\"type\":\"Answer\",\"id\":2,\"comment\":null},\"signal\":{\"type\":\"Signal\",\"id\":3,\"comment\":null},\"ack\":{\"type\":\"Acknowledgement\",\"id\":4,\"comment\":null}},\"comment\":null},\"Offer\":{\"fields\":{},\"comment\":null},\"Signal\":{\"fields\":{\"json\":{\"type\":\"string\",\"id\":1,\"comment\":null}},\"comment\":null}}}}}}},\"google\":{\"nested\":{\"protobuf\":{\"nested\":{\"Any\":{\"fields\":{\"type_url\":{\"type\":\"string\",\"id\":1},\"value\":{\"type\":\"bytes\",\"id\":2}},\"comment\":null}}}}}}}");
|
|
28
29
|
export const schema = Schema.fromJson<TYPES, SERVICES>(schemaJson, substitutions);
|
package/src/protocol-factory.ts
CHANGED
|
@@ -40,11 +40,15 @@ describe('MessageRouter', () => {
|
|
|
40
40
|
await broker1.stop();
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
const createSignalClientAndMessageRouter = async (
|
|
44
|
-
signalApiUrl
|
|
45
|
-
onSignal
|
|
46
|
-
onOffer
|
|
47
|
-
|
|
43
|
+
const createSignalClientAndMessageRouter = async ({
|
|
44
|
+
signalApiUrl,
|
|
45
|
+
onSignal = (async () => { }) as any,
|
|
46
|
+
onOffer = async () => ({ accept: true })
|
|
47
|
+
}: {
|
|
48
|
+
signalApiUrl: string;
|
|
49
|
+
onSignal?: (msg: Message) => Promise<void>;
|
|
50
|
+
onOffer?: (msg: Message) => Promise<Answer>;
|
|
51
|
+
}) => {
|
|
48
52
|
|
|
49
53
|
// eslint-disable-next-line prefer-const
|
|
50
54
|
let api: SignalClient;
|
|
@@ -54,6 +58,7 @@ describe('MessageRouter', () => {
|
|
|
54
58
|
onSignal: onSignal,
|
|
55
59
|
onOffer: onOffer
|
|
56
60
|
});
|
|
61
|
+
afterTest(() => router.destroy());
|
|
57
62
|
|
|
58
63
|
api = new SignalClient(
|
|
59
64
|
signalApiUrl,
|
|
@@ -70,8 +75,8 @@ describe('MessageRouter', () => {
|
|
|
70
75
|
|
|
71
76
|
test('signaling between 2 clients', async () => {
|
|
72
77
|
const signalMock1 = mockFn<(msg: Message) => Promise<void>>().resolvesTo();
|
|
73
|
-
const { api: api1 } = await createSignalClientAndMessageRouter(signalApiUrl1, signalMock1);
|
|
74
|
-
const { api: api2, router: router2 } = await createSignalClientAndMessageRouter(signalApiUrl1);
|
|
78
|
+
const { api: api1 } = await createSignalClientAndMessageRouter({ signalApiUrl: signalApiUrl1, onSignal: signalMock1 });
|
|
79
|
+
const { api: api2, router: router2 } = await createSignalClientAndMessageRouter({ signalApiUrl: signalApiUrl1 });
|
|
75
80
|
|
|
76
81
|
await api1.join(topic, peer1);
|
|
77
82
|
await api2.join(topic, peer2);
|
|
@@ -92,15 +97,19 @@ describe('MessageRouter', () => {
|
|
|
92
97
|
|
|
93
98
|
test('offer/answer', async () => {
|
|
94
99
|
const { api: api1, router: router1 } = await createSignalClientAndMessageRouter(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
{
|
|
101
|
+
signalApiUrl: signalApiUrl1,
|
|
102
|
+
onSignal: (async () => { }) as any,
|
|
103
|
+
onOffer:
|
|
104
|
+
async () => ({ accept: true })
|
|
105
|
+
});
|
|
99
106
|
const { api: api2 } = await createSignalClientAndMessageRouter(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
{
|
|
108
|
+
signalApiUrl: signalApiUrl1,
|
|
109
|
+
onSignal: (async () => { }) as any,
|
|
110
|
+
onOffer:
|
|
111
|
+
async () => ({ accept: true })
|
|
112
|
+
});
|
|
104
113
|
|
|
105
114
|
await api1.join(topic, peer1);
|
|
106
115
|
await api2.join(topic, peer2);
|
|
@@ -112,28 +121,34 @@ describe('MessageRouter', () => {
|
|
|
112
121
|
topic,
|
|
113
122
|
data: { offer: { } }
|
|
114
123
|
});
|
|
115
|
-
expect(answer).toEqual(
|
|
124
|
+
expect(answer.accept).toEqual(true);
|
|
116
125
|
}).timeout(5_000);
|
|
117
126
|
|
|
118
127
|
test('signaling between 3 clients', async () => {
|
|
119
128
|
const signalMock1 = mockFn<(msg: Message) => Promise<void>>().resolvesTo();
|
|
120
129
|
const { api: api1, router: router1 } = await createSignalClientAndMessageRouter(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
{
|
|
131
|
+
signalApiUrl: signalApiUrl1,
|
|
132
|
+
onSignal: signalMock1,
|
|
133
|
+
onOffer:
|
|
134
|
+
async () => ({ accept: true })
|
|
135
|
+
});
|
|
125
136
|
const signalMock2 = mockFn<(msg: Message) => Promise<void>>().resolvesTo();
|
|
126
137
|
const { api: api2, router: router2 } = await createSignalClientAndMessageRouter(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
138
|
+
{
|
|
139
|
+
signalApiUrl: signalApiUrl1,
|
|
140
|
+
onSignal: signalMock2,
|
|
141
|
+
onOffer:
|
|
142
|
+
async () => ({ accept: true })
|
|
143
|
+
});
|
|
131
144
|
const signalMock3 = mockFn<(msg: Message) => Promise<void>>().resolvesTo();
|
|
132
145
|
const { api: api3, router: router3 } = await createSignalClientAndMessageRouter(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
146
|
+
{
|
|
147
|
+
signalApiUrl: signalApiUrl1,
|
|
148
|
+
onSignal: signalMock3,
|
|
149
|
+
onOffer:
|
|
150
|
+
async () => ({ accept: true })
|
|
151
|
+
});
|
|
137
152
|
|
|
138
153
|
await api1.join(topic, peer1);
|
|
139
154
|
await api2.join(topic, peer2);
|
|
@@ -182,15 +197,19 @@ describe('MessageRouter', () => {
|
|
|
182
197
|
|
|
183
198
|
test('two offers', async () => {
|
|
184
199
|
const { api: api1, router: router1 } = await createSignalClientAndMessageRouter(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
200
|
+
{
|
|
201
|
+
signalApiUrl: signalApiUrl1,
|
|
202
|
+
onSignal: (async () => { }) as any,
|
|
203
|
+
onOffer:
|
|
204
|
+
async () => ({ accept: true })
|
|
205
|
+
});
|
|
189
206
|
const { api: api2, router: router2 } = await createSignalClientAndMessageRouter(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
207
|
+
{
|
|
208
|
+
signalApiUrl: signalApiUrl1,
|
|
209
|
+
onSignal: (async () => { }) as any,
|
|
210
|
+
onOffer:
|
|
211
|
+
async () => ({ accept: true })
|
|
212
|
+
});
|
|
194
213
|
|
|
195
214
|
await api1.join(topic, peer1);
|
|
196
215
|
await api2.join(topic, peer2);
|
|
@@ -203,7 +222,7 @@ describe('MessageRouter', () => {
|
|
|
203
222
|
topic,
|
|
204
223
|
data: { offer: {} }
|
|
205
224
|
});
|
|
206
|
-
expect(answer1).toEqual(
|
|
225
|
+
expect(answer1.accept).toEqual(true);
|
|
207
226
|
|
|
208
227
|
// sending offer from peer2 to peer1.
|
|
209
228
|
const answer2 = await router2.offer({
|
|
@@ -213,6 +232,103 @@ describe('MessageRouter', () => {
|
|
|
213
232
|
topic,
|
|
214
233
|
data: { offer: {} }
|
|
215
234
|
});
|
|
216
|
-
expect(answer2).toEqual(
|
|
235
|
+
expect(answer2.accept).toEqual(true);
|
|
217
236
|
}).timeout(5_000);
|
|
237
|
+
|
|
238
|
+
describe('Reliability', () => {
|
|
239
|
+
const setup = ({
|
|
240
|
+
onSignal1 = async () => { },
|
|
241
|
+
onSignal2 = async () => { },
|
|
242
|
+
// Imitates signal network disruptions (e. g. message doubling, ).
|
|
243
|
+
messageDisruption = msg => [msg]
|
|
244
|
+
}: {
|
|
245
|
+
onSignal1?: (msg: Message) => Promise<void>;
|
|
246
|
+
onSignal2?: (msg: Message) => Promise<void>;
|
|
247
|
+
messageDisruption?: (msg: Message) => Message[];
|
|
248
|
+
}): {mr1: MessageRouter; mr2: MessageRouter} => {
|
|
249
|
+
|
|
250
|
+
const mr1: MessageRouter = new MessageRouter({
|
|
251
|
+
sendMessage: async msg => messageDisruption(msg).forEach(msg => mr2.receiveMessage(msg)),
|
|
252
|
+
onOffer: async () => ({ accept: true }),
|
|
253
|
+
onSignal: onSignal1
|
|
254
|
+
});
|
|
255
|
+
afterTest(() => mr1.destroy());
|
|
256
|
+
|
|
257
|
+
const mr2: MessageRouter = new MessageRouter({
|
|
258
|
+
sendMessage: async msg => messageDisruption(msg).forEach(msg => mr1.receiveMessage(msg)),
|
|
259
|
+
onOffer: async () => ({ accept: true }),
|
|
260
|
+
onSignal: onSignal2
|
|
261
|
+
});
|
|
262
|
+
afterTest(() => mr1.destroy());
|
|
263
|
+
|
|
264
|
+
return { mr1, mr2 };
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
test('signaling with non reliable connection', async () => {
|
|
268
|
+
// Simulate unreliable connection.
|
|
269
|
+
// Only each 3rd message is sent.
|
|
270
|
+
let i = 0;
|
|
271
|
+
const unreliableConnection = (msg: Message): Message[] => {
|
|
272
|
+
i++;
|
|
273
|
+
if (i % 3 !== 0) {
|
|
274
|
+
return [msg];
|
|
275
|
+
}
|
|
276
|
+
return [];
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const received: Message[] = [];
|
|
280
|
+
const signalMock1 = async (msg: Message) => {
|
|
281
|
+
received.push(msg);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
const { mr2 } = await setup({
|
|
285
|
+
onSignal1: signalMock1,
|
|
286
|
+
messageDisruption: unreliableConnection
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Sending 3 messages.
|
|
290
|
+
// Setup sends messages directly to between. So we don`t need to specify any ids.
|
|
291
|
+
Array(3).fill(0).forEach(async () => {
|
|
292
|
+
await mr2.signal({
|
|
293
|
+
id: PublicKey.random(),
|
|
294
|
+
remoteId: PublicKey.random(),
|
|
295
|
+
sessionId: PublicKey.random(),
|
|
296
|
+
topic: PublicKey.random(),
|
|
297
|
+
data: { signal: { json: 'asd' } }
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
// expect to receive 3 messages.
|
|
301
|
+
await waitForExpect(() => {
|
|
302
|
+
expect(received.length).toEqual(3);
|
|
303
|
+
}, 4_000);
|
|
304
|
+
}).timeout(5_000);
|
|
305
|
+
|
|
306
|
+
test('ignoring doubled messages', async () => {
|
|
307
|
+
// Message got doubled going through signal network.
|
|
308
|
+
const doublingMessage = (msg: Message) => [msg, msg];
|
|
309
|
+
|
|
310
|
+
const received: Message[] = [];
|
|
311
|
+
const signalMock1 = async (msg: Message) => {
|
|
312
|
+
received.push(msg);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
const { mr2 } = setup({
|
|
316
|
+
onSignal1: signalMock1,
|
|
317
|
+
messageDisruption: doublingMessage
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
// sending message.
|
|
321
|
+
await mr2.signal({
|
|
322
|
+
id: PublicKey.random(),
|
|
323
|
+
remoteId: PublicKey.random(),
|
|
324
|
+
sessionId: PublicKey.random(),
|
|
325
|
+
topic: PublicKey.random(),
|
|
326
|
+
data: { signal: { json: 'asd' } }
|
|
327
|
+
});
|
|
328
|
+
// expect to receive 1 message.
|
|
329
|
+
await waitForExpect(() => {
|
|
330
|
+
expect(received.length).toEqual(1);
|
|
331
|
+
}, 4_000);
|
|
332
|
+
}).timeout(5_000);
|
|
333
|
+
});
|
|
218
334
|
});
|