@aztec/p2p 0.41.0 → 0.43.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/dest/bootstrap/bootstrap.d.ts +1 -1
- package/dest/bootstrap/bootstrap.d.ts.map +1 -1
- package/dest/bootstrap/bootstrap.js +9 -4
- package/dest/client/index.d.ts.map +1 -1
- package/dest/client/index.js +32 -3
- package/dest/client/mocks.js +2 -2
- package/dest/config.d.ts +12 -16
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +10 -9
- package/dest/service/discV5_service.d.ts.map +1 -1
- package/dest/service/discV5_service.js +15 -5
- package/dest/service/libp2p_service.d.ts +2 -7
- package/dest/service/libp2p_service.d.ts.map +1 -1
- package/dest/service/libp2p_service.js +20 -53
- package/dest/service/tx_messages.d.ts.map +1 -1
- package/dest/service/tx_messages.js +4 -4
- package/dest/util.d.ts +21 -0
- package/dest/util.d.ts.map +1 -0
- package/dest/util.js +59 -0
- package/package.json +5 -5
- package/src/bootstrap/bootstrap.ts +12 -5
- package/src/client/index.ts +40 -2
- package/src/client/mocks.ts +1 -1
- package/src/config.ts +27 -31
- package/src/service/discV5_service.ts +19 -4
- package/src/service/libp2p_service.ts +21 -69
- package/src/service/tx_messages.ts +3 -3
- package/src/util.ts +62 -0
- package/dest/service/peer_store.d.ts +0 -18
- package/dest/service/peer_store.d.ts.map +0 -1
- package/dest/service/peer_store.js +0 -25
- package/src/service/peer_store.ts +0 -36
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
2
2
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
3
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
3
4
|
|
|
4
5
|
import { Discv5, type Discv5EventEmitter } from '@chainsafe/discv5';
|
|
5
6
|
import { type ENR, SignableENR } from '@chainsafe/enr';
|
|
@@ -8,6 +9,7 @@ import { multiaddr } from '@multiformats/multiaddr';
|
|
|
8
9
|
import EventEmitter from 'events';
|
|
9
10
|
|
|
10
11
|
import type { P2PConfig } from '../config.js';
|
|
12
|
+
import { convertToMultiaddr } from '../util.js';
|
|
11
13
|
import { type PeerDiscoveryService, PeerDiscoveryState } from './service.js';
|
|
12
14
|
|
|
13
15
|
export const AZTEC_ENR_KEY = 'aztec_network';
|
|
@@ -39,17 +41,24 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
39
41
|
|
|
40
42
|
constructor(private peerId: PeerId, config: P2PConfig, private logger = createDebugLogger('aztec:discv5_service')) {
|
|
41
43
|
super();
|
|
42
|
-
const {
|
|
44
|
+
const { tcpAnnounceAddress, udpAnnounceAddress, udpListenAddress, bootstrapNodes } = config;
|
|
43
45
|
this.bootstrapNodes = bootstrapNodes;
|
|
44
46
|
// create ENR from PeerId
|
|
45
47
|
this.enr = SignableENR.createFromPeerId(peerId);
|
|
46
48
|
// Add aztec identification to ENR
|
|
47
49
|
this.enr.set(AZTEC_ENR_KEY, Uint8Array.from([AZTEC_NET]));
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
if (!tcpAnnounceAddress) {
|
|
52
|
+
throw new Error('You need to provide at least a TCP announce address.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const multiAddrTcp = multiaddr(`${convertToMultiaddr(tcpAnnounceAddress, 'tcp')}/p2p/${peerId.toString()}`);
|
|
56
|
+
// if no udp announce address is provided, use the tcp announce address
|
|
57
|
+
const multiAddrUdp = multiaddr(
|
|
58
|
+
`${convertToMultiaddr(udpAnnounceAddress || tcpAnnounceAddress, 'udp')}/p2p/${peerId.toString()}`,
|
|
59
|
+
);
|
|
51
60
|
|
|
52
|
-
const listenMultiAddrUdp = multiaddr(
|
|
61
|
+
const listenMultiAddrUdp = multiaddr(convertToMultiaddr(udpListenAddress, 'udp'));
|
|
53
62
|
|
|
54
63
|
// set location multiaddr in ENR record
|
|
55
64
|
this.enr.setLocationMultiaddr(multiAddrUdp);
|
|
@@ -61,6 +70,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
61
70
|
bindAddrs: { ip4: listenMultiAddrUdp },
|
|
62
71
|
config: {
|
|
63
72
|
lookupTimeout: 2000,
|
|
73
|
+
allowUnverifiedSessions: true,
|
|
64
74
|
},
|
|
65
75
|
});
|
|
66
76
|
|
|
@@ -85,6 +95,7 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
85
95
|
}
|
|
86
96
|
this.logger.info('Starting DiscV5');
|
|
87
97
|
await this.discv5.start();
|
|
98
|
+
|
|
88
99
|
this.logger.info('DiscV5 started');
|
|
89
100
|
this.currentState = PeerDiscoveryState.RUNNING;
|
|
90
101
|
|
|
@@ -100,6 +111,10 @@ export class DiscV5Service extends EventEmitter implements PeerDiscoveryService
|
|
|
100
111
|
}
|
|
101
112
|
}
|
|
102
113
|
|
|
114
|
+
// First, wait some time before starting the peer discovery
|
|
115
|
+
// reference: https://github.com/ChainSafe/lodestar/issues/3423
|
|
116
|
+
await sleep(2000);
|
|
117
|
+
|
|
103
118
|
this.runningPromise.start();
|
|
104
119
|
}
|
|
105
120
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Tx, type TxHash } from '@aztec/circuit-types';
|
|
2
2
|
import { SerialQueue } from '@aztec/foundation/fifo';
|
|
3
3
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
4
|
-
import { type AztecKVStore } from '@aztec/kv-store';
|
|
5
4
|
import { AztecLmdbStore } from '@aztec/kv-store/lmdb';
|
|
6
5
|
|
|
7
6
|
import { ENR } from '@chainsafe/enr';
|
|
@@ -9,21 +8,20 @@ import { type GossipsubEvents, gossipsub } from '@chainsafe/libp2p-gossipsub';
|
|
|
9
8
|
import { noise } from '@chainsafe/libp2p-noise';
|
|
10
9
|
import { yamux } from '@chainsafe/libp2p-yamux';
|
|
11
10
|
import { identify } from '@libp2p/identify';
|
|
12
|
-
import type {
|
|
11
|
+
import type { PeerId, PubSub, Stream } from '@libp2p/interface';
|
|
13
12
|
import '@libp2p/kad-dht';
|
|
14
13
|
import { mplex } from '@libp2p/mplex';
|
|
15
14
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
16
15
|
import { createFromJSON, createSecp256k1PeerId } from '@libp2p/peer-id-factory';
|
|
17
16
|
import { tcp } from '@libp2p/tcp';
|
|
18
|
-
import { pipe } from 'it-pipe';
|
|
19
17
|
import { type Libp2p, createLibp2p } from 'libp2p';
|
|
20
18
|
|
|
21
19
|
import { type P2PConfig } from '../config.js';
|
|
22
20
|
import { type TxPool } from '../tx_pool/index.js';
|
|
21
|
+
import { convertToMultiaddr } from '../util.js';
|
|
23
22
|
import { AztecDatastore } from './data_store.js';
|
|
24
23
|
import { KnownTxLookup } from './known_txs.js';
|
|
25
24
|
import { PeerManager } from './peer_manager.js';
|
|
26
|
-
import { AztecPeerDb, type AztecPeerStore } from './peer_store.js';
|
|
27
25
|
import type { P2PService, PeerDiscoveryService } from './service.js';
|
|
28
26
|
import { AztecTxMessageCreator, fromTxMessage } from './tx_messages.js';
|
|
29
27
|
|
|
@@ -61,7 +59,6 @@ export class LibP2PService implements P2PService {
|
|
|
61
59
|
private config: P2PConfig,
|
|
62
60
|
private node: PubSubLibp2p,
|
|
63
61
|
private peerDiscoveryService: PeerDiscoveryService,
|
|
64
|
-
private peerStore: AztecPeerStore,
|
|
65
62
|
private protocolId: string,
|
|
66
63
|
private txPool: TxPool,
|
|
67
64
|
private bootstrapPeerIds: PeerId[] = [],
|
|
@@ -79,15 +76,16 @@ export class LibP2PService implements P2PService {
|
|
|
79
76
|
if (this.node.status === 'started') {
|
|
80
77
|
throw new Error('P2P service already started');
|
|
81
78
|
}
|
|
82
|
-
const {
|
|
83
|
-
this.logger.info(`Starting P2P node on ${
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (enableNat) {
|
|
88
|
-
this.logger.info(`Enabling NAT in libp2p module`);
|
|
79
|
+
const { tcpListenAddress, tcpAnnounceAddress } = this.config;
|
|
80
|
+
this.logger.info(`Starting P2P node on ${tcpListenAddress}`);
|
|
81
|
+
|
|
82
|
+
if (!tcpAnnounceAddress) {
|
|
83
|
+
throw new Error('Announce address not provided.');
|
|
89
84
|
}
|
|
90
85
|
|
|
86
|
+
const announceTcpMultiaddr = convertToMultiaddr(tcpAnnounceAddress, 'tcp');
|
|
87
|
+
|
|
88
|
+
this.logger.info(`Announcing at ${announceTcpMultiaddr}`);
|
|
91
89
|
// handle discovered peers from external discovery service
|
|
92
90
|
this.peerDiscoveryService.on('peer:discovered', async (enr: ENR) => {
|
|
93
91
|
await this.addPeer(enr);
|
|
@@ -101,9 +99,9 @@ export class LibP2PService implements P2PService {
|
|
|
101
99
|
this.node.addEventListener('peer:disconnect', async evt => {
|
|
102
100
|
const peerId = evt.detail;
|
|
103
101
|
if (this.isBootstrapPeer(peerId)) {
|
|
104
|
-
this.logger.
|
|
102
|
+
this.logger.info(`Disconnect from bootstrap peer ${peerId.toString()}`);
|
|
105
103
|
} else {
|
|
106
|
-
this.logger.
|
|
104
|
+
this.logger.info(`Disconnected from transaction peer ${peerId.toString()}`);
|
|
107
105
|
await this.peerManager.updateDiscoveryService();
|
|
108
106
|
}
|
|
109
107
|
});
|
|
@@ -111,9 +109,6 @@ export class LibP2PService implements P2PService {
|
|
|
111
109
|
this.jobQueue.start();
|
|
112
110
|
await this.peerDiscoveryService.start();
|
|
113
111
|
await this.node.start();
|
|
114
|
-
await this.node.handle(this.protocolId, (incoming: IncomingStreamData) =>
|
|
115
|
-
this.jobQueue.put(() => Promise.resolve(this.handleProtocolDial(incoming))),
|
|
116
|
-
);
|
|
117
112
|
this.logger.info(`Started P2P client with Peer ID ${this.node.peerId.toString()}`);
|
|
118
113
|
|
|
119
114
|
// Subscribe to standard topics by default
|
|
@@ -124,7 +119,7 @@ export class LibP2PService implements P2PService {
|
|
|
124
119
|
const { msg } = e.detail;
|
|
125
120
|
this.logger.debug(`Received PUBSUB message.`);
|
|
126
121
|
|
|
127
|
-
await this.handleNewGossipMessage(msg.topic, msg.data);
|
|
122
|
+
await this.jobQueue.put(() => this.handleNewGossipMessage(msg.topic, msg.data));
|
|
128
123
|
});
|
|
129
124
|
}
|
|
130
125
|
|
|
@@ -151,17 +146,11 @@ export class LibP2PService implements P2PService {
|
|
|
151
146
|
peerDiscoveryService: PeerDiscoveryService,
|
|
152
147
|
peerId: PeerId,
|
|
153
148
|
txPool: TxPool,
|
|
154
|
-
store: AztecKVStore,
|
|
155
149
|
) {
|
|
156
|
-
const {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
maxPeerCount,
|
|
161
|
-
dataDirectory,
|
|
162
|
-
transactionProtocol: protocolId,
|
|
163
|
-
} = config;
|
|
164
|
-
const bindAddrTcp = `/ip4/${tcpListenIp}/tcp/${tcpListenPort}`;
|
|
150
|
+
const { tcpListenAddress, minPeerCount, maxPeerCount, transactionProtocol: protocolId } = config;
|
|
151
|
+
const bindAddrTcp = convertToMultiaddr(tcpListenAddress, 'tcp');
|
|
152
|
+
|
|
153
|
+
const datastore = new AztecDatastore(AztecLmdbStore.open());
|
|
165
154
|
|
|
166
155
|
// The autonat service seems quite problematic in that using it seems to cause a lot of attempts
|
|
167
156
|
// to dial ephemeral ports. I suspect that it works better if you can get the uPNPnat service to
|
|
@@ -177,8 +166,6 @@ export class LibP2PService implements P2PService {
|
|
|
177
166
|
// services.uPnPNAT = uPnPNATService();
|
|
178
167
|
// }
|
|
179
168
|
|
|
180
|
-
const datastore = new AztecDatastore(AztecLmdbStore.open(dataDirectory));
|
|
181
|
-
|
|
182
169
|
const node = await createLibp2p({
|
|
183
170
|
start: false,
|
|
184
171
|
peerId,
|
|
@@ -213,9 +200,6 @@ export class LibP2PService implements P2PService {
|
|
|
213
200
|
},
|
|
214
201
|
});
|
|
215
202
|
|
|
216
|
-
// Create an LMDB peer store
|
|
217
|
-
const peerDb = new AztecPeerDb(store);
|
|
218
|
-
|
|
219
203
|
// extract bootstrap node peer IDs
|
|
220
204
|
let bootstrapPeerIds: PeerId[] = [];
|
|
221
205
|
if (config.bootstrapNodes.length) {
|
|
@@ -224,7 +208,7 @@ export class LibP2PService implements P2PService {
|
|
|
224
208
|
);
|
|
225
209
|
}
|
|
226
210
|
|
|
227
|
-
return new LibP2PService(config, node, peerDiscoveryService,
|
|
211
|
+
return new LibP2PService(config, node, peerDiscoveryService, protocolId, txPool, bootstrapPeerIds);
|
|
228
212
|
}
|
|
229
213
|
|
|
230
214
|
/**
|
|
@@ -307,13 +291,8 @@ export class LibP2PService implements P2PService {
|
|
|
307
291
|
let stream: Stream | undefined;
|
|
308
292
|
try {
|
|
309
293
|
stream = await this.node.dialProtocol(peerMultiAddr, this.protocolId);
|
|
310
|
-
|
|
311
|
-
// dial successful, add to DB as well
|
|
312
|
-
if (!this.peerStore.getPeer(peerIdStr)) {
|
|
313
|
-
await this.peerStore.addPeer(peerIdStr, enr);
|
|
314
|
-
}
|
|
315
294
|
} catch (err) {
|
|
316
|
-
this.logger.
|
|
295
|
+
this.logger.debug(`Failed to dial peer ${peerIdStr}: ${err}`);
|
|
317
296
|
} finally {
|
|
318
297
|
if (stream) {
|
|
319
298
|
await stream.close();
|
|
@@ -322,38 +301,11 @@ export class LibP2PService implements P2PService {
|
|
|
322
301
|
}
|
|
323
302
|
}
|
|
324
303
|
|
|
325
|
-
private async handleProtocolDial(incomingStreamData: IncomingStreamData) {
|
|
326
|
-
try {
|
|
327
|
-
const { message, peer } = await this.consumeInboundStream(incomingStreamData);
|
|
328
|
-
if (!message.length) {
|
|
329
|
-
this.logger.verbose(`Ignoring 0 byte message from peer${peer.toString()}`);
|
|
330
|
-
}
|
|
331
|
-
// await this.processTransactionMessage(message, peer);
|
|
332
|
-
} catch (err) {
|
|
333
|
-
this.logger.error(
|
|
334
|
-
`Failed to handle received message from peer ${incomingStreamData.connection.remotePeer.toString()}`,
|
|
335
|
-
err,
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
private async consumeInboundStream(incomingStreamData: IncomingStreamData) {
|
|
341
|
-
let buffer = Buffer.alloc(0);
|
|
342
|
-
await pipe(incomingStreamData.stream, async source => {
|
|
343
|
-
for await (const msg of source) {
|
|
344
|
-
const payload = msg.subarray();
|
|
345
|
-
buffer = Buffer.concat([buffer, Buffer.from(payload)]);
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
await incomingStreamData.stream.close();
|
|
349
|
-
return { message: buffer, peer: incomingStreamData.connection.remotePeer };
|
|
350
|
-
}
|
|
351
|
-
|
|
352
304
|
private async handleNewConnection(peerId: PeerId) {
|
|
353
305
|
if (this.isBootstrapPeer(peerId)) {
|
|
354
|
-
this.logger.
|
|
306
|
+
this.logger.info(`Connected to bootstrap peer ${peerId.toString()}`);
|
|
355
307
|
} else {
|
|
356
|
-
this.logger.
|
|
308
|
+
this.logger.info(`Connected to transaction peer ${peerId.toString()}`);
|
|
357
309
|
await this.peerManager.updateDiscoveryService();
|
|
358
310
|
}
|
|
359
311
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EncryptedTxL2Logs, Tx, UnencryptedTxL2Logs } from '@aztec/circuit-types';
|
|
1
|
+
import { EncryptedNoteTxL2Logs, EncryptedTxL2Logs, Tx, UnencryptedTxL2Logs } from '@aztec/circuit-types';
|
|
2
2
|
import { PrivateKernelTailCircuitPublicInputs, Proof, PublicCallRequest } from '@aztec/circuits.js';
|
|
3
3
|
import { numToUInt32BE } from '@aztec/foundation/serialize';
|
|
4
4
|
|
|
@@ -115,9 +115,9 @@ export function fromTxMessage(buffer: Buffer): Tx {
|
|
|
115
115
|
const publicInputs = toObject(buffer.subarray(4), PrivateKernelTailCircuitPublicInputs);
|
|
116
116
|
const proof = toObject(publicInputs.remainingData, Proof);
|
|
117
117
|
|
|
118
|
-
const noteEncryptedLogs = toObject(proof.remainingData,
|
|
118
|
+
const noteEncryptedLogs = toObject(proof.remainingData, EncryptedNoteTxL2Logs);
|
|
119
119
|
if (!noteEncryptedLogs.obj) {
|
|
120
|
-
noteEncryptedLogs.obj = new
|
|
120
|
+
noteEncryptedLogs.obj = new EncryptedNoteTxL2Logs([]);
|
|
121
121
|
}
|
|
122
122
|
const encryptedLogs = toObject(noteEncryptedLogs.remainingData, EncryptedTxL2Logs);
|
|
123
123
|
if (!encryptedLogs.obj) {
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an address string to a multiaddr string.
|
|
3
|
+
* Example usage:
|
|
4
|
+
* const tcpAddr = '123.456.7.8:80' -> /ip4/123.456.7.8/tcp/80
|
|
5
|
+
* const udpAddr = '[2001:db8::1]:8080' -> /ip6/2001:db8::1/udp/8080
|
|
6
|
+
* const dnsAddr = 'example.com:443' -> /dns4/example.com/tcp/443
|
|
7
|
+
* @param address - The address string to convert. Has to be in the format <addr>:<port>.
|
|
8
|
+
* @param protocol - The protocol to use in the multiaddr string.
|
|
9
|
+
* @returns A multiaddr compliant string.
|
|
10
|
+
*/
|
|
11
|
+
export function convertToMultiaddr(address: string, protocol: 'tcp' | 'udp'): string {
|
|
12
|
+
const [addr, port] = splitAddressPort(address, false);
|
|
13
|
+
|
|
14
|
+
let multiaddrPrefix: string;
|
|
15
|
+
|
|
16
|
+
if (addr.includes(':')) {
|
|
17
|
+
// IPv6 address
|
|
18
|
+
multiaddrPrefix = 'ip6';
|
|
19
|
+
} else if (addr.match(/^[\d.]+$/)) {
|
|
20
|
+
// IPv4 address
|
|
21
|
+
multiaddrPrefix = 'ip4';
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error('Invalid address format. Expected an IPv4 or IPv6 address.');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return `/${multiaddrPrefix}/${addr}/${protocol}/${port}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Splits an <address>:<port> string into its components.
|
|
31
|
+
* @returns The ip6 or ip4 address & port separately
|
|
32
|
+
*/
|
|
33
|
+
export function splitAddressPort(address: string, allowEmptyAddress: boolean): [string, string] {
|
|
34
|
+
let addr: string;
|
|
35
|
+
let port: string;
|
|
36
|
+
|
|
37
|
+
if (address.startsWith('[')) {
|
|
38
|
+
// IPv6 address enclosed in square brackets
|
|
39
|
+
const match = address.match(/^\[([^\]]+)\]:(\d+)$/);
|
|
40
|
+
if (!match) {
|
|
41
|
+
throw new Error(`Invalid IPv6 address format:${address}. Expected format: [<addr>]:<port>`);
|
|
42
|
+
}
|
|
43
|
+
[, addr, port] = match;
|
|
44
|
+
} else {
|
|
45
|
+
// IPv4 address
|
|
46
|
+
[addr, port] = address.split(':');
|
|
47
|
+
if ((!addr && !allowEmptyAddress) || !port) {
|
|
48
|
+
throw new Error(`Invalid address format: ${address}. Expected format: <addr>:<port>`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return [addr, port];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Queries the public IP address of the machine.
|
|
57
|
+
*/
|
|
58
|
+
export async function getPublicIp(): Promise<string> {
|
|
59
|
+
const resp = await fetch('http://checkip.amazonaws.com/');
|
|
60
|
+
const text = await resp.text();
|
|
61
|
+
return text.trim();
|
|
62
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AztecKVStore } from '@aztec/kv-store';
|
|
2
|
-
import type { ENR } from '@chainsafe/enr';
|
|
3
|
-
export interface AztecPeerStore {
|
|
4
|
-
addPeer(peerId: string, enr: ENR): Promise<void>;
|
|
5
|
-
removePeer(peerId: string): Promise<void>;
|
|
6
|
-
getPeer(peerId: string): ENR | undefined;
|
|
7
|
-
getAllPeers(): IterableIterator<ENR>;
|
|
8
|
-
}
|
|
9
|
-
export declare class AztecPeerDb implements AztecPeerStore {
|
|
10
|
-
#private;
|
|
11
|
-
private db;
|
|
12
|
-
constructor(db: AztecKVStore);
|
|
13
|
-
addPeer(peerId: string, enr: ENR): Promise<void>;
|
|
14
|
-
removePeer(peerId: string): Promise<void>;
|
|
15
|
-
getPeer(peerId: string): ENR | undefined;
|
|
16
|
-
getAllPeers(): IterableIterator<ENR>;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=peer_store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"peer_store.d.ts","sourceRoot":"","sources":["../../src/service/peer_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAY,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC;IACzC,WAAW,IAAI,gBAAgB,CAAC,GAAG,CAAC,CAAC;CACtC;AAED,qBAAa,WAAY,YAAW,cAAc;;IAGpC,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,YAAY;IAI9B,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAIvC,WAAW,IAAI,gBAAgB,CAAC,GAAG,CAAC;CAKtC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var _AztecPeerDb_peers;
|
|
2
|
-
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
-
export class AztecPeerDb {
|
|
4
|
-
constructor(db) {
|
|
5
|
-
this.db = db;
|
|
6
|
-
_AztecPeerDb_peers.set(this, void 0);
|
|
7
|
-
__classPrivateFieldSet(this, _AztecPeerDb_peers, db.openMap('p2p_peers'), "f");
|
|
8
|
-
}
|
|
9
|
-
async addPeer(peerId, enr) {
|
|
10
|
-
void (await __classPrivateFieldGet(this, _AztecPeerDb_peers, "f").set(peerId, enr));
|
|
11
|
-
}
|
|
12
|
-
async removePeer(peerId) {
|
|
13
|
-
void (await __classPrivateFieldGet(this, _AztecPeerDb_peers, "f").delete(peerId));
|
|
14
|
-
}
|
|
15
|
-
getPeer(peerId) {
|
|
16
|
-
return __classPrivateFieldGet(this, _AztecPeerDb_peers, "f").get(peerId);
|
|
17
|
-
}
|
|
18
|
-
*getAllPeers() {
|
|
19
|
-
for (const enr of __classPrivateFieldGet(this, _AztecPeerDb_peers, "f").values()) {
|
|
20
|
-
yield enr;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
_AztecPeerDb_peers = new WeakMap();
|
|
25
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGVlcl9zdG9yZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9zZXJ2aWNlL3BlZXJfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFXQSxNQUFNLE9BQU8sV0FBVztJQUd0QixZQUFvQixFQUFnQjtRQUFoQixPQUFFLEdBQUYsRUFBRSxDQUFjO1FBRnBDLHFDQUE4QjtRQUc1Qix1QkFBQSxJQUFJLHNCQUFVLEVBQUUsQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLE1BQUEsQ0FBQztJQUN4QyxDQUFDO0lBRUQsS0FBSyxDQUFDLE9BQU8sQ0FBQyxNQUFjLEVBQUUsR0FBUTtRQUNwQyxLQUFLLENBQUMsTUFBTSx1QkFBQSxJQUFJLDBCQUFPLENBQUMsR0FBRyxDQUFDLE1BQU0sRUFBRSxHQUFHLENBQUMsQ0FBQyxDQUFDO0lBQzVDLENBQUM7SUFFRCxLQUFLLENBQUMsVUFBVSxDQUFDLE1BQWM7UUFDN0IsS0FBSyxDQUFDLE1BQU0sdUJBQUEsSUFBSSwwQkFBTyxDQUFDLE1BQU0sQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFDO0lBQzFDLENBQUM7SUFFRCxPQUFPLENBQUMsTUFBYztRQUNwQixPQUFPLHVCQUFBLElBQUksMEJBQU8sQ0FBQyxHQUFHLENBQUMsTUFBTSxDQUFDLENBQUM7SUFDakMsQ0FBQztJQUVELENBQUMsV0FBVztRQUNWLEtBQUssTUFBTSxHQUFHLElBQUksdUJBQUEsSUFBSSwwQkFBTyxDQUFDLE1BQU0sRUFBRSxFQUFFLENBQUM7WUFDdkMsTUFBTSxHQUFHLENBQUM7UUFDWixDQUFDO0lBQ0gsQ0FBQztDQUNGIn0=
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { AztecKVStore, AztecMap } from '@aztec/kv-store';
|
|
2
|
-
|
|
3
|
-
import type { ENR } from '@chainsafe/enr';
|
|
4
|
-
|
|
5
|
-
export interface AztecPeerStore {
|
|
6
|
-
addPeer(peerId: string, enr: ENR): Promise<void>;
|
|
7
|
-
removePeer(peerId: string): Promise<void>;
|
|
8
|
-
getPeer(peerId: string): ENR | undefined;
|
|
9
|
-
getAllPeers(): IterableIterator<ENR>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class AztecPeerDb implements AztecPeerStore {
|
|
13
|
-
#peers: AztecMap<string, ENR>;
|
|
14
|
-
|
|
15
|
-
constructor(private db: AztecKVStore) {
|
|
16
|
-
this.#peers = db.openMap('p2p_peers');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async addPeer(peerId: string, enr: ENR): Promise<void> {
|
|
20
|
-
void (await this.#peers.set(peerId, enr));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async removePeer(peerId: string): Promise<void> {
|
|
24
|
-
void (await this.#peers.delete(peerId));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getPeer(peerId: string): ENR | undefined {
|
|
28
|
-
return this.#peers.get(peerId);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
*getAllPeers(): IterableIterator<ENR> {
|
|
32
|
-
for (const enr of this.#peers.values()) {
|
|
33
|
-
yield enr;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|