@dxos/network-manager 0.3.1-main.cf090ba → 0.3.1-next.2d5b138
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-TRMX3E42.mjs → chunk-UE5KR5PC.mjs} +183 -108
- package/dist/lib/browser/chunk-UE5KR5PC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/index.cjs +173 -98
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +173 -98
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/swarm/connection.d.ts +1 -0
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/swarm/connection.ts +27 -5
- package/src/swarm/peer.ts +47 -11
- package/src/swarm/swarm.ts +10 -7
- package/dist/lib/browser/chunk-TRMX3E42.mjs.map +0 -7
|
@@ -668,6 +668,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
668
668
|
}
|
|
669
669
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
670
670
|
var STARTING_SIGNALLING_DELAY = 10;
|
|
671
|
+
var TRANSPORT_CONNECTION_TIMEOUT = 1e4;
|
|
671
672
|
var MAX_SIGNALLING_DELAY = 300;
|
|
672
673
|
var ConnectionState;
|
|
673
674
|
(function(ConnectionState6) {
|
|
@@ -723,6 +724,7 @@ var Connection = class {
|
|
|
723
724
|
this._transportFactory = _transportFactory;
|
|
724
725
|
this._callbacks = _callbacks;
|
|
725
726
|
this._ctx = new import_context.Context();
|
|
727
|
+
this.connectedTimeoutContext = new import_context.Context();
|
|
726
728
|
this._state = ConnectionState.CREATED;
|
|
727
729
|
this._incomingSignalBuffer = [];
|
|
728
730
|
this._outgoingSignalBuffer = [];
|
|
@@ -741,7 +743,7 @@ var Connection = class {
|
|
|
741
743
|
initiator: this.initiator
|
|
742
744
|
}, {
|
|
743
745
|
F: __dxlog_file2,
|
|
744
|
-
L:
|
|
746
|
+
L: 129,
|
|
745
747
|
S: this,
|
|
746
748
|
C: (f, a) => f(...a)
|
|
747
749
|
});
|
|
@@ -761,7 +763,7 @@ var Connection = class {
|
|
|
761
763
|
async openConnection() {
|
|
762
764
|
(0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
763
765
|
F: __dxlog_file2,
|
|
764
|
-
L:
|
|
766
|
+
L: 154,
|
|
765
767
|
S: this,
|
|
766
768
|
A: [
|
|
767
769
|
"this._state === ConnectionState.INITIAL",
|
|
@@ -772,7 +774,7 @@ var Connection = class {
|
|
|
772
774
|
id: this._instanceId
|
|
773
775
|
}), {
|
|
774
776
|
F: __dxlog_file2,
|
|
775
|
-
L:
|
|
777
|
+
L: 155,
|
|
776
778
|
S: this,
|
|
777
779
|
C: (f, a) => f(...a)
|
|
778
780
|
});
|
|
@@ -784,7 +786,7 @@ var Connection = class {
|
|
|
784
786
|
initiator: this.initiator
|
|
785
787
|
}, {
|
|
786
788
|
F: __dxlog_file2,
|
|
787
|
-
L:
|
|
789
|
+
L: 156,
|
|
788
790
|
S: this,
|
|
789
791
|
C: (f, a) => f(...a)
|
|
790
792
|
});
|
|
@@ -795,15 +797,24 @@ var Connection = class {
|
|
|
795
797
|
this._protocol.stream.on("close", () => {
|
|
796
798
|
(0, import_log2.log)("protocol stream closed", void 0, {
|
|
797
799
|
F: __dxlog_file2,
|
|
798
|
-
L:
|
|
800
|
+
L: 173,
|
|
799
801
|
S: this,
|
|
800
802
|
C: (f, a) => f(...a)
|
|
801
803
|
});
|
|
802
804
|
this.close(new import_protocols.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
|
|
803
805
|
});
|
|
806
|
+
(0, import_async2.scheduleTask)(this.connectedTimeoutContext, async () => {
|
|
807
|
+
import_log2.log.warn("timeout waiting for transport to connect, aborting", void 0, {
|
|
808
|
+
F: __dxlog_file2,
|
|
809
|
+
L: 180,
|
|
810
|
+
S: this,
|
|
811
|
+
C: (f, a) => f(...a)
|
|
812
|
+
});
|
|
813
|
+
await this.abort().catch((err) => this.errors.raise(err));
|
|
814
|
+
}, TRANSPORT_CONNECTION_TIMEOUT);
|
|
804
815
|
(0, import_invariant.invariant)(!this._transport, void 0, {
|
|
805
816
|
F: __dxlog_file2,
|
|
806
|
-
L:
|
|
817
|
+
L: 186,
|
|
807
818
|
S: this,
|
|
808
819
|
A: [
|
|
809
820
|
"!this._transport",
|
|
@@ -815,26 +826,27 @@ var Connection = class {
|
|
|
815
826
|
stream: this._protocol.stream,
|
|
816
827
|
sendSignal: async (signal) => this._sendSignal(signal)
|
|
817
828
|
});
|
|
818
|
-
this._transport.connected.once(() => {
|
|
829
|
+
this._transport.connected.once(async () => {
|
|
819
830
|
this._changeState(ConnectionState.CONNECTED);
|
|
831
|
+
await this.connectedTimeoutContext.dispose();
|
|
820
832
|
this._callbacks?.onConnected?.();
|
|
821
833
|
});
|
|
822
834
|
this._transport.closed.once(() => {
|
|
823
835
|
this._transport = void 0;
|
|
824
836
|
(0, import_log2.log)("abort triggered by transport close", void 0, {
|
|
825
837
|
F: __dxlog_file2,
|
|
826
|
-
L:
|
|
838
|
+
L: 201,
|
|
827
839
|
S: this,
|
|
828
840
|
C: (f, a) => f(...a)
|
|
829
841
|
});
|
|
830
842
|
this.abort().catch((err) => this.errors.raise(err));
|
|
831
843
|
});
|
|
832
|
-
this._transport.errors.handle((err) => {
|
|
844
|
+
this._transport.errors.handle(async (err) => {
|
|
833
845
|
(0, import_log2.log)("transport error:", {
|
|
834
846
|
err
|
|
835
847
|
}, {
|
|
836
848
|
F: __dxlog_file2,
|
|
837
|
-
L:
|
|
849
|
+
L: 206,
|
|
838
850
|
S: this,
|
|
839
851
|
C: (f, a) => f(...a)
|
|
840
852
|
});
|
|
@@ -844,7 +856,7 @@ var Connection = class {
|
|
|
844
856
|
if (err instanceof import_protocols.ConnectionResetError) {
|
|
845
857
|
import_log2.log.warn("aborting due to transport ConnectionResetError", void 0, {
|
|
846
858
|
F: __dxlog_file2,
|
|
847
|
-
L:
|
|
859
|
+
L: 213,
|
|
848
860
|
S: this,
|
|
849
861
|
C: (f, a) => f(...a)
|
|
850
862
|
});
|
|
@@ -852,7 +864,7 @@ var Connection = class {
|
|
|
852
864
|
} else if (err instanceof import_protocols.ConnectivityError) {
|
|
853
865
|
import_log2.log.warn("aborting due to transport ConnectivityError", void 0, {
|
|
854
866
|
F: __dxlog_file2,
|
|
855
|
-
L:
|
|
867
|
+
L: 216,
|
|
856
868
|
S: this,
|
|
857
869
|
C: (f, a) => f(...a)
|
|
858
870
|
});
|
|
@@ -862,12 +874,13 @@ var Connection = class {
|
|
|
862
874
|
err
|
|
863
875
|
}, {
|
|
864
876
|
F: __dxlog_file2,
|
|
865
|
-
L:
|
|
877
|
+
L: 219,
|
|
866
878
|
S: this,
|
|
867
879
|
C: (f, a) => f(...a)
|
|
868
880
|
});
|
|
869
881
|
}
|
|
870
882
|
if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
|
|
883
|
+
await this.connectedTimeoutContext.dispose();
|
|
871
884
|
this.errors.raise(err);
|
|
872
885
|
}
|
|
873
886
|
});
|
|
@@ -879,7 +892,7 @@ var Connection = class {
|
|
|
879
892
|
id: this._instanceId
|
|
880
893
|
}), {
|
|
881
894
|
F: __dxlog_file2,
|
|
882
|
-
L:
|
|
895
|
+
L: 235,
|
|
883
896
|
S: this,
|
|
884
897
|
C: (f, a) => f(...a)
|
|
885
898
|
});
|
|
@@ -889,30 +902,29 @@ var Connection = class {
|
|
|
889
902
|
err
|
|
890
903
|
}, {
|
|
891
904
|
F: __dxlog_file2,
|
|
892
|
-
L:
|
|
905
|
+
L: 242,
|
|
893
906
|
S: this,
|
|
894
907
|
C: (f, a) => f(...a)
|
|
895
908
|
});
|
|
896
909
|
if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
|
|
897
910
|
(0, import_log2.log)(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
898
911
|
F: __dxlog_file2,
|
|
899
|
-
L:
|
|
912
|
+
L: 244,
|
|
900
913
|
S: this,
|
|
901
914
|
C: (f, a) => f(...a)
|
|
902
915
|
});
|
|
903
916
|
return;
|
|
904
917
|
}
|
|
918
|
+
await this.connectedTimeoutContext.dispose();
|
|
905
919
|
this._changeState(ConnectionState.ABORTING);
|
|
906
920
|
if (!this.closeReason) {
|
|
907
921
|
this.closeReason = err?.message;
|
|
908
922
|
}
|
|
909
923
|
await this._ctx.dispose();
|
|
910
924
|
try {
|
|
911
|
-
(0, import_log2.log)("aborting protocol... ", {
|
|
912
|
-
proto: this._protocol
|
|
913
|
-
}, {
|
|
925
|
+
(0, import_log2.log)("aborting protocol... ", void 0, {
|
|
914
926
|
F: __dxlog_file2,
|
|
915
|
-
L:
|
|
927
|
+
L: 258,
|
|
916
928
|
S: this,
|
|
917
929
|
C: (f, a) => f(...a)
|
|
918
930
|
});
|
|
@@ -920,7 +932,7 @@ var Connection = class {
|
|
|
920
932
|
} catch (err2) {
|
|
921
933
|
import_log2.log.catch(err2, void 0, {
|
|
922
934
|
F: __dxlog_file2,
|
|
923
|
-
L:
|
|
935
|
+
L: 261,
|
|
924
936
|
S: this,
|
|
925
937
|
C: (f, a) => f(...a)
|
|
926
938
|
});
|
|
@@ -930,7 +942,7 @@ var Connection = class {
|
|
|
930
942
|
} catch (err2) {
|
|
931
943
|
import_log2.log.catch(err2, void 0, {
|
|
932
944
|
F: __dxlog_file2,
|
|
933
|
-
L:
|
|
945
|
+
L: 268,
|
|
934
946
|
S: this,
|
|
935
947
|
C: (f, a) => f(...a)
|
|
936
948
|
});
|
|
@@ -940,7 +952,7 @@ var Connection = class {
|
|
|
940
952
|
} catch (err2) {
|
|
941
953
|
import_log2.log.catch(err2, void 0, {
|
|
942
954
|
F: __dxlog_file2,
|
|
943
|
-
L:
|
|
955
|
+
L: 274,
|
|
944
956
|
S: this,
|
|
945
957
|
C: (f, a) => f(...a)
|
|
946
958
|
});
|
|
@@ -950,18 +962,21 @@ var Connection = class {
|
|
|
950
962
|
async close(err) {
|
|
951
963
|
if (!this.closeReason) {
|
|
952
964
|
this.closeReason = err?.message;
|
|
965
|
+
} else {
|
|
966
|
+
this.closeReason += `; ${err?.message}`;
|
|
953
967
|
}
|
|
954
968
|
if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTING || this._state === ConnectionState.ABORTED) {
|
|
955
969
|
return;
|
|
956
970
|
}
|
|
957
971
|
const lastState = this._state;
|
|
958
972
|
this._changeState(ConnectionState.CLOSING);
|
|
973
|
+
await this.connectedTimeoutContext.dispose();
|
|
959
974
|
await this._ctx.dispose();
|
|
960
975
|
(0, import_log2.log)("closing...", {
|
|
961
976
|
peerId: this.ownId
|
|
962
977
|
}, {
|
|
963
978
|
F: __dxlog_file2,
|
|
964
|
-
L:
|
|
979
|
+
L: 299,
|
|
965
980
|
S: this,
|
|
966
981
|
C: (f, a) => f(...a)
|
|
967
982
|
});
|
|
@@ -971,7 +986,7 @@ var Connection = class {
|
|
|
971
986
|
} catch (err2) {
|
|
972
987
|
import_log2.log.catch(err2, void 0, {
|
|
973
988
|
F: __dxlog_file2,
|
|
974
|
-
L:
|
|
989
|
+
L: 306,
|
|
975
990
|
S: this,
|
|
976
991
|
C: (f, a) => f(...a)
|
|
977
992
|
});
|
|
@@ -981,7 +996,7 @@ var Connection = class {
|
|
|
981
996
|
} catch (err2) {
|
|
982
997
|
import_log2.log.catch(err2, void 0, {
|
|
983
998
|
F: __dxlog_file2,
|
|
984
|
-
L:
|
|
999
|
+
L: 313,
|
|
985
1000
|
S: this,
|
|
986
1001
|
C: (f, a) => f(...a)
|
|
987
1002
|
});
|
|
@@ -991,7 +1006,7 @@ var Connection = class {
|
|
|
991
1006
|
peerId: this.ownId
|
|
992
1007
|
}, {
|
|
993
1008
|
F: __dxlog_file2,
|
|
994
|
-
L:
|
|
1009
|
+
L: 317,
|
|
995
1010
|
S: this,
|
|
996
1011
|
C: (f, a) => f(...a)
|
|
997
1012
|
});
|
|
@@ -1027,14 +1042,14 @@ var Connection = class {
|
|
|
1027
1042
|
}
|
|
1028
1043
|
});
|
|
1029
1044
|
} catch (err) {
|
|
1030
|
-
if (err instanceof import_protocols.CancelledError) {
|
|
1045
|
+
if (err instanceof import_protocols.CancelledError || err instanceof Error && err.message?.includes("CANCELLED")) {
|
|
1031
1046
|
return;
|
|
1032
1047
|
}
|
|
1033
1048
|
import_log2.log.warn("signal failed", {
|
|
1034
1049
|
err
|
|
1035
1050
|
}, {
|
|
1036
1051
|
F: __dxlog_file2,
|
|
1037
|
-
L:
|
|
1052
|
+
L: 355,
|
|
1038
1053
|
S: this,
|
|
1039
1054
|
C: (f, a) => f(...a)
|
|
1040
1055
|
});
|
|
@@ -1047,7 +1062,7 @@ var Connection = class {
|
|
|
1047
1062
|
async signal(msg) {
|
|
1048
1063
|
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
1049
1064
|
F: __dxlog_file2,
|
|
1050
|
-
L:
|
|
1065
|
+
L: 364,
|
|
1051
1066
|
S: this,
|
|
1052
1067
|
A: [
|
|
1053
1068
|
"msg.sessionId",
|
|
@@ -1057,7 +1072,7 @@ var Connection = class {
|
|
|
1057
1072
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
1058
1073
|
(0, import_log2.log)("dropping signal for incorrect session id", void 0, {
|
|
1059
1074
|
F: __dxlog_file2,
|
|
1060
|
-
L:
|
|
1075
|
+
L: 366,
|
|
1061
1076
|
S: this,
|
|
1062
1077
|
C: (f, a) => f(...a)
|
|
1063
1078
|
});
|
|
@@ -1065,7 +1080,7 @@ var Connection = class {
|
|
|
1065
1080
|
}
|
|
1066
1081
|
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
1067
1082
|
F: __dxlog_file2,
|
|
1068
|
-
L:
|
|
1083
|
+
L: 369,
|
|
1069
1084
|
S: this,
|
|
1070
1085
|
A: [
|
|
1071
1086
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -1074,7 +1089,7 @@ var Connection = class {
|
|
|
1074
1089
|
});
|
|
1075
1090
|
(0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
|
|
1076
1091
|
F: __dxlog_file2,
|
|
1077
|
-
L:
|
|
1092
|
+
L: 370,
|
|
1078
1093
|
S: this,
|
|
1079
1094
|
A: [
|
|
1080
1095
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -1083,7 +1098,7 @@ var Connection = class {
|
|
|
1083
1098
|
});
|
|
1084
1099
|
(0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
|
|
1085
1100
|
F: __dxlog_file2,
|
|
1086
|
-
L:
|
|
1101
|
+
L: 371,
|
|
1087
1102
|
S: this,
|
|
1088
1103
|
A: [
|
|
1089
1104
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -1107,7 +1122,7 @@ var Connection = class {
|
|
|
1107
1122
|
msg: msg.data
|
|
1108
1123
|
}, {
|
|
1109
1124
|
F: __dxlog_file2,
|
|
1110
|
-
L:
|
|
1125
|
+
L: 380,
|
|
1111
1126
|
S: this,
|
|
1112
1127
|
C: (f, a) => f(...a)
|
|
1113
1128
|
});
|
|
@@ -1115,7 +1130,7 @@ var Connection = class {
|
|
|
1115
1130
|
} else {
|
|
1116
1131
|
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
1117
1132
|
F: __dxlog_file2,
|
|
1118
|
-
L:
|
|
1133
|
+
L: 383,
|
|
1119
1134
|
S: this,
|
|
1120
1135
|
A: [
|
|
1121
1136
|
"this._transport",
|
|
@@ -1128,7 +1143,7 @@ var Connection = class {
|
|
|
1128
1143
|
msg: msg.data
|
|
1129
1144
|
}, {
|
|
1130
1145
|
F: __dxlog_file2,
|
|
1131
|
-
L:
|
|
1146
|
+
L: 384,
|
|
1132
1147
|
S: this,
|
|
1133
1148
|
C: (f, a) => f(...a)
|
|
1134
1149
|
});
|
|
@@ -1146,13 +1161,13 @@ var Connection = class {
|
|
|
1146
1161
|
peerId: this.ownId
|
|
1147
1162
|
}, {
|
|
1148
1163
|
F: __dxlog_file2,
|
|
1149
|
-
L:
|
|
1164
|
+
L: 395,
|
|
1150
1165
|
S: this,
|
|
1151
1166
|
C: (f, a) => f(...a)
|
|
1152
1167
|
});
|
|
1153
1168
|
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
1154
1169
|
F: __dxlog_file2,
|
|
1155
|
-
L:
|
|
1170
|
+
L: 396,
|
|
1156
1171
|
S: this,
|
|
1157
1172
|
A: [
|
|
1158
1173
|
"state !== this._state",
|
|
@@ -1229,11 +1244,12 @@ var Peer = class {
|
|
|
1229
1244
|
const remoteId = message.author;
|
|
1230
1245
|
if (this.connection && ![
|
|
1231
1246
|
ConnectionState.CREATED,
|
|
1232
|
-
ConnectionState.INITIAL
|
|
1247
|
+
ConnectionState.INITIAL,
|
|
1248
|
+
ConnectionState.CONNECTING
|
|
1233
1249
|
].includes(this.connection.state)) {
|
|
1234
1250
|
import_log3.log.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
1235
1251
|
F: __dxlog_file3,
|
|
1236
|
-
L:
|
|
1252
|
+
L: 115,
|
|
1237
1253
|
S: this,
|
|
1238
1254
|
C: (f, a) => f(...a)
|
|
1239
1255
|
});
|
|
@@ -1250,7 +1266,7 @@ var Peer = class {
|
|
|
1250
1266
|
sessionId: this.connection?.sessionId
|
|
1251
1267
|
}, {
|
|
1252
1268
|
F: __dxlog_file3,
|
|
1253
|
-
L:
|
|
1269
|
+
L: 124,
|
|
1254
1270
|
S: this,
|
|
1255
1271
|
C: (f, a) => f(...a)
|
|
1256
1272
|
});
|
|
@@ -1267,7 +1283,7 @@ var Peer = class {
|
|
|
1267
1283
|
if (!this.connection) {
|
|
1268
1284
|
(0, import_invariant2.invariant)(message.sessionId, void 0, {
|
|
1269
1285
|
F: __dxlog_file3,
|
|
1270
|
-
L:
|
|
1286
|
+
L: 144,
|
|
1271
1287
|
S: this,
|
|
1272
1288
|
A: [
|
|
1273
1289
|
"message.sessionId",
|
|
@@ -1288,7 +1304,7 @@ var Peer = class {
|
|
|
1288
1304
|
err
|
|
1289
1305
|
}, {
|
|
1290
1306
|
F: __dxlog_file3,
|
|
1291
|
-
L:
|
|
1307
|
+
L: 154,
|
|
1292
1308
|
S: this,
|
|
1293
1309
|
C: (f, a) => f(...a)
|
|
1294
1310
|
});
|
|
@@ -1310,7 +1326,7 @@ var Peer = class {
|
|
|
1310
1326
|
async initiateConnection() {
|
|
1311
1327
|
(0, import_invariant2.invariant)(!this.initiating, "Initiation in progress.", {
|
|
1312
1328
|
F: __dxlog_file3,
|
|
1313
|
-
L:
|
|
1329
|
+
L: 171,
|
|
1314
1330
|
S: this,
|
|
1315
1331
|
A: [
|
|
1316
1332
|
"!this.initiating",
|
|
@@ -1319,7 +1335,7 @@ var Peer = class {
|
|
|
1319
1335
|
});
|
|
1320
1336
|
(0, import_invariant2.invariant)(!this.connection, "Already connected.", {
|
|
1321
1337
|
F: __dxlog_file3,
|
|
1322
|
-
L:
|
|
1338
|
+
L: 172,
|
|
1323
1339
|
S: this,
|
|
1324
1340
|
A: [
|
|
1325
1341
|
"!this.connection",
|
|
@@ -1334,16 +1350,17 @@ var Peer = class {
|
|
|
1334
1350
|
sessionId
|
|
1335
1351
|
}, {
|
|
1336
1352
|
F: __dxlog_file3,
|
|
1337
|
-
L:
|
|
1353
|
+
L: 174,
|
|
1338
1354
|
S: this,
|
|
1339
1355
|
C: (f, a) => f(...a)
|
|
1340
1356
|
});
|
|
1341
1357
|
const connection = this._createConnection(true, sessionId);
|
|
1342
1358
|
this.initiating = true;
|
|
1359
|
+
let answer;
|
|
1343
1360
|
try {
|
|
1344
1361
|
await this._connectionLimiter.connecting(sessionId);
|
|
1345
1362
|
connection.initiate();
|
|
1346
|
-
|
|
1363
|
+
answer = await this._signalMessaging.offer({
|
|
1347
1364
|
author: this.localPeerId,
|
|
1348
1365
|
recipient: this.id,
|
|
1349
1366
|
sessionId,
|
|
@@ -1359,46 +1376,87 @@ var Peer = class {
|
|
|
1359
1376
|
remoteId: this.id
|
|
1360
1377
|
}, {
|
|
1361
1378
|
F: __dxlog_file3,
|
|
1362
|
-
L:
|
|
1379
|
+
L: 191,
|
|
1363
1380
|
S: this,
|
|
1364
1381
|
C: (f, a) => f(...a)
|
|
1365
1382
|
});
|
|
1366
1383
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1367
1384
|
(0, import_log3.log)("ignoring response", void 0, {
|
|
1368
1385
|
F: __dxlog_file3,
|
|
1369
|
-
L:
|
|
1386
|
+
L: 193,
|
|
1370
1387
|
S: this,
|
|
1371
1388
|
C: (f, a) => f(...a)
|
|
1372
1389
|
});
|
|
1373
1390
|
return;
|
|
1374
1391
|
}
|
|
1392
|
+
} catch (err) {
|
|
1393
|
+
(0, import_log3.log)("initiation error: send offer", {
|
|
1394
|
+
err,
|
|
1395
|
+
topic: this.topic,
|
|
1396
|
+
peerId: this.localPeerId,
|
|
1397
|
+
remoteId: this.id
|
|
1398
|
+
}, {
|
|
1399
|
+
F: __dxlog_file3,
|
|
1400
|
+
L: 197,
|
|
1401
|
+
S: this,
|
|
1402
|
+
C: (f, a) => f(...a)
|
|
1403
|
+
});
|
|
1404
|
+
await connection.abort(err);
|
|
1405
|
+
throw err;
|
|
1406
|
+
} finally {
|
|
1407
|
+
this.initiating = false;
|
|
1408
|
+
}
|
|
1409
|
+
try {
|
|
1375
1410
|
if (!answer.accept) {
|
|
1376
1411
|
this._callbacks.onRejected();
|
|
1377
1412
|
return;
|
|
1378
1413
|
}
|
|
1414
|
+
} catch (err) {
|
|
1415
|
+
(0, import_log3.log)("initiation error: accept answer", {
|
|
1416
|
+
err,
|
|
1417
|
+
topic: this.topic,
|
|
1418
|
+
peerId: this.localPeerId,
|
|
1419
|
+
remoteId: this.id
|
|
1420
|
+
}, {
|
|
1421
|
+
F: __dxlog_file3,
|
|
1422
|
+
L: 210,
|
|
1423
|
+
S: this,
|
|
1424
|
+
C: (f, a) => f(...a)
|
|
1425
|
+
});
|
|
1426
|
+
await connection.abort(err);
|
|
1427
|
+
throw err;
|
|
1428
|
+
} finally {
|
|
1429
|
+
this.initiating = false;
|
|
1430
|
+
}
|
|
1431
|
+
try {
|
|
1432
|
+
(0, import_log3.log)("opening connection as initiator", void 0, {
|
|
1433
|
+
F: __dxlog_file3,
|
|
1434
|
+
L: 223,
|
|
1435
|
+
S: this,
|
|
1436
|
+
C: (f, a) => f(...a)
|
|
1437
|
+
});
|
|
1379
1438
|
await connection.openConnection();
|
|
1380
1439
|
this._callbacks.onAccepted();
|
|
1381
1440
|
} catch (err) {
|
|
1382
|
-
(0, import_log3.log)("initiation error", {
|
|
1441
|
+
(0, import_log3.log)("initiation error: open connection", {
|
|
1383
1442
|
err,
|
|
1384
1443
|
topic: this.topic,
|
|
1385
1444
|
peerId: this.localPeerId,
|
|
1386
1445
|
remoteId: this.id
|
|
1387
1446
|
}, {
|
|
1388
1447
|
F: __dxlog_file3,
|
|
1389
|
-
L:
|
|
1448
|
+
L: 227,
|
|
1449
|
+
S: this,
|
|
1450
|
+
C: (f, a) => f(...a)
|
|
1451
|
+
});
|
|
1452
|
+
import_log3.log.warn("closing connection due to unhandled error on openConnection", {
|
|
1453
|
+
err
|
|
1454
|
+
}, {
|
|
1455
|
+
F: __dxlog_file3,
|
|
1456
|
+
L: 234,
|
|
1390
1457
|
S: this,
|
|
1391
1458
|
C: (f, a) => f(...a)
|
|
1392
1459
|
});
|
|
1393
|
-
if (err instanceof import_protocols2.TimeoutError) {
|
|
1394
|
-
import_log3.log.warn("aborting connection due to signalling failure", void 0, {
|
|
1395
|
-
F: __dxlog_file3,
|
|
1396
|
-
L: 202,
|
|
1397
|
-
S: this,
|
|
1398
|
-
C: (f, a) => f(...a)
|
|
1399
|
-
});
|
|
1400
|
-
await connection.abort(err);
|
|
1401
|
-
}
|
|
1402
1460
|
await this.closeConnection(err);
|
|
1403
1461
|
throw err;
|
|
1404
1462
|
} finally {
|
|
@@ -1418,13 +1476,13 @@ var Peer = class {
|
|
|
1418
1476
|
sessionId
|
|
1419
1477
|
}, {
|
|
1420
1478
|
F: __dxlog_file3,
|
|
1421
|
-
L:
|
|
1479
|
+
L: 248,
|
|
1422
1480
|
S: this,
|
|
1423
1481
|
C: (f, a) => f(...a)
|
|
1424
1482
|
});
|
|
1425
1483
|
(0, import_invariant2.invariant)(!this.connection, "Already connected.", {
|
|
1426
1484
|
F: __dxlog_file3,
|
|
1427
|
-
L:
|
|
1485
|
+
L: 255,
|
|
1428
1486
|
S: this,
|
|
1429
1487
|
A: [
|
|
1430
1488
|
"!this.connection",
|
|
@@ -1460,7 +1518,7 @@ var Peer = class {
|
|
|
1460
1518
|
initiator
|
|
1461
1519
|
}, {
|
|
1462
1520
|
F: __dxlog_file3,
|
|
1463
|
-
L:
|
|
1521
|
+
L: 274,
|
|
1464
1522
|
S: this,
|
|
1465
1523
|
C: (f, a) => f(...a)
|
|
1466
1524
|
});
|
|
@@ -1473,14 +1531,14 @@ var Peer = class {
|
|
|
1473
1531
|
initiator
|
|
1474
1532
|
}, {
|
|
1475
1533
|
F: __dxlog_file3,
|
|
1476
|
-
L:
|
|
1534
|
+
L: 283,
|
|
1477
1535
|
S: this,
|
|
1478
1536
|
C: (f, a) => f(...a)
|
|
1479
1537
|
});
|
|
1480
1538
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1481
1539
|
(0, import_invariant2.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1482
1540
|
F: __dxlog_file3,
|
|
1483
|
-
L:
|
|
1541
|
+
L: 288,
|
|
1484
1542
|
S: this,
|
|
1485
1543
|
A: [
|
|
1486
1544
|
"this.connection === connection",
|
|
@@ -1495,7 +1553,7 @@ var Peer = class {
|
|
|
1495
1553
|
initiator
|
|
1496
1554
|
}, {
|
|
1497
1555
|
F: __dxlog_file3,
|
|
1498
|
-
L:
|
|
1556
|
+
L: 290,
|
|
1499
1557
|
S: this,
|
|
1500
1558
|
C: (f, a) => f(...a)
|
|
1501
1559
|
});
|
|
@@ -1522,7 +1580,7 @@ var Peer = class {
|
|
|
1522
1580
|
void this._connectionCtx?.dispose();
|
|
1523
1581
|
this._connectionCtx = this._ctx.derive();
|
|
1524
1582
|
connection.errors.handle((err) => {
|
|
1525
|
-
import_log3.log.warn("connection error", {
|
|
1583
|
+
import_log3.log.warn("connection error, closing", {
|
|
1526
1584
|
topic: this.topic,
|
|
1527
1585
|
peerId: this.localPeerId,
|
|
1528
1586
|
remoteId: this.id,
|
|
@@ -1530,7 +1588,7 @@ var Peer = class {
|
|
|
1530
1588
|
err
|
|
1531
1589
|
}, {
|
|
1532
1590
|
F: __dxlog_file3,
|
|
1533
|
-
L:
|
|
1591
|
+
L: 330,
|
|
1534
1592
|
S: this,
|
|
1535
1593
|
C: (f, a) => f(...a)
|
|
1536
1594
|
});
|
|
@@ -1543,7 +1601,7 @@ var Peer = class {
|
|
|
1543
1601
|
err
|
|
1544
1602
|
}, {
|
|
1545
1603
|
F: __dxlog_file3,
|
|
1546
|
-
L:
|
|
1604
|
+
L: 337,
|
|
1547
1605
|
S: this,
|
|
1548
1606
|
C: (f, a) => f(...a)
|
|
1549
1607
|
});
|
|
@@ -1562,7 +1620,7 @@ var Peer = class {
|
|
|
1562
1620
|
sessionId: connection.sessionId
|
|
1563
1621
|
}, {
|
|
1564
1622
|
F: __dxlog_file3,
|
|
1565
|
-
L:
|
|
1623
|
+
L: 362,
|
|
1566
1624
|
S: this,
|
|
1567
1625
|
C: (f, a) => f(...a)
|
|
1568
1626
|
});
|
|
@@ -1572,7 +1630,7 @@ var Peer = class {
|
|
|
1572
1630
|
sessionId: connection.sessionId
|
|
1573
1631
|
}, {
|
|
1574
1632
|
F: __dxlog_file3,
|
|
1575
|
-
L:
|
|
1633
|
+
L: 368,
|
|
1576
1634
|
S: this,
|
|
1577
1635
|
C: (f, a) => f(...a)
|
|
1578
1636
|
});
|
|
@@ -1583,7 +1641,7 @@ var Peer = class {
|
|
|
1583
1641
|
message
|
|
1584
1642
|
}, {
|
|
1585
1643
|
F: __dxlog_file3,
|
|
1586
|
-
L:
|
|
1644
|
+
L: 373,
|
|
1587
1645
|
S: this,
|
|
1588
1646
|
C: (f, a) => f(...a)
|
|
1589
1647
|
});
|
|
@@ -1591,18 +1649,18 @@ var Peer = class {
|
|
|
1591
1649
|
}
|
|
1592
1650
|
await this.connection.signal(message);
|
|
1593
1651
|
}
|
|
1594
|
-
async destroy() {
|
|
1652
|
+
async destroy(reason) {
|
|
1595
1653
|
await this._ctx.dispose();
|
|
1596
1654
|
(0, import_log3.log)("Destroying peer", {
|
|
1597
1655
|
peerId: this.id,
|
|
1598
1656
|
topic: this.topic
|
|
1599
1657
|
}, {
|
|
1600
1658
|
F: __dxlog_file3,
|
|
1601
|
-
L:
|
|
1659
|
+
L: 383,
|
|
1602
1660
|
S: this,
|
|
1603
1661
|
C: (f, a) => f(...a)
|
|
1604
1662
|
});
|
|
1605
|
-
await this?.connection?.close();
|
|
1663
|
+
await this?.connection?.close(reason);
|
|
1606
1664
|
}
|
|
1607
1665
|
};
|
|
1608
1666
|
_ts_decorate2([
|
|
@@ -1975,7 +2033,7 @@ var Swarm = class {
|
|
|
1975
2033
|
this._listeningHandle = void 0;
|
|
1976
2034
|
await this._ctx.dispose();
|
|
1977
2035
|
await this._topology.destroy();
|
|
1978
|
-
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
2036
|
+
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1979
2037
|
(0, import_log5.log)("destroyed", void 0, {
|
|
1980
2038
|
F: __dxlog_file5,
|
|
1981
2039
|
L: 148,
|
|
@@ -2047,13 +2105,22 @@ var Swarm = class {
|
|
|
2047
2105
|
if (peer) {
|
|
2048
2106
|
peer.advertizing = false;
|
|
2049
2107
|
if (peer.connection?.state !== ConnectionState.CONNECTED) {
|
|
2050
|
-
void this._destroyPeer(peer.id).catch((err) => import_log5.log.catch(err, void 0, {
|
|
2108
|
+
void this._destroyPeer(peer.id, "peer left").catch((err) => import_log5.log.catch(err, void 0, {
|
|
2051
2109
|
F: __dxlog_file5,
|
|
2052
2110
|
L: 189,
|
|
2053
2111
|
S: this,
|
|
2054
2112
|
C: (f, a) => f(...a)
|
|
2055
2113
|
}));
|
|
2056
2114
|
}
|
|
2115
|
+
} else {
|
|
2116
|
+
(0, import_log5.log)("received peerLeft but no peer found", {
|
|
2117
|
+
peer: swarmEvent.peerLeft.peer
|
|
2118
|
+
}, {
|
|
2119
|
+
F: __dxlog_file5,
|
|
2120
|
+
L: 192,
|
|
2121
|
+
S: this,
|
|
2122
|
+
C: (f, a) => f(...a)
|
|
2123
|
+
});
|
|
2057
2124
|
}
|
|
2058
2125
|
}
|
|
2059
2126
|
this._topology.update();
|
|
@@ -2063,14 +2130,14 @@ var Swarm = class {
|
|
|
2063
2130
|
message
|
|
2064
2131
|
}, {
|
|
2065
2132
|
F: __dxlog_file5,
|
|
2066
|
-
L:
|
|
2133
|
+
L: 201,
|
|
2067
2134
|
S: this,
|
|
2068
2135
|
C: (f, a) => f(...a)
|
|
2069
2136
|
});
|
|
2070
2137
|
if (this._ctx.disposed) {
|
|
2071
2138
|
(0, import_log5.log)("ignored for disposed swarm", void 0, {
|
|
2072
2139
|
F: __dxlog_file5,
|
|
2073
|
-
L:
|
|
2140
|
+
L: 203,
|
|
2074
2141
|
S: this,
|
|
2075
2142
|
C: (f, a) => f(...a)
|
|
2076
2143
|
});
|
|
@@ -2080,7 +2147,7 @@ var Swarm = class {
|
|
|
2080
2147
|
}
|
|
2081
2148
|
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
2082
2149
|
F: __dxlog_file5,
|
|
2083
|
-
L:
|
|
2150
|
+
L: 208,
|
|
2084
2151
|
S: this,
|
|
2085
2152
|
A: [
|
|
2086
2153
|
"message.author",
|
|
@@ -2092,7 +2159,7 @@ var Swarm = class {
|
|
|
2092
2159
|
message
|
|
2093
2160
|
}, {
|
|
2094
2161
|
F: __dxlog_file5,
|
|
2095
|
-
L:
|
|
2162
|
+
L: 210,
|
|
2096
2163
|
S: this,
|
|
2097
2164
|
C: (f, a) => f(...a)
|
|
2098
2165
|
});
|
|
@@ -2105,7 +2172,7 @@ var Swarm = class {
|
|
|
2105
2172
|
message
|
|
2106
2173
|
}, {
|
|
2107
2174
|
F: __dxlog_file5,
|
|
2108
|
-
L:
|
|
2175
|
+
L: 214,
|
|
2109
2176
|
S: this,
|
|
2110
2177
|
C: (f, a) => f(...a)
|
|
2111
2178
|
});
|
|
@@ -2123,14 +2190,14 @@ var Swarm = class {
|
|
|
2123
2190
|
message
|
|
2124
2191
|
}, {
|
|
2125
2192
|
F: __dxlog_file5,
|
|
2126
|
-
L:
|
|
2193
|
+
L: 225,
|
|
2127
2194
|
S: this,
|
|
2128
2195
|
C: (f, a) => f(...a)
|
|
2129
2196
|
});
|
|
2130
2197
|
if (this._ctx.disposed) {
|
|
2131
2198
|
import_log5.log.info("ignored for offline swarm", void 0, {
|
|
2132
2199
|
F: __dxlog_file5,
|
|
2133
|
-
L:
|
|
2200
|
+
L: 227,
|
|
2134
2201
|
S: this,
|
|
2135
2202
|
C: (f, a) => f(...a)
|
|
2136
2203
|
});
|
|
@@ -2138,7 +2205,7 @@ var Swarm = class {
|
|
|
2138
2205
|
}
|
|
2139
2206
|
(0, import_invariant4.invariant)(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
2140
2207
|
F: __dxlog_file5,
|
|
2141
|
-
L:
|
|
2208
|
+
L: 230,
|
|
2142
2209
|
S: this,
|
|
2143
2210
|
A: [
|
|
2144
2211
|
"message.recipient?.equals(this._ownPeerId)",
|
|
@@ -2147,7 +2214,7 @@ var Swarm = class {
|
|
|
2147
2214
|
});
|
|
2148
2215
|
(0, import_invariant4.invariant)(message.topic?.equals(this._topic), void 0, {
|
|
2149
2216
|
F: __dxlog_file5,
|
|
2150
|
-
L:
|
|
2217
|
+
L: 234,
|
|
2151
2218
|
S: this,
|
|
2152
2219
|
A: [
|
|
2153
2220
|
"message.topic?.equals(this._topic)",
|
|
@@ -2156,7 +2223,7 @@ var Swarm = class {
|
|
|
2156
2223
|
});
|
|
2157
2224
|
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
2158
2225
|
F: __dxlog_file5,
|
|
2159
|
-
L:
|
|
2226
|
+
L: 235,
|
|
2160
2227
|
S: this,
|
|
2161
2228
|
A: [
|
|
2162
2229
|
"message.author",
|
|
@@ -2171,7 +2238,7 @@ var Swarm = class {
|
|
|
2171
2238
|
await this._ctx.dispose();
|
|
2172
2239
|
await Promise.all([
|
|
2173
2240
|
...this._peers.keys()
|
|
2174
|
-
].map((peerId) => this._destroyPeer(peerId)));
|
|
2241
|
+
].map((peerId) => this._destroyPeer(peerId, "goOffline")));
|
|
2175
2242
|
}
|
|
2176
2243
|
// For debug purposes
|
|
2177
2244
|
async goOnline() {
|
|
@@ -2189,14 +2256,22 @@ var Swarm = class {
|
|
|
2189
2256
|
},
|
|
2190
2257
|
onDisconnected: async () => {
|
|
2191
2258
|
if (!peer.advertizing) {
|
|
2192
|
-
await this._destroyPeer(peer.id);
|
|
2259
|
+
await this._destroyPeer(peer.id, "peer disconnected");
|
|
2193
2260
|
}
|
|
2194
2261
|
this.disconnected.emit(peerId);
|
|
2195
2262
|
this._topology.update();
|
|
2196
2263
|
},
|
|
2197
2264
|
onRejected: () => {
|
|
2198
2265
|
if (this._peers.has(peerId)) {
|
|
2199
|
-
|
|
2266
|
+
(0, import_log5.log)("peer rejected connection", {
|
|
2267
|
+
peerId
|
|
2268
|
+
}, {
|
|
2269
|
+
F: __dxlog_file5,
|
|
2270
|
+
L: 284,
|
|
2271
|
+
S: this,
|
|
2272
|
+
C: (f, a) => f(...a)
|
|
2273
|
+
});
|
|
2274
|
+
void this._destroyPeer(peerId, "peer rejected connection");
|
|
2200
2275
|
}
|
|
2201
2276
|
},
|
|
2202
2277
|
onAccepted: () => {
|
|
@@ -2213,17 +2288,17 @@ var Swarm = class {
|
|
|
2213
2288
|
}
|
|
2214
2289
|
return peer;
|
|
2215
2290
|
}
|
|
2216
|
-
async _destroyPeer(peerId) {
|
|
2291
|
+
async _destroyPeer(peerId, reason) {
|
|
2217
2292
|
(0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
|
|
2218
2293
|
F: __dxlog_file5,
|
|
2219
|
-
L:
|
|
2294
|
+
L: 306,
|
|
2220
2295
|
S: this,
|
|
2221
2296
|
A: [
|
|
2222
2297
|
"this._peers.has(peerId)",
|
|
2223
2298
|
""
|
|
2224
2299
|
]
|
|
2225
2300
|
});
|
|
2226
|
-
await this._peers.get(peerId).destroy();
|
|
2301
|
+
await this._peers.get(peerId).destroy(new Error(reason));
|
|
2227
2302
|
this._peers.delete(peerId);
|
|
2228
2303
|
}
|
|
2229
2304
|
_getSwarmController() {
|
|
@@ -2243,7 +2318,7 @@ var Swarm = class {
|
|
|
2243
2318
|
} catch (err) {
|
|
2244
2319
|
(0, import_log5.log)("initiation error", err, {
|
|
2245
2320
|
F: __dxlog_file5,
|
|
2246
|
-
L:
|
|
2321
|
+
L: 332,
|
|
2247
2322
|
S: this,
|
|
2248
2323
|
C: (f, a) => f(...a)
|
|
2249
2324
|
});
|
|
@@ -2271,7 +2346,7 @@ var Swarm = class {
|
|
|
2271
2346
|
remoteId
|
|
2272
2347
|
}, {
|
|
2273
2348
|
F: __dxlog_file5,
|
|
2274
|
-
L:
|
|
2349
|
+
L: 359,
|
|
2275
2350
|
S: this,
|
|
2276
2351
|
C: (f, a) => f(...a)
|
|
2277
2352
|
});
|
|
@@ -2288,7 +2363,7 @@ var Swarm = class {
|
|
|
2288
2363
|
remoteId
|
|
2289
2364
|
}, {
|
|
2290
2365
|
F: __dxlog_file5,
|
|
2291
|
-
L:
|
|
2366
|
+
L: 373,
|
|
2292
2367
|
S: this,
|
|
2293
2368
|
C: (f, a) => f(...a)
|
|
2294
2369
|
});
|
|
@@ -2298,7 +2373,7 @@ var Swarm = class {
|
|
|
2298
2373
|
remoteId
|
|
2299
2374
|
}, {
|
|
2300
2375
|
F: __dxlog_file5,
|
|
2301
|
-
L:
|
|
2376
|
+
L: 376,
|
|
2302
2377
|
S: this,
|
|
2303
2378
|
C: (f, a) => f(...a)
|
|
2304
2379
|
});
|