@dxos/network-manager 0.1.58-main.fa022ee → 0.1.58-main.ffb4cc4
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/lib/browser/{chunk-66HPNABI.mjs → chunk-3KLH55NB.mjs} +132 -79
- package/dist/lib/browser/chunk-3KLH55NB.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +5 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -148
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/index.cjs +562 -397
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +923 -891
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +2 -2
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +2 -2
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/topology/star-topology.d.ts.map +1 -1
- package/dist/types/src/transport/index.d.ts +1 -0
- package/dist/types/src/transport/index.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts +12 -0
- package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -0
- package/package.json +18 -17
- package/src/swarm/connection.test.ts +1 -1
- package/src/swarm/connection.ts +4 -3
- package/src/swarm/peer.ts +7 -2
- package/src/swarm/swarm-mapper.ts +4 -7
- package/src/swarm/swarm.test.ts +3 -3
- package/src/swarm/swarm.ts +3 -3
- package/src/testing/test-builder.ts +1 -1
- package/src/tests/basic-test-suite.ts +1 -1
- package/src/tests/memory-transport.test.ts +2 -2
- package/src/tests/tcp-transport.test.ts +2 -2
- package/src/tests/webrtc-transport.test.ts +1 -1
- package/src/topology/star-topology.ts +1 -4
- package/src/transport/index.ts +1 -0
- package/src/transport/simplepeer-transport-proxy.ts +25 -24
- package/src/transport/simplepeer-transport-service.ts +9 -5
- package/src/transport/simplepeer-transport.ts +5 -0
- package/src/transport/tcp-transport.browser.ts +28 -0
- package/dist/lib/browser/chunk-66HPNABI.mjs.map +0 -7
package/dist/lib/node/index.cjs
CHANGED
|
@@ -527,6 +527,8 @@ __export(src_exports, {
|
|
|
527
527
|
Swarm: () => Swarm,
|
|
528
528
|
SwarmMapper: () => SwarmMapper,
|
|
529
529
|
SwarmMessenger: () => SwarmMessenger,
|
|
530
|
+
TcpTransport: () => TcpTransport,
|
|
531
|
+
TcpTransportFactory: () => TcpTransportFactory,
|
|
530
532
|
TransportKind: () => TransportKind,
|
|
531
533
|
cleanup: () => cleanup,
|
|
532
534
|
createLibDataChannelTransportFactory: () => createLibDataChannelTransportFactory,
|
|
@@ -735,7 +737,7 @@ var Connection = class {
|
|
|
735
737
|
this.closeReason = err?.message;
|
|
736
738
|
}
|
|
737
739
|
if (err instanceof import_protocols.ConnectionResetError) {
|
|
738
|
-
|
|
740
|
+
import_log.log.warn("aborting due to transport ConnectionResetError", void 0, {
|
|
739
741
|
F: __dxlog_file,
|
|
740
742
|
L: 197,
|
|
741
743
|
S: this,
|
|
@@ -743,7 +745,7 @@ var Connection = class {
|
|
|
743
745
|
});
|
|
744
746
|
this.abort().catch((err2) => this.errors.raise(err2));
|
|
745
747
|
} else if (err instanceof import_protocols.ConnectivityError) {
|
|
746
|
-
|
|
748
|
+
import_log.log.warn("aborting due to transport ConnectivityError", void 0, {
|
|
747
749
|
F: __dxlog_file,
|
|
748
750
|
L: 200,
|
|
749
751
|
S: this,
|
|
@@ -751,7 +753,7 @@ var Connection = class {
|
|
|
751
753
|
});
|
|
752
754
|
this.abort().catch((err2) => this.errors.raise(err2));
|
|
753
755
|
} else if (err instanceof import_protocols.UnknownProtocolError) {
|
|
754
|
-
|
|
756
|
+
import_log.log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
|
|
755
757
|
err
|
|
756
758
|
}, {
|
|
757
759
|
F: __dxlog_file,
|
|
@@ -782,14 +784,14 @@ var Connection = class {
|
|
|
782
784
|
err
|
|
783
785
|
}, {
|
|
784
786
|
F: __dxlog_file,
|
|
785
|
-
L:
|
|
787
|
+
L: 225,
|
|
786
788
|
S: this,
|
|
787
789
|
C: (f, a) => f(...a)
|
|
788
790
|
});
|
|
789
791
|
if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
|
|
790
792
|
(0, import_log.log)(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
791
793
|
F: __dxlog_file,
|
|
792
|
-
L:
|
|
794
|
+
L: 227,
|
|
793
795
|
S: this,
|
|
794
796
|
C: (f, a) => f(...a)
|
|
795
797
|
});
|
|
@@ -805,7 +807,7 @@ var Connection = class {
|
|
|
805
807
|
proto: this._protocol
|
|
806
808
|
}, {
|
|
807
809
|
F: __dxlog_file,
|
|
808
|
-
L:
|
|
810
|
+
L: 240,
|
|
809
811
|
S: this,
|
|
810
812
|
C: (f, a) => f(...a)
|
|
811
813
|
});
|
|
@@ -813,7 +815,7 @@ var Connection = class {
|
|
|
813
815
|
} catch (err2) {
|
|
814
816
|
import_log.log.catch(err2, void 0, {
|
|
815
817
|
F: __dxlog_file,
|
|
816
|
-
L:
|
|
818
|
+
L: 243,
|
|
817
819
|
S: this,
|
|
818
820
|
C: (f, a) => f(...a)
|
|
819
821
|
});
|
|
@@ -823,7 +825,7 @@ var Connection = class {
|
|
|
823
825
|
} catch (err2) {
|
|
824
826
|
import_log.log.catch(err2, void 0, {
|
|
825
827
|
F: __dxlog_file,
|
|
826
|
-
L:
|
|
828
|
+
L: 250,
|
|
827
829
|
S: this,
|
|
828
830
|
C: (f, a) => f(...a)
|
|
829
831
|
});
|
|
@@ -833,7 +835,7 @@ var Connection = class {
|
|
|
833
835
|
} catch (err2) {
|
|
834
836
|
import_log.log.catch(err2, void 0, {
|
|
835
837
|
F: __dxlog_file,
|
|
836
|
-
L:
|
|
838
|
+
L: 256,
|
|
837
839
|
S: this,
|
|
838
840
|
C: (f, a) => f(...a)
|
|
839
841
|
});
|
|
@@ -854,7 +856,7 @@ var Connection = class {
|
|
|
854
856
|
peerId: this.ownId
|
|
855
857
|
}, {
|
|
856
858
|
F: __dxlog_file,
|
|
857
|
-
L:
|
|
859
|
+
L: 278,
|
|
858
860
|
S: this,
|
|
859
861
|
C: (f, a) => f(...a)
|
|
860
862
|
});
|
|
@@ -864,7 +866,7 @@ var Connection = class {
|
|
|
864
866
|
} catch (err2) {
|
|
865
867
|
import_log.log.catch(err2, void 0, {
|
|
866
868
|
F: __dxlog_file,
|
|
867
|
-
L:
|
|
869
|
+
L: 285,
|
|
868
870
|
S: this,
|
|
869
871
|
C: (f, a) => f(...a)
|
|
870
872
|
});
|
|
@@ -874,7 +876,7 @@ var Connection = class {
|
|
|
874
876
|
} catch (err2) {
|
|
875
877
|
import_log.log.catch(err2, void 0, {
|
|
876
878
|
F: __dxlog_file,
|
|
877
|
-
L:
|
|
879
|
+
L: 292,
|
|
878
880
|
S: this,
|
|
879
881
|
C: (f, a) => f(...a)
|
|
880
882
|
});
|
|
@@ -884,7 +886,7 @@ var Connection = class {
|
|
|
884
886
|
peerId: this.ownId
|
|
885
887
|
}, {
|
|
886
888
|
F: __dxlog_file,
|
|
887
|
-
L:
|
|
889
|
+
L: 296,
|
|
888
890
|
S: this,
|
|
889
891
|
C: (f, a) => f(...a)
|
|
890
892
|
});
|
|
@@ -927,7 +929,7 @@ var Connection = class {
|
|
|
927
929
|
err
|
|
928
930
|
}, {
|
|
929
931
|
F: __dxlog_file,
|
|
930
|
-
L:
|
|
932
|
+
L: 333,
|
|
931
933
|
S: this,
|
|
932
934
|
C: (f, a) => f(...a)
|
|
933
935
|
});
|
|
@@ -940,7 +942,7 @@ var Connection = class {
|
|
|
940
942
|
async signal(msg) {
|
|
941
943
|
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
942
944
|
F: __dxlog_file,
|
|
943
|
-
L:
|
|
945
|
+
L: 342,
|
|
944
946
|
S: this,
|
|
945
947
|
A: [
|
|
946
948
|
"msg.sessionId",
|
|
@@ -950,7 +952,7 @@ var Connection = class {
|
|
|
950
952
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
951
953
|
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
952
954
|
F: __dxlog_file,
|
|
953
|
-
L:
|
|
955
|
+
L: 344,
|
|
954
956
|
S: this,
|
|
955
957
|
C: (f, a) => f(...a)
|
|
956
958
|
});
|
|
@@ -958,7 +960,7 @@ var Connection = class {
|
|
|
958
960
|
}
|
|
959
961
|
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
960
962
|
F: __dxlog_file,
|
|
961
|
-
L:
|
|
963
|
+
L: 347,
|
|
962
964
|
S: this,
|
|
963
965
|
A: [
|
|
964
966
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -967,7 +969,7 @@ var Connection = class {
|
|
|
967
969
|
});
|
|
968
970
|
(0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
|
|
969
971
|
F: __dxlog_file,
|
|
970
|
-
L:
|
|
972
|
+
L: 348,
|
|
971
973
|
S: this,
|
|
972
974
|
A: [
|
|
973
975
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -976,7 +978,7 @@ var Connection = class {
|
|
|
976
978
|
});
|
|
977
979
|
(0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
|
|
978
980
|
F: __dxlog_file,
|
|
979
|
-
L:
|
|
981
|
+
L: 349,
|
|
980
982
|
S: this,
|
|
981
983
|
A: [
|
|
982
984
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -1000,7 +1002,7 @@ var Connection = class {
|
|
|
1000
1002
|
msg: msg.data
|
|
1001
1003
|
}, {
|
|
1002
1004
|
F: __dxlog_file,
|
|
1003
|
-
L:
|
|
1005
|
+
L: 358,
|
|
1004
1006
|
S: this,
|
|
1005
1007
|
C: (f, a) => f(...a)
|
|
1006
1008
|
});
|
|
@@ -1008,7 +1010,7 @@ var Connection = class {
|
|
|
1008
1010
|
} else {
|
|
1009
1011
|
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
1010
1012
|
F: __dxlog_file,
|
|
1011
|
-
L:
|
|
1013
|
+
L: 361,
|
|
1012
1014
|
S: this,
|
|
1013
1015
|
A: [
|
|
1014
1016
|
"this._transport",
|
|
@@ -1021,7 +1023,7 @@ var Connection = class {
|
|
|
1021
1023
|
msg: msg.data
|
|
1022
1024
|
}, {
|
|
1023
1025
|
F: __dxlog_file,
|
|
1024
|
-
L:
|
|
1026
|
+
L: 362,
|
|
1025
1027
|
S: this,
|
|
1026
1028
|
C: (f, a) => f(...a)
|
|
1027
1029
|
});
|
|
@@ -1039,13 +1041,13 @@ var Connection = class {
|
|
|
1039
1041
|
peerId: this.ownId
|
|
1040
1042
|
}, {
|
|
1041
1043
|
F: __dxlog_file,
|
|
1042
|
-
L:
|
|
1044
|
+
L: 373,
|
|
1043
1045
|
S: this,
|
|
1044
1046
|
C: (f, a) => f(...a)
|
|
1045
1047
|
});
|
|
1046
1048
|
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
1047
1049
|
F: __dxlog_file,
|
|
1048
|
-
L:
|
|
1050
|
+
L: 374,
|
|
1049
1051
|
S: this,
|
|
1050
1052
|
A: [
|
|
1051
1053
|
"state !== this._state",
|
|
@@ -1073,245 +1075,13 @@ var import_log4 = require("@dxos/log");
|
|
|
1073
1075
|
var import_protocols4 = require("@dxos/protocols");
|
|
1074
1076
|
var import_util2 = require("@dxos/util");
|
|
1075
1077
|
|
|
1076
|
-
// packages/core/mesh/network-manager/src/
|
|
1078
|
+
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
1079
|
+
var import_async2 = require("@dxos/async");
|
|
1077
1080
|
var import_context2 = require("@dxos/context");
|
|
1078
1081
|
var import_invariant2 = require("@dxos/invariant");
|
|
1079
1082
|
var import_keys2 = require("@dxos/keys");
|
|
1080
1083
|
var import_log2 = require("@dxos/log");
|
|
1081
1084
|
var import_protocols2 = require("@dxos/protocols");
|
|
1082
|
-
var import_util = require("@dxos/util");
|
|
1083
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
1084
|
-
var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
1085
|
-
var SwarmMessenger = class {
|
|
1086
|
-
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
1087
|
-
this._ctx = new import_context2.Context();
|
|
1088
|
-
this._offerRecords = new import_util.ComplexMap((key) => key.toHex());
|
|
1089
|
-
this._sendMessage = sendMessage;
|
|
1090
|
-
this._onSignal = onSignal;
|
|
1091
|
-
this._onOffer = onOffer;
|
|
1092
|
-
this._topic = topic;
|
|
1093
|
-
}
|
|
1094
|
-
async receiveMessage({ author, recipient, payload }) {
|
|
1095
|
-
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
1096
|
-
return;
|
|
1097
|
-
}
|
|
1098
|
-
const message = SwarmMessage.decode(payload.value);
|
|
1099
|
-
if (!this._topic.equals(message.topic)) {
|
|
1100
|
-
return;
|
|
1101
|
-
}
|
|
1102
|
-
(0, import_log2.log)("received", {
|
|
1103
|
-
from: author,
|
|
1104
|
-
to: recipient,
|
|
1105
|
-
msg: message
|
|
1106
|
-
}, {
|
|
1107
|
-
F: __dxlog_file2,
|
|
1108
|
-
L: 69,
|
|
1109
|
-
S: this,
|
|
1110
|
-
C: (f, a) => f(...a)
|
|
1111
|
-
});
|
|
1112
|
-
if (message.data?.offer) {
|
|
1113
|
-
await this._handleOffer({
|
|
1114
|
-
author,
|
|
1115
|
-
recipient,
|
|
1116
|
-
message
|
|
1117
|
-
});
|
|
1118
|
-
} else if (message.data?.answer) {
|
|
1119
|
-
await this._resolveAnswers(message);
|
|
1120
|
-
} else if (message.data?.signal) {
|
|
1121
|
-
await this._handleSignal({
|
|
1122
|
-
author,
|
|
1123
|
-
recipient,
|
|
1124
|
-
message
|
|
1125
|
-
});
|
|
1126
|
-
} else if (message.data?.signalBatch) {
|
|
1127
|
-
await this._handleSignal({
|
|
1128
|
-
author,
|
|
1129
|
-
recipient,
|
|
1130
|
-
message
|
|
1131
|
-
});
|
|
1132
|
-
} else {
|
|
1133
|
-
import_log2.log.warn("unknown message", {
|
|
1134
|
-
message
|
|
1135
|
-
}, {
|
|
1136
|
-
F: __dxlog_file2,
|
|
1137
|
-
L: 80,
|
|
1138
|
-
S: this,
|
|
1139
|
-
C: (f, a) => f(...a)
|
|
1140
|
-
});
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
async signal(message) {
|
|
1144
|
-
(0, import_invariant2.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
1145
|
-
F: __dxlog_file2,
|
|
1146
|
-
L: 85,
|
|
1147
|
-
S: this,
|
|
1148
|
-
A: [
|
|
1149
|
-
"message.data?.signal || message.data?.signalBatch",
|
|
1150
|
-
"'Invalid message'"
|
|
1151
|
-
]
|
|
1152
|
-
});
|
|
1153
|
-
await this._sendReliableMessage({
|
|
1154
|
-
author: message.author,
|
|
1155
|
-
recipient: message.recipient,
|
|
1156
|
-
message
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
async offer(message) {
|
|
1160
|
-
const networkMessage = {
|
|
1161
|
-
...message,
|
|
1162
|
-
messageId: import_keys2.PublicKey.random()
|
|
1163
|
-
};
|
|
1164
|
-
return new Promise((resolve, reject) => {
|
|
1165
|
-
this._offerRecords.set(networkMessage.messageId, {
|
|
1166
|
-
resolve
|
|
1167
|
-
});
|
|
1168
|
-
this._sendReliableMessage({
|
|
1169
|
-
author: message.author,
|
|
1170
|
-
recipient: message.recipient,
|
|
1171
|
-
message: networkMessage
|
|
1172
|
-
}).catch((err) => reject(err));
|
|
1173
|
-
});
|
|
1174
|
-
}
|
|
1175
|
-
async _sendReliableMessage({ author, recipient, message }) {
|
|
1176
|
-
const networkMessage = {
|
|
1177
|
-
...message,
|
|
1178
|
-
// Setting unique message_id if it not specified yet.
|
|
1179
|
-
messageId: message.messageId ?? import_keys2.PublicKey.random()
|
|
1180
|
-
};
|
|
1181
|
-
(0, import_log2.log)("sending", {
|
|
1182
|
-
from: author,
|
|
1183
|
-
to: recipient,
|
|
1184
|
-
msg: networkMessage
|
|
1185
|
-
}, {
|
|
1186
|
-
F: __dxlog_file2,
|
|
1187
|
-
L: 123,
|
|
1188
|
-
S: this,
|
|
1189
|
-
C: (f, a) => f(...a)
|
|
1190
|
-
});
|
|
1191
|
-
await this._sendMessage({
|
|
1192
|
-
author,
|
|
1193
|
-
recipient,
|
|
1194
|
-
payload: {
|
|
1195
|
-
type_url: "dxos.mesh.swarm.SwarmMessage",
|
|
1196
|
-
value: SwarmMessage.encode(networkMessage)
|
|
1197
|
-
}
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
async _resolveAnswers(message) {
|
|
1201
|
-
(0, import_invariant2.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
1202
|
-
F: __dxlog_file2,
|
|
1203
|
-
L: 135,
|
|
1204
|
-
S: this,
|
|
1205
|
-
A: [
|
|
1206
|
-
"message.data?.answer?.offerMessageId",
|
|
1207
|
-
"'No offerMessageId'"
|
|
1208
|
-
]
|
|
1209
|
-
});
|
|
1210
|
-
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
1211
|
-
if (offerRecord) {
|
|
1212
|
-
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
1213
|
-
(0, import_invariant2.invariant)(message.data?.answer, "No answer", {
|
|
1214
|
-
F: __dxlog_file2,
|
|
1215
|
-
L: 139,
|
|
1216
|
-
S: this,
|
|
1217
|
-
A: [
|
|
1218
|
-
"message.data?.answer",
|
|
1219
|
-
"'No answer'"
|
|
1220
|
-
]
|
|
1221
|
-
});
|
|
1222
|
-
(0, import_log2.log)("resolving", {
|
|
1223
|
-
answer: message.data.answer
|
|
1224
|
-
}, {
|
|
1225
|
-
F: __dxlog_file2,
|
|
1226
|
-
L: 140,
|
|
1227
|
-
S: this,
|
|
1228
|
-
C: (f, a) => f(...a)
|
|
1229
|
-
});
|
|
1230
|
-
offerRecord.resolve(message.data.answer);
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
async _handleOffer({ author, recipient, message }) {
|
|
1234
|
-
(0, import_invariant2.invariant)(message.data.offer, "No offer", {
|
|
1235
|
-
F: __dxlog_file2,
|
|
1236
|
-
L: 154,
|
|
1237
|
-
S: this,
|
|
1238
|
-
A: [
|
|
1239
|
-
"message.data.offer",
|
|
1240
|
-
"'No offer'"
|
|
1241
|
-
]
|
|
1242
|
-
});
|
|
1243
|
-
const offerMessage = {
|
|
1244
|
-
author,
|
|
1245
|
-
recipient,
|
|
1246
|
-
...message,
|
|
1247
|
-
data: {
|
|
1248
|
-
offer: message.data.offer
|
|
1249
|
-
}
|
|
1250
|
-
};
|
|
1251
|
-
const answer = await this._onOffer(offerMessage);
|
|
1252
|
-
answer.offerMessageId = message.messageId;
|
|
1253
|
-
try {
|
|
1254
|
-
await this._sendReliableMessage({
|
|
1255
|
-
author: recipient,
|
|
1256
|
-
recipient: author,
|
|
1257
|
-
message: {
|
|
1258
|
-
topic: message.topic,
|
|
1259
|
-
sessionId: message.sessionId,
|
|
1260
|
-
data: {
|
|
1261
|
-
answer
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
});
|
|
1265
|
-
} catch (err) {
|
|
1266
|
-
import_log2.log.warn("error sending answer", {
|
|
1267
|
-
err
|
|
1268
|
-
}, {
|
|
1269
|
-
F: __dxlog_file2,
|
|
1270
|
-
L: 174,
|
|
1271
|
-
S: this,
|
|
1272
|
-
C: (f, a) => f(...a)
|
|
1273
|
-
});
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
async _handleSignal({ author, recipient, message }) {
|
|
1277
|
-
(0, import_invariant2.invariant)(message.messageId, void 0, {
|
|
1278
|
-
F: __dxlog_file2,
|
|
1279
|
-
L: 187,
|
|
1280
|
-
S: this,
|
|
1281
|
-
A: [
|
|
1282
|
-
"message.messageId",
|
|
1283
|
-
""
|
|
1284
|
-
]
|
|
1285
|
-
});
|
|
1286
|
-
(0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
1287
|
-
F: __dxlog_file2,
|
|
1288
|
-
L: 188,
|
|
1289
|
-
S: this,
|
|
1290
|
-
A: [
|
|
1291
|
-
"message.data.signal || message.data.signalBatch",
|
|
1292
|
-
"'Invalid message'"
|
|
1293
|
-
]
|
|
1294
|
-
});
|
|
1295
|
-
const signalMessage = {
|
|
1296
|
-
author,
|
|
1297
|
-
recipient,
|
|
1298
|
-
...message,
|
|
1299
|
-
data: {
|
|
1300
|
-
signal: message.data.signal,
|
|
1301
|
-
signalBatch: message.data.signalBatch
|
|
1302
|
-
}
|
|
1303
|
-
};
|
|
1304
|
-
await this._onSignal(signalMessage);
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
|
-
|
|
1308
|
-
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
1309
|
-
var import_async2 = require("@dxos/async");
|
|
1310
|
-
var import_context3 = require("@dxos/context");
|
|
1311
|
-
var import_invariant3 = require("@dxos/invariant");
|
|
1312
|
-
var import_keys3 = require("@dxos/keys");
|
|
1313
|
-
var import_log3 = require("@dxos/log");
|
|
1314
|
-
var import_protocols3 = require("@dxos/protocols");
|
|
1315
1085
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
1316
1086
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1317
1087
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -1322,8 +1092,8 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
1322
1092
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1323
1093
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1324
1094
|
}
|
|
1325
|
-
var
|
|
1326
|
-
var ConnectionDisplacedError = class extends
|
|
1095
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
1096
|
+
var ConnectionDisplacedError = class extends import_protocols2.SystemError {
|
|
1327
1097
|
constructor() {
|
|
1328
1098
|
super("Connection displaced by remote initiator.");
|
|
1329
1099
|
}
|
|
@@ -1342,7 +1112,7 @@ var Peer = class {
|
|
|
1342
1112
|
this._callbacks = _callbacks;
|
|
1343
1113
|
this._availableAfter = 0;
|
|
1344
1114
|
this.availableToConnect = true;
|
|
1345
|
-
this._ctx = new
|
|
1115
|
+
this._ctx = new import_context2.Context();
|
|
1346
1116
|
this.advertizing = false;
|
|
1347
1117
|
this.initiating = false;
|
|
1348
1118
|
this.connectionDisplaced = new import_async2.Event();
|
|
@@ -1352,16 +1122,30 @@ var Peer = class {
|
|
|
1352
1122
|
*/
|
|
1353
1123
|
async onOffer(message) {
|
|
1354
1124
|
const remoteId = message.author;
|
|
1125
|
+
if (this.connection && ![
|
|
1126
|
+
ConnectionState.CREATED,
|
|
1127
|
+
ConnectionState.INITIAL
|
|
1128
|
+
].includes(this.connection.state)) {
|
|
1129
|
+
import_log2.log.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
1130
|
+
F: __dxlog_file2,
|
|
1131
|
+
L: 112,
|
|
1132
|
+
S: this,
|
|
1133
|
+
C: (f, a) => f(...a)
|
|
1134
|
+
});
|
|
1135
|
+
return {
|
|
1136
|
+
accept: false
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1355
1139
|
if (this.connection || this.initiating) {
|
|
1356
1140
|
if (remoteId.toHex() < this.localPeerId.toHex()) {
|
|
1357
|
-
(0,
|
|
1141
|
+
(0, import_log2.log)("close local connection", {
|
|
1358
1142
|
localPeerId: this.id,
|
|
1359
1143
|
topic: this.topic,
|
|
1360
1144
|
remotePeerId: this.localPeerId,
|
|
1361
1145
|
sessionId: this.connection?.sessionId
|
|
1362
1146
|
}, {
|
|
1363
|
-
F:
|
|
1364
|
-
L:
|
|
1147
|
+
F: __dxlog_file2,
|
|
1148
|
+
L: 121,
|
|
1365
1149
|
S: this,
|
|
1366
1150
|
C: (f, a) => f(...a)
|
|
1367
1151
|
});
|
|
@@ -1376,9 +1160,9 @@ var Peer = class {
|
|
|
1376
1160
|
}
|
|
1377
1161
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
1378
1162
|
if (!this.connection) {
|
|
1379
|
-
(0,
|
|
1380
|
-
F:
|
|
1381
|
-
L:
|
|
1163
|
+
(0, import_invariant2.invariant)(message.sessionId, void 0, {
|
|
1164
|
+
F: __dxlog_file2,
|
|
1165
|
+
L: 141,
|
|
1382
1166
|
S: this,
|
|
1383
1167
|
A: [
|
|
1384
1168
|
"message.sessionId",
|
|
@@ -1391,15 +1175,15 @@ var Peer = class {
|
|
|
1391
1175
|
connection.initiate();
|
|
1392
1176
|
await connection.openConnection();
|
|
1393
1177
|
} catch (err) {
|
|
1394
|
-
if (!(err instanceof
|
|
1395
|
-
|
|
1178
|
+
if (!(err instanceof import_protocols2.CancelledError)) {
|
|
1179
|
+
import_log2.log.warn("connection error", {
|
|
1396
1180
|
topic: this.topic,
|
|
1397
1181
|
peerId: this.localPeerId,
|
|
1398
1182
|
remoteId: this.id,
|
|
1399
1183
|
err
|
|
1400
1184
|
}, {
|
|
1401
|
-
F:
|
|
1402
|
-
L:
|
|
1185
|
+
F: __dxlog_file2,
|
|
1186
|
+
L: 151,
|
|
1403
1187
|
S: this,
|
|
1404
1188
|
C: (f, a) => f(...a)
|
|
1405
1189
|
});
|
|
@@ -1419,33 +1203,33 @@ var Peer = class {
|
|
|
1419
1203
|
* Initiate a connection to the remote peer.
|
|
1420
1204
|
*/
|
|
1421
1205
|
async initiateConnection() {
|
|
1422
|
-
(0,
|
|
1423
|
-
F:
|
|
1424
|
-
L:
|
|
1206
|
+
(0, import_invariant2.invariant)(!this.initiating, "Initiation in progress.", {
|
|
1207
|
+
F: __dxlog_file2,
|
|
1208
|
+
L: 168,
|
|
1425
1209
|
S: this,
|
|
1426
1210
|
A: [
|
|
1427
1211
|
"!this.initiating",
|
|
1428
1212
|
"'Initiation in progress.'"
|
|
1429
1213
|
]
|
|
1430
1214
|
});
|
|
1431
|
-
(0,
|
|
1432
|
-
F:
|
|
1433
|
-
L:
|
|
1215
|
+
(0, import_invariant2.invariant)(!this.connection, "Already connected.", {
|
|
1216
|
+
F: __dxlog_file2,
|
|
1217
|
+
L: 169,
|
|
1434
1218
|
S: this,
|
|
1435
1219
|
A: [
|
|
1436
1220
|
"!this.connection",
|
|
1437
1221
|
"'Already connected.'"
|
|
1438
1222
|
]
|
|
1439
1223
|
});
|
|
1440
|
-
const sessionId =
|
|
1441
|
-
(0,
|
|
1224
|
+
const sessionId = import_keys2.PublicKey.random();
|
|
1225
|
+
(0, import_log2.log)("initiating...", {
|
|
1442
1226
|
id: this.id,
|
|
1443
1227
|
topic: this.topic,
|
|
1444
1228
|
peerId: this.id,
|
|
1445
1229
|
sessionId
|
|
1446
1230
|
}, {
|
|
1447
|
-
F:
|
|
1448
|
-
L:
|
|
1231
|
+
F: __dxlog_file2,
|
|
1232
|
+
L: 171,
|
|
1449
1233
|
S: this,
|
|
1450
1234
|
C: (f, a) => f(...a)
|
|
1451
1235
|
});
|
|
@@ -1463,21 +1247,21 @@ var Peer = class {
|
|
|
1463
1247
|
offer: {}
|
|
1464
1248
|
}
|
|
1465
1249
|
});
|
|
1466
|
-
(0,
|
|
1250
|
+
(0, import_log2.log)("received", {
|
|
1467
1251
|
answer,
|
|
1468
1252
|
topic: this.topic,
|
|
1469
1253
|
ownId: this.localPeerId,
|
|
1470
1254
|
remoteId: this.id
|
|
1471
1255
|
}, {
|
|
1472
|
-
F:
|
|
1473
|
-
L:
|
|
1256
|
+
F: __dxlog_file2,
|
|
1257
|
+
L: 187,
|
|
1474
1258
|
S: this,
|
|
1475
1259
|
C: (f, a) => f(...a)
|
|
1476
1260
|
});
|
|
1477
1261
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1478
|
-
(0,
|
|
1479
|
-
F:
|
|
1480
|
-
L:
|
|
1262
|
+
(0, import_log2.log)("ignoring response", void 0, {
|
|
1263
|
+
F: __dxlog_file2,
|
|
1264
|
+
L: 189,
|
|
1481
1265
|
S: this,
|
|
1482
1266
|
C: (f, a) => f(...a)
|
|
1483
1267
|
});
|
|
@@ -1490,18 +1274,24 @@ var Peer = class {
|
|
|
1490
1274
|
await connection.openConnection();
|
|
1491
1275
|
this._callbacks.onAccepted();
|
|
1492
1276
|
} catch (err) {
|
|
1493
|
-
(0,
|
|
1277
|
+
(0, import_log2.log)("initiation error", {
|
|
1494
1278
|
err,
|
|
1495
1279
|
topic: this.topic,
|
|
1496
1280
|
peerId: this.localPeerId,
|
|
1497
1281
|
remoteId: this.id
|
|
1498
1282
|
}, {
|
|
1499
|
-
F:
|
|
1500
|
-
L:
|
|
1283
|
+
F: __dxlog_file2,
|
|
1284
|
+
L: 200,
|
|
1501
1285
|
S: this,
|
|
1502
1286
|
C: (f, a) => f(...a)
|
|
1503
1287
|
});
|
|
1504
|
-
if (err instanceof
|
|
1288
|
+
if (err instanceof import_protocols2.TimeoutError) {
|
|
1289
|
+
import_log2.log.warn("aborting connection due to signalling failure", void 0, {
|
|
1290
|
+
F: __dxlog_file2,
|
|
1291
|
+
L: 202,
|
|
1292
|
+
S: this,
|
|
1293
|
+
C: (f, a) => f(...a)
|
|
1294
|
+
});
|
|
1505
1295
|
await connection.abort(err);
|
|
1506
1296
|
}
|
|
1507
1297
|
await this.closeConnection(err);
|
|
@@ -1515,21 +1305,21 @@ var Peer = class {
|
|
|
1515
1305
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
1516
1306
|
*/
|
|
1517
1307
|
_createConnection(initiator, sessionId) {
|
|
1518
|
-
(0,
|
|
1308
|
+
(0, import_log2.log)("creating connection", {
|
|
1519
1309
|
topic: this.topic,
|
|
1520
1310
|
peerId: this.localPeerId,
|
|
1521
1311
|
remoteId: this.id,
|
|
1522
1312
|
initiator,
|
|
1523
1313
|
sessionId
|
|
1524
1314
|
}, {
|
|
1525
|
-
F:
|
|
1526
|
-
L:
|
|
1315
|
+
F: __dxlog_file2,
|
|
1316
|
+
L: 218,
|
|
1527
1317
|
S: this,
|
|
1528
1318
|
C: (f, a) => f(...a)
|
|
1529
1319
|
});
|
|
1530
|
-
(0,
|
|
1531
|
-
F:
|
|
1532
|
-
L:
|
|
1320
|
+
(0, import_invariant2.invariant)(!this.connection, "Already connected.", {
|
|
1321
|
+
F: __dxlog_file2,
|
|
1322
|
+
L: 225,
|
|
1533
1323
|
S: this,
|
|
1534
1324
|
A: [
|
|
1535
1325
|
"!this.connection",
|
|
@@ -1557,50 +1347,50 @@ var Peer = class {
|
|
|
1557
1347
|
this._lastConnectionTime = Date.now();
|
|
1558
1348
|
this._callbacks.onConnected();
|
|
1559
1349
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1560
|
-
|
|
1350
|
+
import_log2.log.trace("dxos.mesh.connection.connected", {
|
|
1561
1351
|
topic: this.topic,
|
|
1562
1352
|
localPeerId: this.localPeerId,
|
|
1563
1353
|
remotePeerId: this.id,
|
|
1564
1354
|
sessionId,
|
|
1565
1355
|
initiator
|
|
1566
1356
|
}, {
|
|
1567
|
-
F:
|
|
1568
|
-
L:
|
|
1357
|
+
F: __dxlog_file2,
|
|
1358
|
+
L: 244,
|
|
1569
1359
|
S: this,
|
|
1570
1360
|
C: (f, a) => f(...a)
|
|
1571
1361
|
});
|
|
1572
1362
|
},
|
|
1573
1363
|
onClosed: (err) => {
|
|
1574
|
-
(0,
|
|
1364
|
+
(0, import_log2.log)("connection closed", {
|
|
1575
1365
|
topic: this.topic,
|
|
1576
1366
|
peerId: this.localPeerId,
|
|
1577
1367
|
remoteId: this.id,
|
|
1578
1368
|
initiator
|
|
1579
1369
|
}, {
|
|
1580
|
-
F:
|
|
1581
|
-
L:
|
|
1370
|
+
F: __dxlog_file2,
|
|
1371
|
+
L: 253,
|
|
1582
1372
|
S: this,
|
|
1583
1373
|
C: (f, a) => f(...a)
|
|
1584
1374
|
});
|
|
1585
1375
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1586
|
-
(0,
|
|
1587
|
-
F:
|
|
1588
|
-
L:
|
|
1376
|
+
(0, import_invariant2.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1377
|
+
F: __dxlog_file2,
|
|
1378
|
+
L: 258,
|
|
1589
1379
|
S: this,
|
|
1590
1380
|
A: [
|
|
1591
1381
|
"this.connection === connection",
|
|
1592
1382
|
"'Connection mismatch (race condition).'"
|
|
1593
1383
|
]
|
|
1594
1384
|
});
|
|
1595
|
-
|
|
1385
|
+
import_log2.log.trace("dxos.mesh.connection.closed", {
|
|
1596
1386
|
topic: this.topic,
|
|
1597
1387
|
localPeerId: this.localPeerId,
|
|
1598
1388
|
remotePeerId: this.id,
|
|
1599
1389
|
sessionId,
|
|
1600
1390
|
initiator
|
|
1601
1391
|
}, {
|
|
1602
|
-
F:
|
|
1603
|
-
L:
|
|
1392
|
+
F: __dxlog_file2,
|
|
1393
|
+
L: 260,
|
|
1604
1394
|
S: this,
|
|
1605
1395
|
C: (f, a) => f(...a)
|
|
1606
1396
|
});
|
|
@@ -1627,103 +1417,335 @@ var Peer = class {
|
|
|
1627
1417
|
void this._connectionCtx?.dispose();
|
|
1628
1418
|
this._connectionCtx = this._ctx.derive();
|
|
1629
1419
|
connection.errors.handle((err) => {
|
|
1630
|
-
|
|
1420
|
+
import_log2.log.warn("connection error", {
|
|
1631
1421
|
topic: this.topic,
|
|
1632
1422
|
peerId: this.localPeerId,
|
|
1633
1423
|
remoteId: this.id,
|
|
1634
1424
|
initiator,
|
|
1635
1425
|
err
|
|
1636
1426
|
}, {
|
|
1637
|
-
F:
|
|
1638
|
-
L:
|
|
1427
|
+
F: __dxlog_file2,
|
|
1428
|
+
L: 300,
|
|
1639
1429
|
S: this,
|
|
1640
1430
|
C: (f, a) => f(...a)
|
|
1641
1431
|
});
|
|
1642
|
-
|
|
1432
|
+
import_log2.log.trace("dxos.mesh.connection.error", {
|
|
1643
1433
|
topic: this.topic,
|
|
1644
1434
|
localPeerId: this.localPeerId,
|
|
1645
1435
|
remotePeerId: this.id,
|
|
1646
1436
|
sessionId,
|
|
1647
1437
|
initiator,
|
|
1648
1438
|
err
|
|
1439
|
+
}, {
|
|
1440
|
+
F: __dxlog_file2,
|
|
1441
|
+
L: 301,
|
|
1442
|
+
S: this,
|
|
1443
|
+
C: (f, a) => f(...a)
|
|
1444
|
+
});
|
|
1445
|
+
void this.closeConnection(err);
|
|
1446
|
+
});
|
|
1447
|
+
this.connection = connection;
|
|
1448
|
+
return connection;
|
|
1449
|
+
}
|
|
1450
|
+
async closeConnection(err) {
|
|
1451
|
+
if (!this.connection) {
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
const connection = this.connection;
|
|
1455
|
+
(0, import_log2.log)("closing...", {
|
|
1456
|
+
peerId: this.id,
|
|
1457
|
+
sessionId: connection.sessionId
|
|
1458
|
+
}, {
|
|
1459
|
+
F: __dxlog_file2,
|
|
1460
|
+
L: 326,
|
|
1461
|
+
S: this,
|
|
1462
|
+
C: (f, a) => f(...a)
|
|
1463
|
+
});
|
|
1464
|
+
await connection.close(err);
|
|
1465
|
+
(0, import_log2.log)("closed", {
|
|
1466
|
+
peerId: this.id,
|
|
1467
|
+
sessionId: connection.sessionId
|
|
1468
|
+
}, {
|
|
1469
|
+
F: __dxlog_file2,
|
|
1470
|
+
L: 332,
|
|
1471
|
+
S: this,
|
|
1472
|
+
C: (f, a) => f(...a)
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
async onSignal(message) {
|
|
1476
|
+
if (!this.connection) {
|
|
1477
|
+
(0, import_log2.log)("dropping signal message for non-existent connection", {
|
|
1478
|
+
message
|
|
1479
|
+
}, {
|
|
1480
|
+
F: __dxlog_file2,
|
|
1481
|
+
L: 337,
|
|
1482
|
+
S: this,
|
|
1483
|
+
C: (f, a) => f(...a)
|
|
1484
|
+
});
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
await this.connection.signal(message);
|
|
1488
|
+
}
|
|
1489
|
+
async destroy() {
|
|
1490
|
+
await this._ctx.dispose();
|
|
1491
|
+
(0, import_log2.log)("Destroying peer", {
|
|
1492
|
+
peerId: this.id,
|
|
1493
|
+
topic: this.topic
|
|
1494
|
+
}, {
|
|
1495
|
+
F: __dxlog_file2,
|
|
1496
|
+
L: 347,
|
|
1497
|
+
S: this,
|
|
1498
|
+
C: (f, a) => f(...a)
|
|
1499
|
+
});
|
|
1500
|
+
await this?.connection?.close();
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
_ts_decorate2([
|
|
1504
|
+
import_async2.synchronized
|
|
1505
|
+
], Peer.prototype, "destroy", null);
|
|
1506
|
+
var increaseInterval = (interval) => {
|
|
1507
|
+
if (interval === 0) {
|
|
1508
|
+
return 50;
|
|
1509
|
+
} else if (interval < 500) {
|
|
1510
|
+
return 500;
|
|
1511
|
+
} else if (interval < 1e3) {
|
|
1512
|
+
return 1e3;
|
|
1513
|
+
} else if (interval < 5e3) {
|
|
1514
|
+
return 5e3;
|
|
1515
|
+
}
|
|
1516
|
+
return 1e4;
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
1520
|
+
var import_context3 = require("@dxos/context");
|
|
1521
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
1522
|
+
var import_keys3 = require("@dxos/keys");
|
|
1523
|
+
var import_log3 = require("@dxos/log");
|
|
1524
|
+
var import_protocols3 = require("@dxos/protocols");
|
|
1525
|
+
var import_util = require("@dxos/util");
|
|
1526
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
1527
|
+
var SwarmMessage = import_protocols3.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
1528
|
+
var SwarmMessenger = class {
|
|
1529
|
+
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
1530
|
+
this._ctx = new import_context3.Context();
|
|
1531
|
+
this._offerRecords = new import_util.ComplexMap((key) => key.toHex());
|
|
1532
|
+
this._sendMessage = sendMessage;
|
|
1533
|
+
this._onSignal = onSignal;
|
|
1534
|
+
this._onOffer = onOffer;
|
|
1535
|
+
this._topic = topic;
|
|
1536
|
+
}
|
|
1537
|
+
async receiveMessage({ author, recipient, payload }) {
|
|
1538
|
+
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
const message = SwarmMessage.decode(payload.value);
|
|
1542
|
+
if (!this._topic.equals(message.topic)) {
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
(0, import_log3.log)("received", {
|
|
1546
|
+
from: author,
|
|
1547
|
+
to: recipient,
|
|
1548
|
+
msg: message
|
|
1549
|
+
}, {
|
|
1550
|
+
F: __dxlog_file3,
|
|
1551
|
+
L: 69,
|
|
1552
|
+
S: this,
|
|
1553
|
+
C: (f, a) => f(...a)
|
|
1554
|
+
});
|
|
1555
|
+
if (message.data?.offer) {
|
|
1556
|
+
await this._handleOffer({
|
|
1557
|
+
author,
|
|
1558
|
+
recipient,
|
|
1559
|
+
message
|
|
1560
|
+
});
|
|
1561
|
+
} else if (message.data?.answer) {
|
|
1562
|
+
await this._resolveAnswers(message);
|
|
1563
|
+
} else if (message.data?.signal) {
|
|
1564
|
+
await this._handleSignal({
|
|
1565
|
+
author,
|
|
1566
|
+
recipient,
|
|
1567
|
+
message
|
|
1568
|
+
});
|
|
1569
|
+
} else if (message.data?.signalBatch) {
|
|
1570
|
+
await this._handleSignal({
|
|
1571
|
+
author,
|
|
1572
|
+
recipient,
|
|
1573
|
+
message
|
|
1574
|
+
});
|
|
1575
|
+
} else {
|
|
1576
|
+
import_log3.log.warn("unknown message", {
|
|
1577
|
+
message
|
|
1649
1578
|
}, {
|
|
1650
1579
|
F: __dxlog_file3,
|
|
1651
|
-
L:
|
|
1580
|
+
L: 80,
|
|
1652
1581
|
S: this,
|
|
1653
1582
|
C: (f, a) => f(...a)
|
|
1654
1583
|
});
|
|
1655
|
-
void this.closeConnection(err);
|
|
1656
|
-
});
|
|
1657
|
-
this.connection = connection;
|
|
1658
|
-
return connection;
|
|
1659
|
-
}
|
|
1660
|
-
async closeConnection(err) {
|
|
1661
|
-
if (!this.connection) {
|
|
1662
|
-
return;
|
|
1663
1584
|
}
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
sessionId: connection.sessionId
|
|
1668
|
-
}, {
|
|
1585
|
+
}
|
|
1586
|
+
async signal(message) {
|
|
1587
|
+
(0, import_invariant3.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
1669
1588
|
F: __dxlog_file3,
|
|
1670
|
-
L:
|
|
1589
|
+
L: 85,
|
|
1671
1590
|
S: this,
|
|
1672
|
-
|
|
1591
|
+
A: [
|
|
1592
|
+
"message.data?.signal || message.data?.signalBatch",
|
|
1593
|
+
"'Invalid message'"
|
|
1594
|
+
]
|
|
1673
1595
|
});
|
|
1674
|
-
await
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1596
|
+
await this._sendReliableMessage({
|
|
1597
|
+
author: message.author,
|
|
1598
|
+
recipient: message.recipient,
|
|
1599
|
+
message
|
|
1600
|
+
});
|
|
1601
|
+
}
|
|
1602
|
+
async offer(message) {
|
|
1603
|
+
const networkMessage = {
|
|
1604
|
+
...message,
|
|
1605
|
+
messageId: import_keys3.PublicKey.random()
|
|
1606
|
+
};
|
|
1607
|
+
return new Promise((resolve, reject) => {
|
|
1608
|
+
this._offerRecords.set(networkMessage.messageId, {
|
|
1609
|
+
resolve
|
|
1610
|
+
});
|
|
1611
|
+
this._sendReliableMessage({
|
|
1612
|
+
author: message.author,
|
|
1613
|
+
recipient: message.recipient,
|
|
1614
|
+
message: networkMessage
|
|
1615
|
+
}).catch((err) => reject(err));
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
async _sendReliableMessage({ author, recipient, message }) {
|
|
1619
|
+
const networkMessage = {
|
|
1620
|
+
...message,
|
|
1621
|
+
// Setting unique message_id if it not specified yet.
|
|
1622
|
+
messageId: message.messageId ?? import_keys3.PublicKey.random()
|
|
1623
|
+
};
|
|
1624
|
+
(0, import_log3.log)("sending", {
|
|
1625
|
+
from: author,
|
|
1626
|
+
to: recipient,
|
|
1627
|
+
msg: networkMessage
|
|
1678
1628
|
}, {
|
|
1679
1629
|
F: __dxlog_file3,
|
|
1680
|
-
L:
|
|
1630
|
+
L: 123,
|
|
1681
1631
|
S: this,
|
|
1682
1632
|
C: (f, a) => f(...a)
|
|
1683
1633
|
});
|
|
1634
|
+
await this._sendMessage({
|
|
1635
|
+
author,
|
|
1636
|
+
recipient,
|
|
1637
|
+
payload: {
|
|
1638
|
+
type_url: "dxos.mesh.swarm.SwarmMessage",
|
|
1639
|
+
value: SwarmMessage.encode(networkMessage)
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1684
1642
|
}
|
|
1685
|
-
async
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1643
|
+
async _resolveAnswers(message) {
|
|
1644
|
+
(0, import_invariant3.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
1645
|
+
F: __dxlog_file3,
|
|
1646
|
+
L: 135,
|
|
1647
|
+
S: this,
|
|
1648
|
+
A: [
|
|
1649
|
+
"message.data?.answer?.offerMessageId",
|
|
1650
|
+
"'No offerMessageId'"
|
|
1651
|
+
]
|
|
1652
|
+
});
|
|
1653
|
+
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
1654
|
+
if (offerRecord) {
|
|
1655
|
+
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
1656
|
+
(0, import_invariant3.invariant)(message.data?.answer, "No answer", {
|
|
1657
|
+
F: __dxlog_file3,
|
|
1658
|
+
L: 139,
|
|
1659
|
+
S: this,
|
|
1660
|
+
A: [
|
|
1661
|
+
"message.data?.answer",
|
|
1662
|
+
"'No answer'"
|
|
1663
|
+
]
|
|
1664
|
+
});
|
|
1665
|
+
(0, import_log3.log)("resolving", {
|
|
1666
|
+
answer: message.data.answer
|
|
1689
1667
|
}, {
|
|
1690
1668
|
F: __dxlog_file3,
|
|
1691
|
-
L:
|
|
1669
|
+
L: 140,
|
|
1692
1670
|
S: this,
|
|
1693
1671
|
C: (f, a) => f(...a)
|
|
1694
1672
|
});
|
|
1695
|
-
|
|
1673
|
+
offerRecord.resolve(message.data.answer);
|
|
1696
1674
|
}
|
|
1697
|
-
await this.connection.signal(message);
|
|
1698
1675
|
}
|
|
1699
|
-
async
|
|
1700
|
-
|
|
1701
|
-
(0, import_log3.log)("Destroying peer", {
|
|
1702
|
-
peerId: this.id,
|
|
1703
|
-
topic: this.topic
|
|
1704
|
-
}, {
|
|
1676
|
+
async _handleOffer({ author, recipient, message }) {
|
|
1677
|
+
(0, import_invariant3.invariant)(message.data.offer, "No offer", {
|
|
1705
1678
|
F: __dxlog_file3,
|
|
1706
|
-
L:
|
|
1679
|
+
L: 154,
|
|
1707
1680
|
S: this,
|
|
1708
|
-
|
|
1681
|
+
A: [
|
|
1682
|
+
"message.data.offer",
|
|
1683
|
+
"'No offer'"
|
|
1684
|
+
]
|
|
1709
1685
|
});
|
|
1710
|
-
|
|
1686
|
+
const offerMessage = {
|
|
1687
|
+
author,
|
|
1688
|
+
recipient,
|
|
1689
|
+
...message,
|
|
1690
|
+
data: {
|
|
1691
|
+
offer: message.data.offer
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1694
|
+
const answer = await this._onOffer(offerMessage);
|
|
1695
|
+
answer.offerMessageId = message.messageId;
|
|
1696
|
+
try {
|
|
1697
|
+
await this._sendReliableMessage({
|
|
1698
|
+
author: recipient,
|
|
1699
|
+
recipient: author,
|
|
1700
|
+
message: {
|
|
1701
|
+
topic: message.topic,
|
|
1702
|
+
sessionId: message.sessionId,
|
|
1703
|
+
data: {
|
|
1704
|
+
answer
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
} catch (err) {
|
|
1709
|
+
import_log3.log.warn("error sending answer", {
|
|
1710
|
+
err
|
|
1711
|
+
}, {
|
|
1712
|
+
F: __dxlog_file3,
|
|
1713
|
+
L: 174,
|
|
1714
|
+
S: this,
|
|
1715
|
+
C: (f, a) => f(...a)
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1711
1718
|
}
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1719
|
+
async _handleSignal({ author, recipient, message }) {
|
|
1720
|
+
(0, import_invariant3.invariant)(message.messageId, void 0, {
|
|
1721
|
+
F: __dxlog_file3,
|
|
1722
|
+
L: 187,
|
|
1723
|
+
S: this,
|
|
1724
|
+
A: [
|
|
1725
|
+
"message.messageId",
|
|
1726
|
+
""
|
|
1727
|
+
]
|
|
1728
|
+
});
|
|
1729
|
+
(0, import_invariant3.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
1730
|
+
F: __dxlog_file3,
|
|
1731
|
+
L: 188,
|
|
1732
|
+
S: this,
|
|
1733
|
+
A: [
|
|
1734
|
+
"message.data.signal || message.data.signalBatch",
|
|
1735
|
+
"'Invalid message'"
|
|
1736
|
+
]
|
|
1737
|
+
});
|
|
1738
|
+
const signalMessage = {
|
|
1739
|
+
author,
|
|
1740
|
+
recipient,
|
|
1741
|
+
...message,
|
|
1742
|
+
data: {
|
|
1743
|
+
signal: message.data.signal,
|
|
1744
|
+
signalBatch: message.data.signalBatch
|
|
1745
|
+
}
|
|
1746
|
+
};
|
|
1747
|
+
await this._onSignal(signalMessage);
|
|
1725
1748
|
}
|
|
1726
|
-
return 1e4;
|
|
1727
1749
|
};
|
|
1728
1750
|
|
|
1729
1751
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
@@ -2216,7 +2238,6 @@ var SwarmMapper = class {
|
|
|
2216
2238
|
get peers() {
|
|
2217
2239
|
return Array.from(this._peers.values());
|
|
2218
2240
|
}
|
|
2219
|
-
// prettier-ignore
|
|
2220
2241
|
constructor(_swarm) {
|
|
2221
2242
|
this._swarm = _swarm;
|
|
2222
2243
|
this._subscriptions = new import_async4.EventSubscriptions();
|
|
@@ -2239,7 +2260,7 @@ var SwarmMapper = class {
|
|
|
2239
2260
|
_update() {
|
|
2240
2261
|
(0, import_log5.log)("updating swarm", void 0, {
|
|
2241
2262
|
F: __dxlog_file5,
|
|
2242
|
-
L:
|
|
2263
|
+
L: 72,
|
|
2243
2264
|
S: this,
|
|
2244
2265
|
C: (f, a) => f(...a)
|
|
2245
2266
|
});
|
|
@@ -2263,7 +2284,7 @@ var SwarmMapper = class {
|
|
|
2263
2284
|
totalPeersInSwarm: this._peers.size
|
|
2264
2285
|
}, {
|
|
2265
2286
|
F: __dxlog_file5,
|
|
2266
|
-
L:
|
|
2287
|
+
L: 113,
|
|
2267
2288
|
S: this,
|
|
2268
2289
|
C: (f, a) => f(...a)
|
|
2269
2290
|
});
|
|
@@ -2823,7 +2844,6 @@ var import_invariant9 = require("@dxos/invariant");
|
|
|
2823
2844
|
var import_log9 = require("@dxos/log");
|
|
2824
2845
|
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2825
2846
|
var StarTopology = class {
|
|
2826
|
-
// prettier-ignore
|
|
2827
2847
|
constructor(_centralPeer) {
|
|
2828
2848
|
this._centralPeer = _centralPeer;
|
|
2829
2849
|
}
|
|
@@ -2833,7 +2853,7 @@ var StarTopology = class {
|
|
|
2833
2853
|
init(controller) {
|
|
2834
2854
|
(0, import_invariant9.invariant)(!this._controller, "Already initialized.", {
|
|
2835
2855
|
F: __dxlog_file10,
|
|
2836
|
-
L:
|
|
2856
|
+
L: 21,
|
|
2837
2857
|
S: this,
|
|
2838
2858
|
A: [
|
|
2839
2859
|
"!this._controller",
|
|
@@ -2845,7 +2865,7 @@ var StarTopology = class {
|
|
|
2845
2865
|
update() {
|
|
2846
2866
|
(0, import_invariant9.invariant)(this._controller, "Not initialized.", {
|
|
2847
2867
|
F: __dxlog_file10,
|
|
2848
|
-
L:
|
|
2868
|
+
L: 26,
|
|
2849
2869
|
S: this,
|
|
2850
2870
|
A: [
|
|
2851
2871
|
"this._controller",
|
|
@@ -2856,7 +2876,7 @@ var StarTopology = class {
|
|
|
2856
2876
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
2857
2877
|
(0, import_log9.log)("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
2858
2878
|
F: __dxlog_file10,
|
|
2859
|
-
L:
|
|
2879
|
+
L: 29,
|
|
2860
2880
|
S: this,
|
|
2861
2881
|
C: (f, a) => f(...a)
|
|
2862
2882
|
});
|
|
@@ -2866,7 +2886,7 @@ var StarTopology = class {
|
|
|
2866
2886
|
peer
|
|
2867
2887
|
}, {
|
|
2868
2888
|
F: __dxlog_file10,
|
|
2869
|
-
L:
|
|
2889
|
+
L: 34,
|
|
2870
2890
|
S: this,
|
|
2871
2891
|
C: (f, a) => f(...a)
|
|
2872
2892
|
});
|
|
@@ -2880,7 +2900,7 @@ var StarTopology = class {
|
|
|
2880
2900
|
peer
|
|
2881
2901
|
}, {
|
|
2882
2902
|
F: __dxlog_file10,
|
|
2883
|
-
L:
|
|
2903
|
+
L: 43,
|
|
2884
2904
|
S: this,
|
|
2885
2905
|
C: (f, a) => f(...a)
|
|
2886
2906
|
});
|
|
@@ -2891,7 +2911,7 @@ var StarTopology = class {
|
|
|
2891
2911
|
async onOffer(peer) {
|
|
2892
2912
|
(0, import_invariant9.invariant)(this._controller, "Not initialized.", {
|
|
2893
2913
|
F: __dxlog_file10,
|
|
2894
|
-
L:
|
|
2914
|
+
L: 50,
|
|
2895
2915
|
S: this,
|
|
2896
2916
|
A: [
|
|
2897
2917
|
"this._controller",
|
|
@@ -2905,7 +2925,7 @@ var StarTopology = class {
|
|
|
2905
2925
|
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
2906
2926
|
}, {
|
|
2907
2927
|
F: __dxlog_file10,
|
|
2908
|
-
L:
|
|
2928
|
+
L: 52,
|
|
2909
2929
|
S: this,
|
|
2910
2930
|
C: (f, a) => f(...a)
|
|
2911
2931
|
});
|
|
@@ -3207,24 +3227,28 @@ var SimplePeerTransport = class {
|
|
|
3207
3227
|
switch (err.code) {
|
|
3208
3228
|
case "ERR_WEBRTC_SUPPORT":
|
|
3209
3229
|
this.errors.raise(new import_protocols7.ProtocolError("WebRTC not supported", err));
|
|
3230
|
+
break;
|
|
3210
3231
|
case "ERR_ICE_CONNECTION_FAILURE":
|
|
3211
3232
|
case "ERR_DATA_CHANNEL":
|
|
3212
3233
|
case "ERR_CONNECTION_FAILURE":
|
|
3213
3234
|
case "ERR_SIGNALING":
|
|
3214
3235
|
this.errors.raise(new import_protocols7.ConnectivityError("unknown communication failure", err));
|
|
3236
|
+
break;
|
|
3215
3237
|
case "ERR_CREATE_OFFER":
|
|
3216
3238
|
case "ERR_CREATE_ANSWER":
|
|
3217
3239
|
case "ERR_SET_LOCAL_DESCRIPTION":
|
|
3218
3240
|
case "ERR_SET_REMOTE_DESCRIPTION":
|
|
3219
3241
|
case "ERR_ADD_ICE_CANDIDATE":
|
|
3220
3242
|
this.errors.raise(new import_protocols7.UnknownProtocolError("unknown simple-peer library failure", err));
|
|
3243
|
+
break;
|
|
3221
3244
|
default:
|
|
3222
3245
|
this.errors.raise(new Error("unknown simple-peer error"));
|
|
3246
|
+
break;
|
|
3223
3247
|
}
|
|
3224
3248
|
} else {
|
|
3225
3249
|
import_log11.log.info("unknown peer connection error", err, {
|
|
3226
3250
|
F: __dxlog_file12,
|
|
3227
|
-
L:
|
|
3251
|
+
L: 101,
|
|
3228
3252
|
S: this,
|
|
3229
3253
|
C: (f, a) => f(...a)
|
|
3230
3254
|
});
|
|
@@ -3238,7 +3262,7 @@ var SimplePeerTransport = class {
|
|
|
3238
3262
|
stats
|
|
3239
3263
|
}, {
|
|
3240
3264
|
F: __dxlog_file12,
|
|
3241
|
-
L:
|
|
3265
|
+
L: 109,
|
|
3242
3266
|
S: this,
|
|
3243
3267
|
C: (f, a) => f(...a)
|
|
3244
3268
|
});
|
|
@@ -3247,7 +3271,7 @@ var SimplePeerTransport = class {
|
|
|
3247
3271
|
} catch (err2) {
|
|
3248
3272
|
import_log11.log.catch(err2, void 0, {
|
|
3249
3273
|
F: __dxlog_file12,
|
|
3250
|
-
L:
|
|
3274
|
+
L: 116,
|
|
3251
3275
|
S: this,
|
|
3252
3276
|
C: (f, a) => f(...a)
|
|
3253
3277
|
});
|
|
@@ -3258,7 +3282,7 @@ var SimplePeerTransport = class {
|
|
|
3258
3282
|
id: this._instanceId
|
|
3259
3283
|
}), {
|
|
3260
3284
|
F: __dxlog_file12,
|
|
3261
|
-
L:
|
|
3285
|
+
L: 121,
|
|
3262
3286
|
S: this,
|
|
3263
3287
|
C: (f, a) => f(...a)
|
|
3264
3288
|
});
|
|
@@ -3266,7 +3290,7 @@ var SimplePeerTransport = class {
|
|
|
3266
3290
|
async destroy() {
|
|
3267
3291
|
(0, import_log11.log)("closing...", void 0, {
|
|
3268
3292
|
F: __dxlog_file12,
|
|
3269
|
-
L:
|
|
3293
|
+
L: 125,
|
|
3270
3294
|
S: this,
|
|
3271
3295
|
C: (f, a) => f(...a)
|
|
3272
3296
|
});
|
|
@@ -3276,7 +3300,7 @@ var SimplePeerTransport = class {
|
|
|
3276
3300
|
this.closed.emit();
|
|
3277
3301
|
(0, import_log11.log)("closed", void 0, {
|
|
3278
3302
|
F: __dxlog_file12,
|
|
3279
|
-
L:
|
|
3303
|
+
L: 130,
|
|
3280
3304
|
S: this,
|
|
3281
3305
|
C: (f, a) => f(...a)
|
|
3282
3306
|
});
|
|
@@ -3309,7 +3333,6 @@ var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
|
3309
3333
|
var import_util8 = require("@dxos/util");
|
|
3310
3334
|
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
|
|
3311
3335
|
var SimplePeerTransportService = class {
|
|
3312
|
-
// prettier-ignore
|
|
3313
3336
|
constructor(_webrtcConfig) {
|
|
3314
3337
|
this._webrtcConfig = _webrtcConfig;
|
|
3315
3338
|
this.transports = new import_util8.ComplexMap(import_keys11.PublicKey.hash);
|
|
@@ -3379,7 +3402,8 @@ var SimplePeerTransportService = class {
|
|
|
3379
3402
|
const transportState = {
|
|
3380
3403
|
transport,
|
|
3381
3404
|
stream: duplex,
|
|
3382
|
-
writeCallbacks: []
|
|
3405
|
+
writeCallbacks: [],
|
|
3406
|
+
state: "OPEN"
|
|
3383
3407
|
};
|
|
3384
3408
|
ready();
|
|
3385
3409
|
this.transports.set(request.proxyId, transportState);
|
|
@@ -3389,7 +3413,7 @@ var SimplePeerTransportService = class {
|
|
|
3389
3413
|
async sendSignal({ proxyId, signal }) {
|
|
3390
3414
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3391
3415
|
F: __dxlog_file13,
|
|
3392
|
-
L:
|
|
3416
|
+
L: 112,
|
|
3393
3417
|
S: this,
|
|
3394
3418
|
A: [
|
|
3395
3419
|
"this.transports.has(proxyId)",
|
|
@@ -3399,9 +3423,17 @@ var SimplePeerTransportService = class {
|
|
|
3399
3423
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
3400
3424
|
}
|
|
3401
3425
|
async sendData({ proxyId, payload }) {
|
|
3426
|
+
if (this.transports.get(proxyId)?.state !== "OPEN") {
|
|
3427
|
+
import_log12.log.debug("transport is closed", void 0, {
|
|
3428
|
+
F: __dxlog_file13,
|
|
3429
|
+
L: 118,
|
|
3430
|
+
S: this,
|
|
3431
|
+
C: (f, a) => f(...a)
|
|
3432
|
+
});
|
|
3433
|
+
}
|
|
3402
3434
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3403
3435
|
F: __dxlog_file13,
|
|
3404
|
-
L:
|
|
3436
|
+
L: 120,
|
|
3405
3437
|
S: this,
|
|
3406
3438
|
A: [
|
|
3407
3439
|
"this.transports.has(proxyId)",
|
|
@@ -3419,10 +3451,12 @@ var SimplePeerTransportService = class {
|
|
|
3419
3451
|
async close({ proxyId }) {
|
|
3420
3452
|
await this.transports.get(proxyId)?.transport.destroy();
|
|
3421
3453
|
await this.transports.get(proxyId)?.stream.end();
|
|
3422
|
-
this.transports.
|
|
3454
|
+
if (this.transports.get(proxyId)) {
|
|
3455
|
+
this.transports.get(proxyId).state = "CLOSED";
|
|
3456
|
+
}
|
|
3423
3457
|
(0, import_log12.log)("Closed.", void 0, {
|
|
3424
3458
|
F: __dxlog_file13,
|
|
3425
|
-
L:
|
|
3459
|
+
L: 136,
|
|
3426
3460
|
S: this,
|
|
3427
3461
|
C: (f, a) => f(...a)
|
|
3428
3462
|
});
|
|
@@ -3442,7 +3476,6 @@ var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
|
3442
3476
|
var import_util9 = require("@dxos/util");
|
|
3443
3477
|
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
|
|
3444
3478
|
var SimplePeerTransportProxy = class {
|
|
3445
|
-
// prettier-ignore
|
|
3446
3479
|
constructor(_params) {
|
|
3447
3480
|
this._params = _params;
|
|
3448
3481
|
this._proxyId = import_keys12.PublicKey.random();
|
|
@@ -3459,7 +3492,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3459
3492
|
this._serviceStream.subscribe(async (event) => {
|
|
3460
3493
|
(0, import_log13.log)("SimplePeerTransportProxy: event", event, {
|
|
3461
3494
|
F: __dxlog_file14,
|
|
3462
|
-
L:
|
|
3495
|
+
L: 55,
|
|
3463
3496
|
S: this,
|
|
3464
3497
|
C: (f, a) => f(...a)
|
|
3465
3498
|
});
|
|
@@ -3488,7 +3521,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3488
3521
|
}));
|
|
3489
3522
|
}, (error) => import_log13.log.catch(error, void 0, {
|
|
3490
3523
|
F: __dxlog_file14,
|
|
3491
|
-
L:
|
|
3524
|
+
L: 83,
|
|
3492
3525
|
S: this,
|
|
3493
3526
|
C: (f, a) => f(...a)
|
|
3494
3527
|
}));
|
|
@@ -3534,7 +3567,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3534
3567
|
} catch (err) {
|
|
3535
3568
|
import_log13.log.catch(err, void 0, {
|
|
3536
3569
|
F: __dxlog_file14,
|
|
3537
|
-
L:
|
|
3570
|
+
L: 134,
|
|
3538
3571
|
S: this,
|
|
3539
3572
|
C: (f, a) => f(...a)
|
|
3540
3573
|
});
|
|
@@ -3570,7 +3603,7 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3570
3603
|
createTransport(options) {
|
|
3571
3604
|
(0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
|
|
3572
3605
|
F: __dxlog_file14,
|
|
3573
|
-
L:
|
|
3606
|
+
L: 171,
|
|
3574
3607
|
S: this,
|
|
3575
3608
|
A: [
|
|
3576
3609
|
"this._bridgeService",
|
|
@@ -3588,15 +3621,15 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3588
3621
|
};
|
|
3589
3622
|
var decodeError = (err) => {
|
|
3590
3623
|
const message = typeof err === "string" ? err : err.message;
|
|
3591
|
-
if (message.includes("
|
|
3624
|
+
if (message.includes("CONNECTION_RESET")) {
|
|
3592
3625
|
return new import_protocols8.ConnectionResetError(message);
|
|
3593
|
-
} else if (message.includes("
|
|
3626
|
+
} else if (message.includes("TIMEOUT")) {
|
|
3594
3627
|
return new import_protocols8.TimeoutError(message);
|
|
3595
|
-
} else if (message.includes("
|
|
3628
|
+
} else if (message.includes("PROTOCOL_ERROR")) {
|
|
3596
3629
|
return new import_protocols8.ProtocolError(message);
|
|
3597
|
-
} else if (message.includes("
|
|
3630
|
+
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
3598
3631
|
return new import_protocols8.ConnectivityError(message);
|
|
3599
|
-
} else if (message.includes("
|
|
3632
|
+
} else if (message.includes("UNKNOWN_PROTOCOL_ERROR")) {
|
|
3600
3633
|
return new import_protocols8.UnknownProtocolError(message);
|
|
3601
3634
|
} else {
|
|
3602
3635
|
return typeof err === "string" ? new Error(err) : err;
|
|
@@ -3945,6 +3978,136 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
|
|
|
3945
3978
|
})
|
|
3946
3979
|
});
|
|
3947
3980
|
|
|
3981
|
+
// packages/core/mesh/network-manager/src/transport/tcp-transport.ts
|
|
3982
|
+
var import_node_net = require("node:net");
|
|
3983
|
+
var import_async12 = require("@dxos/async");
|
|
3984
|
+
var import_debug8 = require("@dxos/debug");
|
|
3985
|
+
var import_log15 = require("@dxos/log");
|
|
3986
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
|
|
3987
|
+
var TcpTransportFactory = {
|
|
3988
|
+
createTransport: (params) => new TcpTransport(params)
|
|
3989
|
+
};
|
|
3990
|
+
var TcpTransport = class {
|
|
3991
|
+
constructor(options) {
|
|
3992
|
+
this.options = options;
|
|
3993
|
+
this._server = void 0;
|
|
3994
|
+
this._socket = void 0;
|
|
3995
|
+
this.closed = new import_async12.Event();
|
|
3996
|
+
this.connected = new import_async12.Event();
|
|
3997
|
+
this.errors = new import_debug8.ErrorStream();
|
|
3998
|
+
this._destroyed = false;
|
|
3999
|
+
this._connected = false;
|
|
4000
|
+
(0, import_log15.log)("creating", void 0, {
|
|
4001
|
+
F: __dxlog_file16,
|
|
4002
|
+
L: 34,
|
|
4003
|
+
S: this,
|
|
4004
|
+
C: (f, a) => f(...a)
|
|
4005
|
+
});
|
|
4006
|
+
if (this.options.initiator) {
|
|
4007
|
+
setTimeout(async () => {
|
|
4008
|
+
const { Server } = await import("node:net");
|
|
4009
|
+
this._server = new Server((socket) => {
|
|
4010
|
+
(0, import_log15.log)("new connection", void 0, {
|
|
4011
|
+
F: __dxlog_file16,
|
|
4012
|
+
L: 42,
|
|
4013
|
+
S: this,
|
|
4014
|
+
C: (f, a) => f(...a)
|
|
4015
|
+
});
|
|
4016
|
+
if (this._connected) {
|
|
4017
|
+
socket.destroy();
|
|
4018
|
+
}
|
|
4019
|
+
this._handleSocket(socket);
|
|
4020
|
+
});
|
|
4021
|
+
this._server.on("listening", () => {
|
|
4022
|
+
const { port } = this._server.address();
|
|
4023
|
+
(0, import_log15.log)("listening", {
|
|
4024
|
+
port
|
|
4025
|
+
}, {
|
|
4026
|
+
F: __dxlog_file16,
|
|
4027
|
+
L: 51,
|
|
4028
|
+
S: this,
|
|
4029
|
+
C: (f, a) => f(...a)
|
|
4030
|
+
});
|
|
4031
|
+
void this.options.sendSignal({
|
|
4032
|
+
payload: {
|
|
4033
|
+
port
|
|
4034
|
+
}
|
|
4035
|
+
}).catch((err) => {
|
|
4036
|
+
if (!this._destroyed) {
|
|
4037
|
+
this.errors.raise(err);
|
|
4038
|
+
}
|
|
4039
|
+
});
|
|
4040
|
+
});
|
|
4041
|
+
this._server.on("error", (err) => {
|
|
4042
|
+
this.errors.raise(err);
|
|
4043
|
+
});
|
|
4044
|
+
this._server.listen(0);
|
|
4045
|
+
});
|
|
4046
|
+
}
|
|
4047
|
+
}
|
|
4048
|
+
async destroy() {
|
|
4049
|
+
(0, import_log15.log)("closing", void 0, {
|
|
4050
|
+
F: __dxlog_file16,
|
|
4051
|
+
L: 72,
|
|
4052
|
+
S: this,
|
|
4053
|
+
C: (f, a) => f(...a)
|
|
4054
|
+
});
|
|
4055
|
+
this._socket?.destroy();
|
|
4056
|
+
this._server?.close();
|
|
4057
|
+
this._destroyed = true;
|
|
4058
|
+
}
|
|
4059
|
+
signal({ payload }) {
|
|
4060
|
+
(0, import_log15.log)("received signal", {
|
|
4061
|
+
payload
|
|
4062
|
+
}, {
|
|
4063
|
+
F: __dxlog_file16,
|
|
4064
|
+
L: 80,
|
|
4065
|
+
S: this,
|
|
4066
|
+
C: (f, a) => f(...a)
|
|
4067
|
+
});
|
|
4068
|
+
if (this.options.initiator || this._connected) {
|
|
4069
|
+
return;
|
|
4070
|
+
}
|
|
4071
|
+
const socket = new import_node_net.Socket();
|
|
4072
|
+
this._handleSocket(socket);
|
|
4073
|
+
socket.connect({
|
|
4074
|
+
port: payload.port,
|
|
4075
|
+
host: "localhost"
|
|
4076
|
+
});
|
|
4077
|
+
}
|
|
4078
|
+
_handleSocket(socket) {
|
|
4079
|
+
(0, import_log15.log)("handling socket", {
|
|
4080
|
+
remotePort: socket.remotePort,
|
|
4081
|
+
localPort: socket.localPort
|
|
4082
|
+
}, {
|
|
4083
|
+
F: __dxlog_file16,
|
|
4084
|
+
L: 91,
|
|
4085
|
+
S: this,
|
|
4086
|
+
C: (f, a) => f(...a)
|
|
4087
|
+
});
|
|
4088
|
+
this._socket = socket;
|
|
4089
|
+
this.connected.emit();
|
|
4090
|
+
this.options.stream.pipe(this._socket).pipe(this.options.stream);
|
|
4091
|
+
this._socket.on("connect", () => {
|
|
4092
|
+
(0, import_log15.log)("connected to", {
|
|
4093
|
+
port: this._socket?.remotePort
|
|
4094
|
+
}, {
|
|
4095
|
+
F: __dxlog_file16,
|
|
4096
|
+
L: 97,
|
|
4097
|
+
S: this,
|
|
4098
|
+
C: (f, a) => f(...a)
|
|
4099
|
+
});
|
|
4100
|
+
this._connected = true;
|
|
4101
|
+
});
|
|
4102
|
+
this._socket.on("error", (err) => {
|
|
4103
|
+
this.errors.raise(err);
|
|
4104
|
+
});
|
|
4105
|
+
this._socket.on("close", () => {
|
|
4106
|
+
this.closed.emit();
|
|
4107
|
+
});
|
|
4108
|
+
}
|
|
4109
|
+
};
|
|
4110
|
+
|
|
3948
4111
|
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
3949
4112
|
var import_teleport = require("@dxos/teleport");
|
|
3950
4113
|
var createTeleportProtocolFactory = (onConnection) => {
|
|
@@ -3990,6 +4153,8 @@ var createTeleportProtocolFactory = (onConnection) => {
|
|
|
3990
4153
|
Swarm,
|
|
3991
4154
|
SwarmMapper,
|
|
3992
4155
|
SwarmMessenger,
|
|
4156
|
+
TcpTransport,
|
|
4157
|
+
TcpTransportFactory,
|
|
3993
4158
|
TransportKind,
|
|
3994
4159
|
cleanup,
|
|
3995
4160
|
createLibDataChannelTransportFactory,
|