libp2p 0.44.0-ed2fa794 → 0.44.0-ef7a5f67
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 +12 -12
- 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/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 +1 -15
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +2 -387
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/transport-manager.d.ts +0 -4
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +4 -20
- package/dist/src/transport-manager.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 +4 -4
- package/src/address-manager/index.ts +42 -4
- package/src/address-manager/utils.ts +14 -0
- package/src/identify/identify.ts +518 -0
- package/src/identify/index.ts +5 -505
- package/src/transport-manager.ts +4 -24
- package/src/version.ts +1 -1
|
@@ -2,6 +2,8 @@ import type { Multiaddr } from '@multiformats/multiaddr';
|
|
|
2
2
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
3
3
|
import type { TransportManager } from '@libp2p/interface-transport';
|
|
4
4
|
import type { PeerStore } from '@libp2p/interface-peer-store';
|
|
5
|
+
import type { EventEmitter } from '@libp2p/interfaces/dist/src/events';
|
|
6
|
+
import type { Libp2pEvents } from '@libp2p/interface-libp2p';
|
|
5
7
|
export interface AddressManagerInit {
|
|
6
8
|
/**
|
|
7
9
|
* Pass an function in this field to override the list of addresses
|
|
@@ -25,6 +27,7 @@ export interface DefaultAddressManagerComponents {
|
|
|
25
27
|
peerId: PeerId;
|
|
26
28
|
transportManager: TransportManager;
|
|
27
29
|
peerStore: PeerStore;
|
|
30
|
+
events: EventEmitter<Libp2pEvents>;
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
30
33
|
* A function that takes a list of multiaddrs and returns a list
|
|
@@ -46,6 +49,7 @@ export declare class DefaultAddressManager {
|
|
|
46
49
|
* while the announce addresses will be used for the peer addresses' to other peers in the network.
|
|
47
50
|
*/
|
|
48
51
|
constructor(components: DefaultAddressManagerComponents, init?: AddressManagerInit);
|
|
52
|
+
_updatePeerStoreAddresses(): void;
|
|
49
53
|
/**
|
|
50
54
|
* Get peer listen multiaddrs
|
|
51
55
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/address-manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/address-manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAE7D,OAAO,KAAK,EAAE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AAE,IAAI,EAAE,SAAS,GAAG,IAAI;IAO1C,YAAY,IAAK,SAAS,EAAE;CAkC7B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
3
3
|
import { logger } from '@libp2p/logger';
|
|
4
|
+
import { debounce } from './utils.js';
|
|
4
5
|
const log = logger('libp2p:address-manager');
|
|
5
6
|
const defaultAddressFilter = (addrs) => addrs;
|
|
6
7
|
/**
|
|
@@ -32,6 +33,36 @@ export class DefaultAddressManager {
|
|
|
32
33
|
this.announce = new Set(announce.map(ma => ma.toString()));
|
|
33
34
|
this.observed = new Map();
|
|
34
35
|
this.announceFilter = init.announceFilter ?? defaultAddressFilter;
|
|
36
|
+
// this method gets called repeatedly on startup when transports start listening so
|
|
37
|
+
// debounce it so we don't cause multiple self:peer:update events to be emitted
|
|
38
|
+
this._updatePeerStoreAddresses = debounce(this._updatePeerStoreAddresses.bind(this), 1000);
|
|
39
|
+
// update our stored addresses when new transports listen
|
|
40
|
+
components.events.addEventListener('transport:listening', () => {
|
|
41
|
+
this._updatePeerStoreAddresses();
|
|
42
|
+
});
|
|
43
|
+
// update our stored addresses when existing transports stop listening
|
|
44
|
+
components.events.addEventListener('transport:close', () => {
|
|
45
|
+
this._updatePeerStoreAddresses();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
_updatePeerStoreAddresses() {
|
|
49
|
+
// if announce addresses have been configured, ensure they make it into our peer
|
|
50
|
+
// record for things like identify
|
|
51
|
+
const addrs = this.getAnnounceAddrs()
|
|
52
|
+
.concat(this.components.transportManager.getAddrs())
|
|
53
|
+
.concat([...this.observed.entries()]
|
|
54
|
+
.filter(([_, metadata]) => metadata.confident)
|
|
55
|
+
.map(([str]) => multiaddr(str))).map(ma => {
|
|
56
|
+
// strip our peer id if it is present
|
|
57
|
+
if (ma.getPeerId() === this.components.peerId.toString()) {
|
|
58
|
+
return ma.decapsulate(`/p2p/${this.components.peerId.toString()}`);
|
|
59
|
+
}
|
|
60
|
+
return ma;
|
|
61
|
+
});
|
|
62
|
+
this.components.peerStore.patch(this.components.peerId, {
|
|
63
|
+
multiaddrs: addrs
|
|
64
|
+
})
|
|
65
|
+
.catch(err => { log.error('error updating addresses', err); });
|
|
35
66
|
}
|
|
36
67
|
/**
|
|
37
68
|
* Get peer listen multiaddrs
|
|
@@ -77,10 +108,7 @@ export class DefaultAddressManager {
|
|
|
77
108
|
});
|
|
78
109
|
// only trigger the 'self:peer:update' event if our confidence in an address has changed
|
|
79
110
|
if (!startingConfidence) {
|
|
80
|
-
this.
|
|
81
|
-
multiaddrs: this.getAddresses()
|
|
82
|
-
})
|
|
83
|
-
.catch(err => { log.error('error updating addresses', err); });
|
|
111
|
+
this._updatePeerStoreAddresses();
|
|
84
112
|
}
|
|
85
113
|
}
|
|
86
114
|
removeObservedAddr(addr) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/address-manager/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/address-manager/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGvC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,MAAM,GAAG,GAAG,MAAM,CAAC,wBAAwB,CAAC,CAAA;AAwC5C,MAAM,oBAAoB,GAAG,CAAC,KAAkB,EAAe,EAAE,CAAC,KAA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I,GAAG,CAAC,KAAK,CAAC,CAAA;QAE9B,0BAA0B;QAC1B,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC;aAC3C,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;aAC3B,GAAG,CAAC,EAAE,CAAC,EAAE;YACR,0EAA0E;YAC1E,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,KAAK,IAAI,EAAE;gBACpC,OAAO,EAAE,CAAA;aACV;YAED,IAAI,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE;gBACxD,OAAO,EAAE,CAAA;aACV;YAED,OAAO,EAAE,CAAC,WAAW,CAAC,QAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;QACpE,CAAC,CAAC,CAAA;IACN,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/address-manager/utils.ts"],"names":[],"mappings":"AACA,wBAAgB,QAAQ,CAAE,IAAI,EAAE,MAAM,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,IAAI,CAYpE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/address-manager/utils.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,QAAQ,CAAE,IAAgB,EAAE,IAAY;IACtD,IAAI,OAAkD,CAAA;IAEtD,OAAO;QACL,MAAM,KAAK,GAAG;YACZ,OAAO,GAAG,SAAS,CAAA;YACnB,IAAI,EAAE,CAAA;QACR,CAAC,CAAA;QAED,YAAY,CAAC,OAAO,CAAC,CAAA;QACrB,OAAO,GAAG,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;IACnC,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Identify } from './pb/message.js';
|
|
2
|
+
import type { IncomingStreamData } from '@libp2p/interface-registrar';
|
|
3
|
+
import type { Connection } from '@libp2p/interface-connection';
|
|
4
|
+
import type { Startable } from '@libp2p/interfaces/startable';
|
|
5
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
6
|
+
import type { IdentifyServiceComponents, IdentifyServiceInit } from './index.js';
|
|
7
|
+
export declare class DefaultIdentifyService implements Startable {
|
|
8
|
+
#private;
|
|
9
|
+
private readonly identifyProtocolStr;
|
|
10
|
+
private readonly identifyPushProtocolStr;
|
|
11
|
+
readonly host: {
|
|
12
|
+
protocolVersion: string;
|
|
13
|
+
agentVersion: string;
|
|
14
|
+
};
|
|
15
|
+
private started;
|
|
16
|
+
private readonly timeout;
|
|
17
|
+
private readonly peerId;
|
|
18
|
+
private readonly peerStore;
|
|
19
|
+
private readonly registrar;
|
|
20
|
+
private readonly connectionManager;
|
|
21
|
+
private readonly addressManager;
|
|
22
|
+
private readonly maxInboundStreams;
|
|
23
|
+
private readonly maxOutboundStreams;
|
|
24
|
+
private readonly maxPushIncomingStreams;
|
|
25
|
+
private readonly maxPushOutgoingStreams;
|
|
26
|
+
private readonly maxIdentifyMessageSize;
|
|
27
|
+
private readonly maxObservedAddresses;
|
|
28
|
+
private readonly events;
|
|
29
|
+
constructor(components: IdentifyServiceComponents, init: IdentifyServiceInit);
|
|
30
|
+
isStarted(): boolean;
|
|
31
|
+
start(): Promise<void>;
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Send an Identify Push update to the list of connections
|
|
35
|
+
*/
|
|
36
|
+
pushToConnections(connections: Connection[]): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Calls `push` on all peer connections
|
|
39
|
+
*/
|
|
40
|
+
push(): Promise<void>;
|
|
41
|
+
_identify(connection: Connection, options?: AbortOptions): Promise<Identify>;
|
|
42
|
+
identify(connection: Connection, options?: AbortOptions): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Sends the `Identify` response with the Signed Peer Record
|
|
45
|
+
* to the requesting peer over the given `connection`
|
|
46
|
+
*/
|
|
47
|
+
_handleIdentify(data: IncomingStreamData): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Reads the Identify Push message from the given `connection`
|
|
50
|
+
*/
|
|
51
|
+
_handlePush(data: IncomingStreamData): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=identify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identify.d.ts","sourceRoot":"","sources":["../../../src/identify/identify.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAW1C,OAAO,KAAK,EAAE,kBAAkB,EAAa,MAAM,6BAA6B,CAAA;AAChF,OAAO,KAAK,EAAE,UAAU,EAAU,MAAM,8BAA8B,CAAA;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAE7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAWtD,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAsBhF,qBAAa,sBAAuB,YAAW,SAAS;;IACtD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAQ;IAChD,SAAgB,IAAI,EAAE;QACpB,eAAe,EAAE,MAAM,CAAA;QACvB,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;IAED,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,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
|
+
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 _DefaultIdentifyService_instances, _DefaultIdentifyService_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
|
+
import { Identify } from './pb/message.js';
|
|
15
|
+
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record';
|
|
16
|
+
import { AGENT_VERSION, IDENTIFY_PROTOCOL_VERSION, MULTICODEC_IDENTIFY_PROTOCOL_NAME, MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME, MULTICODEC_IDENTIFY_PROTOCOL_VERSION, MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION } from './consts.js';
|
|
17
|
+
import { codes } from '../errors.js';
|
|
18
|
+
import { peerIdFromKeys } from '@libp2p/peer-id';
|
|
19
|
+
import { abortableDuplex } from 'abortable-iterator';
|
|
20
|
+
import { setMaxListeners } from 'events';
|
|
21
|
+
import { anySignal } from 'any-signal';
|
|
22
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
23
|
+
import { pbStream } from 'it-pb-stream';
|
|
24
|
+
import { isNode, isBrowser, isWebWorker, isElectronMain, isElectronRenderer, isReactNative } from 'wherearewe';
|
|
25
|
+
const log = logger('libp2p:identify');
|
|
26
|
+
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L52
|
|
27
|
+
const MAX_IDENTIFY_MESSAGE_SIZE = 1024 * 8;
|
|
28
|
+
const defaultValues = {
|
|
29
|
+
protocolPrefix: 'ipfs',
|
|
30
|
+
agentVersion: AGENT_VERSION,
|
|
31
|
+
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/identify/id.go#L48
|
|
32
|
+
timeout: 60000,
|
|
33
|
+
maxInboundStreams: 1,
|
|
34
|
+
maxOutboundStreams: 1,
|
|
35
|
+
maxPushIncomingStreams: 1,
|
|
36
|
+
maxPushOutgoingStreams: 1,
|
|
37
|
+
maxObservedAddresses: 10,
|
|
38
|
+
maxIdentifyMessageSize: 8192
|
|
39
|
+
};
|
|
40
|
+
export class DefaultIdentifyService {
|
|
41
|
+
constructor(components, init) {
|
|
42
|
+
_DefaultIdentifyService_instances.add(this);
|
|
43
|
+
this.started = false;
|
|
44
|
+
this.peerId = components.peerId;
|
|
45
|
+
this.peerStore = components.peerStore;
|
|
46
|
+
this.registrar = components.registrar;
|
|
47
|
+
this.addressManager = components.addressManager;
|
|
48
|
+
this.connectionManager = components.connectionManager;
|
|
49
|
+
this.events = components.events;
|
|
50
|
+
this.identifyProtocolStr = `/${init.protocolPrefix ?? defaultValues.protocolPrefix}/${MULTICODEC_IDENTIFY_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PROTOCOL_VERSION}`;
|
|
51
|
+
this.identifyPushProtocolStr = `/${init.protocolPrefix ?? defaultValues.protocolPrefix}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME}/${MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION}`;
|
|
52
|
+
this.timeout = init.timeout ?? defaultValues.timeout;
|
|
53
|
+
this.maxInboundStreams = init.maxInboundStreams ?? defaultValues.maxInboundStreams;
|
|
54
|
+
this.maxOutboundStreams = init.maxOutboundStreams ?? defaultValues.maxOutboundStreams;
|
|
55
|
+
this.maxPushIncomingStreams = init.maxPushIncomingStreams ?? defaultValues.maxPushIncomingStreams;
|
|
56
|
+
this.maxPushOutgoingStreams = init.maxPushOutgoingStreams ?? defaultValues.maxPushOutgoingStreams;
|
|
57
|
+
this.maxIdentifyMessageSize = init.maxIdentifyMessageSize ?? defaultValues.maxIdentifyMessageSize;
|
|
58
|
+
this.maxObservedAddresses = init.maxObservedAddresses ?? defaultValues.maxObservedAddresses;
|
|
59
|
+
// Store self host metadata
|
|
60
|
+
this.host = {
|
|
61
|
+
protocolVersion: `${init.protocolPrefix ?? defaultValues.protocolPrefix}/${IDENTIFY_PROTOCOL_VERSION}`,
|
|
62
|
+
agentVersion: init.agentVersion ?? defaultValues.agentVersion
|
|
63
|
+
};
|
|
64
|
+
// When a new connection happens, trigger identify
|
|
65
|
+
components.events.addEventListener('connection:open', (evt) => {
|
|
66
|
+
const connection = evt.detail;
|
|
67
|
+
this.identify(connection).catch(err => { log.error('error during identify trigged by connection:open', err); });
|
|
68
|
+
});
|
|
69
|
+
// When self peer record changes, trigger identify-push
|
|
70
|
+
components.events.addEventListener('self:peer:update', (evt) => {
|
|
71
|
+
void this.push().catch(err => { log.error(err); });
|
|
72
|
+
});
|
|
73
|
+
// Append user agent version to default AGENT_VERSION depending on the environment
|
|
74
|
+
if (this.host.agentVersion === AGENT_VERSION) {
|
|
75
|
+
if (isNode || isElectronMain) {
|
|
76
|
+
this.host.agentVersion += ` UserAgent=${globalThis.process.version}`;
|
|
77
|
+
}
|
|
78
|
+
else if (isBrowser || isWebWorker || isElectronRenderer || isReactNative) {
|
|
79
|
+
this.host.agentVersion += ` UserAgent=${globalThis.navigator.userAgent}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
isStarted() {
|
|
84
|
+
return this.started;
|
|
85
|
+
}
|
|
86
|
+
async start() {
|
|
87
|
+
if (this.started) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await this.peerStore.merge(this.peerId, {
|
|
91
|
+
metadata: {
|
|
92
|
+
AgentVersion: uint8ArrayFromString(this.host.agentVersion),
|
|
93
|
+
ProtocolVersion: uint8ArrayFromString(this.host.protocolVersion)
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
await this.registrar.handle(this.identifyProtocolStr, (data) => {
|
|
97
|
+
void this._handleIdentify(data).catch(err => {
|
|
98
|
+
log.error(err);
|
|
99
|
+
});
|
|
100
|
+
}, {
|
|
101
|
+
maxInboundStreams: this.maxInboundStreams,
|
|
102
|
+
maxOutboundStreams: this.maxOutboundStreams
|
|
103
|
+
});
|
|
104
|
+
await this.registrar.handle(this.identifyPushProtocolStr, (data) => {
|
|
105
|
+
void this._handlePush(data).catch(err => {
|
|
106
|
+
log.error(err);
|
|
107
|
+
});
|
|
108
|
+
}, {
|
|
109
|
+
maxInboundStreams: this.maxPushIncomingStreams,
|
|
110
|
+
maxOutboundStreams: this.maxPushOutgoingStreams
|
|
111
|
+
});
|
|
112
|
+
this.started = true;
|
|
113
|
+
}
|
|
114
|
+
async stop() {
|
|
115
|
+
await this.registrar.unhandle(this.identifyProtocolStr);
|
|
116
|
+
await this.registrar.unhandle(this.identifyPushProtocolStr);
|
|
117
|
+
this.started = false;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Send an Identify Push update to the list of connections
|
|
121
|
+
*/
|
|
122
|
+
async pushToConnections(connections) {
|
|
123
|
+
const listenAddresses = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code));
|
|
124
|
+
const peerRecord = new PeerRecord({
|
|
125
|
+
peerId: this.peerId,
|
|
126
|
+
multiaddrs: listenAddresses
|
|
127
|
+
});
|
|
128
|
+
const signedPeerRecord = await RecordEnvelope.seal(peerRecord, this.peerId);
|
|
129
|
+
const supportedProtocols = this.registrar.getProtocols();
|
|
130
|
+
const peer = await this.peerStore.get(this.peerId);
|
|
131
|
+
const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') ?? uint8ArrayFromString(this.host.agentVersion));
|
|
132
|
+
const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') ?? uint8ArrayFromString(this.host.protocolVersion));
|
|
133
|
+
const pushes = connections.map(async (connection) => {
|
|
134
|
+
let stream;
|
|
135
|
+
const signal = AbortSignal.timeout(this.timeout);
|
|
136
|
+
try {
|
|
137
|
+
// fails on node < 15.4
|
|
138
|
+
setMaxListeners?.(Infinity, signal);
|
|
139
|
+
}
|
|
140
|
+
catch { }
|
|
141
|
+
try {
|
|
142
|
+
stream = await connection.newStream([this.identifyPushProtocolStr], {
|
|
143
|
+
signal
|
|
144
|
+
});
|
|
145
|
+
// make stream abortable
|
|
146
|
+
const source = abortableDuplex(stream, signal);
|
|
147
|
+
await source.sink(pipe([Identify.encode({
|
|
148
|
+
listenAddrs: listenAddresses.map(ma => ma.bytes),
|
|
149
|
+
signedPeerRecord: signedPeerRecord.marshal(),
|
|
150
|
+
protocols: supportedProtocols,
|
|
151
|
+
agentVersion,
|
|
152
|
+
protocolVersion
|
|
153
|
+
})], (source) => lp.encode(source)));
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
// Just log errors
|
|
157
|
+
log.error('could not push identify update to peer', err);
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
if (stream != null) {
|
|
161
|
+
stream.close();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
await Promise.all(pushes);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Calls `push` on all peer connections
|
|
169
|
+
*/
|
|
170
|
+
async push() {
|
|
171
|
+
// Do not try to push if we are not running
|
|
172
|
+
if (!this.isStarted()) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const connections = [];
|
|
176
|
+
await Promise.all(this.connectionManager.getConnections().map(async (conn) => {
|
|
177
|
+
try {
|
|
178
|
+
const peer = await this.peerStore.get(conn.remotePeer);
|
|
179
|
+
if (!peer.protocols.includes(this.identifyPushProtocolStr)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
connections.push(conn);
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
if (err.code !== codes.ERR_NOT_FOUND) {
|
|
186
|
+
throw err;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}));
|
|
190
|
+
await this.pushToConnections(connections);
|
|
191
|
+
}
|
|
192
|
+
async _identify(connection, options = {}) {
|
|
193
|
+
let stream;
|
|
194
|
+
const signal = anySignal([AbortSignal.timeout(this.timeout), options?.signal]);
|
|
195
|
+
try {
|
|
196
|
+
// fails on node < 15.4
|
|
197
|
+
setMaxListeners?.(Infinity, signal);
|
|
198
|
+
}
|
|
199
|
+
catch { }
|
|
200
|
+
try {
|
|
201
|
+
stream = await connection.newStream([this.identifyProtocolStr], {
|
|
202
|
+
signal
|
|
203
|
+
});
|
|
204
|
+
// make stream abortable
|
|
205
|
+
const source = abortableDuplex(stream, signal);
|
|
206
|
+
const data = await pipe([], source, (source) => lp.decode(source, {
|
|
207
|
+
maxDataLength: this.maxIdentifyMessageSize ?? MAX_IDENTIFY_MESSAGE_SIZE
|
|
208
|
+
}), async (source) => await first(source));
|
|
209
|
+
if (data == null) {
|
|
210
|
+
throw new CodeError('No data could be retrieved', codes.ERR_CONNECTION_ENDED);
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
return Identify.decode(data);
|
|
214
|
+
}
|
|
215
|
+
catch (err) {
|
|
216
|
+
throw new CodeError(String(err), codes.ERR_INVALID_MESSAGE);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
if (stream != null) {
|
|
221
|
+
stream.close();
|
|
222
|
+
}
|
|
223
|
+
signal.clear();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async identify(connection, options = {}) {
|
|
227
|
+
const message = await this._identify(connection, options);
|
|
228
|
+
const { publicKey, protocols, observedAddr } = message;
|
|
229
|
+
if (publicKey == null) {
|
|
230
|
+
throw new CodeError('public key was missing from identify message', codes.ERR_MISSING_PUBLIC_KEY);
|
|
231
|
+
}
|
|
232
|
+
const id = await peerIdFromKeys(publicKey);
|
|
233
|
+
if (!connection.remotePeer.equals(id)) {
|
|
234
|
+
throw new CodeError('identified peer does not match the expected peer', codes.ERR_INVALID_PEER);
|
|
235
|
+
}
|
|
236
|
+
if (this.peerId.equals(id)) {
|
|
237
|
+
throw new CodeError('identified peer is our own peer id?', codes.ERR_INVALID_PEER);
|
|
238
|
+
}
|
|
239
|
+
// Get the observedAddr if there is one
|
|
240
|
+
const cleanObservedAddr = getCleanMultiaddr(observedAddr);
|
|
241
|
+
log('identify completed for peer %p and protocols %o', id, protocols);
|
|
242
|
+
log('our observed address is %s', cleanObservedAddr);
|
|
243
|
+
if (cleanObservedAddr != null &&
|
|
244
|
+
this.addressManager.getObservedAddrs().length < (this.maxObservedAddresses ?? Infinity)) {
|
|
245
|
+
log('storing our observed address %s', cleanObservedAddr?.toString());
|
|
246
|
+
this.addressManager.addObservedAddr(cleanObservedAddr);
|
|
247
|
+
}
|
|
248
|
+
const signedPeerRecord = await __classPrivateFieldGet(this, _DefaultIdentifyService_instances, "m", _DefaultIdentifyService_consumeIdentifyMessage).call(this, connection.remotePeer, message);
|
|
249
|
+
const result = {
|
|
250
|
+
peerId: id,
|
|
251
|
+
protocolVersion: message.protocolVersion,
|
|
252
|
+
agentVersion: message.agentVersion,
|
|
253
|
+
publicKey: message.publicKey,
|
|
254
|
+
listenAddrs: message.listenAddrs.map(buf => multiaddr(buf)),
|
|
255
|
+
observedAddr: message.observedAddr == null ? undefined : multiaddr(message.observedAddr),
|
|
256
|
+
protocols: message.protocols,
|
|
257
|
+
signedPeerRecord
|
|
258
|
+
};
|
|
259
|
+
this.events.safeDispatchEvent('peer:identify', { detail: result });
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Sends the `Identify` response with the Signed Peer Record
|
|
263
|
+
* to the requesting peer over the given `connection`
|
|
264
|
+
*/
|
|
265
|
+
async _handleIdentify(data) {
|
|
266
|
+
const { connection, stream } = data;
|
|
267
|
+
const signal = AbortSignal.timeout(this.timeout);
|
|
268
|
+
try {
|
|
269
|
+
// fails on node < 15.4
|
|
270
|
+
setMaxListeners?.(Infinity, signal);
|
|
271
|
+
}
|
|
272
|
+
catch { }
|
|
273
|
+
try {
|
|
274
|
+
const publicKey = this.peerId.publicKey ?? new Uint8Array(0);
|
|
275
|
+
const peerData = await this.peerStore.get(this.peerId);
|
|
276
|
+
const multiaddrs = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code));
|
|
277
|
+
let signedPeerRecord = peerData.peerRecordEnvelope;
|
|
278
|
+
if (multiaddrs.length > 0 && signedPeerRecord == null) {
|
|
279
|
+
const peerRecord = new PeerRecord({
|
|
280
|
+
peerId: this.peerId,
|
|
281
|
+
multiaddrs
|
|
282
|
+
});
|
|
283
|
+
const envelope = await RecordEnvelope.seal(peerRecord, this.peerId);
|
|
284
|
+
signedPeerRecord = envelope.marshal().subarray();
|
|
285
|
+
}
|
|
286
|
+
const message = Identify.encode({
|
|
287
|
+
protocolVersion: this.host.protocolVersion,
|
|
288
|
+
agentVersion: this.host.agentVersion,
|
|
289
|
+
publicKey,
|
|
290
|
+
listenAddrs: multiaddrs.map(addr => addr.bytes),
|
|
291
|
+
signedPeerRecord,
|
|
292
|
+
observedAddr: connection.remoteAddr.bytes,
|
|
293
|
+
protocols: peerData.protocols
|
|
294
|
+
});
|
|
295
|
+
// make stream abortable
|
|
296
|
+
const source = abortableDuplex(stream, signal);
|
|
297
|
+
const msgWithLenPrefix = pipe([message], (source) => lp.encode(source));
|
|
298
|
+
await source.sink(msgWithLenPrefix);
|
|
299
|
+
}
|
|
300
|
+
catch (err) {
|
|
301
|
+
log.error('could not respond to identify request', err);
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
stream.close();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Reads the Identify Push message from the given `connection`
|
|
309
|
+
*/
|
|
310
|
+
async _handlePush(data) {
|
|
311
|
+
const { connection, stream } = data;
|
|
312
|
+
try {
|
|
313
|
+
if (this.peerId.equals(connection.remotePeer)) {
|
|
314
|
+
throw new Error('received push from ourselves?');
|
|
315
|
+
}
|
|
316
|
+
// make stream abortable
|
|
317
|
+
const source = abortableDuplex(stream, AbortSignal.timeout(this.timeout));
|
|
318
|
+
const pb = pbStream(source, {
|
|
319
|
+
maxDataLength: this.maxIdentifyMessageSize ?? MAX_IDENTIFY_MESSAGE_SIZE
|
|
320
|
+
});
|
|
321
|
+
const message = await pb.readPB(Identify);
|
|
322
|
+
await __classPrivateFieldGet(this, _DefaultIdentifyService_instances, "m", _DefaultIdentifyService_consumeIdentifyMessage).call(this, connection.remotePeer, message);
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
log.error('received invalid message', err);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
finally {
|
|
329
|
+
stream.close();
|
|
330
|
+
}
|
|
331
|
+
log('handled push from %p', connection.remotePeer);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
_DefaultIdentifyService_instances = new WeakSet(), _DefaultIdentifyService_consumeIdentifyMessage = async function _DefaultIdentifyService_consumeIdentifyMessage(remotePeer, message) {
|
|
335
|
+
if (message == null) {
|
|
336
|
+
throw new Error('Message was null or undefined');
|
|
337
|
+
}
|
|
338
|
+
log('received identify from %p', remotePeer);
|
|
339
|
+
if (message.signedPeerRecord == null) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
const envelope = await RecordEnvelope.openAndCertify(message.signedPeerRecord, PeerRecord.DOMAIN);
|
|
343
|
+
const peerRecord = PeerRecord.createFromProtobuf(envelope.payload);
|
|
344
|
+
// Verify peerId
|
|
345
|
+
if (!peerRecord.peerId.equals(envelope.peerId)) {
|
|
346
|
+
throw new Error('signing key does not match PeerId in the PeerRecord');
|
|
347
|
+
}
|
|
348
|
+
// Make sure remote peer is the one sending the record
|
|
349
|
+
if (!remotePeer.equals(peerRecord.peerId)) {
|
|
350
|
+
throw new Error('signing key does not match remote PeerId');
|
|
351
|
+
}
|
|
352
|
+
let peer;
|
|
353
|
+
try {
|
|
354
|
+
peer = await this.peerStore.get(peerRecord.peerId);
|
|
355
|
+
}
|
|
356
|
+
catch (err) {
|
|
357
|
+
if (err.code !== 'ERR_NOT_FOUND') {
|
|
358
|
+
throw err;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
log('received signedPeerRecord in push from %p', remotePeer);
|
|
362
|
+
let metadata = new Map();
|
|
363
|
+
if (peer?.peerRecordEnvelope != null) {
|
|
364
|
+
const storedEnvelope = await RecordEnvelope.createFromProtobuf(peer.peerRecordEnvelope);
|
|
365
|
+
const storedRecord = PeerRecord.createFromProtobuf(storedEnvelope.payload);
|
|
366
|
+
// ensure seq is greater than, or equal to, the last received
|
|
367
|
+
if (storedRecord.seqNumber >= peerRecord.seqNumber) {
|
|
368
|
+
log('sequence number was lower or equal to existing sequence number - stored: %d received: %d', storedRecord.seqNumber, peerRecord.seqNumber);
|
|
369
|
+
}
|
|
370
|
+
metadata = peer.metadata;
|
|
371
|
+
}
|
|
372
|
+
if (message.agentVersion != null) {
|
|
373
|
+
metadata.set('AgentVersion', uint8ArrayFromString(message.agentVersion));
|
|
374
|
+
}
|
|
375
|
+
if (message.protocolVersion != null) {
|
|
376
|
+
metadata.set('ProtocolVersion', uint8ArrayFromString(message.protocolVersion));
|
|
377
|
+
}
|
|
378
|
+
await this.peerStore.patch(peerRecord.peerId, {
|
|
379
|
+
peerRecordEnvelope: message.signedPeerRecord,
|
|
380
|
+
protocols: message.protocols,
|
|
381
|
+
addresses: peerRecord.multiaddrs.map(multiaddr => ({
|
|
382
|
+
isCertified: true,
|
|
383
|
+
multiaddr
|
|
384
|
+
})),
|
|
385
|
+
metadata
|
|
386
|
+
});
|
|
387
|
+
log('consumed signedPeerRecord sent in push from %p', remotePeer);
|
|
388
|
+
return {
|
|
389
|
+
seq: peerRecord.seqNumber,
|
|
390
|
+
addresses: peerRecord.multiaddrs
|
|
391
|
+
};
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* Takes the `addr` and converts it to a Multiaddr if possible
|
|
395
|
+
*/
|
|
396
|
+
function getCleanMultiaddr(addr) {
|
|
397
|
+
if (addr != null && addr.length > 0) {
|
|
398
|
+
try {
|
|
399
|
+
return multiaddr(addr);
|
|
400
|
+
}
|
|
401
|
+
catch {
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
//# sourceMappingURL=identify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identify.js","sourceRoot":"","sources":["../../../src/identify/identify.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,aAAa,EACb,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;AAEhD,O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