Packages: core (BIP39/32/44/49/84/86 derivation, WIF), keystore (PBKDF2 + AES-GCM), psbt, p2p (BIP157/158 SPV daemon, Dandelion++ broadcast with relay-echo verification), blockbook, rpc, electrum, net, bns, web-ui (React/Vite), mobile (Expo). ops/ holds the nginx vhost, systemd unit and push.sh deploy script for digibyte.x/web.
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
// Milestone A2 demo — start a peer pool, watch it bootstrap from DNS
|
|
// seeds, connect to N peers, exchange getaddr, discover more peers.
|
|
// Prints every meaningful event and a summary after ~30 seconds.
|
|
|
|
import { PeerPool } from '../src/index.js';
|
|
|
|
const RUN_MS = Number(process.argv[2]) || 30_000;
|
|
const POOL_SIZE = Number(process.argv[3]) || 8;
|
|
|
|
console.log('\n=== DigiByte P2P Peer Pool Demo ===\n');
|
|
console.log(`Target pool size: ${POOL_SIZE}`);
|
|
console.log(`Runtime: ${RUN_MS / 1000}s\n`);
|
|
|
|
const pool = new PeerPool({
|
|
poolSize: POOL_SIZE,
|
|
peerOpts: { handshakeTimeoutMs: 10_000 },
|
|
});
|
|
|
|
let seededTotal = 0;
|
|
let connectCount = 0;
|
|
let failCount = 0;
|
|
let discoveredTotal = 0;
|
|
|
|
pool.on('seed', ({ seed, ips }: { seed: string; ips: string[] }) => {
|
|
console.log(` [seed] ${seed} -> ${ips.length} IPv4`);
|
|
seededTotal += ips.length;
|
|
});
|
|
pool.on('seedError', ({ seed, error }: { seed: string; error: string }) => {
|
|
console.log(` [seed] ${seed} -> ERROR ${error}`);
|
|
});
|
|
pool.on(
|
|
'connect',
|
|
({ host, port, userAgent, services, startHeight }: {
|
|
host: string;
|
|
port: number;
|
|
userAgent: string;
|
|
services: string;
|
|
startHeight: number;
|
|
}) => {
|
|
connectCount++;
|
|
console.log(` [connect] ${host}:${port} ua=${userAgent} h=${startHeight.toLocaleString()} services=${services}`);
|
|
},
|
|
);
|
|
pool.on('connectFail', ({ host, port, error }: { host: string; port: number; error: string }) => {
|
|
failCount++;
|
|
// Only log the first handful of failures; a healthy pool sees many.
|
|
if (failCount <= 5) {
|
|
console.log(` [connectFail] ${host}:${port} -> ${error}`);
|
|
}
|
|
});
|
|
pool.on(
|
|
'discovered',
|
|
({ count, poolSize, candidates }: { count: number; poolSize: number; candidates: number }) => {
|
|
discoveredTotal += count;
|
|
console.log(` [discovered] +${count} new peers (pool=${poolSize} live, ${candidates} queued)`);
|
|
},
|
|
);
|
|
pool.on('disconnect', ({ key }: { key: string }) => {
|
|
console.log(` [disconnect] ${key}`);
|
|
});
|
|
|
|
setTimeout(() => {
|
|
console.log('\n--- summary ---');
|
|
console.log(` seeded from DNS: ${seededTotal} IPs`);
|
|
console.log(` connect successes: ${connectCount}`);
|
|
console.log(` connect failures: ${failCount}${failCount > 5 ? ' (first 5 shown above)' : ''}`);
|
|
console.log(` peers discovered: ${discoveredTotal} via getaddr`);
|
|
console.log(` live at end: ${pool.liveCount}/${POOL_SIZE}`);
|
|
console.log(` queued candidates: ${pool.candidateCount}`);
|
|
console.log();
|
|
pool.stop();
|
|
process.exit(0);
|
|
}, RUN_MS);
|