@dxos/network-manager 0.6.5 → 0.6.6-main.e1a6e1f
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-3UBXH53L.mjs → chunk-2KJH3U3C.mjs} +506 -439
- package/dist/lib/browser/chunk-2KJH3U3C.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-VXLEPDWN.cjs → chunk-F5GUHIHT.cjs} +591 -525
- package/dist/lib/node/chunk-F5GUHIHT.cjs.map +7 -0
- package/dist/lib/node/index.cjs +29 -27
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -18
- package/dist/types/src/signal/ice.d.ts +6 -0
- package/dist/types/src/signal/ice.d.ts.map +1 -0
- package/dist/types/src/signal/ice.test.d.ts +2 -0
- package/dist/types/src/signal/ice.test.d.ts.map +1 -0
- package/dist/types/src/signal/index.d.ts +1 -0
- package/dist/types/src/signal/index.d.ts.map +1 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts +3 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts +3 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts +5 -3
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/package.json +19 -17
- package/src/signal/ice.test.ts +42 -0
- package/src/signal/ice.ts +38 -0
- package/src/signal/index.ts +1 -0
- package/src/transport/libdatachannel-transport.ts +23 -7
- package/src/transport/simplepeer-transport-service.ts +6 -1
- package/src/transport/simplepeer-transport.ts +94 -70
- package/dist/lib/browser/chunk-3UBXH53L.mjs.map +0 -7
- package/dist/lib/node/chunk-VXLEPDWN.cjs.map +0 -7
|
@@ -589,19 +589,47 @@ _ts_decorate([
|
|
|
589
589
|
synchronized
|
|
590
590
|
], Connection.prototype, "close", null);
|
|
591
591
|
|
|
592
|
+
// packages/core/mesh/network-manager/src/signal/ice.ts
|
|
593
|
+
import { asyncTimeout } from "@dxos/async";
|
|
594
|
+
import { log as log2 } from "@dxos/log";
|
|
595
|
+
import { isNotNullOrUndefined } from "@dxos/util";
|
|
596
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/ice.ts";
|
|
597
|
+
var createIceProvider = (iceProviders) => {
|
|
598
|
+
let cachedIceServers;
|
|
599
|
+
return {
|
|
600
|
+
getIceServers: async () => {
|
|
601
|
+
if (cachedIceServers) {
|
|
602
|
+
return cachedIceServers;
|
|
603
|
+
}
|
|
604
|
+
cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => asyncTimeout(fetch(urls, {
|
|
605
|
+
method: "GET"
|
|
606
|
+
}), 1e4).then((response) => response.json()).catch((err) => log2.error("Failed to fetch ICE servers from provider", {
|
|
607
|
+
urls,
|
|
608
|
+
err
|
|
609
|
+
}, {
|
|
610
|
+
F: __dxlog_file2,
|
|
611
|
+
L: 27,
|
|
612
|
+
S: void 0,
|
|
613
|
+
C: (f, a) => f(...a)
|
|
614
|
+
}))))).filter(isNotNullOrUndefined).map(({ iceServers }) => iceServers).flat();
|
|
615
|
+
return cachedIceServers;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
};
|
|
619
|
+
|
|
592
620
|
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
593
621
|
import { Context as Context2 } from "@dxos/context";
|
|
594
622
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
595
623
|
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
596
|
-
import { log as
|
|
624
|
+
import { log as log3 } from "@dxos/log";
|
|
597
625
|
import { schema, TimeoutError as TimeoutError2 } from "@dxos/protocols";
|
|
598
626
|
import { ComplexMap } from "@dxos/util";
|
|
599
|
-
var
|
|
627
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
600
628
|
var SwarmMessage = schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
601
629
|
var SwarmMessenger = class {
|
|
602
630
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
603
631
|
this._ctx = new Context2(void 0, {
|
|
604
|
-
F:
|
|
632
|
+
F: __dxlog_file3,
|
|
605
633
|
L: 33
|
|
606
634
|
});
|
|
607
635
|
this._offerRecords = new ComplexMap((key) => key.toHex());
|
|
@@ -618,12 +646,12 @@ var SwarmMessenger = class {
|
|
|
618
646
|
if (!this._topic.equals(message.topic)) {
|
|
619
647
|
return;
|
|
620
648
|
}
|
|
621
|
-
|
|
649
|
+
log3("received", {
|
|
622
650
|
from: author,
|
|
623
651
|
to: recipient,
|
|
624
652
|
msg: message
|
|
625
653
|
}, {
|
|
626
|
-
F:
|
|
654
|
+
F: __dxlog_file3,
|
|
627
655
|
L: 69,
|
|
628
656
|
S: this,
|
|
629
657
|
C: (f, a) => f(...a)
|
|
@@ -649,10 +677,10 @@ var SwarmMessenger = class {
|
|
|
649
677
|
message
|
|
650
678
|
});
|
|
651
679
|
} else {
|
|
652
|
-
|
|
680
|
+
log3.warn("unknown message", {
|
|
653
681
|
message
|
|
654
682
|
}, {
|
|
655
|
-
F:
|
|
683
|
+
F: __dxlog_file3,
|
|
656
684
|
L: 80,
|
|
657
685
|
S: this,
|
|
658
686
|
C: (f, a) => f(...a)
|
|
@@ -661,7 +689,7 @@ var SwarmMessenger = class {
|
|
|
661
689
|
}
|
|
662
690
|
async signal(message) {
|
|
663
691
|
invariant2(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
664
|
-
F:
|
|
692
|
+
F: __dxlog_file3,
|
|
665
693
|
L: 85,
|
|
666
694
|
S: this,
|
|
667
695
|
A: [
|
|
@@ -697,12 +725,12 @@ var SwarmMessenger = class {
|
|
|
697
725
|
// Setting unique message_id if it not specified yet.
|
|
698
726
|
messageId: message.messageId ?? PublicKey2.random()
|
|
699
727
|
};
|
|
700
|
-
|
|
728
|
+
log3("sending", {
|
|
701
729
|
from: author,
|
|
702
730
|
to: recipient,
|
|
703
731
|
msg: networkMessage
|
|
704
732
|
}, {
|
|
705
|
-
F:
|
|
733
|
+
F: __dxlog_file3,
|
|
706
734
|
L: 123,
|
|
707
735
|
S: this,
|
|
708
736
|
C: (f, a) => f(...a)
|
|
@@ -718,7 +746,7 @@ var SwarmMessenger = class {
|
|
|
718
746
|
}
|
|
719
747
|
async _resolveAnswers(message) {
|
|
720
748
|
invariant2(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
721
|
-
F:
|
|
749
|
+
F: __dxlog_file3,
|
|
722
750
|
L: 135,
|
|
723
751
|
S: this,
|
|
724
752
|
A: [
|
|
@@ -730,7 +758,7 @@ var SwarmMessenger = class {
|
|
|
730
758
|
if (offerRecord) {
|
|
731
759
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
732
760
|
invariant2(message.data?.answer, "No answer", {
|
|
733
|
-
F:
|
|
761
|
+
F: __dxlog_file3,
|
|
734
762
|
L: 139,
|
|
735
763
|
S: this,
|
|
736
764
|
A: [
|
|
@@ -738,10 +766,10 @@ var SwarmMessenger = class {
|
|
|
738
766
|
"'No answer'"
|
|
739
767
|
]
|
|
740
768
|
});
|
|
741
|
-
|
|
769
|
+
log3("resolving", {
|
|
742
770
|
answer: message.data.answer
|
|
743
771
|
}, {
|
|
744
|
-
F:
|
|
772
|
+
F: __dxlog_file3,
|
|
745
773
|
L: 140,
|
|
746
774
|
S: this,
|
|
747
775
|
C: (f, a) => f(...a)
|
|
@@ -751,7 +779,7 @@ var SwarmMessenger = class {
|
|
|
751
779
|
}
|
|
752
780
|
async _handleOffer({ author, recipient, message }) {
|
|
753
781
|
invariant2(message.data.offer, "No offer", {
|
|
754
|
-
F:
|
|
782
|
+
F: __dxlog_file3,
|
|
755
783
|
L: 154,
|
|
756
784
|
S: this,
|
|
757
785
|
A: [
|
|
@@ -783,19 +811,19 @@ var SwarmMessenger = class {
|
|
|
783
811
|
});
|
|
784
812
|
} catch (err) {
|
|
785
813
|
if (err instanceof TimeoutError2) {
|
|
786
|
-
|
|
814
|
+
log3.info("timeout sending answer to offer", {
|
|
787
815
|
err
|
|
788
816
|
}, {
|
|
789
|
-
F:
|
|
817
|
+
F: __dxlog_file3,
|
|
790
818
|
L: 175,
|
|
791
819
|
S: this,
|
|
792
820
|
C: (f, a) => f(...a)
|
|
793
821
|
});
|
|
794
822
|
} else {
|
|
795
|
-
|
|
823
|
+
log3.info("error sending answer to offer", {
|
|
796
824
|
err
|
|
797
825
|
}, {
|
|
798
|
-
F:
|
|
826
|
+
F: __dxlog_file3,
|
|
799
827
|
L: 177,
|
|
800
828
|
S: this,
|
|
801
829
|
C: (f, a) => f(...a)
|
|
@@ -805,7 +833,7 @@ var SwarmMessenger = class {
|
|
|
805
833
|
}
|
|
806
834
|
async _handleSignal({ author, recipient, message }) {
|
|
807
835
|
invariant2(message.messageId, void 0, {
|
|
808
|
-
F:
|
|
836
|
+
F: __dxlog_file3,
|
|
809
837
|
L: 191,
|
|
810
838
|
S: this,
|
|
811
839
|
A: [
|
|
@@ -814,7 +842,7 @@ var SwarmMessenger = class {
|
|
|
814
842
|
]
|
|
815
843
|
});
|
|
816
844
|
invariant2(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
817
|
-
F:
|
|
845
|
+
F: __dxlog_file3,
|
|
818
846
|
L: 192,
|
|
819
847
|
S: this,
|
|
820
848
|
A: [
|
|
@@ -841,16 +869,16 @@ import { Context as Context4 } from "@dxos/context";
|
|
|
841
869
|
import { ErrorStream as ErrorStream2 } from "@dxos/debug";
|
|
842
870
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
843
871
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
844
|
-
import { log as
|
|
872
|
+
import { log as log5, logInfo as logInfo2 } from "@dxos/log";
|
|
845
873
|
import { trace as trace2 } from "@dxos/protocols";
|
|
846
|
-
import { ComplexMap as ComplexMap2, isNotNullOrUndefined } from "@dxos/util";
|
|
874
|
+
import { ComplexMap as ComplexMap2, isNotNullOrUndefined as isNotNullOrUndefined2 } from "@dxos/util";
|
|
847
875
|
|
|
848
876
|
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
849
877
|
import { Event as Event2, scheduleTask as scheduleTask2, synchronized as synchronized2 } from "@dxos/async";
|
|
850
878
|
import { Context as Context3 } from "@dxos/context";
|
|
851
879
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
852
880
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
853
|
-
import { log as
|
|
881
|
+
import { log as log4 } from "@dxos/log";
|
|
854
882
|
import { CancelledError as CancelledError2, SystemError } from "@dxos/protocols";
|
|
855
883
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
856
884
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -862,7 +890,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
862
890
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
863
891
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
864
892
|
}
|
|
865
|
-
var
|
|
893
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
866
894
|
var ConnectionDisplacedError = class extends SystemError {
|
|
867
895
|
constructor() {
|
|
868
896
|
super("Connection displaced by remote initiator.");
|
|
@@ -882,7 +910,7 @@ var Peer = class {
|
|
|
882
910
|
this._availableAfter = 0;
|
|
883
911
|
this.availableToConnect = true;
|
|
884
912
|
this._ctx = new Context3(void 0, {
|
|
885
|
-
F:
|
|
913
|
+
F: __dxlog_file4,
|
|
886
914
|
L: 79
|
|
887
915
|
});
|
|
888
916
|
this.advertizing = false;
|
|
@@ -899,8 +927,8 @@ var Peer = class {
|
|
|
899
927
|
ConnectionState.INITIAL,
|
|
900
928
|
ConnectionState.CONNECTING
|
|
901
929
|
].includes(this.connection.state)) {
|
|
902
|
-
|
|
903
|
-
F:
|
|
930
|
+
log4.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
931
|
+
F: __dxlog_file4,
|
|
904
932
|
L: 114,
|
|
905
933
|
S: this,
|
|
906
934
|
C: (f, a) => f(...a)
|
|
@@ -911,13 +939,13 @@ var Peer = class {
|
|
|
911
939
|
}
|
|
912
940
|
if (this.connection || this.initiating) {
|
|
913
941
|
if (remoteId.toHex() < this.localPeerId.toHex()) {
|
|
914
|
-
|
|
942
|
+
log4("close local connection", {
|
|
915
943
|
localPeerId: this.id,
|
|
916
944
|
topic: this.topic,
|
|
917
945
|
remotePeerId: this.localPeerId,
|
|
918
946
|
sessionId: this.connection?.sessionId
|
|
919
947
|
}, {
|
|
920
|
-
F:
|
|
948
|
+
F: __dxlog_file4,
|
|
921
949
|
L: 123,
|
|
922
950
|
S: this,
|
|
923
951
|
C: (f, a) => f(...a)
|
|
@@ -934,7 +962,7 @@ var Peer = class {
|
|
|
934
962
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
935
963
|
if (!this.connection) {
|
|
936
964
|
invariant3(message.sessionId, void 0, {
|
|
937
|
-
F:
|
|
965
|
+
F: __dxlog_file4,
|
|
938
966
|
L: 143,
|
|
939
967
|
S: this,
|
|
940
968
|
A: [
|
|
@@ -949,13 +977,13 @@ var Peer = class {
|
|
|
949
977
|
await connection.openConnection();
|
|
950
978
|
} catch (err) {
|
|
951
979
|
if (!(err instanceof CancelledError2)) {
|
|
952
|
-
|
|
980
|
+
log4.info("connection error", {
|
|
953
981
|
topic: this.topic,
|
|
954
982
|
peerId: this.localPeerId,
|
|
955
983
|
remoteId: this.id,
|
|
956
984
|
err
|
|
957
985
|
}, {
|
|
958
|
-
F:
|
|
986
|
+
F: __dxlog_file4,
|
|
959
987
|
L: 153,
|
|
960
988
|
S: this,
|
|
961
989
|
C: (f, a) => f(...a)
|
|
@@ -977,7 +1005,7 @@ var Peer = class {
|
|
|
977
1005
|
*/
|
|
978
1006
|
async initiateConnection() {
|
|
979
1007
|
invariant3(!this.initiating, "Initiation in progress.", {
|
|
980
|
-
F:
|
|
1008
|
+
F: __dxlog_file4,
|
|
981
1009
|
L: 170,
|
|
982
1010
|
S: this,
|
|
983
1011
|
A: [
|
|
@@ -986,7 +1014,7 @@ var Peer = class {
|
|
|
986
1014
|
]
|
|
987
1015
|
});
|
|
988
1016
|
invariant3(!this.connection, "Already connected.", {
|
|
989
|
-
F:
|
|
1017
|
+
F: __dxlog_file4,
|
|
990
1018
|
L: 171,
|
|
991
1019
|
S: this,
|
|
992
1020
|
A: [
|
|
@@ -995,13 +1023,13 @@ var Peer = class {
|
|
|
995
1023
|
]
|
|
996
1024
|
});
|
|
997
1025
|
const sessionId = PublicKey3.random();
|
|
998
|
-
|
|
1026
|
+
log4("initiating...", {
|
|
999
1027
|
ownPeerId: this.localPeerId,
|
|
1000
1028
|
topic: this.topic,
|
|
1001
1029
|
remotePeerId: this.id,
|
|
1002
1030
|
sessionId
|
|
1003
1031
|
}, {
|
|
1004
|
-
F:
|
|
1032
|
+
F: __dxlog_file4,
|
|
1005
1033
|
L: 173,
|
|
1006
1034
|
S: this,
|
|
1007
1035
|
C: (f, a) => f(...a)
|
|
@@ -1021,20 +1049,20 @@ var Peer = class {
|
|
|
1021
1049
|
offer: {}
|
|
1022
1050
|
}
|
|
1023
1051
|
});
|
|
1024
|
-
|
|
1052
|
+
log4("received", {
|
|
1025
1053
|
answer,
|
|
1026
1054
|
topic: this.topic,
|
|
1027
1055
|
ownId: this.localPeerId,
|
|
1028
1056
|
remoteId: this.id
|
|
1029
1057
|
}, {
|
|
1030
|
-
F:
|
|
1058
|
+
F: __dxlog_file4,
|
|
1031
1059
|
L: 190,
|
|
1032
1060
|
S: this,
|
|
1033
1061
|
C: (f, a) => f(...a)
|
|
1034
1062
|
});
|
|
1035
1063
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1036
|
-
|
|
1037
|
-
F:
|
|
1064
|
+
log4("ignoring response", void 0, {
|
|
1065
|
+
F: __dxlog_file4,
|
|
1038
1066
|
L: 192,
|
|
1039
1067
|
S: this,
|
|
1040
1068
|
C: (f, a) => f(...a)
|
|
@@ -1042,13 +1070,13 @@ var Peer = class {
|
|
|
1042
1070
|
return;
|
|
1043
1071
|
}
|
|
1044
1072
|
} catch (err) {
|
|
1045
|
-
|
|
1073
|
+
log4("initiation error: send offer", {
|
|
1046
1074
|
err,
|
|
1047
1075
|
topic: this.topic,
|
|
1048
1076
|
peerId: this.localPeerId,
|
|
1049
1077
|
remoteId: this.id
|
|
1050
1078
|
}, {
|
|
1051
|
-
F:
|
|
1079
|
+
F: __dxlog_file4,
|
|
1052
1080
|
L: 196,
|
|
1053
1081
|
S: this,
|
|
1054
1082
|
C: (f, a) => f(...a)
|
|
@@ -1064,13 +1092,13 @@ var Peer = class {
|
|
|
1064
1092
|
return;
|
|
1065
1093
|
}
|
|
1066
1094
|
} catch (err) {
|
|
1067
|
-
|
|
1095
|
+
log4("initiation error: accept answer", {
|
|
1068
1096
|
err,
|
|
1069
1097
|
topic: this.topic,
|
|
1070
1098
|
peerId: this.localPeerId,
|
|
1071
1099
|
remoteId: this.id
|
|
1072
1100
|
}, {
|
|
1073
|
-
F:
|
|
1101
|
+
F: __dxlog_file4,
|
|
1074
1102
|
L: 209,
|
|
1075
1103
|
S: this,
|
|
1076
1104
|
C: (f, a) => f(...a)
|
|
@@ -1081,8 +1109,8 @@ var Peer = class {
|
|
|
1081
1109
|
this.initiating = false;
|
|
1082
1110
|
}
|
|
1083
1111
|
try {
|
|
1084
|
-
|
|
1085
|
-
F:
|
|
1112
|
+
log4("opening connection as initiator", void 0, {
|
|
1113
|
+
F: __dxlog_file4,
|
|
1086
1114
|
L: 222,
|
|
1087
1115
|
S: this,
|
|
1088
1116
|
C: (f, a) => f(...a)
|
|
@@ -1090,21 +1118,21 @@ var Peer = class {
|
|
|
1090
1118
|
await connection.openConnection();
|
|
1091
1119
|
this._callbacks.onAccepted();
|
|
1092
1120
|
} catch (err) {
|
|
1093
|
-
|
|
1121
|
+
log4("initiation error: open connection", {
|
|
1094
1122
|
err,
|
|
1095
1123
|
topic: this.topic,
|
|
1096
1124
|
peerId: this.localPeerId,
|
|
1097
1125
|
remoteId: this.id
|
|
1098
1126
|
}, {
|
|
1099
|
-
F:
|
|
1127
|
+
F: __dxlog_file4,
|
|
1100
1128
|
L: 226,
|
|
1101
1129
|
S: this,
|
|
1102
1130
|
C: (f, a) => f(...a)
|
|
1103
1131
|
});
|
|
1104
|
-
|
|
1132
|
+
log4.warn("closing connection due to unhandled error on openConnection", {
|
|
1105
1133
|
err
|
|
1106
1134
|
}, {
|
|
1107
|
-
F:
|
|
1135
|
+
F: __dxlog_file4,
|
|
1108
1136
|
L: 233,
|
|
1109
1137
|
S: this,
|
|
1110
1138
|
C: (f, a) => f(...a)
|
|
@@ -1120,20 +1148,20 @@ var Peer = class {
|
|
|
1120
1148
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
1121
1149
|
*/
|
|
1122
1150
|
_createConnection(initiator, sessionId) {
|
|
1123
|
-
|
|
1151
|
+
log4("creating connection", {
|
|
1124
1152
|
topic: this.topic,
|
|
1125
1153
|
peerId: this.localPeerId,
|
|
1126
1154
|
remoteId: this.id,
|
|
1127
1155
|
initiator,
|
|
1128
1156
|
sessionId
|
|
1129
1157
|
}, {
|
|
1130
|
-
F:
|
|
1158
|
+
F: __dxlog_file4,
|
|
1131
1159
|
L: 247,
|
|
1132
1160
|
S: this,
|
|
1133
1161
|
C: (f, a) => f(...a)
|
|
1134
1162
|
});
|
|
1135
1163
|
invariant3(!this.connection, "Already connected.", {
|
|
1136
|
-
F:
|
|
1164
|
+
F: __dxlog_file4,
|
|
1137
1165
|
L: 254,
|
|
1138
1166
|
S: this,
|
|
1139
1167
|
A: [
|
|
@@ -1162,34 +1190,34 @@ var Peer = class {
|
|
|
1162
1190
|
this._lastConnectionTime = Date.now();
|
|
1163
1191
|
this._callbacks.onConnected();
|
|
1164
1192
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1165
|
-
|
|
1193
|
+
log4.trace("dxos.mesh.connection.connected", {
|
|
1166
1194
|
topic: this.topic,
|
|
1167
1195
|
localPeerId: this.localPeerId,
|
|
1168
1196
|
remotePeerId: this.id,
|
|
1169
1197
|
sessionId,
|
|
1170
1198
|
initiator
|
|
1171
1199
|
}, {
|
|
1172
|
-
F:
|
|
1200
|
+
F: __dxlog_file4,
|
|
1173
1201
|
L: 273,
|
|
1174
1202
|
S: this,
|
|
1175
1203
|
C: (f, a) => f(...a)
|
|
1176
1204
|
});
|
|
1177
1205
|
},
|
|
1178
1206
|
onClosed: (err) => {
|
|
1179
|
-
|
|
1207
|
+
log4("connection closed", {
|
|
1180
1208
|
topic: this.topic,
|
|
1181
1209
|
peerId: this.localPeerId,
|
|
1182
1210
|
remoteId: this.id,
|
|
1183
1211
|
initiator
|
|
1184
1212
|
}, {
|
|
1185
|
-
F:
|
|
1213
|
+
F: __dxlog_file4,
|
|
1186
1214
|
L: 282,
|
|
1187
1215
|
S: this,
|
|
1188
1216
|
C: (f, a) => f(...a)
|
|
1189
1217
|
});
|
|
1190
1218
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1191
1219
|
invariant3(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1192
|
-
F:
|
|
1220
|
+
F: __dxlog_file4,
|
|
1193
1221
|
L: 287,
|
|
1194
1222
|
S: this,
|
|
1195
1223
|
A: [
|
|
@@ -1197,14 +1225,14 @@ var Peer = class {
|
|
|
1197
1225
|
"'Connection mismatch (race condition).'"
|
|
1198
1226
|
]
|
|
1199
1227
|
});
|
|
1200
|
-
|
|
1228
|
+
log4.trace("dxos.mesh.connection.closed", {
|
|
1201
1229
|
topic: this.topic,
|
|
1202
1230
|
localPeerId: this.localPeerId,
|
|
1203
1231
|
remotePeerId: this.id,
|
|
1204
1232
|
sessionId,
|
|
1205
1233
|
initiator
|
|
1206
1234
|
}, {
|
|
1207
|
-
F:
|
|
1235
|
+
F: __dxlog_file4,
|
|
1208
1236
|
L: 289,
|
|
1209
1237
|
S: this,
|
|
1210
1238
|
C: (f, a) => f(...a)
|
|
@@ -1232,19 +1260,19 @@ var Peer = class {
|
|
|
1232
1260
|
void this._connectionCtx?.dispose();
|
|
1233
1261
|
this._connectionCtx = this._ctx.derive();
|
|
1234
1262
|
connection.errors.handle((err) => {
|
|
1235
|
-
|
|
1263
|
+
log4.info("connection error, closing", {
|
|
1236
1264
|
topic: this.topic,
|
|
1237
1265
|
peerId: this.localPeerId,
|
|
1238
1266
|
remoteId: this.id,
|
|
1239
1267
|
initiator,
|
|
1240
1268
|
err
|
|
1241
1269
|
}, {
|
|
1242
|
-
F:
|
|
1270
|
+
F: __dxlog_file4,
|
|
1243
1271
|
L: 329,
|
|
1244
1272
|
S: this,
|
|
1245
1273
|
C: (f, a) => f(...a)
|
|
1246
1274
|
});
|
|
1247
|
-
|
|
1275
|
+
log4.trace("dxos.mesh.connection.error", {
|
|
1248
1276
|
topic: this.topic,
|
|
1249
1277
|
localPeerId: this.localPeerId,
|
|
1250
1278
|
remotePeerId: this.id,
|
|
@@ -1252,7 +1280,7 @@ var Peer = class {
|
|
|
1252
1280
|
initiator,
|
|
1253
1281
|
err
|
|
1254
1282
|
}, {
|
|
1255
|
-
F:
|
|
1283
|
+
F: __dxlog_file4,
|
|
1256
1284
|
L: 336,
|
|
1257
1285
|
S: this,
|
|
1258
1286
|
C: (f, a) => f(...a)
|
|
@@ -1267,21 +1295,21 @@ var Peer = class {
|
|
|
1267
1295
|
return;
|
|
1268
1296
|
}
|
|
1269
1297
|
const connection = this.connection;
|
|
1270
|
-
|
|
1298
|
+
log4("closing...", {
|
|
1271
1299
|
peerId: this.id,
|
|
1272
1300
|
sessionId: connection.sessionId
|
|
1273
1301
|
}, {
|
|
1274
|
-
F:
|
|
1302
|
+
F: __dxlog_file4,
|
|
1275
1303
|
L: 361,
|
|
1276
1304
|
S: this,
|
|
1277
1305
|
C: (f, a) => f(...a)
|
|
1278
1306
|
});
|
|
1279
1307
|
await connection.close(err);
|
|
1280
|
-
|
|
1308
|
+
log4("closed", {
|
|
1281
1309
|
peerId: this.id,
|
|
1282
1310
|
sessionId: connection.sessionId
|
|
1283
1311
|
}, {
|
|
1284
|
-
F:
|
|
1312
|
+
F: __dxlog_file4,
|
|
1285
1313
|
L: 367,
|
|
1286
1314
|
S: this,
|
|
1287
1315
|
C: (f, a) => f(...a)
|
|
@@ -1289,10 +1317,10 @@ var Peer = class {
|
|
|
1289
1317
|
}
|
|
1290
1318
|
async onSignal(message) {
|
|
1291
1319
|
if (!this.connection) {
|
|
1292
|
-
|
|
1320
|
+
log4("dropping signal message for non-existent connection", {
|
|
1293
1321
|
message
|
|
1294
1322
|
}, {
|
|
1295
|
-
F:
|
|
1323
|
+
F: __dxlog_file4,
|
|
1296
1324
|
L: 372,
|
|
1297
1325
|
S: this,
|
|
1298
1326
|
C: (f, a) => f(...a)
|
|
@@ -1303,11 +1331,11 @@ var Peer = class {
|
|
|
1303
1331
|
}
|
|
1304
1332
|
async safeDestroy(reason) {
|
|
1305
1333
|
await this._ctx.dispose();
|
|
1306
|
-
|
|
1334
|
+
log4("Destroying peer", {
|
|
1307
1335
|
peerId: this.id,
|
|
1308
1336
|
topic: this.topic
|
|
1309
1337
|
}, {
|
|
1310
|
-
F:
|
|
1338
|
+
F: __dxlog_file4,
|
|
1311
1339
|
L: 382,
|
|
1312
1340
|
S: this,
|
|
1313
1341
|
C: (f, a) => f(...a)
|
|
@@ -1342,7 +1370,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
1342
1370
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1343
1371
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1344
1372
|
}
|
|
1345
|
-
var
|
|
1373
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1346
1374
|
var INITIATION_DELAY = 100;
|
|
1347
1375
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1348
1376
|
var Swarm = class {
|
|
@@ -1359,7 +1387,7 @@ var Swarm = class {
|
|
|
1359
1387
|
this._connectionLimiter = _connectionLimiter;
|
|
1360
1388
|
this._initiationDelay = _initiationDelay;
|
|
1361
1389
|
this._ctx = new Context4(void 0, {
|
|
1362
|
-
F:
|
|
1390
|
+
F: __dxlog_file5,
|
|
1363
1391
|
L: 39
|
|
1364
1392
|
});
|
|
1365
1393
|
this._listeningHandle = void 0;
|
|
@@ -1369,22 +1397,22 @@ var Swarm = class {
|
|
|
1369
1397
|
this.disconnected = new Event3();
|
|
1370
1398
|
this.connected = new Event3();
|
|
1371
1399
|
this.errors = new ErrorStream2();
|
|
1372
|
-
|
|
1400
|
+
log5.trace("dxos.mesh.swarm.constructor", trace2.begin({
|
|
1373
1401
|
id: this._instanceId,
|
|
1374
1402
|
data: {
|
|
1375
1403
|
topic: this._topic.toHex(),
|
|
1376
1404
|
peerId: this._ownPeerId.toHex()
|
|
1377
1405
|
}
|
|
1378
1406
|
}), {
|
|
1379
|
-
F:
|
|
1407
|
+
F: __dxlog_file5,
|
|
1380
1408
|
L: 89,
|
|
1381
1409
|
S: this,
|
|
1382
1410
|
C: (f, a) => f(...a)
|
|
1383
1411
|
});
|
|
1384
|
-
|
|
1412
|
+
log5("creating swarm", {
|
|
1385
1413
|
peerId: _ownPeerId
|
|
1386
1414
|
}, {
|
|
1387
|
-
F:
|
|
1415
|
+
F: __dxlog_file5,
|
|
1388
1416
|
L: 93,
|
|
1389
1417
|
S: this,
|
|
1390
1418
|
C: (f, a) => f(...a)
|
|
@@ -1396,17 +1424,17 @@ var Swarm = class {
|
|
|
1396
1424
|
onOffer: async (msg) => await this.onOffer(msg),
|
|
1397
1425
|
topic: this._topic
|
|
1398
1426
|
});
|
|
1399
|
-
|
|
1427
|
+
log5.trace("dxos.mesh.swarm.constructor", trace2.end({
|
|
1400
1428
|
id: this._instanceId
|
|
1401
1429
|
}), {
|
|
1402
|
-
F:
|
|
1430
|
+
F: __dxlog_file5,
|
|
1403
1431
|
L: 102,
|
|
1404
1432
|
S: this,
|
|
1405
1433
|
C: (f, a) => f(...a)
|
|
1406
1434
|
});
|
|
1407
1435
|
}
|
|
1408
1436
|
get connections() {
|
|
1409
|
-
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(
|
|
1437
|
+
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(isNotNullOrUndefined2);
|
|
1410
1438
|
}
|
|
1411
1439
|
get ownPeerId() {
|
|
1412
1440
|
return this._ownPeerId;
|
|
@@ -1422,7 +1450,7 @@ var Swarm = class {
|
|
|
1422
1450
|
}
|
|
1423
1451
|
async open() {
|
|
1424
1452
|
invariant4(!this._listeningHandle, void 0, {
|
|
1425
|
-
F:
|
|
1453
|
+
F: __dxlog_file5,
|
|
1426
1454
|
L: 129,
|
|
1427
1455
|
S: this,
|
|
1428
1456
|
A: [
|
|
@@ -1434,10 +1462,10 @@ var Swarm = class {
|
|
|
1434
1462
|
peerId: this._ownPeerId,
|
|
1435
1463
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1436
1464
|
onMessage: async (message) => {
|
|
1437
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) =>
|
|
1465
|
+
await this._swarmMessenger.receiveMessage(message).catch((err) => log5.info("Error while receiving message", {
|
|
1438
1466
|
err
|
|
1439
1467
|
}, {
|
|
1440
|
-
F:
|
|
1468
|
+
F: __dxlog_file5,
|
|
1441
1469
|
L: 137,
|
|
1442
1470
|
S: this,
|
|
1443
1471
|
C: (f, a) => f(...a)
|
|
@@ -1446,8 +1474,8 @@ var Swarm = class {
|
|
|
1446
1474
|
});
|
|
1447
1475
|
}
|
|
1448
1476
|
async destroy() {
|
|
1449
|
-
|
|
1450
|
-
F:
|
|
1477
|
+
log5("destroying...", void 0, {
|
|
1478
|
+
F: __dxlog_file5,
|
|
1451
1479
|
L: 143,
|
|
1452
1480
|
S: this,
|
|
1453
1481
|
C: (f, a) => f(...a)
|
|
@@ -1457,8 +1485,8 @@ var Swarm = class {
|
|
|
1457
1485
|
await this._ctx.dispose();
|
|
1458
1486
|
await this._topology.destroy();
|
|
1459
1487
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1460
|
-
|
|
1461
|
-
F:
|
|
1488
|
+
log5("destroyed", void 0, {
|
|
1489
|
+
F: __dxlog_file5,
|
|
1462
1490
|
L: 150,
|
|
1463
1491
|
S: this,
|
|
1464
1492
|
C: (f, a) => f(...a)
|
|
@@ -1466,7 +1494,7 @@ var Swarm = class {
|
|
|
1466
1494
|
}
|
|
1467
1495
|
async setTopology(topology) {
|
|
1468
1496
|
invariant4(!this._ctx.disposed, "Swarm is offline", {
|
|
1469
|
-
F:
|
|
1497
|
+
F: __dxlog_file5,
|
|
1470
1498
|
L: 154,
|
|
1471
1499
|
S: this,
|
|
1472
1500
|
A: [
|
|
@@ -1477,11 +1505,11 @@ var Swarm = class {
|
|
|
1477
1505
|
if (topology === this._topology) {
|
|
1478
1506
|
return;
|
|
1479
1507
|
}
|
|
1480
|
-
|
|
1508
|
+
log5("setting topology", {
|
|
1481
1509
|
previous: getClassName(this._topology),
|
|
1482
1510
|
topology: getClassName(topology)
|
|
1483
1511
|
}, {
|
|
1484
|
-
F:
|
|
1512
|
+
F: __dxlog_file5,
|
|
1485
1513
|
L: 158,
|
|
1486
1514
|
S: this,
|
|
1487
1515
|
C: (f, a) => f(...a)
|
|
@@ -1492,17 +1520,17 @@ var Swarm = class {
|
|
|
1492
1520
|
this._topology.update();
|
|
1493
1521
|
}
|
|
1494
1522
|
onSwarmEvent(swarmEvent) {
|
|
1495
|
-
|
|
1523
|
+
log5("swarm event", {
|
|
1496
1524
|
swarmEvent
|
|
1497
1525
|
}, {
|
|
1498
|
-
F:
|
|
1526
|
+
F: __dxlog_file5,
|
|
1499
1527
|
L: 171,
|
|
1500
1528
|
S: this,
|
|
1501
1529
|
C: (f, a) => f(...a)
|
|
1502
1530
|
});
|
|
1503
1531
|
if (this._ctx.disposed) {
|
|
1504
|
-
|
|
1505
|
-
F:
|
|
1532
|
+
log5("swarm event ignored for disposed swarm", void 0, {
|
|
1533
|
+
F: __dxlog_file5,
|
|
1506
1534
|
L: 174,
|
|
1507
1535
|
S: this,
|
|
1508
1536
|
C: (f, a) => f(...a)
|
|
@@ -1512,10 +1540,10 @@ var Swarm = class {
|
|
|
1512
1540
|
if (swarmEvent.peerAvailable) {
|
|
1513
1541
|
const peerId = PublicKey4.from(swarmEvent.peerAvailable.peer);
|
|
1514
1542
|
if (!peerId.equals(this._ownPeerId)) {
|
|
1515
|
-
|
|
1543
|
+
log5("new peer", {
|
|
1516
1544
|
peerId
|
|
1517
1545
|
}, {
|
|
1518
|
-
F:
|
|
1546
|
+
F: __dxlog_file5,
|
|
1519
1547
|
L: 181,
|
|
1520
1548
|
S: this,
|
|
1521
1549
|
C: (f, a) => f(...a)
|
|
@@ -1528,18 +1556,18 @@ var Swarm = class {
|
|
|
1528
1556
|
if (peer) {
|
|
1529
1557
|
peer.advertizing = false;
|
|
1530
1558
|
if (peer.connection?.state !== ConnectionState.CONNECTED) {
|
|
1531
|
-
void this._destroyPeer(peer.id, "peer left").catch((err) =>
|
|
1532
|
-
F:
|
|
1559
|
+
void this._destroyPeer(peer.id, "peer left").catch((err) => log5.catch(err, void 0, {
|
|
1560
|
+
F: __dxlog_file5,
|
|
1533
1561
|
L: 191,
|
|
1534
1562
|
S: this,
|
|
1535
1563
|
C: (f, a) => f(...a)
|
|
1536
1564
|
}));
|
|
1537
1565
|
}
|
|
1538
1566
|
} else {
|
|
1539
|
-
|
|
1567
|
+
log5("received peerLeft but no peer found", {
|
|
1540
1568
|
peer: swarmEvent.peerLeft.peer
|
|
1541
1569
|
}, {
|
|
1542
|
-
F:
|
|
1570
|
+
F: __dxlog_file5,
|
|
1543
1571
|
L: 194,
|
|
1544
1572
|
S: this,
|
|
1545
1573
|
C: (f, a) => f(...a)
|
|
@@ -1549,17 +1577,17 @@ var Swarm = class {
|
|
|
1549
1577
|
this._topology.update();
|
|
1550
1578
|
}
|
|
1551
1579
|
async onOffer(message) {
|
|
1552
|
-
|
|
1580
|
+
log5("offer", {
|
|
1553
1581
|
message
|
|
1554
1582
|
}, {
|
|
1555
|
-
F:
|
|
1583
|
+
F: __dxlog_file5,
|
|
1556
1584
|
L: 203,
|
|
1557
1585
|
S: this,
|
|
1558
1586
|
C: (f, a) => f(...a)
|
|
1559
1587
|
});
|
|
1560
1588
|
if (this._ctx.disposed) {
|
|
1561
|
-
|
|
1562
|
-
F:
|
|
1589
|
+
log5("ignored for disposed swarm", void 0, {
|
|
1590
|
+
F: __dxlog_file5,
|
|
1563
1591
|
L: 205,
|
|
1564
1592
|
S: this,
|
|
1565
1593
|
C: (f, a) => f(...a)
|
|
@@ -1569,7 +1597,7 @@ var Swarm = class {
|
|
|
1569
1597
|
};
|
|
1570
1598
|
}
|
|
1571
1599
|
invariant4(message.author, void 0, {
|
|
1572
|
-
F:
|
|
1600
|
+
F: __dxlog_file5,
|
|
1573
1601
|
L: 210,
|
|
1574
1602
|
S: this,
|
|
1575
1603
|
A: [
|
|
@@ -1578,10 +1606,10 @@ var Swarm = class {
|
|
|
1578
1606
|
]
|
|
1579
1607
|
});
|
|
1580
1608
|
if (!message.recipient?.equals(this._ownPeerId)) {
|
|
1581
|
-
|
|
1609
|
+
log5("rejecting offer with incorrect peerId", {
|
|
1582
1610
|
message
|
|
1583
1611
|
}, {
|
|
1584
|
-
F:
|
|
1612
|
+
F: __dxlog_file5,
|
|
1585
1613
|
L: 212,
|
|
1586
1614
|
S: this,
|
|
1587
1615
|
C: (f, a) => f(...a)
|
|
@@ -1591,10 +1619,10 @@ var Swarm = class {
|
|
|
1591
1619
|
};
|
|
1592
1620
|
}
|
|
1593
1621
|
if (!message.topic?.equals(this._topic)) {
|
|
1594
|
-
|
|
1622
|
+
log5("rejecting offer with incorrect topic", {
|
|
1595
1623
|
message
|
|
1596
1624
|
}, {
|
|
1597
|
-
F:
|
|
1625
|
+
F: __dxlog_file5,
|
|
1598
1626
|
L: 216,
|
|
1599
1627
|
S: this,
|
|
1600
1628
|
C: (f, a) => f(...a)
|
|
@@ -1609,17 +1637,17 @@ var Swarm = class {
|
|
|
1609
1637
|
return answer;
|
|
1610
1638
|
}
|
|
1611
1639
|
async onSignal(message) {
|
|
1612
|
-
|
|
1640
|
+
log5("signal", {
|
|
1613
1641
|
message
|
|
1614
1642
|
}, {
|
|
1615
|
-
F:
|
|
1643
|
+
F: __dxlog_file5,
|
|
1616
1644
|
L: 227,
|
|
1617
1645
|
S: this,
|
|
1618
1646
|
C: (f, a) => f(...a)
|
|
1619
1647
|
});
|
|
1620
1648
|
if (this._ctx.disposed) {
|
|
1621
|
-
|
|
1622
|
-
F:
|
|
1649
|
+
log5.info("ignored for offline swarm", void 0, {
|
|
1650
|
+
F: __dxlog_file5,
|
|
1623
1651
|
L: 229,
|
|
1624
1652
|
S: this,
|
|
1625
1653
|
C: (f, a) => f(...a)
|
|
@@ -1627,7 +1655,7 @@ var Swarm = class {
|
|
|
1627
1655
|
return;
|
|
1628
1656
|
}
|
|
1629
1657
|
invariant4(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1630
|
-
F:
|
|
1658
|
+
F: __dxlog_file5,
|
|
1631
1659
|
L: 232,
|
|
1632
1660
|
S: this,
|
|
1633
1661
|
A: [
|
|
@@ -1636,7 +1664,7 @@ var Swarm = class {
|
|
|
1636
1664
|
]
|
|
1637
1665
|
});
|
|
1638
1666
|
invariant4(message.topic?.equals(this._topic), void 0, {
|
|
1639
|
-
F:
|
|
1667
|
+
F: __dxlog_file5,
|
|
1640
1668
|
L: 236,
|
|
1641
1669
|
S: this,
|
|
1642
1670
|
A: [
|
|
@@ -1645,7 +1673,7 @@ var Swarm = class {
|
|
|
1645
1673
|
]
|
|
1646
1674
|
});
|
|
1647
1675
|
invariant4(message.author, void 0, {
|
|
1648
|
-
F:
|
|
1676
|
+
F: __dxlog_file5,
|
|
1649
1677
|
L: 237,
|
|
1650
1678
|
S: this,
|
|
1651
1679
|
A: [
|
|
@@ -1666,7 +1694,7 @@ var Swarm = class {
|
|
|
1666
1694
|
// For debug purposes
|
|
1667
1695
|
async goOnline() {
|
|
1668
1696
|
this._ctx = new Context4(void 0, {
|
|
1669
|
-
F:
|
|
1697
|
+
F: __dxlog_file5,
|
|
1670
1698
|
L: 253
|
|
1671
1699
|
});
|
|
1672
1700
|
}
|
|
@@ -1692,10 +1720,10 @@ var Swarm = class {
|
|
|
1692
1720
|
},
|
|
1693
1721
|
onRejected: () => {
|
|
1694
1722
|
if (!this._isUnregistered(peer)) {
|
|
1695
|
-
|
|
1723
|
+
log5("peer rejected connection", {
|
|
1696
1724
|
peerId
|
|
1697
1725
|
}, {
|
|
1698
|
-
F:
|
|
1726
|
+
F: __dxlog_file5,
|
|
1699
1727
|
L: 289,
|
|
1700
1728
|
S: this,
|
|
1701
1729
|
C: (f, a) => f(...a)
|
|
@@ -1720,7 +1748,7 @@ var Swarm = class {
|
|
|
1720
1748
|
async _destroyPeer(peerId, reason) {
|
|
1721
1749
|
const peer = this._peers.get(peerId);
|
|
1722
1750
|
invariant4(peer, void 0, {
|
|
1723
|
-
F:
|
|
1751
|
+
F: __dxlog_file5,
|
|
1724
1752
|
L: 312,
|
|
1725
1753
|
S: this,
|
|
1726
1754
|
A: [
|
|
@@ -1747,8 +1775,8 @@ var Swarm = class {
|
|
|
1747
1775
|
try {
|
|
1748
1776
|
await this._initiateConnection(peer);
|
|
1749
1777
|
} catch (err) {
|
|
1750
|
-
|
|
1751
|
-
F:
|
|
1778
|
+
log5("initiation error", err, {
|
|
1779
|
+
F: __dxlog_file5,
|
|
1752
1780
|
L: 339,
|
|
1753
1781
|
S: this,
|
|
1754
1782
|
C: (f, a) => f(...a)
|
|
@@ -1774,10 +1802,10 @@ var Swarm = class {
|
|
|
1774
1802
|
const ctx = this._ctx;
|
|
1775
1803
|
const peer = this._getOrCreatePeer(remoteId);
|
|
1776
1804
|
if (remoteId.toHex() < this._ownPeerId.toHex()) {
|
|
1777
|
-
|
|
1805
|
+
log5("initiation delay", {
|
|
1778
1806
|
remoteId
|
|
1779
1807
|
}, {
|
|
1780
|
-
F:
|
|
1808
|
+
F: __dxlog_file5,
|
|
1781
1809
|
L: 367,
|
|
1782
1810
|
S: this,
|
|
1783
1811
|
C: (f, a) => f(...a)
|
|
@@ -1793,20 +1821,20 @@ var Swarm = class {
|
|
|
1793
1821
|
if (peer.connection) {
|
|
1794
1822
|
return;
|
|
1795
1823
|
}
|
|
1796
|
-
|
|
1824
|
+
log5("initiating connection...", {
|
|
1797
1825
|
remoteId
|
|
1798
1826
|
}, {
|
|
1799
|
-
F:
|
|
1827
|
+
F: __dxlog_file5,
|
|
1800
1828
|
L: 383,
|
|
1801
1829
|
S: this,
|
|
1802
1830
|
C: (f, a) => f(...a)
|
|
1803
1831
|
});
|
|
1804
1832
|
await peer.initiateConnection();
|
|
1805
1833
|
this._topology.update();
|
|
1806
|
-
|
|
1834
|
+
log5("initiated", {
|
|
1807
1835
|
remoteId
|
|
1808
1836
|
}, {
|
|
1809
|
-
F:
|
|
1837
|
+
F: __dxlog_file5,
|
|
1810
1838
|
L: 386,
|
|
1811
1839
|
S: this,
|
|
1812
1840
|
C: (f, a) => f(...a)
|
|
@@ -1848,9 +1876,9 @@ _ts_decorate3([
|
|
|
1848
1876
|
// packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts
|
|
1849
1877
|
import { Event as Event4, EventSubscriptions } from "@dxos/async";
|
|
1850
1878
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1851
|
-
import { log as
|
|
1879
|
+
import { log as log6 } from "@dxos/log";
|
|
1852
1880
|
import { ComplexMap as ComplexMap3 } from "@dxos/util";
|
|
1853
|
-
var
|
|
1881
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1854
1882
|
var SwarmMapper = class {
|
|
1855
1883
|
get peers() {
|
|
1856
1884
|
return Array.from(this._peers.values());
|
|
@@ -1875,8 +1903,8 @@ var SwarmMapper = class {
|
|
|
1875
1903
|
this._update();
|
|
1876
1904
|
}
|
|
1877
1905
|
_update() {
|
|
1878
|
-
|
|
1879
|
-
F:
|
|
1906
|
+
log6("updating swarm", void 0, {
|
|
1907
|
+
F: __dxlog_file6,
|
|
1880
1908
|
L: 72,
|
|
1881
1909
|
S: this,
|
|
1882
1910
|
C: (f, a) => f(...a)
|
|
@@ -1896,11 +1924,11 @@ var SwarmMapper = class {
|
|
|
1896
1924
|
]
|
|
1897
1925
|
});
|
|
1898
1926
|
}
|
|
1899
|
-
|
|
1927
|
+
log6("graph changed", {
|
|
1900
1928
|
directConnections: this._swarm.connections.length,
|
|
1901
1929
|
totalPeersInSwarm: this._peers.size
|
|
1902
1930
|
}, {
|
|
1903
|
-
F:
|
|
1931
|
+
F: __dxlog_file6,
|
|
1904
1932
|
L: 113,
|
|
1905
1933
|
S: this,
|
|
1906
1934
|
C: (f, a) => f(...a)
|
|
@@ -1919,15 +1947,15 @@ import { DeferredTask as DeferredTask2 } from "@dxos/async";
|
|
|
1919
1947
|
import { Context as Context5 } from "@dxos/context";
|
|
1920
1948
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1921
1949
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1922
|
-
import { log as
|
|
1950
|
+
import { log as log7 } from "@dxos/log";
|
|
1923
1951
|
import { CancelledError as CancelledError3 } from "@dxos/protocols";
|
|
1924
1952
|
import { ComplexMap as ComplexMap4 } from "@dxos/util";
|
|
1925
|
-
var
|
|
1953
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
1926
1954
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
1927
1955
|
var ConnectionLimiter = class {
|
|
1928
1956
|
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
1929
1957
|
this._ctx = new Context5(void 0, {
|
|
1930
|
-
F:
|
|
1958
|
+
F: __dxlog_file7,
|
|
1931
1959
|
L: 23
|
|
1932
1960
|
});
|
|
1933
1961
|
/**
|
|
@@ -1946,7 +1974,7 @@ var ConnectionLimiter = class {
|
|
|
1946
1974
|
*/
|
|
1947
1975
|
async connecting(sessionId) {
|
|
1948
1976
|
invariant5(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
1949
|
-
F:
|
|
1977
|
+
F: __dxlog_file7,
|
|
1950
1978
|
L: 48,
|
|
1951
1979
|
S: this,
|
|
1952
1980
|
A: [
|
|
@@ -1954,10 +1982,10 @@ var ConnectionLimiter = class {
|
|
|
1954
1982
|
"'Peer is already waiting for connection'"
|
|
1955
1983
|
]
|
|
1956
1984
|
});
|
|
1957
|
-
|
|
1985
|
+
log7("waiting", {
|
|
1958
1986
|
sessionId
|
|
1959
1987
|
}, {
|
|
1960
|
-
F:
|
|
1988
|
+
F: __dxlog_file7,
|
|
1961
1989
|
L: 49,
|
|
1962
1990
|
S: this,
|
|
1963
1991
|
C: (f, a) => f(...a)
|
|
@@ -1969,10 +1997,10 @@ var ConnectionLimiter = class {
|
|
|
1969
1997
|
});
|
|
1970
1998
|
this.resolveWaitingPromises.schedule();
|
|
1971
1999
|
});
|
|
1972
|
-
|
|
2000
|
+
log7("allow", {
|
|
1973
2001
|
sessionId
|
|
1974
2002
|
}, {
|
|
1975
|
-
F:
|
|
2003
|
+
F: __dxlog_file7,
|
|
1976
2004
|
L: 57,
|
|
1977
2005
|
S: this,
|
|
1978
2006
|
C: (f, a) => f(...a)
|
|
@@ -1982,10 +2010,10 @@ var ConnectionLimiter = class {
|
|
|
1982
2010
|
* Rejects promise returned by `connecting` method.
|
|
1983
2011
|
*/
|
|
1984
2012
|
doneConnecting(sessionId) {
|
|
1985
|
-
|
|
2013
|
+
log7("done", {
|
|
1986
2014
|
sessionId
|
|
1987
2015
|
}, {
|
|
1988
|
-
F:
|
|
2016
|
+
F: __dxlog_file7,
|
|
1989
2017
|
L: 64,
|
|
1990
2018
|
S: this,
|
|
1991
2019
|
C: (f, a) => f(...a)
|
|
@@ -2095,7 +2123,7 @@ var gcSwarm = (swarm) => {
|
|
|
2095
2123
|
import { Event as Event6, synchronized as synchronized4 } from "@dxos/async";
|
|
2096
2124
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
2097
2125
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2098
|
-
import { log as
|
|
2126
|
+
import { log as log8 } from "@dxos/log";
|
|
2099
2127
|
import { Messenger } from "@dxos/messaging";
|
|
2100
2128
|
import { trace as trace3 } from "@dxos/protocols";
|
|
2101
2129
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -2110,9 +2138,9 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2110
2138
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2111
2139
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2112
2140
|
}
|
|
2113
|
-
var
|
|
2141
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2114
2142
|
var SwarmNetworkManager = class {
|
|
2115
|
-
constructor({ transportFactory, signalManager, log:
|
|
2143
|
+
constructor({ transportFactory, signalManager, log: log16 }) {
|
|
2116
2144
|
/**
|
|
2117
2145
|
* @internal
|
|
2118
2146
|
*/
|
|
@@ -2133,7 +2161,7 @@ var SwarmNetworkManager = class {
|
|
|
2133
2161
|
leave: (opts) => this._signalManager.leave(opts)
|
|
2134
2162
|
};
|
|
2135
2163
|
this._connectionLimiter = new ConnectionLimiter();
|
|
2136
|
-
if (
|
|
2164
|
+
if (log16) {
|
|
2137
2165
|
this._connectionLog = new ConnectionLog();
|
|
2138
2166
|
}
|
|
2139
2167
|
}
|
|
@@ -2155,20 +2183,20 @@ var SwarmNetworkManager = class {
|
|
|
2155
2183
|
return this._swarms.get(topic);
|
|
2156
2184
|
}
|
|
2157
2185
|
async open() {
|
|
2158
|
-
|
|
2186
|
+
log8.trace("dxos.mesh.network-manager.open", trace3.begin({
|
|
2159
2187
|
id: this._instanceId
|
|
2160
2188
|
}), {
|
|
2161
|
-
F:
|
|
2189
|
+
F: __dxlog_file8,
|
|
2162
2190
|
L: 126,
|
|
2163
2191
|
S: this,
|
|
2164
2192
|
C: (f, a) => f(...a)
|
|
2165
2193
|
});
|
|
2166
2194
|
await this._messenger.open();
|
|
2167
2195
|
await this._signalManager.open();
|
|
2168
|
-
|
|
2196
|
+
log8.trace("dxos.mesh.network-manager.open", trace3.end({
|
|
2169
2197
|
id: this._instanceId
|
|
2170
2198
|
}), {
|
|
2171
|
-
F:
|
|
2199
|
+
F: __dxlog_file8,
|
|
2172
2200
|
L: 129,
|
|
2173
2201
|
S: this,
|
|
2174
2202
|
C: (f, a) => f(...a)
|
|
@@ -2177,8 +2205,8 @@ var SwarmNetworkManager = class {
|
|
|
2177
2205
|
async close() {
|
|
2178
2206
|
for (const topic of this._swarms.keys()) {
|
|
2179
2207
|
await this.leaveSwarm(topic).catch((err) => {
|
|
2180
|
-
|
|
2181
|
-
F:
|
|
2208
|
+
log8(err, void 0, {
|
|
2209
|
+
F: __dxlog_file8,
|
|
2182
2210
|
L: 135,
|
|
2183
2211
|
S: this,
|
|
2184
2212
|
C: (f, a) => f(...a)
|
|
@@ -2193,7 +2221,7 @@ var SwarmNetworkManager = class {
|
|
|
2193
2221
|
*/
|
|
2194
2222
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
2195
2223
|
invariant6(PublicKey8.isPublicKey(topic), void 0, {
|
|
2196
|
-
F:
|
|
2224
|
+
F: __dxlog_file8,
|
|
2197
2225
|
L: 154,
|
|
2198
2226
|
S: this,
|
|
2199
2227
|
A: [
|
|
@@ -2202,7 +2230,7 @@ var SwarmNetworkManager = class {
|
|
|
2202
2230
|
]
|
|
2203
2231
|
});
|
|
2204
2232
|
invariant6(PublicKey8.isPublicKey(peerId), void 0, {
|
|
2205
|
-
F:
|
|
2233
|
+
F: __dxlog_file8,
|
|
2206
2234
|
L: 155,
|
|
2207
2235
|
S: this,
|
|
2208
2236
|
A: [
|
|
@@ -2211,7 +2239,7 @@ var SwarmNetworkManager = class {
|
|
|
2211
2239
|
]
|
|
2212
2240
|
});
|
|
2213
2241
|
invariant6(topology, void 0, {
|
|
2214
|
-
F:
|
|
2242
|
+
F: __dxlog_file8,
|
|
2215
2243
|
L: 156,
|
|
2216
2244
|
S: this,
|
|
2217
2245
|
A: [
|
|
@@ -2220,7 +2248,7 @@ var SwarmNetworkManager = class {
|
|
|
2220
2248
|
]
|
|
2221
2249
|
});
|
|
2222
2250
|
invariant6(typeof protocol === "function", void 0, {
|
|
2223
|
-
F:
|
|
2251
|
+
F: __dxlog_file8,
|
|
2224
2252
|
L: 157,
|
|
2225
2253
|
S: this,
|
|
2226
2254
|
A: [
|
|
@@ -2231,22 +2259,22 @@ var SwarmNetworkManager = class {
|
|
|
2231
2259
|
if (this._swarms.has(topic)) {
|
|
2232
2260
|
throw new Error(`Already connected to swarm: ${PublicKey8.from(topic)}`);
|
|
2233
2261
|
}
|
|
2234
|
-
|
|
2262
|
+
log8("joining", {
|
|
2235
2263
|
topic: PublicKey8.from(topic),
|
|
2236
2264
|
peerId,
|
|
2237
2265
|
topology: topology.toString()
|
|
2238
2266
|
}, {
|
|
2239
|
-
F:
|
|
2267
|
+
F: __dxlog_file8,
|
|
2240
2268
|
L: 162,
|
|
2241
2269
|
S: this,
|
|
2242
2270
|
C: (f, a) => f(...a)
|
|
2243
2271
|
});
|
|
2244
2272
|
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2245
2273
|
swarm.errors.handle((error) => {
|
|
2246
|
-
|
|
2274
|
+
log8("swarm error", {
|
|
2247
2275
|
error
|
|
2248
2276
|
}, {
|
|
2249
|
-
F:
|
|
2277
|
+
F: __dxlog_file8,
|
|
2250
2278
|
L: 175,
|
|
2251
2279
|
S: this,
|
|
2252
2280
|
C: (f, a) => f(...a)
|
|
@@ -2258,19 +2286,19 @@ var SwarmNetworkManager = class {
|
|
|
2258
2286
|
this._signalConnection.join({
|
|
2259
2287
|
topic,
|
|
2260
2288
|
peerId
|
|
2261
|
-
}).catch((error) =>
|
|
2262
|
-
F:
|
|
2289
|
+
}).catch((error) => log8.catch(error, void 0, {
|
|
2290
|
+
F: __dxlog_file8,
|
|
2263
2291
|
L: 184,
|
|
2264
2292
|
S: this,
|
|
2265
2293
|
C: (f, a) => f(...a)
|
|
2266
2294
|
}));
|
|
2267
2295
|
this.topicsUpdated.emit();
|
|
2268
2296
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2269
|
-
|
|
2297
|
+
log8("joined", {
|
|
2270
2298
|
topic: PublicKey8.from(topic),
|
|
2271
2299
|
count: this._swarms.size
|
|
2272
2300
|
}, {
|
|
2273
|
-
F:
|
|
2301
|
+
F: __dxlog_file8,
|
|
2274
2302
|
L: 188,
|
|
2275
2303
|
S: this,
|
|
2276
2304
|
C: (f, a) => f(...a)
|
|
@@ -2286,10 +2314,10 @@ var SwarmNetworkManager = class {
|
|
|
2286
2314
|
if (!this._swarms.has(topic)) {
|
|
2287
2315
|
return;
|
|
2288
2316
|
}
|
|
2289
|
-
|
|
2317
|
+
log8("leaving", {
|
|
2290
2318
|
topic: PublicKey8.from(topic)
|
|
2291
2319
|
}, {
|
|
2292
|
-
F:
|
|
2320
|
+
F: __dxlog_file8,
|
|
2293
2321
|
L: 205,
|
|
2294
2322
|
S: this,
|
|
2295
2323
|
C: (f, a) => f(...a)
|
|
@@ -2306,11 +2334,11 @@ var SwarmNetworkManager = class {
|
|
|
2306
2334
|
await swarm.destroy();
|
|
2307
2335
|
this._swarms.delete(topic);
|
|
2308
2336
|
this.topicsUpdated.emit();
|
|
2309
|
-
|
|
2337
|
+
log8("left", {
|
|
2310
2338
|
topic: PublicKey8.from(topic),
|
|
2311
2339
|
count: this._swarms.size
|
|
2312
2340
|
}, {
|
|
2313
|
-
F:
|
|
2341
|
+
F: __dxlog_file8,
|
|
2314
2342
|
L: 219,
|
|
2315
2343
|
S: this,
|
|
2316
2344
|
C: (f, a) => f(...a)
|
|
@@ -2352,14 +2380,14 @@ _ts_decorate4([
|
|
|
2352
2380
|
|
|
2353
2381
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
2354
2382
|
import { invariant as invariant7 } from "@dxos/invariant";
|
|
2355
|
-
var
|
|
2383
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2356
2384
|
var FullyConnectedTopology = class {
|
|
2357
2385
|
toString() {
|
|
2358
2386
|
return "FullyConnectedTopology";
|
|
2359
2387
|
}
|
|
2360
2388
|
init(controller) {
|
|
2361
2389
|
invariant7(!this._controller, "Already initialized", {
|
|
2362
|
-
F:
|
|
2390
|
+
F: __dxlog_file9,
|
|
2363
2391
|
L: 18,
|
|
2364
2392
|
S: this,
|
|
2365
2393
|
A: [
|
|
@@ -2371,7 +2399,7 @@ var FullyConnectedTopology = class {
|
|
|
2371
2399
|
}
|
|
2372
2400
|
update() {
|
|
2373
2401
|
invariant7(this._controller, "Not initialized", {
|
|
2374
|
-
F:
|
|
2402
|
+
F: __dxlog_file9,
|
|
2375
2403
|
L: 23,
|
|
2376
2404
|
S: this,
|
|
2377
2405
|
A: [
|
|
@@ -2394,8 +2422,8 @@ var FullyConnectedTopology = class {
|
|
|
2394
2422
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
2395
2423
|
import distance from "xor-distance";
|
|
2396
2424
|
import { invariant as invariant8 } from "@dxos/invariant";
|
|
2397
|
-
import { log as
|
|
2398
|
-
var
|
|
2425
|
+
import { log as log9 } from "@dxos/log";
|
|
2426
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2399
2427
|
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2400
2428
|
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2401
2429
|
var MMSTTopology = class {
|
|
@@ -2408,7 +2436,7 @@ var MMSTTopology = class {
|
|
|
2408
2436
|
}
|
|
2409
2437
|
init(controller) {
|
|
2410
2438
|
invariant8(!this._controller, "Already initialized", {
|
|
2411
|
-
F:
|
|
2439
|
+
F: __dxlog_file10,
|
|
2412
2440
|
L: 51,
|
|
2413
2441
|
S: this,
|
|
2414
2442
|
A: [
|
|
@@ -2420,7 +2448,7 @@ var MMSTTopology = class {
|
|
|
2420
2448
|
}
|
|
2421
2449
|
update() {
|
|
2422
2450
|
invariant8(this._controller, "Not initialized", {
|
|
2423
|
-
F:
|
|
2451
|
+
F: __dxlog_file10,
|
|
2424
2452
|
L: 56,
|
|
2425
2453
|
S: this,
|
|
2426
2454
|
A: [
|
|
@@ -2430,8 +2458,8 @@ var MMSTTopology = class {
|
|
|
2430
2458
|
});
|
|
2431
2459
|
const { connected, candidates } = this._controller.getState();
|
|
2432
2460
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2433
|
-
|
|
2434
|
-
F:
|
|
2461
|
+
log9("Running the algorithm.", void 0, {
|
|
2462
|
+
F: __dxlog_file10,
|
|
2435
2463
|
L: 60,
|
|
2436
2464
|
S: this,
|
|
2437
2465
|
C: (f, a) => f(...a)
|
|
@@ -2446,7 +2474,7 @@ var MMSTTopology = class {
|
|
|
2446
2474
|
}
|
|
2447
2475
|
async onOffer(peer) {
|
|
2448
2476
|
invariant8(this._controller, "Not initialized", {
|
|
2449
|
-
F:
|
|
2477
|
+
F: __dxlog_file10,
|
|
2450
2478
|
L: 72,
|
|
2451
2479
|
S: this,
|
|
2452
2480
|
A: [
|
|
@@ -2456,8 +2484,8 @@ var MMSTTopology = class {
|
|
|
2456
2484
|
});
|
|
2457
2485
|
const { connected } = this._controller.getState();
|
|
2458
2486
|
const accept = connected.length < this._maxPeers;
|
|
2459
|
-
|
|
2460
|
-
F:
|
|
2487
|
+
log9(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2488
|
+
F: __dxlog_file10,
|
|
2461
2489
|
L: 75,
|
|
2462
2490
|
S: this,
|
|
2463
2491
|
C: (f, a) => f(...a)
|
|
@@ -2468,7 +2496,7 @@ var MMSTTopology = class {
|
|
|
2468
2496
|
}
|
|
2469
2497
|
_runAlgorithm() {
|
|
2470
2498
|
invariant8(this._controller, "Not initialized", {
|
|
2471
|
-
F:
|
|
2499
|
+
F: __dxlog_file10,
|
|
2472
2500
|
L: 84,
|
|
2473
2501
|
S: this,
|
|
2474
2502
|
A: [
|
|
@@ -2478,15 +2506,15 @@ var MMSTTopology = class {
|
|
|
2478
2506
|
});
|
|
2479
2507
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2480
2508
|
if (connected.length > this._maxPeers) {
|
|
2481
|
-
|
|
2482
|
-
F:
|
|
2509
|
+
log9(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2510
|
+
F: __dxlog_file10,
|
|
2483
2511
|
L: 90,
|
|
2484
2512
|
S: this,
|
|
2485
2513
|
C: (f, a) => f(...a)
|
|
2486
2514
|
});
|
|
2487
2515
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2488
2516
|
invariant8(sorted.length === 0, void 0, {
|
|
2489
|
-
F:
|
|
2517
|
+
F: __dxlog_file10,
|
|
2490
2518
|
L: 94,
|
|
2491
2519
|
S: this,
|
|
2492
2520
|
A: [
|
|
@@ -2495,8 +2523,8 @@ var MMSTTopology = class {
|
|
|
2495
2523
|
]
|
|
2496
2524
|
});
|
|
2497
2525
|
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2498
|
-
|
|
2499
|
-
F:
|
|
2526
|
+
log9(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2527
|
+
F: __dxlog_file10,
|
|
2500
2528
|
L: 97,
|
|
2501
2529
|
S: this,
|
|
2502
2530
|
C: (f, a) => f(...a)
|
|
@@ -2504,8 +2532,8 @@ var MMSTTopology = class {
|
|
|
2504
2532
|
}
|
|
2505
2533
|
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2506
2534
|
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2507
|
-
|
|
2508
|
-
F:
|
|
2535
|
+
log9(`Disconnect ${peer}.`, void 0, {
|
|
2536
|
+
F: __dxlog_file10,
|
|
2509
2537
|
L: 102,
|
|
2510
2538
|
S: this,
|
|
2511
2539
|
C: (f, a) => f(...a)
|
|
@@ -2514,16 +2542,16 @@ var MMSTTopology = class {
|
|
|
2514
2542
|
}
|
|
2515
2543
|
this._lastAction = /* @__PURE__ */ new Date();
|
|
2516
2544
|
} else {
|
|
2517
|
-
|
|
2518
|
-
F:
|
|
2545
|
+
log9("rate limited disconnect", void 0, {
|
|
2546
|
+
F: __dxlog_file10,
|
|
2519
2547
|
L: 107,
|
|
2520
2548
|
S: this,
|
|
2521
2549
|
C: (f, a) => f(...a)
|
|
2522
2550
|
});
|
|
2523
2551
|
}
|
|
2524
2552
|
} else if (connected.length < this._originateConnections) {
|
|
2525
|
-
|
|
2526
|
-
F:
|
|
2553
|
+
log9(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2554
|
+
F: __dxlog_file10,
|
|
2527
2555
|
L: 111,
|
|
2528
2556
|
S: this,
|
|
2529
2557
|
C: (f, a) => f(...a)
|
|
@@ -2531,8 +2559,8 @@ var MMSTTopology = class {
|
|
|
2531
2559
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2532
2560
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2533
2561
|
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2534
|
-
|
|
2535
|
-
F:
|
|
2562
|
+
log9(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2563
|
+
F: __dxlog_file10,
|
|
2536
2564
|
L: 116,
|
|
2537
2565
|
S: this,
|
|
2538
2566
|
C: (f, a) => f(...a)
|
|
@@ -2540,8 +2568,8 @@ var MMSTTopology = class {
|
|
|
2540
2568
|
}
|
|
2541
2569
|
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2542
2570
|
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2543
|
-
|
|
2544
|
-
F:
|
|
2571
|
+
log9(`Connect ${peer}.`, void 0, {
|
|
2572
|
+
F: __dxlog_file10,
|
|
2545
2573
|
L: 120,
|
|
2546
2574
|
S: this,
|
|
2547
2575
|
C: (f, a) => f(...a)
|
|
@@ -2550,8 +2578,8 @@ var MMSTTopology = class {
|
|
|
2550
2578
|
}
|
|
2551
2579
|
this._lastAction = /* @__PURE__ */ new Date();
|
|
2552
2580
|
} else {
|
|
2553
|
-
|
|
2554
|
-
F:
|
|
2581
|
+
log9("rate limited connect", void 0, {
|
|
2582
|
+
F: __dxlog_file10,
|
|
2555
2583
|
L: 125,
|
|
2556
2584
|
S: this,
|
|
2557
2585
|
C: (f, a) => f(...a)
|
|
@@ -2567,8 +2595,8 @@ var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(dis
|
|
|
2567
2595
|
|
|
2568
2596
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
2569
2597
|
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2570
|
-
import { log as
|
|
2571
|
-
var
|
|
2598
|
+
import { log as log10 } from "@dxos/log";
|
|
2599
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2572
2600
|
var StarTopology = class {
|
|
2573
2601
|
constructor(_centralPeer) {
|
|
2574
2602
|
this._centralPeer = _centralPeer;
|
|
@@ -2578,7 +2606,7 @@ var StarTopology = class {
|
|
|
2578
2606
|
}
|
|
2579
2607
|
init(controller) {
|
|
2580
2608
|
invariant9(!this._controller, "Already initialized.", {
|
|
2581
|
-
F:
|
|
2609
|
+
F: __dxlog_file11,
|
|
2582
2610
|
L: 21,
|
|
2583
2611
|
S: this,
|
|
2584
2612
|
A: [
|
|
@@ -2590,7 +2618,7 @@ var StarTopology = class {
|
|
|
2590
2618
|
}
|
|
2591
2619
|
update() {
|
|
2592
2620
|
invariant9(this._controller, "Not initialized.", {
|
|
2593
|
-
F:
|
|
2621
|
+
F: __dxlog_file11,
|
|
2594
2622
|
L: 26,
|
|
2595
2623
|
S: this,
|
|
2596
2624
|
A: [
|
|
@@ -2600,18 +2628,18 @@ var StarTopology = class {
|
|
|
2600
2628
|
});
|
|
2601
2629
|
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
2602
2630
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
2603
|
-
|
|
2604
|
-
F:
|
|
2631
|
+
log10("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
2632
|
+
F: __dxlog_file11,
|
|
2605
2633
|
L: 29,
|
|
2606
2634
|
S: this,
|
|
2607
2635
|
C: (f, a) => f(...a)
|
|
2608
2636
|
});
|
|
2609
2637
|
for (const peer of connected) {
|
|
2610
2638
|
if (!peer.equals(this._centralPeer)) {
|
|
2611
|
-
|
|
2639
|
+
log10("dropping connection", {
|
|
2612
2640
|
peer
|
|
2613
2641
|
}, {
|
|
2614
|
-
F:
|
|
2642
|
+
F: __dxlog_file11,
|
|
2615
2643
|
L: 34,
|
|
2616
2644
|
S: this,
|
|
2617
2645
|
C: (f, a) => f(...a)
|
|
@@ -2622,10 +2650,10 @@ var StarTopology = class {
|
|
|
2622
2650
|
}
|
|
2623
2651
|
for (const peer of candidates) {
|
|
2624
2652
|
if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
2625
|
-
|
|
2653
|
+
log10("connecting to peer", {
|
|
2626
2654
|
peer
|
|
2627
2655
|
}, {
|
|
2628
|
-
F:
|
|
2656
|
+
F: __dxlog_file11,
|
|
2629
2657
|
L: 43,
|
|
2630
2658
|
S: this,
|
|
2631
2659
|
C: (f, a) => f(...a)
|
|
@@ -2636,7 +2664,7 @@ var StarTopology = class {
|
|
|
2636
2664
|
}
|
|
2637
2665
|
async onOffer(peer) {
|
|
2638
2666
|
invariant9(this._controller, "Not initialized.", {
|
|
2639
|
-
F:
|
|
2667
|
+
F: __dxlog_file11,
|
|
2640
2668
|
L: 50,
|
|
2641
2669
|
S: this,
|
|
2642
2670
|
A: [
|
|
@@ -2645,12 +2673,12 @@ var StarTopology = class {
|
|
|
2645
2673
|
]
|
|
2646
2674
|
});
|
|
2647
2675
|
const { ownPeerId } = this._controller.getState();
|
|
2648
|
-
|
|
2676
|
+
log10("offer", {
|
|
2649
2677
|
peer,
|
|
2650
2678
|
isCentral: peer.equals(this._centralPeer),
|
|
2651
2679
|
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
2652
2680
|
}, {
|
|
2653
|
-
F:
|
|
2681
|
+
F: __dxlog_file11,
|
|
2654
2682
|
L: 52,
|
|
2655
2683
|
S: this,
|
|
2656
2684
|
C: (f, a) => f(...a)
|
|
@@ -2667,7 +2695,7 @@ import { Event as Event7, Trigger as Trigger2 } from "@dxos/async";
|
|
|
2667
2695
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
2668
2696
|
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2669
2697
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
2670
|
-
import { log as
|
|
2698
|
+
import { log as log11, logInfo as logInfo3 } from "@dxos/log";
|
|
2671
2699
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
2672
2700
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
2673
2701
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2679,7 +2707,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
2679
2707
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2680
2708
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2681
2709
|
}
|
|
2682
|
-
var
|
|
2710
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2683
2711
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2684
2712
|
var createStreamDelay = (delay) => {
|
|
2685
2713
|
return new Transform({
|
|
@@ -2708,7 +2736,7 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2708
2736
|
this.connected = new Event7();
|
|
2709
2737
|
this.errors = new ErrorStream3();
|
|
2710
2738
|
invariant10(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2711
|
-
F:
|
|
2739
|
+
F: __dxlog_file12,
|
|
2712
2740
|
L: 64,
|
|
2713
2741
|
S: this,
|
|
2714
2742
|
A: [
|
|
@@ -2722,15 +2750,15 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2722
2750
|
return !this._closed;
|
|
2723
2751
|
}
|
|
2724
2752
|
async open() {
|
|
2725
|
-
|
|
2726
|
-
F:
|
|
2753
|
+
log11("opening...", void 0, {
|
|
2754
|
+
F: __dxlog_file12,
|
|
2727
2755
|
L: 74,
|
|
2728
2756
|
S: this,
|
|
2729
2757
|
C: (f, a) => f(...a)
|
|
2730
2758
|
});
|
|
2731
2759
|
if (this._options.initiator) {
|
|
2732
|
-
|
|
2733
|
-
F:
|
|
2760
|
+
log11("sending signal", void 0, {
|
|
2761
|
+
F: __dxlog_file12,
|
|
2734
2762
|
L: 78,
|
|
2735
2763
|
S: this,
|
|
2736
2764
|
C: (f, a) => f(...a)
|
|
@@ -2761,7 +2789,7 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2761
2789
|
return;
|
|
2762
2790
|
}
|
|
2763
2791
|
invariant10(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2764
|
-
F:
|
|
2792
|
+
F: __dxlog_file12,
|
|
2765
2793
|
L: 104,
|
|
2766
2794
|
S: this,
|
|
2767
2795
|
A: [
|
|
@@ -2771,8 +2799,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2771
2799
|
});
|
|
2772
2800
|
this._remoteConnection._remoteConnection = this;
|
|
2773
2801
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
2774
|
-
|
|
2775
|
-
F:
|
|
2802
|
+
log11("connected", void 0, {
|
|
2803
|
+
F: __dxlog_file12,
|
|
2776
2804
|
L: 108,
|
|
2777
2805
|
S: this,
|
|
2778
2806
|
C: (f, a) => f(...a)
|
|
@@ -2789,8 +2817,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2789
2817
|
}
|
|
2790
2818
|
}
|
|
2791
2819
|
async close() {
|
|
2792
|
-
|
|
2793
|
-
F:
|
|
2820
|
+
log11("closing...", void 0, {
|
|
2821
|
+
F: __dxlog_file12,
|
|
2794
2822
|
L: 129,
|
|
2795
2823
|
S: this,
|
|
2796
2824
|
C: (f, a) => f(...a)
|
|
@@ -2810,18 +2838,18 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2810
2838
|
this._remoteConnection = void 0;
|
|
2811
2839
|
}
|
|
2812
2840
|
this.closed.emit();
|
|
2813
|
-
|
|
2814
|
-
F:
|
|
2841
|
+
log11("closed", void 0, {
|
|
2842
|
+
F: __dxlog_file12,
|
|
2815
2843
|
L: 157,
|
|
2816
2844
|
S: this,
|
|
2817
2845
|
C: (f, a) => f(...a)
|
|
2818
2846
|
});
|
|
2819
2847
|
}
|
|
2820
2848
|
async onSignal({ payload }) {
|
|
2821
|
-
|
|
2849
|
+
log11("received signal", {
|
|
2822
2850
|
payload
|
|
2823
2851
|
}, {
|
|
2824
|
-
F:
|
|
2852
|
+
F: __dxlog_file12,
|
|
2825
2853
|
L: 161,
|
|
2826
2854
|
S: this,
|
|
2827
2855
|
C: (f, a) => f(...a)
|
|
@@ -2868,10 +2896,10 @@ var TransportKind;
|
|
|
2868
2896
|
// packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
|
|
2869
2897
|
import SimplePeerConstructor from "simple-peer";
|
|
2870
2898
|
import invariant11 from "tiny-invariant";
|
|
2871
|
-
import { Event as Event8 } from "@dxos/async";
|
|
2899
|
+
import { Event as Event8, synchronized as synchronized5 } from "@dxos/async";
|
|
2872
2900
|
import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
|
|
2873
2901
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
2874
|
-
import { log as
|
|
2902
|
+
import { log as log12 } from "@dxos/log";
|
|
2875
2903
|
import { ConnectionResetError as ConnectionResetError2, ConnectivityError as ConnectivityError2, ProtocolError as ProtocolError2, UnknownProtocolError as UnknownProtocolError2, trace as trace4 } from "@dxos/protocols";
|
|
2876
2904
|
|
|
2877
2905
|
// packages/core/mesh/network-manager/src/transport/webrtc.ts
|
|
@@ -2882,11 +2910,22 @@ try {
|
|
|
2882
2910
|
}
|
|
2883
2911
|
|
|
2884
2912
|
// packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
|
|
2885
|
-
|
|
2886
|
-
var
|
|
2913
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
2914
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2915
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2916
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2917
|
+
else
|
|
2918
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2919
|
+
if (d = decorators[i])
|
|
2920
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2921
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2922
|
+
}
|
|
2923
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
|
|
2924
|
+
var createSimplePeerTransportFactory = (webrtcConfig, iceProvider) => ({
|
|
2887
2925
|
createTransport: (options) => new SimplePeerTransport({
|
|
2888
2926
|
...options,
|
|
2889
|
-
webrtcConfig
|
|
2927
|
+
webrtcConfig,
|
|
2928
|
+
iceProvider
|
|
2890
2929
|
})
|
|
2891
2930
|
});
|
|
2892
2931
|
var SimplePeerTransport = class {
|
|
@@ -2898,26 +2937,92 @@ var SimplePeerTransport = class {
|
|
|
2898
2937
|
*/
|
|
2899
2938
|
constructor(_params) {
|
|
2900
2939
|
this._params = _params;
|
|
2940
|
+
this._peer = void 0;
|
|
2901
2941
|
this._closed = false;
|
|
2902
2942
|
this._piped = false;
|
|
2903
2943
|
this.closed = new Event8();
|
|
2904
2944
|
this.connected = new Event8();
|
|
2905
2945
|
this.errors = new ErrorStream4();
|
|
2906
2946
|
this._instanceId = PublicKey10.random().toHex();
|
|
2907
|
-
|
|
2947
|
+
}
|
|
2948
|
+
async getStats() {
|
|
2949
|
+
const stats = await this._getStats();
|
|
2950
|
+
if (!stats) {
|
|
2951
|
+
return {
|
|
2952
|
+
bytesSent: 0,
|
|
2953
|
+
bytesReceived: 0,
|
|
2954
|
+
packetsSent: 0,
|
|
2955
|
+
packetsReceived: 0,
|
|
2956
|
+
rawStats: {}
|
|
2957
|
+
};
|
|
2958
|
+
}
|
|
2959
|
+
return {
|
|
2960
|
+
bytesSent: stats.transport.bytesSent,
|
|
2961
|
+
bytesReceived: stats.transport.bytesReceived,
|
|
2962
|
+
packetsSent: stats.transport.packetsSent,
|
|
2963
|
+
packetsReceived: stats.transport.packetsReceived,
|
|
2964
|
+
rawStats: stats.raw
|
|
2965
|
+
};
|
|
2966
|
+
}
|
|
2967
|
+
async _getStats() {
|
|
2968
|
+
if (typeof this._peer?._pc?.getStats !== "function") {
|
|
2969
|
+
return null;
|
|
2970
|
+
}
|
|
2971
|
+
return await this._peer._pc.getStats().then((stats) => {
|
|
2972
|
+
const statsEntries = Array.from(stats.entries());
|
|
2973
|
+
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
2974
|
+
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
2975
|
+
let selectedCandidatePair;
|
|
2976
|
+
let remoteCandidate;
|
|
2977
|
+
if (candidatePair.length > 0) {
|
|
2978
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
2979
|
+
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
2980
|
+
}
|
|
2981
|
+
return {
|
|
2982
|
+
datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
|
|
2983
|
+
transport,
|
|
2984
|
+
selectedCandidatePair,
|
|
2985
|
+
remoteCandidate,
|
|
2986
|
+
raw: Object.fromEntries(stats.entries())
|
|
2987
|
+
};
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
async getDetails() {
|
|
2991
|
+
const stats = await this._getStats();
|
|
2992
|
+
const rc = stats?.remoteCandidate;
|
|
2993
|
+
if (!rc) {
|
|
2994
|
+
return "unavailable";
|
|
2995
|
+
}
|
|
2996
|
+
if (rc.candidateType === "relay") {
|
|
2997
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
2998
|
+
}
|
|
2999
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3000
|
+
}
|
|
3001
|
+
async open() {
|
|
3002
|
+
log12.trace("dxos.mesh.webrtc-transport.open", trace4.begin({
|
|
2908
3003
|
id: this._instanceId
|
|
2909
3004
|
}), {
|
|
2910
|
-
F:
|
|
2911
|
-
L:
|
|
3005
|
+
F: __dxlog_file13,
|
|
3006
|
+
L: 122,
|
|
2912
3007
|
S: this,
|
|
2913
3008
|
C: (f, a) => f(...a)
|
|
2914
3009
|
});
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
3010
|
+
log12("created connection", {
|
|
3011
|
+
params: this._params
|
|
3012
|
+
}, {
|
|
3013
|
+
F: __dxlog_file13,
|
|
3014
|
+
L: 123,
|
|
2918
3015
|
S: this,
|
|
2919
3016
|
C: (f, a) => f(...a)
|
|
2920
3017
|
});
|
|
3018
|
+
const providedIceServers = await this._params.iceProvider?.getIceServers();
|
|
3019
|
+
if (!this._params.webrtcConfig) {
|
|
3020
|
+
this._params.webrtcConfig = {};
|
|
3021
|
+
}
|
|
3022
|
+
this._params.webrtcConfig.iceServers = [
|
|
3023
|
+
...this._params.webrtcConfig.iceServers ?? [],
|
|
3024
|
+
...providedIceServers ?? []
|
|
3025
|
+
];
|
|
2921
3026
|
this._peer = new SimplePeerConstructor({
|
|
2922
3027
|
channelName: "dxos.mesh.transport",
|
|
2923
3028
|
initiator: this._params.initiator,
|
|
@@ -2925,9 +3030,9 @@ var SimplePeerTransport = class {
|
|
|
2925
3030
|
config: this._params.webrtcConfig
|
|
2926
3031
|
});
|
|
2927
3032
|
this._peer.on("signal", async (data) => {
|
|
2928
|
-
|
|
2929
|
-
F:
|
|
2930
|
-
L:
|
|
3033
|
+
log12("signal", data, {
|
|
3034
|
+
F: __dxlog_file13,
|
|
3035
|
+
L: 142,
|
|
2931
3036
|
S: this,
|
|
2932
3037
|
C: (f, a) => f(...a)
|
|
2933
3038
|
});
|
|
@@ -2938,9 +3043,9 @@ var SimplePeerTransport = class {
|
|
|
2938
3043
|
});
|
|
2939
3044
|
});
|
|
2940
3045
|
this._peer.on("connect", () => {
|
|
2941
|
-
|
|
2942
|
-
F:
|
|
2943
|
-
L:
|
|
3046
|
+
log12("connected", void 0, {
|
|
3047
|
+
F: __dxlog_file13,
|
|
3048
|
+
L: 147,
|
|
2944
3049
|
S: this,
|
|
2945
3050
|
C: (f, a) => f(...a)
|
|
2946
3051
|
});
|
|
@@ -2949,9 +3054,9 @@ var SimplePeerTransport = class {
|
|
|
2949
3054
|
this.connected.emit();
|
|
2950
3055
|
});
|
|
2951
3056
|
this._peer.on("close", async () => {
|
|
2952
|
-
|
|
2953
|
-
F:
|
|
2954
|
-
L:
|
|
3057
|
+
log12("closed", void 0, {
|
|
3058
|
+
F: __dxlog_file13,
|
|
3059
|
+
L: 154,
|
|
2955
3060
|
S: this,
|
|
2956
3061
|
C: (f, a) => f(...a)
|
|
2957
3062
|
});
|
|
@@ -2962,20 +3067,20 @@ var SimplePeerTransport = class {
|
|
|
2962
3067
|
if (err.errorDetail === "sctp-failure") {
|
|
2963
3068
|
this.errors.raise(new ConnectionResetError2("sctp-failure from RTCError", err));
|
|
2964
3069
|
} else {
|
|
2965
|
-
|
|
3070
|
+
log12.info("unknown RTCError", {
|
|
2966
3071
|
err
|
|
2967
3072
|
}, {
|
|
2968
|
-
F:
|
|
2969
|
-
L:
|
|
3073
|
+
F: __dxlog_file13,
|
|
3074
|
+
L: 165,
|
|
2970
3075
|
S: this,
|
|
2971
3076
|
C: (f, a) => f(...a)
|
|
2972
3077
|
});
|
|
2973
3078
|
this.errors.raise(new UnknownProtocolError2("unknown RTCError", err));
|
|
2974
3079
|
}
|
|
2975
3080
|
} else if ("code" in err) {
|
|
2976
|
-
|
|
2977
|
-
F:
|
|
2978
|
-
L:
|
|
3081
|
+
log12.info("simple-peer error", err, {
|
|
3082
|
+
F: __dxlog_file13,
|
|
3083
|
+
L: 170,
|
|
2979
3084
|
S: this,
|
|
2980
3085
|
C: (f, a) => f(...a)
|
|
2981
3086
|
});
|
|
@@ -3003,9 +3108,9 @@ var SimplePeerTransport = class {
|
|
|
3003
3108
|
break;
|
|
3004
3109
|
}
|
|
3005
3110
|
} else {
|
|
3006
|
-
|
|
3007
|
-
F:
|
|
3008
|
-
L:
|
|
3111
|
+
log12.info("unknown peer connection error", err, {
|
|
3112
|
+
F: __dxlog_file13,
|
|
3113
|
+
L: 196,
|
|
3009
3114
|
S: this,
|
|
3010
3115
|
C: (f, a) => f(...a)
|
|
3011
3116
|
});
|
|
@@ -3014,95 +3119,40 @@ var SimplePeerTransport = class {
|
|
|
3014
3119
|
try {
|
|
3015
3120
|
if (typeof this._peer?._pc?.getStats === "function") {
|
|
3016
3121
|
this._peer._pc.getStats().then((stats) => {
|
|
3017
|
-
|
|
3122
|
+
log12.info("report after webrtc error", {
|
|
3018
3123
|
config: this._params.webrtcConfig,
|
|
3019
3124
|
stats: Object.fromEntries(stats.entries())
|
|
3020
3125
|
}, {
|
|
3021
|
-
F:
|
|
3022
|
-
L:
|
|
3126
|
+
F: __dxlog_file13,
|
|
3127
|
+
L: 204,
|
|
3023
3128
|
S: this,
|
|
3024
3129
|
C: (f, a) => f(...a)
|
|
3025
3130
|
});
|
|
3026
3131
|
});
|
|
3027
3132
|
}
|
|
3028
3133
|
} catch (err2) {
|
|
3029
|
-
|
|
3030
|
-
F:
|
|
3031
|
-
L:
|
|
3134
|
+
log12.catch(err2, void 0, {
|
|
3135
|
+
F: __dxlog_file13,
|
|
3136
|
+
L: 211,
|
|
3032
3137
|
S: this,
|
|
3033
3138
|
C: (f, a) => f(...a)
|
|
3034
3139
|
});
|
|
3035
3140
|
}
|
|
3036
3141
|
await this.close();
|
|
3037
3142
|
});
|
|
3038
|
-
|
|
3143
|
+
log12.trace("dxos.mesh.webrtc-transport.open", trace4.end({
|
|
3039
3144
|
id: this._instanceId
|
|
3040
3145
|
}), {
|
|
3041
|
-
F:
|
|
3042
|
-
L:
|
|
3146
|
+
F: __dxlog_file13,
|
|
3147
|
+
L: 217,
|
|
3043
3148
|
S: this,
|
|
3044
3149
|
C: (f, a) => f(...a)
|
|
3045
3150
|
});
|
|
3046
3151
|
}
|
|
3047
|
-
async getStats() {
|
|
3048
|
-
const stats = await this._getStats();
|
|
3049
|
-
if (!stats) {
|
|
3050
|
-
return {
|
|
3051
|
-
bytesSent: 0,
|
|
3052
|
-
bytesReceived: 0,
|
|
3053
|
-
packetsSent: 0,
|
|
3054
|
-
packetsReceived: 0,
|
|
3055
|
-
rawStats: {}
|
|
3056
|
-
};
|
|
3057
|
-
}
|
|
3058
|
-
return {
|
|
3059
|
-
bytesSent: stats.transport.bytesSent,
|
|
3060
|
-
bytesReceived: stats.transport.bytesReceived,
|
|
3061
|
-
packetsSent: stats.transport.packetsSent,
|
|
3062
|
-
packetsReceived: stats.transport.packetsReceived,
|
|
3063
|
-
rawStats: stats.raw
|
|
3064
|
-
};
|
|
3065
|
-
}
|
|
3066
|
-
async _getStats() {
|
|
3067
|
-
if (typeof this._peer?._pc?.getStats !== "function") {
|
|
3068
|
-
return null;
|
|
3069
|
-
}
|
|
3070
|
-
return await this._peer._pc.getStats().then((stats) => {
|
|
3071
|
-
const statsEntries = Array.from(stats.entries());
|
|
3072
|
-
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
3073
|
-
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
3074
|
-
let selectedCandidatePair;
|
|
3075
|
-
let remoteCandidate;
|
|
3076
|
-
if (candidatePair.length > 0) {
|
|
3077
|
-
selectedCandidatePair = candidatePair[0][1];
|
|
3078
|
-
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
3079
|
-
}
|
|
3080
|
-
return {
|
|
3081
|
-
datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
|
|
3082
|
-
transport,
|
|
3083
|
-
selectedCandidatePair,
|
|
3084
|
-
remoteCandidate,
|
|
3085
|
-
raw: Object.fromEntries(stats.entries())
|
|
3086
|
-
};
|
|
3087
|
-
});
|
|
3088
|
-
}
|
|
3089
|
-
async getDetails() {
|
|
3090
|
-
const stats = await this._getStats();
|
|
3091
|
-
const rc = stats?.remoteCandidate;
|
|
3092
|
-
if (!rc) {
|
|
3093
|
-
return "unavailable";
|
|
3094
|
-
}
|
|
3095
|
-
if (rc.candidateType === "relay") {
|
|
3096
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3097
|
-
}
|
|
3098
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3099
|
-
}
|
|
3100
|
-
async open() {
|
|
3101
|
-
}
|
|
3102
3152
|
async close() {
|
|
3103
|
-
|
|
3104
|
-
F:
|
|
3105
|
-
L:
|
|
3153
|
+
log12("closing...", void 0, {
|
|
3154
|
+
F: __dxlog_file13,
|
|
3155
|
+
L: 222,
|
|
3106
3156
|
S: this,
|
|
3107
3157
|
C: (f, a) => f(...a)
|
|
3108
3158
|
});
|
|
@@ -3113,9 +3163,9 @@ var SimplePeerTransport = class {
|
|
|
3113
3163
|
this._peer.destroy();
|
|
3114
3164
|
this._closed = true;
|
|
3115
3165
|
this.closed.emit();
|
|
3116
|
-
|
|
3117
|
-
F:
|
|
3118
|
-
L:
|
|
3166
|
+
log12("closed", void 0, {
|
|
3167
|
+
F: __dxlog_file13,
|
|
3168
|
+
L: 230,
|
|
3119
3169
|
S: this,
|
|
3120
3170
|
C: (f, a) => f(...a)
|
|
3121
3171
|
});
|
|
@@ -3125,6 +3175,7 @@ var SimplePeerTransport = class {
|
|
|
3125
3175
|
return;
|
|
3126
3176
|
}
|
|
3127
3177
|
invariant11(signal.payload.data, "Signal message must contain signal data.");
|
|
3178
|
+
invariant11(this._peer, "Peer must be initialized before receiving signals.");
|
|
3128
3179
|
this._peer.signal(signal.payload.data);
|
|
3129
3180
|
}
|
|
3130
3181
|
_disconnectStreams() {
|
|
@@ -3133,19 +3184,29 @@ var SimplePeerTransport = class {
|
|
|
3133
3184
|
}
|
|
3134
3185
|
}
|
|
3135
3186
|
};
|
|
3187
|
+
_ts_decorate6([
|
|
3188
|
+
synchronized5
|
|
3189
|
+
], SimplePeerTransport.prototype, "open", null);
|
|
3190
|
+
_ts_decorate6([
|
|
3191
|
+
synchronized5
|
|
3192
|
+
], SimplePeerTransport.prototype, "close", null);
|
|
3193
|
+
_ts_decorate6([
|
|
3194
|
+
synchronized5
|
|
3195
|
+
], SimplePeerTransport.prototype, "onSignal", null);
|
|
3136
3196
|
|
|
3137
3197
|
// packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts
|
|
3138
3198
|
import { Duplex } from "@dxos/node-std/stream";
|
|
3139
3199
|
import { Stream } from "@dxos/codec-protobuf";
|
|
3140
3200
|
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3141
3201
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
3142
|
-
import { log as
|
|
3202
|
+
import { log as log13 } from "@dxos/log";
|
|
3143
3203
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
3144
3204
|
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
3145
|
-
var
|
|
3205
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
|
|
3146
3206
|
var SimplePeerTransportService = class {
|
|
3147
|
-
constructor(_webrtcConfig) {
|
|
3207
|
+
constructor(_webrtcConfig, _iceProvider) {
|
|
3148
3208
|
this._webrtcConfig = _webrtcConfig;
|
|
3209
|
+
this._iceProvider = _iceProvider;
|
|
3149
3210
|
this.transports = new ComplexMap8(PublicKey11.hash);
|
|
3150
3211
|
}
|
|
3151
3212
|
open(request) {
|
|
@@ -3179,7 +3240,8 @@ var SimplePeerTransportService = class {
|
|
|
3179
3240
|
payload: signal
|
|
3180
3241
|
}
|
|
3181
3242
|
});
|
|
3182
|
-
}
|
|
3243
|
+
},
|
|
3244
|
+
iceProvider: this._iceProvider
|
|
3183
3245
|
});
|
|
3184
3246
|
void transport.open();
|
|
3185
3247
|
next({
|
|
@@ -3224,8 +3286,8 @@ var SimplePeerTransportService = class {
|
|
|
3224
3286
|
}
|
|
3225
3287
|
async sendSignal({ proxyId, signal }) {
|
|
3226
3288
|
invariant12(this.transports.has(proxyId), void 0, {
|
|
3227
|
-
F:
|
|
3228
|
-
L:
|
|
3289
|
+
F: __dxlog_file14,
|
|
3290
|
+
L: 124,
|
|
3229
3291
|
S: this,
|
|
3230
3292
|
A: [
|
|
3231
3293
|
"this.transports.has(proxyId)",
|
|
@@ -3236,8 +3298,8 @@ var SimplePeerTransportService = class {
|
|
|
3236
3298
|
}
|
|
3237
3299
|
async getDetails({ proxyId }) {
|
|
3238
3300
|
invariant12(this.transports.has(proxyId), void 0, {
|
|
3239
|
-
F:
|
|
3240
|
-
L:
|
|
3301
|
+
F: __dxlog_file14,
|
|
3302
|
+
L: 129,
|
|
3241
3303
|
S: this,
|
|
3242
3304
|
A: [
|
|
3243
3305
|
"this.transports.has(proxyId)",
|
|
@@ -3250,8 +3312,8 @@ var SimplePeerTransportService = class {
|
|
|
3250
3312
|
}
|
|
3251
3313
|
async getStats({ proxyId }) {
|
|
3252
3314
|
invariant12(this.transports.has(proxyId), void 0, {
|
|
3253
|
-
F:
|
|
3254
|
-
L:
|
|
3315
|
+
F: __dxlog_file14,
|
|
3316
|
+
L: 134,
|
|
3255
3317
|
S: this,
|
|
3256
3318
|
A: [
|
|
3257
3319
|
"this.transports.has(proxyId)",
|
|
@@ -3264,16 +3326,16 @@ var SimplePeerTransportService = class {
|
|
|
3264
3326
|
}
|
|
3265
3327
|
async sendData({ proxyId, payload }) {
|
|
3266
3328
|
if (this.transports.get(proxyId)?.state !== "OPEN") {
|
|
3267
|
-
|
|
3268
|
-
F:
|
|
3269
|
-
L:
|
|
3329
|
+
log13.debug("transport is closed", void 0, {
|
|
3330
|
+
F: __dxlog_file14,
|
|
3331
|
+
L: 140,
|
|
3270
3332
|
S: this,
|
|
3271
3333
|
C: (f, a) => f(...a)
|
|
3272
3334
|
});
|
|
3273
3335
|
}
|
|
3274
3336
|
invariant12(this.transports.has(proxyId), void 0, {
|
|
3275
|
-
F:
|
|
3276
|
-
L:
|
|
3337
|
+
F: __dxlog_file14,
|
|
3338
|
+
L: 142,
|
|
3277
3339
|
S: this,
|
|
3278
3340
|
A: [
|
|
3279
3341
|
"this.transports.has(proxyId)",
|
|
@@ -3294,9 +3356,9 @@ var SimplePeerTransportService = class {
|
|
|
3294
3356
|
if (this.transports.get(proxyId)) {
|
|
3295
3357
|
this.transports.get(proxyId).state = "CLOSED";
|
|
3296
3358
|
}
|
|
3297
|
-
|
|
3298
|
-
F:
|
|
3299
|
-
L:
|
|
3359
|
+
log13("Closed.", void 0, {
|
|
3360
|
+
F: __dxlog_file14,
|
|
3361
|
+
L: 158,
|
|
3300
3362
|
S: this,
|
|
3301
3363
|
C: (f, a) => f(...a)
|
|
3302
3364
|
});
|
|
@@ -3310,11 +3372,11 @@ import { Context as Context6 } from "@dxos/context";
|
|
|
3310
3372
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
3311
3373
|
import { invariant as invariant13 } from "@dxos/invariant";
|
|
3312
3374
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
3313
|
-
import { log as
|
|
3375
|
+
import { log as log14 } from "@dxos/log";
|
|
3314
3376
|
import { ConnectionResetError as ConnectionResetError3, TimeoutError as TimeoutError3, ProtocolError as ProtocolError3, ConnectivityError as ConnectivityError3, UnknownProtocolError as UnknownProtocolError3 } from "@dxos/protocols";
|
|
3315
3377
|
import { ConnectionState as ConnectionState4 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
3316
3378
|
import { arrayToBuffer } from "@dxos/util";
|
|
3317
|
-
var
|
|
3379
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
|
|
3318
3380
|
var RPC_TIMEOUT = 1e4;
|
|
3319
3381
|
var RESP_MIN_THRESHOLD = 500;
|
|
3320
3382
|
var TIMEOUT_THRESHOLD = 10;
|
|
@@ -3323,7 +3385,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3323
3385
|
this._options = _options;
|
|
3324
3386
|
this._proxyId = PublicKey12.random();
|
|
3325
3387
|
this._ctx = new Context6(void 0, {
|
|
3326
|
-
F:
|
|
3388
|
+
F: __dxlog_file15,
|
|
3327
3389
|
L: 37
|
|
3328
3390
|
});
|
|
3329
3391
|
this._timeoutCount = 0;
|
|
@@ -3344,8 +3406,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3344
3406
|
});
|
|
3345
3407
|
this._serviceStream.waitUntilReady().then(() => {
|
|
3346
3408
|
this._serviceStream.subscribe(async (event) => {
|
|
3347
|
-
|
|
3348
|
-
F:
|
|
3409
|
+
log14("SimplePeerTransportProxy: event", event, {
|
|
3410
|
+
F: __dxlog_file15,
|
|
3349
3411
|
L: 66,
|
|
3350
3412
|
S: this,
|
|
3351
3413
|
C: (f, a) => f(...a)
|
|
@@ -3368,8 +3430,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3368
3430
|
timeout: RPC_TIMEOUT
|
|
3369
3431
|
}).then(() => {
|
|
3370
3432
|
if (performance.now() - then > RESP_MIN_THRESHOLD) {
|
|
3371
|
-
|
|
3372
|
-
F:
|
|
3433
|
+
log14("slow response, delaying callback", void 0, {
|
|
3434
|
+
F: __dxlog_file15,
|
|
3373
3435
|
L: 90,
|
|
3374
3436
|
S: this,
|
|
3375
3437
|
C: (f, a) => f(...a)
|
|
@@ -3384,8 +3446,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3384
3446
|
if (this._timeoutCount++ > TIMEOUT_THRESHOLD) {
|
|
3385
3447
|
throw new TimeoutError3(`too many timeouts (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
|
|
3386
3448
|
} else {
|
|
3387
|
-
|
|
3388
|
-
F:
|
|
3449
|
+
log14("timeout error, but still invoking callback", void 0, {
|
|
3450
|
+
F: __dxlog_file15,
|
|
3389
3451
|
L: 102,
|
|
3390
3452
|
S: this,
|
|
3391
3453
|
C: (f, a) => f(...a)
|
|
@@ -3393,8 +3455,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3393
3455
|
callback();
|
|
3394
3456
|
}
|
|
3395
3457
|
} else {
|
|
3396
|
-
|
|
3397
|
-
F:
|
|
3458
|
+
log14.catch(err, void 0, {
|
|
3459
|
+
F: __dxlog_file15,
|
|
3398
3460
|
L: 106,
|
|
3399
3461
|
S: this,
|
|
3400
3462
|
C: (f, a) => f(...a)
|
|
@@ -3404,18 +3466,18 @@ var SimplePeerTransportProxy = class {
|
|
|
3404
3466
|
}
|
|
3405
3467
|
});
|
|
3406
3468
|
proxyStream.on("error", (err) => {
|
|
3407
|
-
|
|
3469
|
+
log14("proxystream error", {
|
|
3408
3470
|
err
|
|
3409
3471
|
}, {
|
|
3410
|
-
F:
|
|
3472
|
+
F: __dxlog_file15,
|
|
3411
3473
|
L: 114,
|
|
3412
3474
|
S: this,
|
|
3413
3475
|
C: (f, a) => f(...a)
|
|
3414
3476
|
});
|
|
3415
3477
|
});
|
|
3416
3478
|
this._options.stream.pipe(proxyStream);
|
|
3417
|
-
}, (error) =>
|
|
3418
|
-
F:
|
|
3479
|
+
}, (error) => log14.catch(error, void 0, {
|
|
3480
|
+
F: __dxlog_file15,
|
|
3419
3481
|
L: 119,
|
|
3420
3482
|
S: this,
|
|
3421
3483
|
C: (f, a) => f(...a)
|
|
@@ -3434,8 +3496,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3434
3496
|
timeout: RPC_TIMEOUT
|
|
3435
3497
|
});
|
|
3436
3498
|
} catch (err) {
|
|
3437
|
-
|
|
3438
|
-
F:
|
|
3499
|
+
log14.catch(err, void 0, {
|
|
3500
|
+
F: __dxlog_file15,
|
|
3439
3501
|
L: 134,
|
|
3440
3502
|
S: this,
|
|
3441
3503
|
C: (f, a) => f(...a)
|
|
@@ -3514,7 +3576,7 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3514
3576
|
}
|
|
3515
3577
|
createTransport(options) {
|
|
3516
3578
|
invariant13(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
|
|
3517
|
-
F:
|
|
3579
|
+
F: __dxlog_file15,
|
|
3518
3580
|
L: 218,
|
|
3519
3581
|
S: this,
|
|
3520
3582
|
A: [
|
|
@@ -3550,11 +3612,11 @@ var decodeError = (err) => {
|
|
|
3550
3612
|
|
|
3551
3613
|
// packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts
|
|
3552
3614
|
import { Duplex as Duplex2 } from "stream";
|
|
3553
|
-
import { Event as Event10, Trigger as Trigger3, synchronized as
|
|
3615
|
+
import { Event as Event10, Trigger as Trigger3, synchronized as synchronized6 } from "@dxos/async";
|
|
3554
3616
|
import { ErrorStream as ErrorStream6 } from "@dxos/debug";
|
|
3555
3617
|
import { invariant as invariant14 } from "@dxos/invariant";
|
|
3556
|
-
import { log as
|
|
3557
|
-
function
|
|
3618
|
+
import { log as log15 } from "@dxos/log";
|
|
3619
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
3558
3620
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3559
3621
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3560
3622
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3564,16 +3626,19 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
3564
3626
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3565
3627
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3566
3628
|
}
|
|
3567
|
-
var
|
|
3629
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
|
|
3568
3630
|
var DATACHANNEL_LABEL = "dxos.mesh.transport";
|
|
3569
3631
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3570
3632
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3571
|
-
var createLibDataChannelTransportFactory = (webrtcConfig) =>
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3633
|
+
var createLibDataChannelTransportFactory = (webrtcConfig, iceProvider) => {
|
|
3634
|
+
return {
|
|
3635
|
+
createTransport: (options) => new LibDataChannelTransport({
|
|
3636
|
+
...options,
|
|
3637
|
+
webrtcConfig,
|
|
3638
|
+
iceProvider
|
|
3639
|
+
})
|
|
3640
|
+
};
|
|
3641
|
+
};
|
|
3577
3642
|
var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
3578
3643
|
static {
|
|
3579
3644
|
this._instanceCount = 0;
|
|
@@ -3596,42 +3661,43 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3596
3661
|
this.errors.raise(new Error("connection already closed"));
|
|
3597
3662
|
}
|
|
3598
3663
|
const { RTCPeerConnection } = (await importESM("node-datachannel/polyfill")).default;
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
this._options.webrtcConfig = {
|
|
3603
|
-
iceServers: []
|
|
3604
|
-
};
|
|
3664
|
+
const providedIceServers = await this._options.iceProvider?.getIceServers();
|
|
3665
|
+
if (!this._options.webrtcConfig) {
|
|
3666
|
+
this._options.webrtcConfig = {};
|
|
3605
3667
|
}
|
|
3668
|
+
this._options.webrtcConfig.iceServers = [
|
|
3669
|
+
...this._options.webrtcConfig.iceServers ?? [],
|
|
3670
|
+
...providedIceServers ?? []
|
|
3671
|
+
];
|
|
3606
3672
|
this._peer = new RTCPeerConnection(this._options.webrtcConfig);
|
|
3607
3673
|
this._peer.onicecandidateerror = (event) => {
|
|
3608
|
-
|
|
3674
|
+
log15.error("peer.onicecandidateerror", {
|
|
3609
3675
|
event
|
|
3610
3676
|
}, {
|
|
3611
|
-
F:
|
|
3612
|
-
L:
|
|
3677
|
+
F: __dxlog_file16,
|
|
3678
|
+
L: 93,
|
|
3613
3679
|
S: this,
|
|
3614
3680
|
C: (f, a) => f(...a)
|
|
3615
3681
|
});
|
|
3616
3682
|
};
|
|
3617
3683
|
this._peer.onconnectionstatechange = (event) => {
|
|
3618
|
-
|
|
3684
|
+
log15.debug("peer.onconnectionstatechange", {
|
|
3619
3685
|
event,
|
|
3620
3686
|
peerConnectionState: this._peer?.connectionState,
|
|
3621
3687
|
transportConnectionState: this._connected
|
|
3622
3688
|
}, {
|
|
3623
|
-
F:
|
|
3624
|
-
L:
|
|
3689
|
+
F: __dxlog_file16,
|
|
3690
|
+
L: 97,
|
|
3625
3691
|
S: this,
|
|
3626
3692
|
C: (f, a) => f(...a)
|
|
3627
3693
|
});
|
|
3628
3694
|
};
|
|
3629
3695
|
this._peer.onicecandidate = async (event) => {
|
|
3630
|
-
|
|
3696
|
+
log15.debug("peer.onicecandidate", {
|
|
3631
3697
|
event
|
|
3632
3698
|
}, {
|
|
3633
|
-
F:
|
|
3634
|
-
L:
|
|
3699
|
+
F: __dxlog_file16,
|
|
3700
|
+
L: 107,
|
|
3635
3701
|
S: this,
|
|
3636
3702
|
C: (f, a) => f(...a)
|
|
3637
3703
|
});
|
|
@@ -3651,11 +3717,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3651
3717
|
}
|
|
3652
3718
|
});
|
|
3653
3719
|
} catch (err) {
|
|
3654
|
-
|
|
3720
|
+
log15.info("signaling error", {
|
|
3655
3721
|
err
|
|
3656
3722
|
}, {
|
|
3657
|
-
F:
|
|
3658
|
-
L:
|
|
3723
|
+
F: __dxlog_file16,
|
|
3724
|
+
L: 124,
|
|
3659
3725
|
S: this,
|
|
3660
3726
|
C: (f, a) => f(...a)
|
|
3661
3727
|
});
|
|
@@ -3664,8 +3730,8 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3664
3730
|
};
|
|
3665
3731
|
if (this._options.initiator) {
|
|
3666
3732
|
invariant14(this._peer, "not open", {
|
|
3667
|
-
F:
|
|
3668
|
-
L:
|
|
3733
|
+
F: __dxlog_file16,
|
|
3734
|
+
L: 130,
|
|
3669
3735
|
S: this,
|
|
3670
3736
|
A: [
|
|
3671
3737
|
"this._peer",
|
|
@@ -3677,22 +3743,22 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3677
3743
|
return;
|
|
3678
3744
|
}
|
|
3679
3745
|
if (this._peer?.connectionState !== "connecting") {
|
|
3680
|
-
|
|
3746
|
+
log15.error("peer not connecting", {
|
|
3681
3747
|
peer: this._peer
|
|
3682
3748
|
}, {
|
|
3683
|
-
F:
|
|
3684
|
-
L:
|
|
3749
|
+
F: __dxlog_file16,
|
|
3750
|
+
L: 141,
|
|
3685
3751
|
S: this,
|
|
3686
3752
|
C: (f, a) => f(...a)
|
|
3687
3753
|
});
|
|
3688
3754
|
this.errors.raise(new Error("invalid state: peer is initiator, but other peer not in state connecting"));
|
|
3689
3755
|
}
|
|
3690
|
-
|
|
3756
|
+
log15.debug("creating offer", {
|
|
3691
3757
|
peer: this._peer,
|
|
3692
3758
|
offer
|
|
3693
3759
|
}, {
|
|
3694
|
-
F:
|
|
3695
|
-
L:
|
|
3760
|
+
F: __dxlog_file16,
|
|
3761
|
+
L: 145,
|
|
3696
3762
|
S: this,
|
|
3697
3763
|
C: (f, a) => f(...a)
|
|
3698
3764
|
});
|
|
@@ -3709,9 +3775,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3709
3775
|
this.errors.raise(err);
|
|
3710
3776
|
});
|
|
3711
3777
|
this._handleChannel(this._peer.createDataChannel(DATACHANNEL_LABEL));
|
|
3712
|
-
|
|
3713
|
-
F:
|
|
3714
|
-
L:
|
|
3778
|
+
log15.debug("created data channel", void 0, {
|
|
3779
|
+
F: __dxlog_file16,
|
|
3780
|
+
L: 155,
|
|
3715
3781
|
S: this,
|
|
3716
3782
|
C: (f, a) => f(...a)
|
|
3717
3783
|
});
|
|
@@ -3720,11 +3786,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3720
3786
|
};
|
|
3721
3787
|
} else {
|
|
3722
3788
|
this._peer.ondatachannel = (event) => {
|
|
3723
|
-
|
|
3789
|
+
log15.debug("peer.ondatachannel (non-initiator)", {
|
|
3724
3790
|
event
|
|
3725
3791
|
}, {
|
|
3726
|
-
F:
|
|
3727
|
-
L:
|
|
3792
|
+
F: __dxlog_file16,
|
|
3793
|
+
L: 161,
|
|
3728
3794
|
S: this,
|
|
3729
3795
|
C: (f, a) => f(...a)
|
|
3730
3796
|
});
|
|
@@ -3762,9 +3828,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3762
3828
|
_handleChannel(dataChannel) {
|
|
3763
3829
|
this._channel = dataChannel;
|
|
3764
3830
|
this._channel.onopen = () => {
|
|
3765
|
-
|
|
3766
|
-
F:
|
|
3767
|
-
L:
|
|
3831
|
+
log15.debug("channel.onopen", void 0, {
|
|
3832
|
+
F: __dxlog_file16,
|
|
3833
|
+
L: 206,
|
|
3768
3834
|
S: this,
|
|
3769
3835
|
C: (f, a) => f(...a)
|
|
3770
3836
|
});
|
|
@@ -3783,9 +3849,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3783
3849
|
}
|
|
3784
3850
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3785
3851
|
if (this._writeCallback !== null) {
|
|
3786
|
-
|
|
3787
|
-
F:
|
|
3788
|
-
L:
|
|
3852
|
+
log15.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3853
|
+
F: __dxlog_file16,
|
|
3854
|
+
L: 223,
|
|
3789
3855
|
S: this,
|
|
3790
3856
|
C: (f, a) => f(...a)
|
|
3791
3857
|
});
|
|
@@ -3802,11 +3868,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3802
3868
|
this.connected.emit();
|
|
3803
3869
|
};
|
|
3804
3870
|
this._channel.onclose = async (err) => {
|
|
3805
|
-
|
|
3871
|
+
log15.info("channel.onclose", {
|
|
3806
3872
|
err
|
|
3807
3873
|
}, {
|
|
3808
|
-
F:
|
|
3809
|
-
L:
|
|
3874
|
+
F: __dxlog_file16,
|
|
3875
|
+
L: 239,
|
|
3810
3876
|
S: this,
|
|
3811
3877
|
C: (f, a) => f(...a)
|
|
3812
3878
|
});
|
|
@@ -3831,8 +3897,8 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3831
3897
|
}
|
|
3832
3898
|
async onSignal(signal) {
|
|
3833
3899
|
invariant14(this._peer, "not open", {
|
|
3834
|
-
F:
|
|
3835
|
-
L:
|
|
3900
|
+
F: __dxlog_file16,
|
|
3901
|
+
L: 265,
|
|
3836
3902
|
S: this,
|
|
3837
3903
|
A: [
|
|
3838
3904
|
"this._peer",
|
|
@@ -3844,11 +3910,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3844
3910
|
switch (data.type) {
|
|
3845
3911
|
case "offer": {
|
|
3846
3912
|
if (this._peer.connectionState !== "new") {
|
|
3847
|
-
|
|
3913
|
+
log15.error("received offer but peer not in state new", {
|
|
3848
3914
|
peer: this._peer
|
|
3849
3915
|
}, {
|
|
3850
|
-
F:
|
|
3851
|
-
L:
|
|
3916
|
+
F: __dxlog_file16,
|
|
3917
|
+
L: 272,
|
|
3852
3918
|
S: this,
|
|
3853
3919
|
C: (f, a) => f(...a)
|
|
3854
3920
|
});
|
|
@@ -3872,11 +3938,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3872
3938
|
});
|
|
3873
3939
|
this._readyForCandidates.wake();
|
|
3874
3940
|
} catch (err) {
|
|
3875
|
-
|
|
3941
|
+
log15.error("cannot handle offer from signalling server", {
|
|
3876
3942
|
err
|
|
3877
3943
|
}, {
|
|
3878
|
-
F:
|
|
3879
|
-
L:
|
|
3944
|
+
F: __dxlog_file16,
|
|
3945
|
+
L: 284,
|
|
3880
3946
|
S: this,
|
|
3881
3947
|
C: (f, a) => f(...a)
|
|
3882
3948
|
});
|
|
@@ -3892,11 +3958,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3892
3958
|
});
|
|
3893
3959
|
this._readyForCandidates.wake();
|
|
3894
3960
|
} catch (err) {
|
|
3895
|
-
|
|
3961
|
+
log15.error("cannot handle answer from signalling server", {
|
|
3896
3962
|
err
|
|
3897
3963
|
}, {
|
|
3898
|
-
F:
|
|
3899
|
-
L:
|
|
3964
|
+
F: __dxlog_file16,
|
|
3965
|
+
L: 295,
|
|
3900
3966
|
S: this,
|
|
3901
3967
|
C: (f, a) => f(...a)
|
|
3902
3968
|
});
|
|
@@ -3910,21 +3976,21 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3910
3976
|
});
|
|
3911
3977
|
break;
|
|
3912
3978
|
default:
|
|
3913
|
-
|
|
3979
|
+
log15.error("unhandled signal type", {
|
|
3914
3980
|
type: data.type,
|
|
3915
3981
|
signal
|
|
3916
3982
|
}, {
|
|
3917
|
-
F:
|
|
3918
|
-
L:
|
|
3983
|
+
F: __dxlog_file16,
|
|
3984
|
+
L: 306,
|
|
3919
3985
|
S: this,
|
|
3920
3986
|
C: (f, a) => f(...a)
|
|
3921
3987
|
});
|
|
3922
3988
|
this.errors.raise(new Error(`unhandled signal type ${data.type}`));
|
|
3923
3989
|
}
|
|
3924
3990
|
} catch (err) {
|
|
3925
|
-
|
|
3926
|
-
F:
|
|
3927
|
-
L:
|
|
3991
|
+
log15.catch(err, void 0, {
|
|
3992
|
+
F: __dxlog_file16,
|
|
3993
|
+
L: 310,
|
|
3928
3994
|
S: this,
|
|
3929
3995
|
C: (f, a) => f(...a)
|
|
3930
3996
|
});
|
|
@@ -3962,8 +4028,8 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3962
4028
|
}
|
|
3963
4029
|
async _getStats() {
|
|
3964
4030
|
invariant14(this._peer, "not open", {
|
|
3965
|
-
F:
|
|
3966
|
-
L:
|
|
4031
|
+
F: __dxlog_file16,
|
|
4032
|
+
L: 350,
|
|
3967
4033
|
S: this,
|
|
3968
4034
|
A: [
|
|
3969
4035
|
"this._peer",
|
|
@@ -3991,8 +4057,8 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3991
4057
|
this._options.stream.unpipe?.(this._stream)?.unpipe?.(this._options.stream);
|
|
3992
4058
|
}
|
|
3993
4059
|
};
|
|
3994
|
-
|
|
3995
|
-
|
|
4060
|
+
_ts_decorate7([
|
|
4061
|
+
synchronized6
|
|
3996
4062
|
], LibDataChannelTransport.prototype, "_close", null);
|
|
3997
4063
|
var importESM = Function("path", "return import(path)");
|
|
3998
4064
|
|
|
@@ -4054,6 +4120,7 @@ export {
|
|
|
4054
4120
|
process,
|
|
4055
4121
|
ConnectionState,
|
|
4056
4122
|
Connection,
|
|
4123
|
+
createIceProvider,
|
|
4057
4124
|
SwarmMessenger,
|
|
4058
4125
|
Swarm,
|
|
4059
4126
|
SwarmMapper,
|
|
@@ -4079,4 +4146,4 @@ export {
|
|
|
4079
4146
|
TcpTransport,
|
|
4080
4147
|
createTeleportProtocolFactory
|
|
4081
4148
|
};
|
|
4082
|
-
//# sourceMappingURL=chunk-
|
|
4149
|
+
//# sourceMappingURL=chunk-2KJH3U3C.mjs.map
|