libp2p 0.46.21 → 1.0.0-06e6d235f
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/README.md +52 -48
- package/dist/index.min.js +40 -28
- package/dist/src/address-manager/index.d.ts +4 -5
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +3 -3
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/components.d.ts +4 -15
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +2 -2
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +1 -1
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -1
- package/dist/src/config/connection-gater.browser.js.map +1 -1
- package/dist/src/config/connection-gater.d.ts +1 -1
- package/dist/src/config/connection-gater.d.ts.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +1 -2
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection/index.d.ts +4 -6
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +11 -13
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts +3 -6
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +21 -21
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/connection-pruner.d.ts +3 -5
- package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
- package/dist/src/connection-manager/connection-pruner.js +8 -8
- package/dist/src/connection-manager/connection-pruner.js.map +1 -1
- package/dist/src/connection-manager/constants.defaults.d.ts +0 -4
- package/dist/src/connection-manager/constants.defaults.d.ts.map +1 -1
- package/dist/src/connection-manager/constants.defaults.js +0 -4
- package/dist/src/connection-manager/constants.defaults.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts +3 -10
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +30 -38
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +3 -18
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +17 -19
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/utils.js +1 -1
- package/dist/src/connection-manager/utils.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +1 -5
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +2 -2
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts +1 -2
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +1 -1
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/errors.d.ts +0 -2
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +0 -2
- package/dist/src/errors.js.map +1 -1
- package/dist/src/get-peer.d.ts +1 -1
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +1 -5
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/index.d.ts +5 -16
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +4 -12
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +30 -65
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +6 -6
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +12 -9
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/registrar.d.ts +5 -7
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +4 -4
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +5 -9
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +12 -13
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +8 -19
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +75 -38
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/package.json +41 -110
- package/src/address-manager/index.ts +6 -9
- package/src/components.ts +5 -16
- package/src/config/connection-gater.browser.ts +1 -1
- package/src/config/connection-gater.ts +1 -1
- package/src/config.ts +1 -2
- package/src/connection/index.ts +12 -17
- package/src/connection-manager/auto-dial.ts +23 -26
- package/src/connection-manager/connection-pruner.ts +10 -12
- package/src/connection-manager/constants.defaults.ts +0 -5
- package/src/connection-manager/dial-queue.ts +31 -46
- package/src/connection-manager/index.ts +19 -37
- package/src/connection-manager/utils.ts +1 -1
- package/src/content-routing/index.ts +3 -7
- package/src/content-routing/utils.ts +2 -3
- package/src/errors.ts +0 -2
- package/src/get-peer.ts +2 -7
- package/src/index.ts +6 -17
- package/src/libp2p.ts +32 -80
- package/src/peer-routing.ts +16 -15
- package/src/registrar.ts +8 -12
- package/src/transport-manager.ts +15 -22
- package/src/upgrader.ts +110 -64
- package/src/version.ts +1 -1
- package/dist/src/autonat/constants.d.ts +0 -18
- package/dist/src/autonat/constants.d.ts.map +0 -1
- package/dist/src/autonat/constants.js +0 -18
- package/dist/src/autonat/constants.js.map +0 -1
- package/dist/src/autonat/index.d.ts +0 -62
- package/dist/src/autonat/index.d.ts.map +0 -1
- package/dist/src/autonat/index.js +0 -447
- package/dist/src/autonat/index.js.map +0 -1
- package/dist/src/autonat/pb/index.d.ts +0 -57
- package/dist/src/autonat/pb/index.d.ts.map +0 -1
- package/dist/src/autonat/pb/index.js +0 -250
- package/dist/src/autonat/pb/index.js.map +0 -1
- package/dist/src/circuit-relay/constants.d.ts +0 -50
- package/dist/src/circuit-relay/constants.d.ts.map +0 -1
- package/dist/src/circuit-relay/constants.js +0 -56
- package/dist/src/circuit-relay/constants.js.map +0 -1
- package/dist/src/circuit-relay/index.d.ts +0 -55
- package/dist/src/circuit-relay/index.d.ts.map +0 -1
- package/dist/src/circuit-relay/index.js +0 -38
- package/dist/src/circuit-relay/index.js.map +0 -1
- package/dist/src/circuit-relay/pb/index.d.ts +0 -93
- package/dist/src/circuit-relay/pb/index.d.ts.map +0 -1
- package/dist/src/circuit-relay/pb/index.js +0 -425
- package/dist/src/circuit-relay/pb/index.js.map +0 -1
- package/dist/src/circuit-relay/server/advert-service.d.ts +0 -43
- package/dist/src/circuit-relay/server/advert-service.d.ts.map +0 -1
- package/dist/src/circuit-relay/server/advert-service.js +0 -73
- package/dist/src/circuit-relay/server/advert-service.js.map +0 -1
- package/dist/src/circuit-relay/server/index.d.ts +0 -65
- package/dist/src/circuit-relay/server/index.d.ts.map +0 -1
- package/dist/src/circuit-relay/server/index.js +0 -312
- package/dist/src/circuit-relay/server/index.js.map +0 -1
- package/dist/src/circuit-relay/server/reservation-store.d.ts +0 -49
- package/dist/src/circuit-relay/server/reservation-store.d.ts.map +0 -1
- package/dist/src/circuit-relay/server/reservation-store.js +0 -65
- package/dist/src/circuit-relay/server/reservation-store.js.map +0 -1
- package/dist/src/circuit-relay/server/reservation-voucher.d.ts +0 -18
- package/dist/src/circuit-relay/server/reservation-voucher.d.ts.map +0 -1
- package/dist/src/circuit-relay/server/reservation-voucher.js +0 -36
- package/dist/src/circuit-relay/server/reservation-voucher.js.map +0 -1
- package/dist/src/circuit-relay/transport/discovery.d.ts +0 -45
- package/dist/src/circuit-relay/transport/discovery.d.ts.map +0 -1
- package/dist/src/circuit-relay/transport/discovery.js +0 -97
- package/dist/src/circuit-relay/transport/discovery.js.map +0 -1
- package/dist/src/circuit-relay/transport/index.d.ts +0 -57
- package/dist/src/circuit-relay/transport/index.d.ts.map +0 -1
- package/dist/src/circuit-relay/transport/index.js +0 -276
- package/dist/src/circuit-relay/transport/index.js.map +0 -1
- package/dist/src/circuit-relay/transport/listener.d.ts +0 -9
- package/dist/src/circuit-relay/transport/listener.d.ts.map +0 -1
- package/dist/src/circuit-relay/transport/listener.js +0 -66
- package/dist/src/circuit-relay/transport/listener.js.map +0 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +0 -72
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +0 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +0 -209
- package/dist/src/circuit-relay/transport/reservation-store.js.map +0 -1
- package/dist/src/circuit-relay/utils.d.ts +0 -13
- package/dist/src/circuit-relay/utils.d.ts.map +0 -1
- package/dist/src/circuit-relay/utils.js +0 -108
- package/dist/src/circuit-relay/utils.js.map +0 -1
- package/dist/src/dcutr/dcutr.d.ts +0 -43
- package/dist/src/dcutr/dcutr.d.ts.map +0 -1
- package/dist/src/dcutr/dcutr.js +0 -313
- package/dist/src/dcutr/dcutr.js.map +0 -1
- package/dist/src/dcutr/index.d.ts +0 -92
- package/dist/src/dcutr/index.d.ts.map +0 -1
- package/dist/src/dcutr/index.js +0 -63
- package/dist/src/dcutr/index.js.map +0 -1
- package/dist/src/dcutr/pb/message.d.ts +0 -20
- package/dist/src/dcutr/pb/message.d.ts.map +0 -1
- package/dist/src/dcutr/pb/message.js +0 -77
- package/dist/src/dcutr/pb/message.js.map +0 -1
- package/dist/src/dcutr/utils.d.ts +0 -8
- package/dist/src/dcutr/utils.d.ts.map +0 -1
- package/dist/src/dcutr/utils.js +0 -27
- package/dist/src/dcutr/utils.js.map +0 -1
- package/dist/src/fetch/constants.d.ts +0 -3
- package/dist/src/fetch/constants.d.ts.map +0 -1
- package/dist/src/fetch/constants.js +0 -4
- package/dist/src/fetch/constants.js.map +0 -1
- package/dist/src/fetch/index.d.ts +0 -61
- package/dist/src/fetch/index.d.ts.map +0 -1
- package/dist/src/fetch/index.js +0 -205
- package/dist/src/fetch/index.js.map +0 -1
- package/dist/src/fetch/pb/proto.d.ts +0 -28
- package/dist/src/fetch/pb/proto.d.ts.map +0 -1
- package/dist/src/fetch/pb/proto.js +0 -120
- package/dist/src/fetch/pb/proto.js.map +0 -1
- package/dist/src/identify/consts.d.ts +0 -10
- package/dist/src/identify/consts.d.ts.map +0 -1
- package/dist/src/identify/consts.js +0 -11
- package/dist/src/identify/consts.js.map +0 -1
- package/dist/src/identify/identify.d.ts +0 -54
- package/dist/src/identify/identify.d.ts.map +0 -1
- package/dist/src/identify/identify.js +0 -447
- package/dist/src/identify/identify.js.map +0 -1
- package/dist/src/identify/index.d.ts +0 -72
- package/dist/src/identify/index.d.ts.map +0 -1
- package/dist/src/identify/index.js +0 -15
- package/dist/src/identify/index.js.map +0 -1
- package/dist/src/identify/pb/message.d.ts +0 -17
- package/dist/src/identify/pb/message.d.ts.map +0 -1
- package/dist/src/identify/pb/message.js +0 -98
- package/dist/src/identify/pb/message.js.map +0 -1
- package/dist/src/insecure/index.d.ts +0 -26
- package/dist/src/insecure/index.d.ts.map +0 -1
- package/dist/src/insecure/index.js +0 -110
- package/dist/src/insecure/index.js.map +0 -1
- package/dist/src/insecure/pb/proto.d.ts +0 -30
- package/dist/src/insecure/pb/proto.d.ts.map +0 -1
- package/dist/src/insecure/pb/proto.js +0 -127
- package/dist/src/insecure/pb/proto.js.map +0 -1
- package/dist/src/ping/constants.d.ts +0 -9
- package/dist/src/ping/constants.d.ts.map +0 -1
- package/dist/src/ping/constants.js +0 -15
- package/dist/src/ping/constants.js.map +0 -1
- package/dist/src/ping/index.d.ts +0 -24
- package/dist/src/ping/index.d.ts.map +0 -1
- package/dist/src/ping/index.js +0 -115
- package/dist/src/ping/index.js.map +0 -1
- package/dist/src/pnet/crypto.d.ts +0 -18
- package/dist/src/pnet/crypto.d.ts.map +0 -1
- package/dist/src/pnet/crypto.js +0 -60
- package/dist/src/pnet/crypto.js.map +0 -1
- package/dist/src/pnet/errors.d.ts +0 -6
- package/dist/src/pnet/errors.d.ts.map +0 -1
- package/dist/src/pnet/errors.js +0 -6
- package/dist/src/pnet/errors.js.map +0 -1
- package/dist/src/pnet/index.d.ts +0 -31
- package/dist/src/pnet/index.d.ts.map +0 -1
- package/dist/src/pnet/index.js +0 -97
- package/dist/src/pnet/index.js.map +0 -1
- package/dist/src/pnet/key-generator.d.ts +0 -11
- package/dist/src/pnet/key-generator.d.ts.map +0 -1
- package/dist/src/pnet/key-generator.js +0 -22
- package/dist/src/pnet/key-generator.js.map +0 -1
- package/dist/src/upnp-nat/index.d.ts +0 -71
- package/dist/src/upnp-nat/index.d.ts.map +0 -1
- package/dist/src/upnp-nat/index.js +0 -136
- package/dist/src/upnp-nat/index.js.map +0 -1
- package/dist/src/utils/peer-job-queue.d.ts +0 -33
- package/dist/src/utils/peer-job-queue.d.ts.map +0 -1
- package/dist/src/utils/peer-job-queue.js +0 -82
- package/dist/src/utils/peer-job-queue.js.map +0 -1
- package/dist/typedoc-urls.json +0 -71
- package/src/autonat/constants.ts +0 -19
- package/src/autonat/index.ts +0 -597
- package/src/autonat/pb/index.proto +0 -35
- package/src/autonat/pb/index.ts +0 -320
- package/src/circuit-relay/constants.ts +0 -72
- package/src/circuit-relay/index.ts +0 -59
- package/src/circuit-relay/pb/index.proto +0 -67
- package/src/circuit-relay/pb/index.ts +0 -539
- package/src/circuit-relay/server/advert-service.ts +0 -108
- package/src/circuit-relay/server/index.ts +0 -443
- package/src/circuit-relay/server/reservation-store.ts +0 -116
- package/src/circuit-relay/server/reservation-voucher.ts +0 -51
- package/src/circuit-relay/transport/discovery.ts +0 -136
- package/src/circuit-relay/transport/index.ts +0 -396
- package/src/circuit-relay/transport/listener.ts +0 -97
- package/src/circuit-relay/transport/reservation-store.ts +0 -312
- package/src/circuit-relay/utils.ts +0 -136
- package/src/dcutr/dcutr.ts +0 -378
- package/src/dcutr/index.ts +0 -102
- package/src/dcutr/pb/message.proto +0 -12
- package/src/dcutr/pb/message.ts +0 -96
- package/src/dcutr/utils.ts +0 -33
- package/src/fetch/README.md +0 -41
- package/src/fetch/constants.ts +0 -3
- package/src/fetch/index.ts +0 -315
- package/src/fetch/pb/proto.proto +0 -15
- package/src/fetch/pb/proto.ts +0 -153
- package/src/identify/README.md +0 -13
- package/src/identify/consts.ts +0 -12
- package/src/identify/identify.ts +0 -561
- package/src/identify/index.ts +0 -90
- package/src/identify/pb/message.proto +0 -30
- package/src/identify/pb/message.ts +0 -126
- package/src/insecure/index.ts +0 -138
- package/src/insecure/pb/proto.proto +0 -18
- package/src/insecure/pb/proto.ts +0 -161
- package/src/ping/constants.ts +0 -15
- package/src/ping/index.ts +0 -170
- package/src/pnet/README.md +0 -68
- package/src/pnet/crypto.ts +0 -67
- package/src/pnet/errors.ts +0 -5
- package/src/pnet/index.ts +0 -126
- package/src/pnet/key-generator.ts +0 -23
- package/src/upnp-nat/index.ts +0 -212
- package/src/utils/peer-job-queue.ts +0 -119
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/export */
|
|
2
|
-
/* eslint-disable complexity */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
6
|
-
import { encodeMessage, decodeMessage, message } from 'protons-runtime';
|
|
7
|
-
export var Identify;
|
|
8
|
-
(function (Identify) {
|
|
9
|
-
let _codec;
|
|
10
|
-
Identify.codec = () => {
|
|
11
|
-
if (_codec == null) {
|
|
12
|
-
_codec = message((obj, w, opts = {}) => {
|
|
13
|
-
if (opts.lengthDelimited !== false) {
|
|
14
|
-
w.fork();
|
|
15
|
-
}
|
|
16
|
-
if (obj.protocolVersion != null) {
|
|
17
|
-
w.uint32(42);
|
|
18
|
-
w.string(obj.protocolVersion);
|
|
19
|
-
}
|
|
20
|
-
if (obj.agentVersion != null) {
|
|
21
|
-
w.uint32(50);
|
|
22
|
-
w.string(obj.agentVersion);
|
|
23
|
-
}
|
|
24
|
-
if (obj.publicKey != null) {
|
|
25
|
-
w.uint32(10);
|
|
26
|
-
w.bytes(obj.publicKey);
|
|
27
|
-
}
|
|
28
|
-
if (obj.listenAddrs != null) {
|
|
29
|
-
for (const value of obj.listenAddrs) {
|
|
30
|
-
w.uint32(18);
|
|
31
|
-
w.bytes(value);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (obj.observedAddr != null) {
|
|
35
|
-
w.uint32(34);
|
|
36
|
-
w.bytes(obj.observedAddr);
|
|
37
|
-
}
|
|
38
|
-
if (obj.protocols != null) {
|
|
39
|
-
for (const value of obj.protocols) {
|
|
40
|
-
w.uint32(26);
|
|
41
|
-
w.string(value);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (obj.signedPeerRecord != null) {
|
|
45
|
-
w.uint32(66);
|
|
46
|
-
w.bytes(obj.signedPeerRecord);
|
|
47
|
-
}
|
|
48
|
-
if (opts.lengthDelimited !== false) {
|
|
49
|
-
w.ldelim();
|
|
50
|
-
}
|
|
51
|
-
}, (reader, length) => {
|
|
52
|
-
const obj = {
|
|
53
|
-
listenAddrs: [],
|
|
54
|
-
protocols: []
|
|
55
|
-
};
|
|
56
|
-
const end = length == null ? reader.len : reader.pos + length;
|
|
57
|
-
while (reader.pos < end) {
|
|
58
|
-
const tag = reader.uint32();
|
|
59
|
-
switch (tag >>> 3) {
|
|
60
|
-
case 5:
|
|
61
|
-
obj.protocolVersion = reader.string();
|
|
62
|
-
break;
|
|
63
|
-
case 6:
|
|
64
|
-
obj.agentVersion = reader.string();
|
|
65
|
-
break;
|
|
66
|
-
case 1:
|
|
67
|
-
obj.publicKey = reader.bytes();
|
|
68
|
-
break;
|
|
69
|
-
case 2:
|
|
70
|
-
obj.listenAddrs.push(reader.bytes());
|
|
71
|
-
break;
|
|
72
|
-
case 4:
|
|
73
|
-
obj.observedAddr = reader.bytes();
|
|
74
|
-
break;
|
|
75
|
-
case 3:
|
|
76
|
-
obj.protocols.push(reader.string());
|
|
77
|
-
break;
|
|
78
|
-
case 8:
|
|
79
|
-
obj.signedPeerRecord = reader.bytes();
|
|
80
|
-
break;
|
|
81
|
-
default:
|
|
82
|
-
reader.skipType(tag & 7);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return obj;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
return _codec;
|
|
90
|
-
};
|
|
91
|
-
Identify.encode = (obj) => {
|
|
92
|
-
return encodeMessage(obj, Identify.codec());
|
|
93
|
-
};
|
|
94
|
-
Identify.decode = (buf) => {
|
|
95
|
-
return decodeMessage(buf, Identify.codec());
|
|
96
|
-
};
|
|
97
|
-
})(Identify || (Identify = {}));
|
|
98
|
-
//# sourceMappingURL=message.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../src/identify/pb/message.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+BAA+B;AAC/B,oDAAoD;AACpD,8EAA8E;AAC9E,0DAA0D;AAE1D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAcvE,MAAM,KAAW,QAAQ,CAyGxB;AAzGD,WAAiB,QAAQ;IACvB,IAAI,MAAuB,CAAA;IAEd,cAAK,GAAG,GAAoB,EAAE;QACzC,IAAI,MAAM,IAAI,IAAI,EAAE;YAClB,MAAM,GAAG,OAAO,CAAW,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;gBAC/C,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE;oBAClC,CAAC,CAAC,IAAI,EAAE,CAAA;iBACT;gBAED,IAAI,GAAG,CAAC,eAAe,IAAI,IAAI,EAAE;oBAC/B,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;oBACZ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;iBAC9B;gBAED,IAAI,GAAG,CAAC,YAAY,IAAI,IAAI,EAAE;oBAC5B,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;oBACZ,CAAC,CAAC,MAA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AK,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;IAEY,eAAM,GAAG,CAAC,GAAgC,EAAY,EAAE;QACnE,OAAO,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;AACH,CAAC,EAzGgB,QAAQ,KAAR,QAAQ,QAyGxB"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* A connection encrypter that does no connection encryption.
|
|
5
|
-
*
|
|
6
|
-
* This should not be used in production should be used for research purposes only.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { createLibp2p } from 'libp2p'
|
|
12
|
-
* import { plaintext } from 'libp2p/insecure'
|
|
13
|
-
*
|
|
14
|
-
* // Create a Uint8Array and write the swarm key to it
|
|
15
|
-
* const swarmKey = new Uint8Array(95)
|
|
16
|
-
* generateKey(swarmKey)
|
|
17
|
-
*
|
|
18
|
-
* const node = await createLibp2p({
|
|
19
|
-
* // ...other options
|
|
20
|
-
* connectionEncryption: [plaintext()]
|
|
21
|
-
* })
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
import type { ConnectionEncrypter } from '@libp2p/interface/connection-encrypter';
|
|
25
|
-
export declare function plaintext(): () => ConnectionEncrypter;
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/insecure/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AASH,OAAO,KAAK,EAAE,mBAAmB,EAAqB,MAAM,wCAAwC,CAAA;AAwGpG,wBAAgB,SAAS,IAAK,MAAM,mBAAmB,CAEtD"}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* A connection encrypter that does no connection encryption.
|
|
5
|
-
*
|
|
6
|
-
* This should not be used in production should be used for research purposes only.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
*
|
|
10
|
-
* ```typescript
|
|
11
|
-
* import { createLibp2p } from 'libp2p'
|
|
12
|
-
* import { plaintext } from 'libp2p/insecure'
|
|
13
|
-
*
|
|
14
|
-
* // Create a Uint8Array and write the swarm key to it
|
|
15
|
-
* const swarmKey = new Uint8Array(95)
|
|
16
|
-
* generateKey(swarmKey)
|
|
17
|
-
*
|
|
18
|
-
* const node = await createLibp2p({
|
|
19
|
-
* // ...other options
|
|
20
|
-
* connectionEncryption: [plaintext()]
|
|
21
|
-
* })
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
import { UnexpectedPeerError, InvalidCryptoExchangeError } from '@libp2p/interface/errors';
|
|
25
|
-
import { logger } from '@libp2p/logger';
|
|
26
|
-
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id';
|
|
27
|
-
import { handshake } from 'it-handshake';
|
|
28
|
-
import * as lp from 'it-length-prefixed';
|
|
29
|
-
import map from 'it-map';
|
|
30
|
-
import { Exchange, KeyType } from './pb/proto.js';
|
|
31
|
-
const log = logger('libp2p:plaintext');
|
|
32
|
-
const PROTOCOL = '/plaintext/2.0.0';
|
|
33
|
-
function lpEncodeExchange(exchange) {
|
|
34
|
-
const pb = Exchange.encode(exchange);
|
|
35
|
-
return lp.encode.single(pb);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Encrypt connection
|
|
39
|
-
*/
|
|
40
|
-
async function encrypt(localId, conn, remoteId) {
|
|
41
|
-
const shake = handshake(conn);
|
|
42
|
-
let type = KeyType.RSA;
|
|
43
|
-
if (localId.type === 'Ed25519') {
|
|
44
|
-
type = KeyType.Ed25519;
|
|
45
|
-
}
|
|
46
|
-
else if (localId.type === 'secp256k1') {
|
|
47
|
-
type = KeyType.Secp256k1;
|
|
48
|
-
}
|
|
49
|
-
// Encode the public key and write it to the remote peer
|
|
50
|
-
shake.write(lpEncodeExchange({
|
|
51
|
-
id: localId.toBytes(),
|
|
52
|
-
pubkey: {
|
|
53
|
-
Type: type,
|
|
54
|
-
Data: localId.publicKey ?? new Uint8Array(0)
|
|
55
|
-
}
|
|
56
|
-
}).subarray());
|
|
57
|
-
log('write pubkey exchange to peer %p', remoteId);
|
|
58
|
-
// Get the Exchange message
|
|
59
|
-
const response = (await lp.decode.fromReader(shake.reader).next()).value;
|
|
60
|
-
if (response == null) {
|
|
61
|
-
throw new Error('Did not read response');
|
|
62
|
-
}
|
|
63
|
-
const id = Exchange.decode(response);
|
|
64
|
-
log('read pubkey exchange from peer %p', remoteId);
|
|
65
|
-
let peerId;
|
|
66
|
-
try {
|
|
67
|
-
if (id.pubkey == null) {
|
|
68
|
-
throw new Error('Public key missing');
|
|
69
|
-
}
|
|
70
|
-
if (id.pubkey.Data.length === 0) {
|
|
71
|
-
throw new Error('Public key data too short');
|
|
72
|
-
}
|
|
73
|
-
if (id.id == null) {
|
|
74
|
-
throw new Error('Remote id missing');
|
|
75
|
-
}
|
|
76
|
-
peerId = await peerIdFromKeys(id.pubkey.Data);
|
|
77
|
-
if (!peerId.equals(peerIdFromBytes(id.id))) {
|
|
78
|
-
throw new Error('Public key did not match id');
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch (err) {
|
|
82
|
-
log.error(err);
|
|
83
|
-
throw new InvalidCryptoExchangeError('Remote did not provide its public key');
|
|
84
|
-
}
|
|
85
|
-
if (remoteId != null && !peerId.equals(remoteId)) {
|
|
86
|
-
throw new UnexpectedPeerError();
|
|
87
|
-
}
|
|
88
|
-
log('plaintext key exchange completed successfully with peer %p', peerId);
|
|
89
|
-
shake.rest();
|
|
90
|
-
return {
|
|
91
|
-
conn: {
|
|
92
|
-
sink: shake.stream.sink,
|
|
93
|
-
source: map(shake.stream.source, (buf) => buf.subarray())
|
|
94
|
-
},
|
|
95
|
-
remotePeer: peerId
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
class Plaintext {
|
|
99
|
-
protocol = PROTOCOL;
|
|
100
|
-
async secureInbound(localId, conn, remoteId) {
|
|
101
|
-
return encrypt(localId, conn, remoteId);
|
|
102
|
-
}
|
|
103
|
-
async secureOutbound(localId, conn, remoteId) {
|
|
104
|
-
return encrypt(localId, conn, remoteId);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
export function plaintext() {
|
|
108
|
-
return () => new Plaintext();
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/insecure/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AAC1F,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAMjD,MAAM,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AACtC,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AAEnC,SAAS,gBAAgB,CAAE,QAAkB;IAC3C,MAAM,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAEpC,OAAO,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AAC7B,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,OAAO,CAAE,OAAe,EAAE,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,OAAO,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAA;IACzC,CAAC;CACF;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,GAAG,EAAE,CAAC,IAAI,SAAS,EAAE,CAAA;AAC9B,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Codec } from 'protons-runtime';
|
|
2
|
-
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
3
|
-
export interface Exchange {
|
|
4
|
-
id?: Uint8Array;
|
|
5
|
-
pubkey?: PublicKey;
|
|
6
|
-
}
|
|
7
|
-
export declare namespace Exchange {
|
|
8
|
-
const codec: () => Codec<Exchange>;
|
|
9
|
-
const encode: (obj: Partial<Exchange>) => Uint8Array;
|
|
10
|
-
const decode: (buf: Uint8Array | Uint8ArrayList) => Exchange;
|
|
11
|
-
}
|
|
12
|
-
export declare enum KeyType {
|
|
13
|
-
RSA = "RSA",
|
|
14
|
-
Ed25519 = "Ed25519",
|
|
15
|
-
Secp256k1 = "Secp256k1",
|
|
16
|
-
ECDSA = "ECDSA"
|
|
17
|
-
}
|
|
18
|
-
export declare namespace KeyType {
|
|
19
|
-
const codec: () => Codec<KeyType>;
|
|
20
|
-
}
|
|
21
|
-
export interface PublicKey {
|
|
22
|
-
Type: KeyType;
|
|
23
|
-
Data: Uint8Array;
|
|
24
|
-
}
|
|
25
|
-
export declare namespace PublicKey {
|
|
26
|
-
const codec: () => Codec<PublicKey>;
|
|
27
|
-
const encode: (obj: Partial<PublicKey>) => Uint8Array;
|
|
28
|
-
const decode: (buf: Uint8Array | Uint8ArrayList) => PublicKey;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=proto.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proto.d.ts","sourceRoot":"","sources":["../../../../src/insecure/pb/proto.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,UAAU,CAAA;IACf,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,yBAAiB,QAAQ,CAAC;IAGjB,MAAM,KAAK,QAAO,MAAM,QAAQ,CA8CtC,CAAA;IAEM,MAAM,MAAM,QAAS,QAAQ,QAAQ,CAAC,KAAG,UAE/C,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,QAEzD,CAAA;CACF;AAED,oBAAY,OAAO;IACjB,GAAG,QAAQ;IACX,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,KAAK,UAAU;CAChB;AASD,yBAAiB,OAAO,CAAC;IAChB,MAAM,KAAK,QAAO,MAAM,OAAO,CAErC,CAAA;CACF;AACD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,OAAO,CAAA;IACb,IAAI,EAAE,UAAU,CAAA;CACjB;AAED,yBAAiB,SAAS,CAAC;IAGlB,MAAM,KAAK,QAAO,MAAM,SAAS,CAiDvC,CAAA;IAEM,MAAM,MAAM,QAAS,QAAQ,SAAS,CAAC,KAAG,UAEhD,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,SAEzD,CAAA;CACF"}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/export */
|
|
2
|
-
/* eslint-disable complexity */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-namespace */
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
6
|
-
import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime';
|
|
7
|
-
export var Exchange;
|
|
8
|
-
(function (Exchange) {
|
|
9
|
-
let _codec;
|
|
10
|
-
Exchange.codec = () => {
|
|
11
|
-
if (_codec == null) {
|
|
12
|
-
_codec = message((obj, w, opts = {}) => {
|
|
13
|
-
if (opts.lengthDelimited !== false) {
|
|
14
|
-
w.fork();
|
|
15
|
-
}
|
|
16
|
-
if (obj.id != null) {
|
|
17
|
-
w.uint32(10);
|
|
18
|
-
w.bytes(obj.id);
|
|
19
|
-
}
|
|
20
|
-
if (obj.pubkey != null) {
|
|
21
|
-
w.uint32(18);
|
|
22
|
-
PublicKey.codec().encode(obj.pubkey, w);
|
|
23
|
-
}
|
|
24
|
-
if (opts.lengthDelimited !== false) {
|
|
25
|
-
w.ldelim();
|
|
26
|
-
}
|
|
27
|
-
}, (reader, length) => {
|
|
28
|
-
const obj = {};
|
|
29
|
-
const end = length == null ? reader.len : reader.pos + length;
|
|
30
|
-
while (reader.pos < end) {
|
|
31
|
-
const tag = reader.uint32();
|
|
32
|
-
switch (tag >>> 3) {
|
|
33
|
-
case 1:
|
|
34
|
-
obj.id = reader.bytes();
|
|
35
|
-
break;
|
|
36
|
-
case 2:
|
|
37
|
-
obj.pubkey = PublicKey.codec().decode(reader, reader.uint32());
|
|
38
|
-
break;
|
|
39
|
-
default:
|
|
40
|
-
reader.skipType(tag & 7);
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return obj;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return _codec;
|
|
48
|
-
};
|
|
49
|
-
Exchange.encode = (obj) => {
|
|
50
|
-
return encodeMessage(obj, Exchange.codec());
|
|
51
|
-
};
|
|
52
|
-
Exchange.decode = (buf) => {
|
|
53
|
-
return decodeMessage(buf, Exchange.codec());
|
|
54
|
-
};
|
|
55
|
-
})(Exchange || (Exchange = {}));
|
|
56
|
-
export var KeyType;
|
|
57
|
-
(function (KeyType) {
|
|
58
|
-
KeyType["RSA"] = "RSA";
|
|
59
|
-
KeyType["Ed25519"] = "Ed25519";
|
|
60
|
-
KeyType["Secp256k1"] = "Secp256k1";
|
|
61
|
-
KeyType["ECDSA"] = "ECDSA";
|
|
62
|
-
})(KeyType || (KeyType = {}));
|
|
63
|
-
var __KeyTypeValues;
|
|
64
|
-
(function (__KeyTypeValues) {
|
|
65
|
-
__KeyTypeValues[__KeyTypeValues["RSA"] = 0] = "RSA";
|
|
66
|
-
__KeyTypeValues[__KeyTypeValues["Ed25519"] = 1] = "Ed25519";
|
|
67
|
-
__KeyTypeValues[__KeyTypeValues["Secp256k1"] = 2] = "Secp256k1";
|
|
68
|
-
__KeyTypeValues[__KeyTypeValues["ECDSA"] = 3] = "ECDSA";
|
|
69
|
-
})(__KeyTypeValues || (__KeyTypeValues = {}));
|
|
70
|
-
(function (KeyType) {
|
|
71
|
-
KeyType.codec = () => {
|
|
72
|
-
return enumeration(__KeyTypeValues);
|
|
73
|
-
};
|
|
74
|
-
})(KeyType || (KeyType = {}));
|
|
75
|
-
export var PublicKey;
|
|
76
|
-
(function (PublicKey) {
|
|
77
|
-
let _codec;
|
|
78
|
-
PublicKey.codec = () => {
|
|
79
|
-
if (_codec == null) {
|
|
80
|
-
_codec = message((obj, w, opts = {}) => {
|
|
81
|
-
if (opts.lengthDelimited !== false) {
|
|
82
|
-
w.fork();
|
|
83
|
-
}
|
|
84
|
-
if (obj.Type != null && __KeyTypeValues[obj.Type] !== 0) {
|
|
85
|
-
w.uint32(8);
|
|
86
|
-
KeyType.codec().encode(obj.Type, w);
|
|
87
|
-
}
|
|
88
|
-
if ((obj.Data != null && obj.Data.byteLength > 0)) {
|
|
89
|
-
w.uint32(18);
|
|
90
|
-
w.bytes(obj.Data);
|
|
91
|
-
}
|
|
92
|
-
if (opts.lengthDelimited !== false) {
|
|
93
|
-
w.ldelim();
|
|
94
|
-
}
|
|
95
|
-
}, (reader, length) => {
|
|
96
|
-
const obj = {
|
|
97
|
-
Type: KeyType.RSA,
|
|
98
|
-
Data: new Uint8Array(0)
|
|
99
|
-
};
|
|
100
|
-
const end = length == null ? reader.len : reader.pos + length;
|
|
101
|
-
while (reader.pos < end) {
|
|
102
|
-
const tag = reader.uint32();
|
|
103
|
-
switch (tag >>> 3) {
|
|
104
|
-
case 1:
|
|
105
|
-
obj.Type = KeyType.codec().decode(reader);
|
|
106
|
-
break;
|
|
107
|
-
case 2:
|
|
108
|
-
obj.Data = reader.bytes();
|
|
109
|
-
break;
|
|
110
|
-
default:
|
|
111
|
-
reader.skipType(tag & 7);
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return obj;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return _codec;
|
|
119
|
-
};
|
|
120
|
-
PublicKey.encode = (obj) => {
|
|
121
|
-
return encodeMessage(obj, PublicKey.codec());
|
|
122
|
-
};
|
|
123
|
-
PublicKey.decode = (buf) => {
|
|
124
|
-
return decodeMessage(buf, PublicKey.codec());
|
|
125
|
-
};
|
|
126
|
-
})(PublicKey || (PublicKey = {}));
|
|
127
|
-
//# sourceMappingURL=proto.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proto.js","sourceRoot":"","sources":["../../../../src/insecure/pb/proto.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+BAA+B;AAC/B,oDAAoD;AACpD,8EAA8E;AAC9E,0DAA0D;AAE1D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AASpF,MAAM,KAAW,QAAQ,CA0DxB;AA1DD,WAAiB,QAAQ;IACvB,IAAI,MAAuB,CAAA;IAEd,cAAK,GAAG,GAAoB,EAAE;QACzC,IAAI,MAAM,IAAI,IAAI,EAAE;YAClB,MAAM,GAAG,OAAO,CAAW,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;gBAC/C,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE;oBAClC,CAAC,CAAC,IAAI,EAAE,CAAA;iBACT;gBAED,IAAI,GAAG,CAAC,EAAE,IAAI,IAAI,EAAE;oBAClB,CAAC,CAAC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QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAEY,gBAAM,GAAG,CAAC,GAAuB,EAAc,EAAE;QAC5D,OAAO,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAA;IAC9C,CAAC,CAAA;IAEY,gBAAM,GAAG,CAAC,GAAgC,EAAa,EAAE;QACpE,OAAO,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC,CAAA;IAC9C,CAAC,CAAA;AACH,CAAC,EA7DgB,SAAS,KAAT,SAAS,QA6DzB"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare const PROTOCOL = "/ipfs/ping/1.0.0";
|
|
2
|
-
export declare const PING_LENGTH = 32;
|
|
3
|
-
export declare const PROTOCOL_VERSION = "1.0.0";
|
|
4
|
-
export declare const PROTOCOL_NAME = "ping";
|
|
5
|
-
export declare const PROTOCOL_PREFIX = "ipfs";
|
|
6
|
-
export declare const TIMEOUT = 10000;
|
|
7
|
-
export declare const MAX_INBOUND_STREAMS = 2;
|
|
8
|
-
export declare const MAX_OUTBOUND_STREAMS = 1;
|
|
9
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/ping/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,qBAAqB,CAAA;AAC1C,eAAO,MAAM,WAAW,KAAK,CAAA;AAC7B,eAAO,MAAM,gBAAgB,UAAU,CAAA;AACvC,eAAO,MAAM,aAAa,SAAS,CAAA;AACnC,eAAO,MAAM,eAAe,SAAS,CAAA;AACrC,eAAO,MAAM,OAAO,QAAQ,CAAA;AAQ5B,eAAO,MAAM,mBAAmB,IAAI,CAAA;AACpC,eAAO,MAAM,oBAAoB,IAAI,CAAA"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const PROTOCOL = '/ipfs/ping/1.0.0';
|
|
2
|
-
export const PING_LENGTH = 32;
|
|
3
|
-
export const PROTOCOL_VERSION = '1.0.0';
|
|
4
|
-
export const PROTOCOL_NAME = 'ping';
|
|
5
|
-
export const PROTOCOL_PREFIX = 'ipfs';
|
|
6
|
-
export const TIMEOUT = 10000;
|
|
7
|
-
// See https://github.com/libp2p/specs/blob/d4b5fb0152a6bb86cfd9ea/ping/ping.md?plain=1#L38-L43
|
|
8
|
-
// The dialing peer MUST NOT keep more than one outbound stream for the ping protocol per peer.
|
|
9
|
-
// The listening peer SHOULD accept at most two streams per peer since cross-stream behavior is
|
|
10
|
-
// non-linear and stream writes occur asynchronously. The listening peer may perceive the
|
|
11
|
-
// dialing peer closing and opening the wrong streams (for instance, closing stream B and
|
|
12
|
-
// opening stream A even though the dialing peer is opening stream B and closing stream A).
|
|
13
|
-
export const MAX_INBOUND_STREAMS = 2;
|
|
14
|
-
export const MAX_OUTBOUND_STREAMS = 1;
|
|
15
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/ping/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AAC1C,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAA;AAC7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AACvC,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAA;AACnC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAA;AACrC,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAA;AAE5B,+FAA+F;AAC/F,+FAA+F;AAC/F,+FAA+F;AAC/F,yFAAyF;AACzF,yFAAyF;AACzF,2FAA2F;AAC3F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA"}
|
package/dist/src/ping/index.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { AbortOptions } from '@libp2p/interface';
|
|
2
|
-
import type { PeerId } from '@libp2p/interface/peer-id';
|
|
3
|
-
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager';
|
|
4
|
-
import type { Registrar } from '@libp2p/interface-internal/registrar';
|
|
5
|
-
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
6
|
-
export interface PingService {
|
|
7
|
-
ping(peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<number>;
|
|
8
|
-
}
|
|
9
|
-
export interface PingServiceInit {
|
|
10
|
-
protocolPrefix?: string;
|
|
11
|
-
maxInboundStreams?: number;
|
|
12
|
-
maxOutboundStreams?: number;
|
|
13
|
-
runOnTransientConnection?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* How long we should wait for a ping response
|
|
16
|
-
*/
|
|
17
|
-
timeout?: number;
|
|
18
|
-
}
|
|
19
|
-
export interface PingServiceComponents {
|
|
20
|
-
registrar: Registrar;
|
|
21
|
-
connectionManager: ConnectionManager;
|
|
22
|
-
}
|
|
23
|
-
export declare function pingService(init?: PingServiceInit): (components: PingServiceComponents) => PingService;
|
|
24
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ping/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAEvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAA;AACtF,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACzF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACtF;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAElC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,SAAS,CAAA;IACpB,iBAAiB,EAAE,iBAAiB,CAAA;CACrC;AAkID,wBAAgB,WAAW,CAAE,IAAI,GAAE,eAAoB,GAAG,CAAC,UAAU,EAAE,qBAAqB,KAAK,WAAW,CAE3G"}
|
package/dist/src/ping/index.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { randomBytes } from '@libp2p/crypto';
|
|
2
|
-
import { CodeError } from '@libp2p/interface/errors';
|
|
3
|
-
import { logger } from '@libp2p/logger';
|
|
4
|
-
import first from 'it-first';
|
|
5
|
-
import { pipe } from 'it-pipe';
|
|
6
|
-
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
7
|
-
import { codes } from '../errors.js';
|
|
8
|
-
import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS } from './constants.js';
|
|
9
|
-
const log = logger('libp2p:ping');
|
|
10
|
-
class DefaultPingService {
|
|
11
|
-
protocol;
|
|
12
|
-
components;
|
|
13
|
-
started;
|
|
14
|
-
timeout;
|
|
15
|
-
maxInboundStreams;
|
|
16
|
-
maxOutboundStreams;
|
|
17
|
-
runOnTransientConnection;
|
|
18
|
-
constructor(components, init) {
|
|
19
|
-
this.components = components;
|
|
20
|
-
this.started = false;
|
|
21
|
-
this.protocol = `/${init.protocolPrefix ?? PROTOCOL_PREFIX}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`;
|
|
22
|
-
this.timeout = init.timeout ?? TIMEOUT;
|
|
23
|
-
this.maxInboundStreams = init.maxInboundStreams ?? MAX_INBOUND_STREAMS;
|
|
24
|
-
this.maxOutboundStreams = init.maxOutboundStreams ?? MAX_OUTBOUND_STREAMS;
|
|
25
|
-
this.runOnTransientConnection = init.runOnTransientConnection ?? true;
|
|
26
|
-
}
|
|
27
|
-
async start() {
|
|
28
|
-
await this.components.registrar.handle(this.protocol, this.handleMessage, {
|
|
29
|
-
maxInboundStreams: this.maxInboundStreams,
|
|
30
|
-
maxOutboundStreams: this.maxOutboundStreams,
|
|
31
|
-
runOnTransientConnection: this.runOnTransientConnection
|
|
32
|
-
});
|
|
33
|
-
this.started = true;
|
|
34
|
-
}
|
|
35
|
-
async stop() {
|
|
36
|
-
await this.components.registrar.unhandle(this.protocol);
|
|
37
|
-
this.started = false;
|
|
38
|
-
}
|
|
39
|
-
isStarted() {
|
|
40
|
-
return this.started;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* A handler to register with Libp2p to process ping messages
|
|
44
|
-
*/
|
|
45
|
-
handleMessage(data) {
|
|
46
|
-
log('incoming ping from %p', data.connection.remotePeer);
|
|
47
|
-
const { stream } = data;
|
|
48
|
-
const start = Date.now();
|
|
49
|
-
void pipe(stream, stream)
|
|
50
|
-
.catch(err => {
|
|
51
|
-
log.error('incoming ping from %p failed with error', data.connection.remotePeer, err);
|
|
52
|
-
})
|
|
53
|
-
.finally(() => {
|
|
54
|
-
const ms = Date.now() - start;
|
|
55
|
-
log('incoming ping from %p complete in %dms', data.connection.remotePeer, ms);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Ping a given peer and wait for its response, getting the operation latency.
|
|
60
|
-
*
|
|
61
|
-
* @param {PeerId|Multiaddr} peer
|
|
62
|
-
* @returns {Promise<number>}
|
|
63
|
-
*/
|
|
64
|
-
async ping(peer, options = {}) {
|
|
65
|
-
log('pinging %p', peer);
|
|
66
|
-
const start = Date.now();
|
|
67
|
-
const data = randomBytes(PING_LENGTH);
|
|
68
|
-
const connection = await this.components.connectionManager.openConnection(peer, options);
|
|
69
|
-
let stream;
|
|
70
|
-
let onAbort = () => { };
|
|
71
|
-
if (options.signal == null) {
|
|
72
|
-
const signal = AbortSignal.timeout(this.timeout);
|
|
73
|
-
options = {
|
|
74
|
-
...options,
|
|
75
|
-
signal
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
stream = await connection.newStream(this.protocol, {
|
|
80
|
-
...options,
|
|
81
|
-
runOnTransientConnection: this.runOnTransientConnection
|
|
82
|
-
});
|
|
83
|
-
onAbort = () => {
|
|
84
|
-
stream?.abort(new CodeError('ping timeout', codes.ERR_TIMEOUT));
|
|
85
|
-
};
|
|
86
|
-
// make stream abortable
|
|
87
|
-
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
88
|
-
const result = await pipe([data], stream, async (source) => first(source));
|
|
89
|
-
const ms = Date.now() - start;
|
|
90
|
-
if (result == null) {
|
|
91
|
-
throw new CodeError(`Did not receive a ping ack after ${ms}ms`, codes.ERR_WRONG_PING_ACK);
|
|
92
|
-
}
|
|
93
|
-
if (!uint8ArrayEquals(data, result.subarray())) {
|
|
94
|
-
throw new CodeError(`Received wrong ping ack after ${ms}ms`, codes.ERR_WRONG_PING_ACK);
|
|
95
|
-
}
|
|
96
|
-
log('ping %p complete in %dms', connection.remotePeer, ms);
|
|
97
|
-
return ms;
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
log.error('error while pinging %p', connection.remotePeer, err);
|
|
101
|
-
stream?.abort(err);
|
|
102
|
-
throw err;
|
|
103
|
-
}
|
|
104
|
-
finally {
|
|
105
|
-
options.signal?.removeEventListener('abort', onAbort);
|
|
106
|
-
if (stream != null) {
|
|
107
|
-
await stream.close();
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
export function pingService(init = {}) {
|
|
113
|
-
return (components) => new DefaultPingService(components, init);
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ping/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AASlJ,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAuBjC,MAAM,kBAAkB;IACN,QAAQ,CAAQ;IACf,UAAU,CAAuB;IAC1C,OAAO,CAAS;IACP,OAAO,CAAQ;IACf,iBAAiB,CAAQ;IACzB,kBAAkB,CAAQ;IAC1B,wBAAwB,CAAS;IAElD,YAAa,UAAiC,EAAE,IAAqB;QACnE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,cAAc,IAAI,eAAe,IAAI,aAAa,IAAI,gBAAgB,EAAE,CAAA;QACjG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,OAAO,CA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3
|
-
* Creates a stream iterable to encrypt messages in a private network
|
|
4
|
-
*/
|
|
5
|
-
export declare function createBoxStream(nonce: Uint8Array, psk: Uint8Array): (source: Source<Uint8Array>) => AsyncIterable<Uint8Array>;
|
|
6
|
-
/**
|
|
7
|
-
* Creates a stream iterable to decrypt messages in a private network
|
|
8
|
-
*/
|
|
9
|
-
export declare function createUnboxStream(nonce: Uint8Array, psk: Uint8Array): (source: Source<Uint8Array>) => AsyncGenerator<Uint8Array, void, unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Decode the version 1 psk from the given Uint8Array
|
|
12
|
-
*/
|
|
13
|
-
export declare function decodeV1PSK(pskBuffer: Uint8Array): {
|
|
14
|
-
tag: string | undefined;
|
|
15
|
-
codecName: string | undefined;
|
|
16
|
-
psk: Uint8Array;
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/pnet/crypto.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAI7C;;GAEG;AACH,wBAAgB,eAAe,CAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,KAAK,aAAa,CAAC,UAAU,CAAC,CAQ9H;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,UAAU,YACnD,OAAO,UAAU,CAAC,+CAQnC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAE,SAAS,EAAE,UAAU,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,UAAU,CAAA;CAAE,CA0B/H"}
|