libp2p 0.35.8 → 0.35.9-rc.0
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/src/circuit/auto-relay.d.ts +8 -10
- package/dist/src/circuit/auto-relay.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -2
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/content-routing/utils.d.ts +3 -3
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +5 -5
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/identify/index.d.ts +4 -4
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-store/address-book.d.ts +28 -84
- package/dist/src/peer-store/address-book.d.ts.map +1 -1
- package/dist/src/peer-store/index.d.ts +25 -94
- package/dist/src/peer-store/index.d.ts.map +1 -1
- package/dist/src/peer-store/key-book.d.ts +31 -15
- package/dist/src/peer-store/key-book.d.ts.map +1 -1
- package/dist/src/peer-store/metadata-book.d.ts +33 -29
- package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
- package/dist/src/peer-store/pb/peer.d.ts +222 -0
- package/dist/src/peer-store/proto-book.d.ts +28 -29
- package/dist/src/peer-store/proto-book.d.ts.map +1 -1
- package/dist/src/peer-store/store.d.ts +46 -0
- package/dist/src/peer-store/store.d.ts.map +1 -0
- package/dist/src/peer-store/types.d.ts +199 -0
- package/dist/src/peer-store/types.d.ts.map +1 -0
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/record/peer-record/index.d.ts +2 -2
- package/dist/src/record/peer-record/index.d.ts.map +1 -1
- package/dist/src/registrar.d.ts +5 -5
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/package.json +11 -16
- package/src/circuit/auto-relay.js +19 -19
- package/src/connection-manager/auto-dialler.js +6 -3
- package/src/connection-manager/index.js +29 -20
- package/src/content-routing/utils.js +4 -4
- package/src/dialer/dial-request.js +4 -1
- package/src/dialer/index.js +9 -6
- package/src/identify/index.js +28 -23
- package/src/index.js +33 -27
- package/src/peer-routing.js +4 -1
- package/src/peer-store/address-book.js +238 -227
- package/src/peer-store/index.js +77 -110
- package/src/peer-store/key-book.js +99 -54
- package/src/peer-store/metadata-book.js +171 -101
- package/src/peer-store/pb/peer.d.ts +222 -0
- package/src/peer-store/pb/peer.js +643 -0
- package/src/peer-store/pb/peer.proto +31 -0
- package/src/peer-store/proto-book.js +171 -105
- package/src/peer-store/store.js +250 -0
- package/src/peer-store/types.ts +245 -0
- package/src/ping/index.js +6 -0
- package/src/record/peer-record/index.js +1 -1
- package/src/record/utils.js +1 -1
- package/src/registrar.js +4 -4
- package/src/upgrader.js +3 -1
- package/dist/src/peer-store/book.d.ts +0 -81
- package/dist/src/peer-store/book.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/consts.d.ts +0 -6
- package/dist/src/peer-store/persistent/consts.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/index.d.ts +0 -129
- package/dist/src/peer-store/persistent/index.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/pb/address-book.d.ts +0 -198
- package/dist/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
- package/src/peer-store/book.js +0 -124
- package/src/peer-store/persistent/consts.js +0 -15
- package/src/peer-store/persistent/index.js +0 -408
- package/src/peer-store/persistent/pb/address-book.d.ts +0 -198
- package/src/peer-store/persistent/pb/address-book.js +0 -522
- package/src/peer-store/persistent/pb/address-book.proto +0 -27
- package/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
- package/src/peer-store/persistent/pb/proto-book.js +0 -157
- package/src/peer-store/persistent/pb/proto-book.proto +0 -5
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type PeerId from 'peer-id';
|
|
2
|
+
import type { Multiaddr } from 'multiaddr';
|
|
3
|
+
import type Envelope from '../record/envelope';
|
|
4
|
+
import type { PublicKey } from 'libp2p-interfaces/src/keys/types';
|
|
5
|
+
export interface Address {
|
|
6
|
+
/**
|
|
7
|
+
* Peer multiaddr
|
|
8
|
+
*/
|
|
9
|
+
multiaddr: Multiaddr;
|
|
10
|
+
/**
|
|
11
|
+
* Obtained from a signed peer record
|
|
12
|
+
*/
|
|
13
|
+
isCertified: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface Peer {
|
|
16
|
+
/**
|
|
17
|
+
* Peer's peer-id instance
|
|
18
|
+
*/
|
|
19
|
+
id: PeerId;
|
|
20
|
+
/**
|
|
21
|
+
* Peer's addresses containing its multiaddrs and metadata
|
|
22
|
+
*/
|
|
23
|
+
addresses: Address[];
|
|
24
|
+
/**
|
|
25
|
+
* Peer's supported protocols
|
|
26
|
+
*/
|
|
27
|
+
protocols: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Peer's metadata map
|
|
30
|
+
*/
|
|
31
|
+
metadata: Map<string, Uint8Array>;
|
|
32
|
+
/**
|
|
33
|
+
* May be set if the key that this Peer has is an RSA key
|
|
34
|
+
*/
|
|
35
|
+
pubKey?: PublicKey;
|
|
36
|
+
/**
|
|
37
|
+
* The last peer record envelope received
|
|
38
|
+
*/
|
|
39
|
+
peerRecordEnvelope?: Uint8Array;
|
|
40
|
+
}
|
|
41
|
+
export interface CertifiedRecord {
|
|
42
|
+
raw: Uint8Array;
|
|
43
|
+
seqNumber: number;
|
|
44
|
+
}
|
|
45
|
+
export interface AddressBookEntry {
|
|
46
|
+
addresses: Address[];
|
|
47
|
+
record: CertifiedRecord;
|
|
48
|
+
}
|
|
49
|
+
export interface Book<Type> {
|
|
50
|
+
/**
|
|
51
|
+
* Get the known data of a peer
|
|
52
|
+
*/
|
|
53
|
+
get: (peerId: PeerId) => Promise<Type>;
|
|
54
|
+
/**
|
|
55
|
+
* Set the known data of a peer
|
|
56
|
+
*/
|
|
57
|
+
set: (peerId: PeerId, data: Type) => Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Remove the known data of a peer
|
|
60
|
+
*/
|
|
61
|
+
delete: (peerId: PeerId) => Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* AddressBook containing a map of peerIdStr to Address.
|
|
65
|
+
*/
|
|
66
|
+
export interface AddressBook {
|
|
67
|
+
/**
|
|
68
|
+
* ConsumePeerRecord adds addresses from a signed peer record contained in a record envelope.
|
|
69
|
+
* This will return a boolean that indicates if the record was successfully processed and added
|
|
70
|
+
* into the AddressBook
|
|
71
|
+
*/
|
|
72
|
+
consumePeerRecord: (envelope: Envelope) => Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Get the raw Envelope for a peer. Returns
|
|
75
|
+
* undefined if no Envelope is found
|
|
76
|
+
*/
|
|
77
|
+
getRawEnvelope: (peerId: PeerId) => Promise<Uint8Array | undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* Get an Envelope containing a PeerRecord for the given peer.
|
|
80
|
+
* Returns undefined if no record exists.
|
|
81
|
+
*/
|
|
82
|
+
getPeerRecord: (peerId: PeerId) => Promise<Envelope | undefined>;
|
|
83
|
+
/**
|
|
84
|
+
* Add known addresses of a provided peer.
|
|
85
|
+
* If the peer is not known, it is set with the given addresses.
|
|
86
|
+
*/
|
|
87
|
+
add: (peerId: PeerId, multiaddrs: Multiaddr[]) => Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Set the known addresses of a peer
|
|
90
|
+
*/
|
|
91
|
+
set: (peerId: PeerId, data: Multiaddr[]) => Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Return the known addresses of a peer
|
|
94
|
+
*/
|
|
95
|
+
get: (peerId: PeerId) => Promise<Address[]>;
|
|
96
|
+
/**
|
|
97
|
+
* Get the known multiaddrs for a given peer. All returned multiaddrs
|
|
98
|
+
* will include the encapsulated `PeerId` of the peer.
|
|
99
|
+
*/
|
|
100
|
+
getMultiaddrsForPeer: (peerId: PeerId, addressSorter?: (ms: Address[]) => Address[]) => Promise<Multiaddr[]>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* KeyBook containing a map of peerIdStr to their PeerId with public keys.
|
|
104
|
+
*/
|
|
105
|
+
export interface KeyBook {
|
|
106
|
+
/**
|
|
107
|
+
* Get the known data of a peer
|
|
108
|
+
*/
|
|
109
|
+
get: (peerId: PeerId) => Promise<PublicKey | undefined>;
|
|
110
|
+
/**
|
|
111
|
+
* Set the known data of a peer
|
|
112
|
+
*/
|
|
113
|
+
set: (peerId: PeerId, data: PublicKey) => Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
* Remove the known data of a peer
|
|
116
|
+
*/
|
|
117
|
+
delete: (peerId: PeerId) => Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* MetadataBook containing a map of peerIdStr to their metadata Map.
|
|
121
|
+
*/
|
|
122
|
+
export interface MetadataBook extends Book<Map<string, Uint8Array>> {
|
|
123
|
+
/**
|
|
124
|
+
* Set a specific metadata value
|
|
125
|
+
*/
|
|
126
|
+
setValue: (peerId: PeerId, key: string, value: Uint8Array) => Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Get specific metadata value, if it exists
|
|
129
|
+
*/
|
|
130
|
+
getValue: (peerId: PeerId, key: string) => Promise<Uint8Array | undefined>;
|
|
131
|
+
/**
|
|
132
|
+
* Deletes the provided peer metadata key from the book
|
|
133
|
+
*/
|
|
134
|
+
deleteValue: (peerId: PeerId, key: string) => Promise<void>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* ProtoBook containing a map of peerIdStr to supported protocols.
|
|
138
|
+
*/
|
|
139
|
+
export interface ProtoBook extends Book<string[]> {
|
|
140
|
+
/**
|
|
141
|
+
* Adds known protocols of a provided peer.
|
|
142
|
+
* If the peer was not known before, it will be added.
|
|
143
|
+
*/
|
|
144
|
+
add: (peerId: PeerId, protocols: string[]) => Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Removes known protocols of a provided peer.
|
|
147
|
+
* If the protocols did not exist before, nothing will be done.
|
|
148
|
+
*/
|
|
149
|
+
remove: (peerId: PeerId, protocols: string[]) => Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
export interface PeerProtocolsChangeEvent {
|
|
152
|
+
peerId: PeerId;
|
|
153
|
+
protocols: string[];
|
|
154
|
+
}
|
|
155
|
+
export interface PeerMultiaddrsChangeEvent {
|
|
156
|
+
peerId: PeerId;
|
|
157
|
+
multiaddrs: Multiaddr[];
|
|
158
|
+
}
|
|
159
|
+
export interface PeerPublicKeyChangeEvent {
|
|
160
|
+
peerId: PeerId;
|
|
161
|
+
pubKey?: PublicKey;
|
|
162
|
+
}
|
|
163
|
+
export interface PeerMetadataChangeEvent {
|
|
164
|
+
peerId: PeerId;
|
|
165
|
+
metadata: Map<string, Uint8Array>;
|
|
166
|
+
}
|
|
167
|
+
export declare type EventName = 'peer' | 'change:protocols' | 'change:multiaddrs' | 'change:pubkey' | 'change:metadata';
|
|
168
|
+
export interface PeerStoreEvents {
|
|
169
|
+
'peer': (event: PeerId) => void;
|
|
170
|
+
'change:protocols': (event: PeerProtocolsChangeEvent) => void;
|
|
171
|
+
'change:multiaddrs': (event: PeerMultiaddrsChangeEvent) => void;
|
|
172
|
+
'change:pubkey': (event: PeerPublicKeyChangeEvent) => void;
|
|
173
|
+
'change:metadata': (event: PeerMetadataChangeEvent) => void;
|
|
174
|
+
}
|
|
175
|
+
export interface PeerStore {
|
|
176
|
+
addressBook: AddressBook;
|
|
177
|
+
keyBook: KeyBook;
|
|
178
|
+
metadataBook: MetadataBook;
|
|
179
|
+
protoBook: ProtoBook;
|
|
180
|
+
getPeers: () => AsyncIterable<Peer>;
|
|
181
|
+
delete: (peerId: PeerId) => Promise<void>;
|
|
182
|
+
has: (peerId: PeerId) => Promise<boolean>;
|
|
183
|
+
get: (peerId: PeerId) => Promise<Peer>;
|
|
184
|
+
on: <U extends keyof PeerStoreEvents>(event: U, listener: PeerStoreEvents[U]) => this;
|
|
185
|
+
once: <U extends keyof PeerStoreEvents>(event: U, listener: PeerStoreEvents[U]) => this;
|
|
186
|
+
emit: <U extends keyof PeerStoreEvents>(event: U, ...args: Parameters<PeerStoreEvents[U]>) => boolean;
|
|
187
|
+
}
|
|
188
|
+
export interface Store {
|
|
189
|
+
has: (peerId: PeerId) => Promise<boolean>;
|
|
190
|
+
save: (peer: Peer) => Promise<void>;
|
|
191
|
+
load: (peerId: PeerId) => Promise<Peer>;
|
|
192
|
+
merge: (peerId: PeerId, data: Partial<Peer>) => Promise<void>;
|
|
193
|
+
all: () => AsyncIterable<Peer>;
|
|
194
|
+
lock: {
|
|
195
|
+
readLock: () => Promise<() => void>;
|
|
196
|
+
writeLock: () => Promise<() => void>;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/peer-store/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,SAAS,CAAA;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,QAAQ,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAA;AAEjE,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IAEV;;OAEG;IACH,SAAS,EAAE,OAAO,EAAE,CAAA;IAEpB;;OAEG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E9B,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,IAAI,CAAC,CAAA;QACnC,SAAS,EAAE,MAAM,OAAO,CAAC,MAAM,IAAI,CAAC,CAAA;KACrC,CAAA;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ping/index.js"],"names":[],"mappings":";AAiBA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,4BAJW,MAAM,QACN,MAAM,GAAC,SAAS,GACd,QAAQ,MAAM,CAAC,CA2B3B;;;;cAtCY,OAAO,KAAK,CAAC;cAEb,OAAO,SAAS,CAAC;iBADjB,OAAO,WAAW,EAAE,SAAS;AAuC1C;;;;GAIG;AACH,6BAFW,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ping/index.js"],"names":[],"mappings":";AAiBA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,4BAJW,MAAM,QACN,MAAM,GAAC,SAAS,GACd,QAAQ,MAAM,CAAC,CA2B3B;;;;cAtCY,OAAO,KAAK,CAAC;cAEb,OAAO,SAAS,CAAC;iBADjB,OAAO,WAAW,EAAE,SAAS;AAuC1C;;;;GAIG;AACH,6BAFW,MAAM,QAOhB;AAED;;;;GAIG;AACH,+BAFW,MAAM,QAOhB;mBA3DY,OAAO,0CAA0C,EAAE,WAAW"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export = PeerRecord;
|
|
2
2
|
/**
|
|
3
|
-
* @typedef {import('../../peer-store/
|
|
3
|
+
* @typedef {import('../../peer-store/types').Address} Address
|
|
4
4
|
* @typedef {import('libp2p-interfaces/src/record/types').Record} Record
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
@@ -56,5 +56,5 @@ import { Multiaddr } from "multiaddr";
|
|
|
56
56
|
*/
|
|
57
57
|
declare function createFromProtobuf(buf: Uint8Array): PeerRecord;
|
|
58
58
|
import { ENVELOPE_DOMAIN_PEER_RECORD } from "./consts";
|
|
59
|
-
type Address = import('../../peer-store/
|
|
59
|
+
type Address = import('../../peer-store/types').Address;
|
|
60
60
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/peer-record/index.js"],"names":[],"mappings":";AAYA;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;;;;;OASG;IACH;QAJ0B,MAAM,EAArB,MAAM;QACc,UAAU,EAA9B,SAAS,EAAE;QACK,SAAS;OAYnC;IATC,eAAyC;IACzC,kBAA8C;IAE9C,eAAoB;IACpB,wBAA4B;IAC5B,kBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAgBtB;IAED;;;;;OAKG;IACH,cAHW,OAAO,GACL,OAAO,CAuBnB;CACF;;;;cA9EY,OAAO,oCAAoC,EAAE,MAAM;;;AAgFhE;;;;;GAKG;AACH,yCAHW,UAAU,GACR,UAAU,CAUtB;;eA/FY,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/peer-record/index.js"],"names":[],"mappings":";AAYA;;;GAGG;AAEH;;GAEG;AACH;IACE;;;;;;;;;OASG;IACH;QAJ0B,MAAM,EAArB,MAAM;QACc,UAAU,EAA9B,SAAS,EAAE;QACK,SAAS;OAYnC;IATC,eAAyC;IACzC,kBAA8C;IAE9C,eAAoB;IACpB,wBAA4B;IAC5B,kBAA0B;IAG1B,iCAAyB;IAG3B;;;;OAIG;IACH,WAFa,UAAU,CAgBtB;IAED;;;;;OAKG;IACH,cAHW,OAAO,GACL,OAAO,CAuBnB;CACF;;;;cA9EY,OAAO,oCAAoC,EAAE,MAAM;;;AAgFhE;;;;;GAKG;AACH,yCAHW,UAAU,GACR,UAAU,CAUtB;;eA/FY,OAAO,wBAAwB,EAAE,OAAO"}
|
package/dist/src/registrar.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export = Registrar;
|
|
2
2
|
/**
|
|
3
3
|
* @typedef {import('peer-id')} PeerId
|
|
4
|
-
* @typedef {import('./peer-store')} PeerStore
|
|
4
|
+
* @typedef {import('./peer-store/types').PeerStore} PeerStore
|
|
5
5
|
* @typedef {import('./connection-manager')} ConnectionManager
|
|
6
6
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
7
7
|
* @typedef {import('./').HandlerProps} HandlerProps
|
|
@@ -23,7 +23,7 @@ declare class Registrar {
|
|
|
23
23
|
peerStore: PeerStore;
|
|
24
24
|
connectionManager: ConnectionManager;
|
|
25
25
|
});
|
|
26
|
-
peerStore: import("./peer-store");
|
|
26
|
+
peerStore: import("./peer-store/types").PeerStore;
|
|
27
27
|
connectionManager: import("./connection-manager");
|
|
28
28
|
/**
|
|
29
29
|
* Map of topologies
|
|
@@ -59,9 +59,9 @@ declare class Registrar {
|
|
|
59
59
|
* Register handlers for a set of multicodecs given
|
|
60
60
|
*
|
|
61
61
|
* @param {Topology} topology - protocol topology
|
|
62
|
-
* @returns {string} registrar identifier
|
|
62
|
+
* @returns {Promise<string>} registrar identifier
|
|
63
63
|
*/
|
|
64
|
-
register(topology: Topology): string
|
|
64
|
+
register(topology: Topology): Promise<string>;
|
|
65
65
|
/**
|
|
66
66
|
* Unregister topology.
|
|
67
67
|
*
|
|
@@ -76,7 +76,7 @@ declare namespace Registrar {
|
|
|
76
76
|
import Topology = require("libp2p-interfaces/src/topology");
|
|
77
77
|
type Connection = import("libp2p-interfaces/src/connection/connection");
|
|
78
78
|
type PeerId = import('peer-id');
|
|
79
|
-
type PeerStore = import('./peer-store');
|
|
79
|
+
type PeerStore = import('./peer-store/types').PeerStore;
|
|
80
80
|
type ConnectionManager = import('./connection-manager');
|
|
81
81
|
type HandlerProps = import('./').HandlerProps;
|
|
82
82
|
//# sourceMappingURL=registrar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.js"],"names":[],"mappings":";AAaA;;;;;;GAMG;AAEH;;GAEG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH;QAJ4B,SAAS,EAA1B,SAAS;QACgB,iBAAiB,EAA1C,iBAAiB;OAsB3B;IAjBC,
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.js"],"names":[],"mappings":";AAaA;;;;;;GAMG;AAEH;;GAEG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH;QAJ4B,SAAS,EAA1B,SAAS;QACgB,iBAAiB,EAA1C,iBAAiB;OAsB3B;IAjBC,kDAA0B;IAE1B,kDAA0C;IAE1C;;;;OAIG;IACH,YAFU,IAAI,MAAM,EAAE,QAAQ,CAAC,CAEJ;IAE3B,2FAA2F;IAE3F,qBAFuB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAE/D;IA+D1B;;;;;OAKG;IACH,0BAHW,UAAU,GACR,IAAI,CAMhB;IA5DD;;OAEG;IACH,4BATyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,EAWxF;IAZD;;OAEG;IACH,0BAFyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAIxF;IASD;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,UAAU,GAAG,IAAI,CAI7B;IAED;;;;;OAKG;IACH,mBAHW,QAAQ,GACN,QAAQ,MAAM,CAAC,CAiB3B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAInB;CAaF;;;;;;cA9GY,OAAO,SAAS,CAAC;iBACjB,OAAO,oBAAoB,EAAE,SAAS;yBACtC,OAAO,sBAAsB,CAAC;oBAE9B,OAAO,IAAI,EAAE,YAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.js"],"names":[],"mappings":";AAiBA;;;;;;;;GAQG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH;mBAPW,MAAM;;;;mCAIO,UAAU,KAAK,IAAI;sCACnB,UAAU,KAAK,IAAI;OAmB1C;IATC,kBAA0B;IAC1B,yCAAsB;IACtB,0EAAsB;IACtB,qFAAoB;IACpB,sCAAsC;IACtC,WADW,OAAO,QAAQ,CAAC,GAAG,IAAI,CACb;IACrB,yBAA0B;IAC1B,2BAlBsB,UAAU,KAAK,IAAI,CAkBT;IAChC,8BAlBsB,UAAU,KAAK,IAAI,CAkBH;IAGxC;;;;;;OAMG;IACH,uBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CA6D/B;IAED;;;;;;OAMG;IACH,wBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CAoE/B;IAED;;;;;;;;;;;;OAYG;IACH,
|
|
1
|
+
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../src/upgrader.js"],"names":[],"mappings":";AAiBA;;;;;;;;GAQG;AAEH;;;;;GAKG;AAEH;IACE;;;;;;;;OAQG;IACH;mBAPW,MAAM;;;;mCAIO,UAAU,KAAK,IAAI;sCACnB,UAAU,KAAK,IAAI;OAmB1C;IATC,kBAA0B;IAC1B,yCAAsB;IACtB,0EAAsB;IACtB,qFAAoB;IACpB,sCAAsC;IACtC,WADW,OAAO,QAAQ,CAAC,GAAG,IAAI,CACb;IACrB,yBAA0B;IAC1B,2BAlBsB,UAAU,KAAK,IAAI,CAkBT;IAChC,8BAlBsB,UAAU,KAAK,IAAI,CAkBH;IAGxC;;;;;;OAMG;IACH,uBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CA6D/B;IAED;;;;;;OAMG;IACH,wBAHW,mBAAmB,GACjB,QAAQ,UAAU,CAAC,CAoE/B;IAED;;;;;;;;;;;;OAYG;IACH,0BAgHC;IAED;;;;;;;;OAQG;IACH,kBAGC;IAED;;;;;;;;;OASG;IACH,wBAqBC;IAED;;;;;;;;;;;OAWG;IACH,yBAqBC;IAED;;;;;;;;;OASG;IACH,2BAYC;IAED;;;;;;;;;OASG;IACH,0BAWC;CACF;;;;;2BA3bY,OAAO,uCAAuC,EAAE,mBAAmB;;oBACnE,OAAO,0CAA0C,EAAE,YAAY;aAC/D,OAAO,0CAA0C,EAAE,KAAK;mBACxD,OAAO,0CAA0C,EAAE,WAAW;cAC9D,OAAO,oCAAoC,EAAE,MAAM;;iBAEnD,OAAO,WAAW,EAAE,SAAS;;;;;UAK5B,mBAAmB;gBACnB,MAAM;cACN,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libp2p",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.9-rc.0",
|
|
4
4
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
|
5
5
|
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -19,21 +19,18 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "aegir lint",
|
|
22
|
-
"build": "
|
|
23
|
-
"build:proto": "npm run build:proto:circuit && npm run build:proto:identify && npm run build:proto:plaintext && npm run build:proto:address-book && npm run build:proto:proto-book && npm run build:proto:peer-record && npm run build:proto:envelope",
|
|
22
|
+
"build:proto": "npm run build:proto:circuit && npm run build:proto:identify && npm run build:proto:plaintext && npm run build:proto:address-book && npm run build:proto:proto-book && npm run build:proto:peer && npm run build:proto:peer-record && npm run build:proto:envelope",
|
|
24
23
|
"build:proto:circuit": "pbjs -t static-module -w commonjs -r libp2p-circuit --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/circuit/protocol/index.js ./src/circuit/protocol/index.proto",
|
|
25
24
|
"build:proto:identify": "pbjs -t static-module -w commonjs -r libp2p-identify --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/identify/message.js ./src/identify/message.proto",
|
|
26
25
|
"build:proto:plaintext": "pbjs -t static-module -w commonjs -r libp2p-plaintext --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/insecure/proto.js ./src/insecure/proto.proto",
|
|
27
|
-
"build:proto:
|
|
28
|
-
"build:proto:proto-book": "pbjs -t static-module -w commonjs -r libp2p-proto-book --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-store/persistent/pb/proto-book.js ./src/peer-store/persistent/pb/proto-book.proto",
|
|
26
|
+
"build:proto:peer": "pbjs -t static-module -w commonjs -r libp2p-peer --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-store/pb/peer.js ./src/peer-store/pb/peer.proto",
|
|
29
27
|
"build:proto:peer-record": "pbjs -t static-module -w commonjs -r libp2p-peer-record --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/peer-record/peer-record.js ./src/record/peer-record/peer-record.proto",
|
|
30
28
|
"build:proto:envelope": "pbjs -t static-module -w commonjs -r libp2p-envelope --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/record/envelope/envelope.js ./src/record/envelope/envelope.proto",
|
|
31
|
-
"build:proto-types": "npm run build:proto-types:circuit && npm run build:proto-types:identify && npm run build:proto-types:plaintext && npm run build:proto-types:address-book && npm run build:proto-types:proto-book && npm run build:proto-types:peer-record && npm run build:proto-types:envelope",
|
|
29
|
+
"build:proto-types": "npm run build:proto-types:circuit && npm run build:proto-types:identify && npm run build:proto-types:plaintext && npm run build:proto-types:address-book && npm run build:proto-types:proto-book && npm run build:proto-types:peer && npm run build:proto-types:peer-record && npm run build:proto-types:envelope",
|
|
32
30
|
"build:proto-types:circuit": "pbts -o src/circuit/protocol/index.d.ts src/circuit/protocol/index.js",
|
|
33
31
|
"build:proto-types:identify": "pbts -o src/identify/message.d.ts src/identify/message.js",
|
|
34
32
|
"build:proto-types:plaintext": "pbts -o src/insecure/proto.d.ts src/insecure/proto.js",
|
|
35
|
-
"build:proto-types:
|
|
36
|
-
"build:proto-types:proto-book": "pbts -o src/peer-store/persistent/pb/proto-book.d.ts src/peer-store/persistent/pb/proto-book.js",
|
|
33
|
+
"build:proto-types:peer": "pbts -o src/peer-store/pb/peer.d.ts src/peer-store/pb/peer.js",
|
|
37
34
|
"build:proto-types:peer-record": "pbts -o src/record/peer-record/peer-record.d.ts src/record/peer-record/peer-record.js",
|
|
38
35
|
"build:proto-types:envelope": "pbts -o src/record/envelope/envelope.d.ts src/record/envelope/envelope.js",
|
|
39
36
|
"test": "aegir test",
|
|
@@ -42,7 +39,6 @@
|
|
|
42
39
|
"test:browser": "aegir test -t browser",
|
|
43
40
|
"test:examples": "cd examples && npm run test:all",
|
|
44
41
|
"test:interop": "LIBP2P_JS=$PWD npx aegir test -t node -f ./node_modules/libp2p-interop/test/*",
|
|
45
|
-
"prepare": "aegir build --no-bundle",
|
|
46
42
|
"release": "aegir release -t node -t browser",
|
|
47
43
|
"release-minor": "aegir release --type minor -t node -t browser",
|
|
48
44
|
"release-major": "aegir release --type major -t node -t browser",
|
|
@@ -87,6 +83,7 @@
|
|
|
87
83
|
"any-signal": "^2.1.1",
|
|
88
84
|
"bignumber.js": "^9.0.1",
|
|
89
85
|
"class-is": "^1.1.0",
|
|
86
|
+
"datastore-core": "^6.0.7",
|
|
90
87
|
"debug": "^4.3.1",
|
|
91
88
|
"err-code": "^3.0.0",
|
|
92
89
|
"es6-promisify": "^7.0.0",
|
|
@@ -105,10 +102,11 @@
|
|
|
105
102
|
"it-pipe": "^1.1.0",
|
|
106
103
|
"it-take": "^1.0.0",
|
|
107
104
|
"libp2p-crypto": "^0.21.0",
|
|
108
|
-
"libp2p-interfaces": "^
|
|
105
|
+
"libp2p-interfaces": "^4.0.0",
|
|
109
106
|
"libp2p-utils": "^0.4.0",
|
|
110
107
|
"mafmt": "^10.0.0",
|
|
111
108
|
"merge-options": "^3.0.4",
|
|
109
|
+
"mortice": "^2.0.1",
|
|
112
110
|
"multiaddr": "^10.0.0",
|
|
113
111
|
"multiformats": "^9.0.0",
|
|
114
112
|
"multistream-select": "^2.0.0",
|
|
@@ -141,7 +139,6 @@
|
|
|
141
139
|
"@types/varint": "^6.0.0",
|
|
142
140
|
"aegir": "^36.0.0",
|
|
143
141
|
"buffer": "^6.0.3",
|
|
144
|
-
"datastore-core": "^6.0.7",
|
|
145
142
|
"delay": "^5.0.0",
|
|
146
143
|
"into-stream": "^6.0.0",
|
|
147
144
|
"ipfs-http-client": "^54.0.2",
|
|
@@ -152,11 +149,9 @@
|
|
|
152
149
|
"libp2p-bootstrap": "^0.14.0",
|
|
153
150
|
"libp2p-delegated-content-routing": "^0.11.0",
|
|
154
151
|
"libp2p-delegated-peer-routing": "^0.11.1",
|
|
155
|
-
"libp2p-
|
|
156
|
-
"libp2p-
|
|
157
|
-
"libp2p-
|
|
158
|
-
"libp2p-interop": "^0.5.0",
|
|
159
|
-
"libp2p-kad-dht": "^0.27.1",
|
|
152
|
+
"libp2p-interfaces-compliance-tests": "^4.0.8",
|
|
153
|
+
"libp2p-interop": "^0.7.0",
|
|
154
|
+
"libp2p-kad-dht": "^0.28.3",
|
|
160
155
|
"libp2p-mdns": "^0.18.0",
|
|
161
156
|
"libp2p-mplex": "^0.10.1",
|
|
162
157
|
"libp2p-tcp": "^0.17.0",
|
|
@@ -8,7 +8,6 @@ const log = Object.assign(debug('libp2p:auto-relay'), {
|
|
|
8
8
|
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
|
|
9
9
|
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
|
|
10
10
|
const { Multiaddr } = require('multiaddr')
|
|
11
|
-
const PeerId = require('peer-id')
|
|
12
11
|
|
|
13
12
|
const { relay: multicodec } = require('./multicodec')
|
|
14
13
|
const { canHop } = require('./circuit/hop')
|
|
@@ -22,7 +21,8 @@ const {
|
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
25
|
-
* @typedef {import('../peer-store/
|
|
24
|
+
* @typedef {import('../peer-store/types').Address} Address
|
|
25
|
+
* @typedef {import('peer-id')} PeerId
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -91,7 +91,7 @@ class AutoRelay {
|
|
|
91
91
|
|
|
92
92
|
// If no protocol, check if we were keeping the peer before as a listenRelay
|
|
93
93
|
if (!hasProtocol && this._listenRelays.has(id)) {
|
|
94
|
-
this._removeListenRelay(id)
|
|
94
|
+
await this._removeListenRelay(id)
|
|
95
95
|
return
|
|
96
96
|
} else if (!hasProtocol || this._listenRelays.has(id)) {
|
|
97
97
|
return
|
|
@@ -113,7 +113,7 @@ class AutoRelay {
|
|
|
113
113
|
const supportsHop = await canHop({ connection })
|
|
114
114
|
|
|
115
115
|
if (supportsHop) {
|
|
116
|
-
this._peerStore.metadataBook.
|
|
116
|
+
await this._peerStore.metadataBook.setValue(peerId, HOP_METADATA_KEY, uint8ArrayFromString(HOP_METADATA_VALUE))
|
|
117
117
|
await this._addListenRelay(connection, id)
|
|
118
118
|
}
|
|
119
119
|
} catch (/** @type {any} */ err) {
|
|
@@ -125,7 +125,6 @@ class AutoRelay {
|
|
|
125
125
|
* Peer disconnects.
|
|
126
126
|
*
|
|
127
127
|
* @param {Connection} connection - connection to the peer
|
|
128
|
-
* @returns {void}
|
|
129
128
|
*/
|
|
130
129
|
_onPeerDisconnected (connection) {
|
|
131
130
|
const peerId = connection.remotePeer
|
|
@@ -136,7 +135,9 @@ class AutoRelay {
|
|
|
136
135
|
return
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
this._removeListenRelay(id)
|
|
138
|
+
this._removeListenRelay(id).catch(err => {
|
|
139
|
+
log.error(err)
|
|
140
|
+
})
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
/**
|
|
@@ -154,7 +155,7 @@ class AutoRelay {
|
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
// Get peer known addresses and sort them per public addresses first
|
|
157
|
-
const remoteAddrs = this._peerStore.addressBook.getMultiaddrsForPeer(
|
|
158
|
+
const remoteAddrs = await this._peerStore.addressBook.getMultiaddrsForPeer(
|
|
158
159
|
connection.remotePeer, this._addressSorter
|
|
159
160
|
)
|
|
160
161
|
|
|
@@ -180,12 +181,11 @@ class AutoRelay {
|
|
|
180
181
|
*
|
|
181
182
|
* @private
|
|
182
183
|
* @param {string} id - peer identifier string.
|
|
183
|
-
* @returns {void}
|
|
184
184
|
*/
|
|
185
|
-
_removeListenRelay (id) {
|
|
185
|
+
async _removeListenRelay (id) {
|
|
186
186
|
if (this._listenRelays.delete(id)) {
|
|
187
187
|
// TODO: this should be responsibility of the connMgr
|
|
188
|
-
this._listenOnAvailableHopRelays([id])
|
|
188
|
+
await this._listenOnAvailableHopRelays([id])
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
@@ -197,7 +197,6 @@ class AutoRelay {
|
|
|
197
197
|
* 3. Search the network.
|
|
198
198
|
*
|
|
199
199
|
* @param {string[]} [peersToIgnore]
|
|
200
|
-
* @returns {Promise<void>}
|
|
201
200
|
*/
|
|
202
201
|
async _listenOnAvailableHopRelays (peersToIgnore = []) {
|
|
203
202
|
// TODO: The peer redial issue on disconnect should be handled by connection gating
|
|
@@ -209,29 +208,30 @@ class AutoRelay {
|
|
|
209
208
|
const knownHopsToDial = []
|
|
210
209
|
|
|
211
210
|
// Check if we have known hop peers to use and attempt to listen on the already connected
|
|
212
|
-
for (const
|
|
211
|
+
for await (const { id, metadata } of this._peerStore.getPeers()) {
|
|
212
|
+
const idStr = id.toB58String()
|
|
213
|
+
|
|
213
214
|
// Continue to next if listening on this or peer to ignore
|
|
214
|
-
if (this._listenRelays.has(
|
|
215
|
+
if (this._listenRelays.has(idStr) || peersToIgnore.includes(idStr)) {
|
|
215
216
|
continue
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
const supportsHop =
|
|
219
|
+
const supportsHop = metadata.get(HOP_METADATA_KEY)
|
|
219
220
|
|
|
220
221
|
// Continue to next if it does not support Hop
|
|
221
222
|
if (!supportsHop || uint8ArrayToString(supportsHop) !== HOP_METADATA_VALUE) {
|
|
222
223
|
continue
|
|
223
224
|
}
|
|
224
225
|
|
|
225
|
-
const
|
|
226
|
-
const connection = this._connectionManager.get(peerId)
|
|
226
|
+
const connection = this._connectionManager.get(id)
|
|
227
227
|
|
|
228
228
|
// If not connected, store for possible later use.
|
|
229
229
|
if (!connection) {
|
|
230
|
-
knownHopsToDial.push(
|
|
230
|
+
knownHopsToDial.push(id)
|
|
231
231
|
continue
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
await this._addListenRelay(connection,
|
|
234
|
+
await this._addListenRelay(connection, idStr)
|
|
235
235
|
|
|
236
236
|
// Check if already listening on enough relays
|
|
237
237
|
if (this._listenRelays.size >= this.maxListeners) {
|
|
@@ -258,7 +258,7 @@ class AutoRelay {
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
const peerId = provider.id
|
|
261
|
-
this._peerStore.addressBook.add(peerId, provider.multiaddrs)
|
|
261
|
+
await this._peerStore.addressBook.add(peerId, provider.multiaddrs)
|
|
262
262
|
|
|
263
263
|
await this._tryToListenOnRelay(peerId)
|
|
264
264
|
|
|
@@ -4,6 +4,7 @@ const debug = require('debug')
|
|
|
4
4
|
const mergeOptions = require('merge-options')
|
|
5
5
|
// @ts-ignore retimer does not have types
|
|
6
6
|
const retimer = require('retimer')
|
|
7
|
+
const all = require('it-all')
|
|
7
8
|
|
|
8
9
|
const log = Object.assign(debug('libp2p:connection-manager:auto-dialler'), {
|
|
9
10
|
error: debug('libp2p:connection-manager:auto-dialler:err')
|
|
@@ -50,7 +51,7 @@ class AutoDialler {
|
|
|
50
51
|
/**
|
|
51
52
|
* Starts the auto dialer
|
|
52
53
|
*/
|
|
53
|
-
start () {
|
|
54
|
+
async start () {
|
|
54
55
|
if (!this._options.enabled) {
|
|
55
56
|
log('not enabled')
|
|
56
57
|
return
|
|
@@ -86,8 +87,10 @@ class AutoDialler {
|
|
|
86
87
|
return
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
// Sort peers on
|
|
90
|
-
|
|
90
|
+
// Sort peers on whether we know protocols of public keys for them
|
|
91
|
+
// TODO: assuming the `peerStore.getPeers()` order is stable this will mean
|
|
92
|
+
// we keep trying to connect to the same peers?
|
|
93
|
+
const peers = (await all(this._libp2p.peerStore.getPeers()))
|
|
91
94
|
.sort((a, b) => {
|
|
92
95
|
if (b.protocols && b.protocols.length && (!a.protocols || !a.protocols.length)) {
|
|
93
96
|
return 1
|
|
@@ -187,19 +187,22 @@ class ConnectionManager extends EventEmitter {
|
|
|
187
187
|
*
|
|
188
188
|
* @private
|
|
189
189
|
*/
|
|
190
|
-
_checkMetrics () {
|
|
190
|
+
async _checkMetrics () {
|
|
191
191
|
if (this._libp2p.metrics) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
192
|
+
try {
|
|
193
|
+
const movingAverages = this._libp2p.metrics.global.movingAverages
|
|
194
|
+
// @ts-ignore moving averages object types
|
|
195
|
+
const received = movingAverages.dataReceived[this._options.movingAverageInterval].movingAverage()
|
|
196
|
+
await this._checkMaxLimit('maxReceivedData', received)
|
|
197
|
+
// @ts-ignore moving averages object types
|
|
198
|
+
const sent = movingAverages.dataSent[this._options.movingAverageInterval].movingAverage()
|
|
199
|
+
await this._checkMaxLimit('maxSentData', sent)
|
|
200
|
+
const total = received + sent
|
|
201
|
+
await this._checkMaxLimit('maxData', total)
|
|
202
|
+
log('metrics update', total)
|
|
203
|
+
} finally {
|
|
204
|
+
this._timer = retimer(this._checkMetrics, this._options.pollInterval)
|
|
205
|
+
}
|
|
203
206
|
}
|
|
204
207
|
}
|
|
205
208
|
|
|
@@ -207,9 +210,8 @@ class ConnectionManager extends EventEmitter {
|
|
|
207
210
|
* Tracks the incoming connection and check the connection limit
|
|
208
211
|
*
|
|
209
212
|
* @param {Connection} connection
|
|
210
|
-
* @returns {void}
|
|
211
213
|
*/
|
|
212
|
-
onConnect (connection) {
|
|
214
|
+
async onConnect (connection) {
|
|
213
215
|
const peerId = connection.remotePeer
|
|
214
216
|
const peerIdStr = peerId.toB58String()
|
|
215
217
|
const storedConn = this.connections.get(peerIdStr)
|
|
@@ -222,13 +224,13 @@ class ConnectionManager extends EventEmitter {
|
|
|
222
224
|
this.connections.set(peerIdStr, [connection])
|
|
223
225
|
}
|
|
224
226
|
|
|
225
|
-
this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey)
|
|
227
|
+
await this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey)
|
|
226
228
|
|
|
227
229
|
if (!this._peerValues.has(peerIdStr)) {
|
|
228
230
|
this._peerValues.set(peerIdStr, this._options.defaultPeerValue)
|
|
229
231
|
}
|
|
230
232
|
|
|
231
|
-
this._checkMaxLimit('maxConnections', this.size)
|
|
233
|
+
await this._checkMaxLimit('maxConnections', this.size)
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
/**
|
|
@@ -296,6 +298,9 @@ class ConnectionManager extends EventEmitter {
|
|
|
296
298
|
*/
|
|
297
299
|
_onLatencyMeasure (summary) {
|
|
298
300
|
this._checkMaxLimit('maxEventLoopDelay', summary.avgMs)
|
|
301
|
+
.catch(err => {
|
|
302
|
+
log.error(err)
|
|
303
|
+
})
|
|
299
304
|
}
|
|
300
305
|
|
|
301
306
|
/**
|
|
@@ -305,12 +310,12 @@ class ConnectionManager extends EventEmitter {
|
|
|
305
310
|
* @param {string} name - The name of the field to check limits for
|
|
306
311
|
* @param {number} value - The current value of the field
|
|
307
312
|
*/
|
|
308
|
-
_checkMaxLimit (name, value) {
|
|
313
|
+
async _checkMaxLimit (name, value) {
|
|
309
314
|
const limit = this._options[name]
|
|
310
315
|
log('checking limit of %s. current value: %d of %d', name, value, limit)
|
|
311
316
|
if (value > limit) {
|
|
312
317
|
log('%s: limit exceeded: %s, %d', this._peerId, name, value)
|
|
313
|
-
this._maybeDisconnectOne()
|
|
318
|
+
await this._maybeDisconnectOne()
|
|
314
319
|
}
|
|
315
320
|
}
|
|
316
321
|
|
|
@@ -320,7 +325,7 @@ class ConnectionManager extends EventEmitter {
|
|
|
320
325
|
*
|
|
321
326
|
* @private
|
|
322
327
|
*/
|
|
323
|
-
_maybeDisconnectOne () {
|
|
328
|
+
async _maybeDisconnectOne () {
|
|
324
329
|
if (this._options.minConnections < this.connections.size) {
|
|
325
330
|
const peerValues = Array.from(new Map([...this._peerValues.entries()].sort((a, b) => a[1] - b[1])))
|
|
326
331
|
log('%s: sorted peer values: %j', this._peerId, peerValues)
|
|
@@ -331,7 +336,11 @@ class ConnectionManager extends EventEmitter {
|
|
|
331
336
|
log('%s: closing a connection to %j', this._peerId, peerId)
|
|
332
337
|
for (const connections of this.connections.values()) {
|
|
333
338
|
if (connections[0].remotePeer.toB58String() === peerId) {
|
|
334
|
-
connections[0].close()
|
|
339
|
+
connections[0].close().catch(err => {
|
|
340
|
+
log.error(err)
|
|
341
|
+
})
|
|
342
|
+
// TODO: should not need to invoke this manually
|
|
343
|
+
this.onDisconnect(connections[0])
|
|
335
344
|
break
|
|
336
345
|
}
|
|
337
346
|
}
|