libp2p 0.44.0-ba47c957 → 0.44.0-ceed8d89
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/index.min.js +26 -26
- package/dist/src/address-manager/index.d.ts +4 -0
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +32 -4
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/address-manager/utils.d.ts +2 -0
- package/dist/src/address-manager/utils.d.ts.map +1 -0
- package/dist/src/address-manager/utils.js +12 -0
- package/dist/src/address-manager/utils.js.map +1 -0
- package/dist/src/autonat/constants.d.ts +16 -2
- package/dist/src/autonat/constants.d.ts.map +1 -1
- package/dist/src/autonat/constants.js +16 -2
- package/dist/src/autonat/constants.js.map +1 -1
- package/dist/src/autonat/index.d.ts +12 -33
- package/dist/src/autonat/index.d.ts.map +1 -1
- package/dist/src/autonat/index.js +36 -30
- package/dist/src/autonat/index.js.map +1 -1
- package/dist/src/circuit-relay/server/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/server/index.js +3 -0
- package/dist/src/circuit-relay/server/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/discovery.js +2 -2
- package/dist/src/circuit-relay/transport/discovery.js.map +1 -1
- package/dist/src/circuit-relay/transport/index.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/index.js +4 -6
- package/dist/src/circuit-relay/transport/index.js.map +1 -1
- package/dist/src/circuit-relay/transport/listener.d.ts +0 -3
- package/dist/src/circuit-relay/transport/listener.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/listener.js +27 -24
- package/dist/src/circuit-relay/transport/listener.js.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.d.ts +2 -4
- package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +1 -1
- package/dist/src/circuit-relay/transport/reservation-store.js +28 -26
- package/dist/src/circuit-relay/transport/reservation-store.js.map +1 -1
- package/dist/src/components.d.ts +2 -66
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +60 -174
- package/dist/src/components.js.map +1 -1
- package/dist/src/config/connection-gater.browser.d.ts +8 -0
- package/dist/src/config/connection-gater.browser.d.ts.map +1 -0
- package/dist/src/config/connection-gater.browser.js +27 -0
- package/dist/src/config/connection-gater.browser.js.map +1 -0
- package/dist/src/config/connection-gater.d.ts +6 -0
- package/dist/src/config/connection-gater.d.ts.map +1 -0
- package/dist/src/config/connection-gater.js +18 -0
- package/dist/src/config/connection-gater.js.map +1 -0
- package/dist/src/config.d.ts +2 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +0 -62
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dial.js +17 -3
- package/dist/src/connection-manager/auto-dial.js.map +1 -1
- package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
- package/dist/src/connection-manager/dial-queue.js +26 -12
- package/dist/src/connection-manager/dial-queue.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +3 -0
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/content-routing/index.d.ts +0 -10
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +6 -41
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/fetch/index.d.ts +13 -35
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +7 -9
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/identify/identify.d.ts +53 -0
- package/dist/src/identify/identify.d.ts.map +1 -0
- package/dist/src/identify/identify.js +405 -0
- package/dist/src/identify/identify.js.map +1 -0
- package/dist/src/identify/index.d.ts +9 -59
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +5 -364
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/index.d.ts +13 -51
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p.d.ts +10 -35
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +110 -172
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -38
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +0 -59
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/constants.d.ts +4 -0
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +10 -0
- package/dist/src/ping/constants.js.map +1 -1
- package/dist/src/ping/index.d.ts +10 -27
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +18 -21
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/registrar.js +2 -2
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts +7 -6
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +18 -23
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +10 -16
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/upnp-nat/index.d.ts +42 -0
- package/dist/src/upnp-nat/index.d.ts.map +1 -0
- package/dist/src/{nat-manager.js → upnp-nat/index.js} +11 -7
- package/dist/src/upnp-nat/index.js.map +1 -0
- 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 +34 -19
- package/src/address-manager/index.ts +42 -4
- package/src/address-manager/utils.ts +14 -0
- package/src/autonat/constants.ts +17 -2
- package/src/autonat/index.ts +53 -45
- package/src/circuit-relay/server/index.ts +4 -0
- package/src/circuit-relay/transport/discovery.ts +2 -2
- package/src/circuit-relay/transport/index.ts +4 -7
- package/src/circuit-relay/transport/listener.ts +35 -29
- package/src/circuit-relay/transport/reservation-store.ts +21 -15
- package/src/components.ts +67 -248
- package/src/config/connection-gater.browser.ts +31 -0
- package/src/config/connection-gater.ts +19 -0
- package/src/config.ts +3 -64
- package/src/connection-manager/auto-dial.ts +20 -3
- package/src/connection-manager/dial-queue.ts +30 -18
- package/src/connection-manager/index.ts +4 -0
- package/src/content-routing/index.ts +6 -54
- package/src/fetch/index.ts +51 -14
- package/src/identify/identify.ts +518 -0
- package/src/identify/index.ts +15 -465
- package/src/index.ts +14 -59
- package/src/libp2p.ts +102 -215
- package/src/peer-routing.ts +1 -101
- package/src/ping/constants.ts +11 -0
- package/src/ping/index.ts +32 -28
- package/src/registrar.ts +2 -2
- package/src/transport-manager.ts +22 -28
- package/src/upgrader.ts +10 -16
- package/src/{nat-manager.ts → upnp-nat/index.ts} +16 -17
- package/src/version.ts +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +0 -17
- package/dist/src/dht/dht-content-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-content-routing.js +0 -32
- package/dist/src/dht/dht-content-routing.js.map +0 -1
- package/dist/src/dht/dht-peer-routing.d.ts +0 -15
- package/dist/src/dht/dht-peer-routing.d.ts.map +0 -1
- package/dist/src/dht/dht-peer-routing.js +0 -26
- package/dist/src/dht/dht-peer-routing.js.map +0 -1
- package/dist/src/dht/dummy-dht.d.ts +0 -20
- package/dist/src/dht/dummy-dht.d.ts.map +0 -1
- package/dist/src/dht/dummy-dht.js +0 -46
- package/dist/src/dht/dummy-dht.js.map +0 -1
- package/dist/src/nat-manager.d.ts +0 -74
- package/dist/src/nat-manager.d.ts.map +0 -1
- package/dist/src/nat-manager.js.map +0 -1
- package/src/dht/dht-content-routing.ts +0 -44
- package/src/dht/dht-peer-routing.ts +0 -36
- package/src/dht/dummy-dht.ts +0 -60
|
@@ -1,368 +1,6 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var _IdentifyService_instances, _IdentifyService_consumeIdentifyMessage;
|
|
7
|
-
import { logger } from '@libp2p/logger';
|
|
8
|
-
import { CodeError } from '@libp2p/interfaces/errors';
|
|
9
|
-
import * as lp from 'it-length-prefixed';
|
|
10
|
-
import { pipe } from 'it-pipe';
|
|
11
|
-
import first from 'it-first';
|
|
12
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
13
|
-
import { multiaddr, protocols } from '@multiformats/multiaddr';
|
|
14
1
|
import { Identify } from './pb/message.js';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { codes } from '../errors.js';
|
|
18
|
-
import { peerIdFromKeys } from '@libp2p/peer-id';
|
|
19
|
-
import { TimeoutController } from 'timeout-abort-controller';
|
|
20
|
-
import { abortableDuplex } from 'abortable-iterator';
|
|
21
|
-
import { setMaxListeners } from 'events';
|
|
22
|
-
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
23
|
-
import { pbStream } from 'it-pb-stream';
|
|
24
|
-
const log = logger('libp2p:identify');
|
|
25
|
-
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L52
|
|
26
|
-
const MAX_IDENTIFY_MESSAGE_SIZE = 1024 * 8;
|
|
27
|
-
export class IdentifyService {
|
|
28
|
-
constructor(components, init) {
|
|
29
|
-
_IdentifyService_instances.add(this);
|
|
30
|
-
this.components = components;
|
|
31
|
-
this.started = false;
|
|
32
|
-
this.init = init;
|
|
33
|
-
this.identifyProtocolStr = `/${init.protocolPrefix}/${MULTICODEC_IDENTIFY_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PROTOCOL_VERSION}`;
|
|
34
|
-
this.identifyPushProtocolStr = `/${init.protocolPrefix}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION}`;
|
|
35
|
-
// Store self host metadata
|
|
36
|
-
this.host = {
|
|
37
|
-
protocolVersion: `${init.protocolPrefix}/${IDENTIFY_PROTOCOL_VERSION}`,
|
|
38
|
-
...init.host
|
|
39
|
-
};
|
|
40
|
-
// When a new connection happens, trigger identify
|
|
41
|
-
this.components.events.addEventListener('connection:open', (evt) => {
|
|
42
|
-
const connection = evt.detail;
|
|
43
|
-
this.identify(connection).catch(err => { log.error('error during identify trigged by connection:open', err); });
|
|
44
|
-
});
|
|
45
|
-
// When self peer record changes, trigger identify-push
|
|
46
|
-
this.components.events.addEventListener('self:peer:update', (evt) => {
|
|
47
|
-
void this.pushToPeerStore().catch(err => { log.error(err); });
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
isStarted() {
|
|
51
|
-
return this.started;
|
|
52
|
-
}
|
|
53
|
-
async start() {
|
|
54
|
-
if (this.started) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
await this.components.peerStore.merge(this.components.peerId, {
|
|
58
|
-
metadata: {
|
|
59
|
-
AgentVersion: uint8ArrayFromString(this.host.agentVersion),
|
|
60
|
-
ProtocolVersion: uint8ArrayFromString(this.host.protocolVersion)
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
await this.components.registrar.handle(this.identifyProtocolStr, (data) => {
|
|
64
|
-
void this._handleIdentify(data).catch(err => {
|
|
65
|
-
log.error(err);
|
|
66
|
-
});
|
|
67
|
-
}, {
|
|
68
|
-
maxInboundStreams: this.init.maxInboundStreams,
|
|
69
|
-
maxOutboundStreams: this.init.maxOutboundStreams
|
|
70
|
-
});
|
|
71
|
-
await this.components.registrar.handle(this.identifyPushProtocolStr, (data) => {
|
|
72
|
-
void this._handlePush(data).catch(err => {
|
|
73
|
-
log.error(err);
|
|
74
|
-
});
|
|
75
|
-
}, {
|
|
76
|
-
maxInboundStreams: this.init.maxPushIncomingStreams,
|
|
77
|
-
maxOutboundStreams: this.init.maxPushOutgoingStreams
|
|
78
|
-
});
|
|
79
|
-
this.started = true;
|
|
80
|
-
}
|
|
81
|
-
async stop() {
|
|
82
|
-
await this.components.registrar.unhandle(this.identifyProtocolStr);
|
|
83
|
-
await this.components.registrar.unhandle(this.identifyPushProtocolStr);
|
|
84
|
-
this.started = false;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Send an Identify Push update to the list of connections
|
|
88
|
-
*/
|
|
89
|
-
async push(connections) {
|
|
90
|
-
const listenAddresses = this.components.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code));
|
|
91
|
-
const peerRecord = new PeerRecord({
|
|
92
|
-
peerId: this.components.peerId,
|
|
93
|
-
multiaddrs: listenAddresses
|
|
94
|
-
});
|
|
95
|
-
const signedPeerRecord = await RecordEnvelope.seal(peerRecord, this.components.peerId);
|
|
96
|
-
const supportedProtocols = this.components.registrar.getProtocols();
|
|
97
|
-
const peer = await this.components.peerStore.get(this.components.peerId);
|
|
98
|
-
const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') ?? uint8ArrayFromString(this.host.agentVersion));
|
|
99
|
-
const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') ?? uint8ArrayFromString(this.host.protocolVersion));
|
|
100
|
-
const pushes = connections.map(async (connection) => {
|
|
101
|
-
let stream;
|
|
102
|
-
const timeoutController = new TimeoutController(this.init.timeout);
|
|
103
|
-
try {
|
|
104
|
-
// fails on node < 15.4
|
|
105
|
-
setMaxListeners?.(Infinity, timeoutController.signal);
|
|
106
|
-
}
|
|
107
|
-
catch { }
|
|
108
|
-
try {
|
|
109
|
-
stream = await connection.newStream([this.identifyPushProtocolStr], {
|
|
110
|
-
signal: timeoutController.signal
|
|
111
|
-
});
|
|
112
|
-
// make stream abortable
|
|
113
|
-
const source = abortableDuplex(stream, timeoutController.signal);
|
|
114
|
-
await source.sink(pipe([Identify.encode({
|
|
115
|
-
listenAddrs: listenAddresses.map(ma => ma.bytes),
|
|
116
|
-
signedPeerRecord: signedPeerRecord.marshal(),
|
|
117
|
-
protocols: supportedProtocols,
|
|
118
|
-
agentVersion,
|
|
119
|
-
protocolVersion
|
|
120
|
-
})], (source) => lp.encode(source)));
|
|
121
|
-
}
|
|
122
|
-
catch (err) {
|
|
123
|
-
// Just log errors
|
|
124
|
-
log.error('could not push identify update to peer', err);
|
|
125
|
-
}
|
|
126
|
-
finally {
|
|
127
|
-
if (stream != null) {
|
|
128
|
-
stream.close();
|
|
129
|
-
}
|
|
130
|
-
timeoutController.clear();
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
await Promise.all(pushes);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Calls `push` on all peer connections
|
|
137
|
-
*/
|
|
138
|
-
async pushToPeerStore() {
|
|
139
|
-
// Do not try to push if we are not running
|
|
140
|
-
if (!this.isStarted()) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const connections = [];
|
|
144
|
-
for (const conn of this.components.connectionManager.getConnections()) {
|
|
145
|
-
const peerId = conn.remotePeer;
|
|
146
|
-
const peer = await this.components.peerStore.get(peerId);
|
|
147
|
-
if (!peer.protocols.includes(this.identifyPushProtocolStr)) {
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
connections.push(conn);
|
|
151
|
-
}
|
|
152
|
-
await this.push(connections);
|
|
153
|
-
}
|
|
154
|
-
async _identify(connection, options = {}) {
|
|
155
|
-
let timeoutController;
|
|
156
|
-
let signal = options.signal;
|
|
157
|
-
let stream;
|
|
158
|
-
// create a timeout if no abort signal passed
|
|
159
|
-
if (signal == null) {
|
|
160
|
-
timeoutController = new TimeoutController(this.init.timeout);
|
|
161
|
-
signal = timeoutController.signal;
|
|
162
|
-
try {
|
|
163
|
-
// fails on node < 15.4
|
|
164
|
-
setMaxListeners?.(Infinity, timeoutController.signal);
|
|
165
|
-
}
|
|
166
|
-
catch { }
|
|
167
|
-
}
|
|
168
|
-
try {
|
|
169
|
-
stream = await connection.newStream([this.identifyProtocolStr], {
|
|
170
|
-
signal
|
|
171
|
-
});
|
|
172
|
-
// make stream abortable
|
|
173
|
-
const source = abortableDuplex(stream, signal);
|
|
174
|
-
const data = await pipe([], source, (source) => lp.decode(source, {
|
|
175
|
-
maxDataLength: this.init.maxIdentifyMessageSize ?? MAX_IDENTIFY_MESSAGE_SIZE
|
|
176
|
-
}), async (source) => await first(source));
|
|
177
|
-
if (data == null) {
|
|
178
|
-
throw new CodeError('No data could be retrieved', codes.ERR_CONNECTION_ENDED);
|
|
179
|
-
}
|
|
180
|
-
try {
|
|
181
|
-
return Identify.decode(data);
|
|
182
|
-
}
|
|
183
|
-
catch (err) {
|
|
184
|
-
throw new CodeError(String(err), codes.ERR_INVALID_MESSAGE);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
finally {
|
|
188
|
-
if (timeoutController != null) {
|
|
189
|
-
timeoutController.clear();
|
|
190
|
-
}
|
|
191
|
-
if (stream != null) {
|
|
192
|
-
stream.close();
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Requests the `Identify` message from peer associated with the given `connection`.
|
|
198
|
-
* If the identified peer does not match the `PeerId` associated with the connection,
|
|
199
|
-
* an error will be thrown.
|
|
200
|
-
*/
|
|
201
|
-
async identify(connection, options = {}) {
|
|
202
|
-
const message = await this._identify(connection, options);
|
|
203
|
-
const { publicKey, protocols, observedAddr } = message;
|
|
204
|
-
if (publicKey == null) {
|
|
205
|
-
throw new CodeError('public key was missing from identify message', codes.ERR_MISSING_PUBLIC_KEY);
|
|
206
|
-
}
|
|
207
|
-
const id = await peerIdFromKeys(publicKey);
|
|
208
|
-
if (!connection.remotePeer.equals(id)) {
|
|
209
|
-
throw new CodeError('identified peer does not match the expected peer', codes.ERR_INVALID_PEER);
|
|
210
|
-
}
|
|
211
|
-
if (this.components.peerId.equals(id)) {
|
|
212
|
-
throw new CodeError('identified peer is our own peer id?', codes.ERR_INVALID_PEER);
|
|
213
|
-
}
|
|
214
|
-
// Get the observedAddr if there is one
|
|
215
|
-
const cleanObservedAddr = IdentifyService.getCleanMultiaddr(observedAddr);
|
|
216
|
-
log('identify completed for peer %p and protocols %o', id, protocols);
|
|
217
|
-
log('our observed address is %s', cleanObservedAddr);
|
|
218
|
-
if (cleanObservedAddr != null &&
|
|
219
|
-
this.components.addressManager.getObservedAddrs().length < (this.init.maxObservedAddresses ?? Infinity)) {
|
|
220
|
-
log('storing our observed address %s', cleanObservedAddr?.toString());
|
|
221
|
-
this.components.addressManager.addObservedAddr(cleanObservedAddr);
|
|
222
|
-
}
|
|
223
|
-
await __classPrivateFieldGet(this, _IdentifyService_instances, "m", _IdentifyService_consumeIdentifyMessage).call(this, connection.remotePeer, message);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Sends the `Identify` response with the Signed Peer Record
|
|
227
|
-
* to the requesting peer over the given `connection`
|
|
228
|
-
*/
|
|
229
|
-
async _handleIdentify(data) {
|
|
230
|
-
const { connection, stream } = data;
|
|
231
|
-
const timeoutController = new TimeoutController(this.init.timeout);
|
|
232
|
-
try {
|
|
233
|
-
// fails on node < 15.4
|
|
234
|
-
setMaxListeners?.(Infinity, timeoutController.signal);
|
|
235
|
-
}
|
|
236
|
-
catch { }
|
|
237
|
-
try {
|
|
238
|
-
const publicKey = this.components.peerId.publicKey ?? new Uint8Array(0);
|
|
239
|
-
const peerData = await this.components.peerStore.get(this.components.peerId);
|
|
240
|
-
const multiaddrs = this.components.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code));
|
|
241
|
-
let signedPeerRecord = peerData.peerRecordEnvelope;
|
|
242
|
-
if (multiaddrs.length > 0 && signedPeerRecord == null) {
|
|
243
|
-
const peerRecord = new PeerRecord({
|
|
244
|
-
peerId: this.components.peerId,
|
|
245
|
-
multiaddrs
|
|
246
|
-
});
|
|
247
|
-
const envelope = await RecordEnvelope.seal(peerRecord, this.components.peerId);
|
|
248
|
-
signedPeerRecord = envelope.marshal().subarray();
|
|
249
|
-
}
|
|
250
|
-
const message = Identify.encode({
|
|
251
|
-
protocolVersion: this.host.protocolVersion,
|
|
252
|
-
agentVersion: this.host.agentVersion,
|
|
253
|
-
publicKey,
|
|
254
|
-
listenAddrs: multiaddrs.map(addr => addr.bytes),
|
|
255
|
-
signedPeerRecord,
|
|
256
|
-
observedAddr: connection.remoteAddr.bytes,
|
|
257
|
-
protocols: peerData.protocols
|
|
258
|
-
});
|
|
259
|
-
// make stream abortable
|
|
260
|
-
const source = abortableDuplex(stream, timeoutController.signal);
|
|
261
|
-
const msgWithLenPrefix = pipe([message], (source) => lp.encode(source));
|
|
262
|
-
await source.sink(msgWithLenPrefix);
|
|
263
|
-
}
|
|
264
|
-
catch (err) {
|
|
265
|
-
log.error('could not respond to identify request', err);
|
|
266
|
-
}
|
|
267
|
-
finally {
|
|
268
|
-
stream.close();
|
|
269
|
-
timeoutController.clear();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Reads the Identify Push message from the given `connection`
|
|
274
|
-
*/
|
|
275
|
-
async _handlePush(data) {
|
|
276
|
-
const { connection, stream } = data;
|
|
277
|
-
try {
|
|
278
|
-
if (this.components.peerId.equals(connection.remotePeer)) {
|
|
279
|
-
throw new Error('received push from ourselves?');
|
|
280
|
-
}
|
|
281
|
-
// make stream abortable
|
|
282
|
-
const source = abortableDuplex(stream, AbortSignal.timeout(this.init.timeout));
|
|
283
|
-
const pb = pbStream(source, {
|
|
284
|
-
maxDataLength: this.init.maxIdentifyMessageSize ?? MAX_IDENTIFY_MESSAGE_SIZE
|
|
285
|
-
});
|
|
286
|
-
const message = await pb.readPB(Identify);
|
|
287
|
-
await __classPrivateFieldGet(this, _IdentifyService_instances, "m", _IdentifyService_consumeIdentifyMessage).call(this, connection.remotePeer, message);
|
|
288
|
-
}
|
|
289
|
-
catch (err) {
|
|
290
|
-
log.error('received invalid message', err);
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
finally {
|
|
294
|
-
stream.close();
|
|
295
|
-
}
|
|
296
|
-
log('handled push from %p', connection.remotePeer);
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Takes the `addr` and converts it to a Multiaddr if possible
|
|
300
|
-
*/
|
|
301
|
-
static getCleanMultiaddr(addr) {
|
|
302
|
-
if (addr != null && addr.length > 0) {
|
|
303
|
-
try {
|
|
304
|
-
return multiaddr(addr);
|
|
305
|
-
}
|
|
306
|
-
catch {
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
_IdentifyService_instances = new WeakSet(), _IdentifyService_consumeIdentifyMessage = async function _IdentifyService_consumeIdentifyMessage(remotePeer, message) {
|
|
312
|
-
if (message == null) {
|
|
313
|
-
throw new Error('Message was null or undefined');
|
|
314
|
-
}
|
|
315
|
-
log('received identify from %p', remotePeer);
|
|
316
|
-
if (message.signedPeerRecord == null) {
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
const envelope = await RecordEnvelope.openAndCertify(message.signedPeerRecord, PeerRecord.DOMAIN);
|
|
320
|
-
const peerRecord = PeerRecord.createFromProtobuf(envelope.payload);
|
|
321
|
-
// Verify peerId
|
|
322
|
-
if (!peerRecord.peerId.equals(envelope.peerId)) {
|
|
323
|
-
throw new Error('signing key does not match PeerId in the PeerRecord');
|
|
324
|
-
}
|
|
325
|
-
// Make sure remote peer is the one sending the record
|
|
326
|
-
if (!remotePeer.equals(peerRecord.peerId)) {
|
|
327
|
-
throw new Error('signing key does not match remote PeerId');
|
|
328
|
-
}
|
|
329
|
-
let peer;
|
|
330
|
-
try {
|
|
331
|
-
peer = await this.components.peerStore.get(peerRecord.peerId);
|
|
332
|
-
}
|
|
333
|
-
catch (err) {
|
|
334
|
-
if (err.code !== 'ERR_NOT_FOUND') {
|
|
335
|
-
throw err;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
log('received signedPeerRecord in push from %p', remotePeer);
|
|
339
|
-
let metadata = new Map();
|
|
340
|
-
if (peer?.peerRecordEnvelope != null) {
|
|
341
|
-
const storedEnvelope = await RecordEnvelope.createFromProtobuf(peer.peerRecordEnvelope);
|
|
342
|
-
const storedRecord = PeerRecord.createFromProtobuf(storedEnvelope.payload);
|
|
343
|
-
// ensure seq is greater than, or equal to, the last received
|
|
344
|
-
if (storedRecord.seqNumber >= peerRecord.seqNumber) {
|
|
345
|
-
log('sequence number was lower or equal to existing sequence number - stored: %d received: %d', storedRecord.seqNumber, peerRecord.seqNumber);
|
|
346
|
-
}
|
|
347
|
-
metadata = peer.metadata;
|
|
348
|
-
}
|
|
349
|
-
if (message.agentVersion != null) {
|
|
350
|
-
metadata.set('AgentVersion', uint8ArrayFromString(message.agentVersion));
|
|
351
|
-
}
|
|
352
|
-
if (message.protocolVersion != null) {
|
|
353
|
-
metadata.set('ProtocolVersion', uint8ArrayFromString(message.protocolVersion));
|
|
354
|
-
}
|
|
355
|
-
await this.components.peerStore.patch(peerRecord.peerId, {
|
|
356
|
-
peerRecordEnvelope: message.signedPeerRecord,
|
|
357
|
-
protocols: message.protocols,
|
|
358
|
-
addresses: peerRecord.multiaddrs.map(multiaddr => ({
|
|
359
|
-
isCertified: true,
|
|
360
|
-
multiaddr
|
|
361
|
-
})),
|
|
362
|
-
metadata
|
|
363
|
-
});
|
|
364
|
-
log('consumed signedPeerRecord sent in push from %p', remotePeer);
|
|
365
|
-
};
|
|
2
|
+
import { MULTICODEC_IDENTIFY, MULTICODEC_IDENTIFY_PUSH } from './consts.js';
|
|
3
|
+
import { DefaultIdentifyService } from './identify.js';
|
|
366
4
|
/**
|
|
367
5
|
* The protocols the IdentifyService supports
|
|
368
6
|
*/
|
|
@@ -371,4 +9,7 @@ export const multicodecs = {
|
|
|
371
9
|
IDENTIFY_PUSH: MULTICODEC_IDENTIFY_PUSH
|
|
372
10
|
};
|
|
373
11
|
export const Message = { Identify };
|
|
12
|
+
export function identifyService(init = {}) {
|
|
13
|
+
return (components) => new DefaultIdentifyService(components, init);
|
|
14
|
+
}
|
|
374
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identify/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAa,SAAS,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,iCAAiC,EACjC,sCAAsC,EACtC,oCAAoC,EACpC,yCAAyC,EAC1C,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAIpC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAOxC,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,E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CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACrE,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -15,8 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { RecursivePartial } from '@libp2p/interfaces';
|
|
17
17
|
import type { TransportManagerInit } from './transport-manager.js';
|
|
18
|
-
import type { IdentifyServiceInit } from './identify/index.js';
|
|
19
|
-
import type { DualDHT } from '@libp2p/interface-dht';
|
|
20
18
|
import type { Datastore } from 'interface-datastore';
|
|
21
19
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
22
20
|
import type { PeerDiscovery } from '@libp2p/interface-peer-discovery';
|
|
@@ -27,24 +25,20 @@ import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer';
|
|
|
27
25
|
import type { ConnectionEncrypter } from '@libp2p/interface-connection-encrypter';
|
|
28
26
|
import type { PeerRouting } from '@libp2p/interface-peer-routing';
|
|
29
27
|
import type { ContentRouting } from '@libp2p/interface-content-routing';
|
|
30
|
-
import type { PubSub } from '@libp2p/interface-pubsub';
|
|
31
28
|
import type { Metrics } from '@libp2p/interface-metrics';
|
|
32
|
-
import type { PingServiceInit } from './ping/index.js';
|
|
33
|
-
import type { FetchServiceInit } from './fetch/index.js';
|
|
34
|
-
import type { AutonatServiceInit } from './autonat/index.js';
|
|
35
29
|
import type { Components } from './components.js';
|
|
36
|
-
import type { Libp2p } from '@libp2p/interface-libp2p';
|
|
30
|
+
import type { Libp2p, ServiceMap } from '@libp2p/interface-libp2p';
|
|
37
31
|
import type { KeyChainInit } from '@libp2p/keychain';
|
|
38
|
-
import type { NatManagerInit } from './nat-manager.js';
|
|
39
32
|
import type { AddressManagerInit } from './address-manager/index.js';
|
|
40
|
-
import type { PeerRoutingInit } from './peer-routing.js';
|
|
41
33
|
import type { ConnectionManagerInit } from './connection-manager/index.js';
|
|
42
|
-
import type { CircuitRelayService } from './circuit-relay/index.js';
|
|
43
34
|
import type { PersistentPeerStoreInit } from '@libp2p/peer-store';
|
|
35
|
+
export type ServiceFactoryMap<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
36
|
+
[Property in keyof T]: (components: Components) => T[Property];
|
|
37
|
+
};
|
|
44
38
|
/**
|
|
45
39
|
* For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
|
|
46
40
|
*/
|
|
47
|
-
export interface Libp2pInit {
|
|
41
|
+
export interface Libp2pInit<T extends ServiceMap = {}> {
|
|
48
42
|
/**
|
|
49
43
|
* peerId instance (it will be created if not provided)
|
|
50
44
|
*/
|
|
@@ -75,39 +69,10 @@ export interface Libp2pInit {
|
|
|
75
69
|
* libp2p PeerStore configuration
|
|
76
70
|
*/
|
|
77
71
|
peerStore: PersistentPeerStoreInit;
|
|
78
|
-
/**
|
|
79
|
-
* libp2p Peer routing service configuration
|
|
80
|
-
*/
|
|
81
|
-
peerRouting: PeerRoutingInit;
|
|
82
72
|
/**
|
|
83
73
|
* keychain configuration
|
|
84
74
|
*/
|
|
85
75
|
keychain: KeyChainInit;
|
|
86
|
-
/**
|
|
87
|
-
* The NAT manager controls uPNP hole punching
|
|
88
|
-
*/
|
|
89
|
-
nat: NatManagerInit;
|
|
90
|
-
/**
|
|
91
|
-
* If configured as a relay this node will relay certain
|
|
92
|
-
* types of traffic for other peers
|
|
93
|
-
*/
|
|
94
|
-
relay: (components: Components) => CircuitRelayService;
|
|
95
|
-
/**
|
|
96
|
-
* identify protocol options
|
|
97
|
-
*/
|
|
98
|
-
identify: IdentifyServiceInit;
|
|
99
|
-
/**
|
|
100
|
-
* ping protocol options
|
|
101
|
-
*/
|
|
102
|
-
ping: PingServiceInit;
|
|
103
|
-
/**
|
|
104
|
-
* fetch protocol options
|
|
105
|
-
*/
|
|
106
|
-
fetch: FetchServiceInit;
|
|
107
|
-
/**
|
|
108
|
-
* autonat protocol options
|
|
109
|
-
*/
|
|
110
|
-
autonat: AutonatServiceInit;
|
|
111
76
|
/**
|
|
112
77
|
* An array that must include at least 1 compliant transport
|
|
113
78
|
*/
|
|
@@ -117,25 +82,21 @@ export interface Libp2pInit {
|
|
|
117
82
|
peerDiscovery?: Array<(components: Components) => PeerDiscovery>;
|
|
118
83
|
peerRouters?: Array<(components: Components) => PeerRouting>;
|
|
119
84
|
contentRouters?: Array<(components: Components) => ContentRouting>;
|
|
120
|
-
/**
|
|
121
|
-
* Pass a DHT implementation to enable DHT operations
|
|
122
|
-
*/
|
|
123
|
-
dht?: (components: Components) => DualDHT;
|
|
124
85
|
/**
|
|
125
86
|
* A Metrics implementation can be supplied to collect metrics on this node
|
|
126
87
|
*/
|
|
127
88
|
metrics?: (components: Components) => Metrics;
|
|
128
|
-
/**
|
|
129
|
-
* If a PubSub implmentation is supplied, PubSub operations will become available
|
|
130
|
-
*/
|
|
131
|
-
pubsub?: (components: Components) => PubSub;
|
|
132
89
|
/**
|
|
133
90
|
* A ConnectionProtector can be used to create a secure overlay on top of the network using pre-shared keys
|
|
134
91
|
*/
|
|
135
92
|
connectionProtector?: (components: Components) => ConnectionProtector;
|
|
93
|
+
/**
|
|
94
|
+
* Arbitrary libp2p modules
|
|
95
|
+
*/
|
|
96
|
+
services: ServiceFactoryMap<T>;
|
|
136
97
|
}
|
|
137
98
|
export type { Libp2p };
|
|
138
|
-
export type Libp2pOptions = RecursivePartial<Libp2pInit
|
|
99
|
+
export type Libp2pOptions<T extends ServiceMap = {}> = RecursivePartial<Libp2pInit<T>> & {
|
|
139
100
|
start?: boolean;
|
|
140
101
|
};
|
|
141
102
|
/**
|
|
@@ -151,11 +112,12 @@ export type Libp2pOptions = RecursivePartial<Libp2pInit> & {
|
|
|
151
112
|
* import { tcp } from '@libp2p/tcp'
|
|
152
113
|
* import { mplex } from '@libp2p/mplex'
|
|
153
114
|
* import { noise } from '@chainsafe/libp2p-noise'
|
|
115
|
+
* import { yamux } from '@chainsafe/libp2p-yamux'
|
|
154
116
|
*
|
|
155
117
|
* // specify options
|
|
156
118
|
* const options = {
|
|
157
119
|
* transports: [tcp()],
|
|
158
|
-
* streamMuxers: [mplex()],
|
|
120
|
+
* streamMuxers: [yamux(), mplex()],
|
|
159
121
|
* connectionEncryption: [noise()]
|
|
160
122
|
* }
|
|
161
123
|
*
|
|
@@ -163,5 +125,5 @@ export type Libp2pOptions = RecursivePartial<Libp2pInit> & {
|
|
|
163
125
|
* const libp2p = await createLibp2p(options)
|
|
164
126
|
* ```
|
|
165
127
|
*/
|
|
166
|
-
export declare function createLibp2p(options: Libp2pOptions): Promise<Libp2p
|
|
128
|
+
export declare function createLibp2p<T extends ServiceMap = {}>(options: Libp2pOptions<T>): Promise<Libp2p<T>>;
|
|
167
129
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,KAAK,EAAE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,MAAM,CAAC,CAAC,CAAC,CAAC,CAQ7G"}
|
package/dist/src/index.js
CHANGED
|
@@ -27,11 +27,12 @@ import { createLibp2pNode } from './libp2p.js';
|
|
|
27
27
|
* import { tcp } from '@libp2p/tcp'
|
|
28
28
|
* import { mplex } from '@libp2p/mplex'
|
|
29
29
|
* import { noise } from '@chainsafe/libp2p-noise'
|
|
30
|
+
* import { yamux } from '@chainsafe/libp2p-yamux'
|
|
30
31
|
*
|
|
31
32
|
* // specify options
|
|
32
33
|
* const options = {
|
|
33
34
|
* transports: [tcp()],
|
|
34
|
-
* streamMuxers: [mplex()],
|
|
35
|
+
* streamMuxers: [yamux(), mplex()],
|
|
35
36
|
* connectionEncryption: [noise()]
|
|
36
37
|
* }
|
|
37
38
|
*
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAqG9C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAA8B,OAAyB;IACvF,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAE5C,IAAI,OAAO,CAAC,KAAK,KAAK,KAAK,EAAE;QAC3B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAA;KACnB;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/dist/src/libp2p.d.ts
CHANGED
|
@@ -1,46 +1,28 @@
|
|
|
1
1
|
import type { AbortOptions } from '@libp2p/interfaces';
|
|
2
2
|
import { EventEmitter } from '@libp2p/interfaces/events';
|
|
3
3
|
import { Multiaddr } from '@multiformats/multiaddr';
|
|
4
|
-
import { IdentifyService } from './identify/index.js';
|
|
5
|
-
import { FetchService } from './fetch/index.js';
|
|
6
|
-
import { PingService } from './ping/index.js';
|
|
7
|
-
import { AutonatService } from './autonat/index.js';
|
|
8
4
|
import type { Components } from './components.js';
|
|
9
5
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
10
6
|
import type { Connection, Stream } from '@libp2p/interface-connection';
|
|
11
|
-
import type {
|
|
12
|
-
import type { ContentRouting } from '@libp2p/interface-content-routing';
|
|
13
|
-
import type { PubSub } from '@libp2p/interface-pubsub';
|
|
14
|
-
import type { Registrar, StreamHandler, StreamHandlerOptions, Topology } from '@libp2p/interface-registrar';
|
|
15
|
-
import type { ConnectionManager } from '@libp2p/interface-connection-manager';
|
|
16
|
-
import type { PeerInfo } from '@libp2p/interface-peer-info';
|
|
7
|
+
import type { StreamHandler, StreamHandlerOptions, Topology } from '@libp2p/interface-registrar';
|
|
17
8
|
import type { Libp2p, Libp2pInit, Libp2pOptions } from './index.js';
|
|
18
9
|
import type { PeerStore } from '@libp2p/interface-peer-store';
|
|
19
|
-
import type { DualDHT } from '@libp2p/interface-dht';
|
|
20
10
|
import type { Metrics } from '@libp2p/interface-metrics';
|
|
21
11
|
import type { KeyChain } from '@libp2p/interface-keychain';
|
|
22
|
-
import type {
|
|
23
|
-
import
|
|
24
|
-
|
|
12
|
+
import type { Libp2pEvents, PendingDial, ServiceMap } from '@libp2p/interface-libp2p';
|
|
13
|
+
import { ContentRouting } from '@libp2p/interface-content-routing';
|
|
14
|
+
import { PeerRouting } from '@libp2p/interface-peer-routing';
|
|
15
|
+
export declare class Libp2pNode<T extends ServiceMap = {}> extends EventEmitter<Libp2pEvents> implements Libp2p<T> {
|
|
16
|
+
#private;
|
|
25
17
|
peerId: PeerId;
|
|
26
|
-
dht: DualDHT;
|
|
27
|
-
pubsub: PubSub;
|
|
28
|
-
identifyService: IdentifyService;
|
|
29
|
-
circuitService?: CircuitRelayService;
|
|
30
|
-
fetchService: FetchService;
|
|
31
|
-
pingService: PingService;
|
|
32
|
-
autonatService: AutonatService;
|
|
33
|
-
components: Components;
|
|
34
18
|
peerStore: PeerStore;
|
|
35
19
|
contentRouting: ContentRouting;
|
|
36
20
|
peerRouting: PeerRouting;
|
|
37
21
|
keychain: KeyChain;
|
|
38
|
-
connectionManager: ConnectionManager;
|
|
39
|
-
registrar: Registrar;
|
|
40
22
|
metrics?: Metrics;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
constructor(init: Libp2pInit);
|
|
23
|
+
services: T;
|
|
24
|
+
components: Components;
|
|
25
|
+
constructor(init: Libp2pInit<T>);
|
|
44
26
|
private configureComponent;
|
|
45
27
|
/**
|
|
46
28
|
* Starts the libp2p node and all its subsystems
|
|
@@ -63,21 +45,14 @@ export declare class Libp2pNode extends EventEmitter<Libp2pEvents> implements Li
|
|
|
63
45
|
* Get the public key for the given peer id
|
|
64
46
|
*/
|
|
65
47
|
getPublicKey(peer: PeerId, options?: AbortOptions): Promise<Uint8Array>;
|
|
66
|
-
fetch(peer: PeerId | Multiaddr, key: string, options?: AbortOptions): Promise<Uint8Array | null>;
|
|
67
|
-
ping(peer: PeerId | Multiaddr, options?: AbortOptions): Promise<number>;
|
|
68
48
|
handle(protocols: string | string[], handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>;
|
|
69
49
|
unhandle(protocols: string[] | string): Promise<void>;
|
|
70
50
|
register(protocol: string, topology: Topology): Promise<string>;
|
|
71
51
|
unregister(id: string): void;
|
|
72
|
-
/**
|
|
73
|
-
* Called whenever peer discovery services emit `peer` events and adds peers
|
|
74
|
-
* to the peer store.
|
|
75
|
-
*/
|
|
76
|
-
onDiscoveryPeer(evt: CustomEvent<PeerInfo>): void;
|
|
77
52
|
}
|
|
78
53
|
/**
|
|
79
54
|
* Returns a new Libp2pNode instance - this exposes more of the internals than the
|
|
80
55
|
* libp2p interface and is useful for testing and debugging.
|
|
81
56
|
*/
|
|
82
|
-
export declare function createLibp2pNode(options: Libp2pOptions): Promise<Libp2pNode
|
|
57
|
+
export declare function createLibp2pNode<T extends ServiceMap = {}>(options: Libp2pOptions<T>): Promise<Libp2pNode<T>>;
|
|
83
58
|
//# sourceMappingURL=libp2p.d.ts.map
|