mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-07-31 04:02:06 +00:00
Increase discovery interval and dial all mutiaddr
This commit is contained in:
parent
042b588a48
commit
461610f023
4
packages/cache/package.json
vendored
4
packages/cache/package.json
vendored
@ -29,8 +29,8 @@
|
||||
"@types/debug": "^4.1.5",
|
||||
"@types/fs-extra": "^9.0.11",
|
||||
"@types/level": "^6.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
"eslint-config-standard": "^16.0.3",
|
||||
|
@ -28,8 +28,8 @@
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/node": "16.11.7",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
"eslint-config-standard": "^5.0.0",
|
||||
"eslint-plugin-import": "^2.23.3",
|
||||
|
@ -41,8 +41,8 @@
|
||||
"@openzeppelin/contracts": "^4.3.2",
|
||||
"@types/js-yaml": "^4.0.3",
|
||||
"@types/node": "^16.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
"eslint-config-standard": "^16.0.3",
|
||||
|
@ -12,8 +12,8 @@
|
||||
"@types/chai": "^4.2.18",
|
||||
"@types/chai-spies": "^1.0.3",
|
||||
"@types/pluralize": "^0.0.29",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"chai": "^4.3.4",
|
||||
"chai-spies": "^1.0.0",
|
||||
"eslint": "^7.27.0",
|
||||
|
@ -32,8 +32,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/ws": "^8.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
"eslint-config-standard": "^16.0.3",
|
||||
|
@ -8,14 +8,16 @@ Package used for connecting between peers and send messages
|
||||
- [x] Connect between peers and send messages
|
||||
- [x] Use package in browser
|
||||
- [x] Use package in server
|
||||
- [ ] Send messages between systems in different LANs
|
||||
- [x] Send messages between systems in different LANs
|
||||
|
||||
## Issues
|
||||
|
||||
- Error is thrown when connecting peers in different LANs
|
||||
```
|
||||
|
||||
```text
|
||||
AggregateError: All promises were rejected
|
||||
```
|
||||
|
||||
According to stack trace error is thrown in [@libp2p/mplex](https://github.com/libp2p/js-libp2p-mplex) package
|
||||
|
||||
- `peer:disconnect` event is not fired when remote peer browser is closed
|
||||
|
@ -44,8 +44,8 @@
|
||||
"devDependencies": {
|
||||
"@libp2p/webrtc-star-signalling-server": "^2.0.5",
|
||||
"@types/node": "16.11.7",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
"eslint-config-standard": "^16.0.3",
|
||||
|
5
packages/peer/src/constants.ts
Normal file
5
packages/peer/src/constants.ts
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Copyright 2023 Vulcanize, Inc.
|
||||
//
|
||||
|
||||
export const PUBSUB_DISCOVERY_INTERVAL = 10000;
|
@ -23,6 +23,7 @@ import { multiaddr, Multiaddr } from '@multiformats/multiaddr';
|
||||
import { bootstrap } from '@libp2p/bootstrap';
|
||||
import { floodsub } from '@libp2p/floodsub';
|
||||
import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery';
|
||||
import { PUBSUB_DISCOVERY_INTERVAL } from './constants.js';
|
||||
|
||||
export const PROTOCOL = '/chat/1.0.0';
|
||||
export const DEFAULT_SIGNAL_SERVER_URL = '/ip4/127.0.0.1/tcp/13579/wss/p2p-webrtc-star';
|
||||
@ -52,14 +53,14 @@ export class Peer {
|
||||
async init (signalServerURL = DEFAULT_SIGNAL_SERVER_URL, relayNodeURL?: string): Promise<void> {
|
||||
let peerDiscovery: any;
|
||||
if (relayNodeURL) {
|
||||
console.log('Bootstrapping relay node');
|
||||
this._relayNodeMultiaddr = multiaddr(relayNodeURL);
|
||||
console.log(`Bootstrapping with relay node ${this._relayNodeMultiaddr.toString()}`);
|
||||
peerDiscovery = [
|
||||
bootstrap({
|
||||
list: [this._relayNodeMultiaddr.toString()]
|
||||
}),
|
||||
pubsubPeerDiscovery({
|
||||
interval: 1000
|
||||
interval: PUBSUB_DISCOVERY_INTERVAL
|
||||
})
|
||||
];
|
||||
} else {
|
||||
@ -105,7 +106,7 @@ export class Peer {
|
||||
if (peerId.equals(this._node.peerId)) {
|
||||
console.log('Updated self multiaddrs', this._node.getMultiaddrs().map(addr => addr.toString()));
|
||||
} else {
|
||||
console.log('Updated other node\'s multiaddrs', multiaddrs.map((addr: Multiaddr) => addr.toString()));
|
||||
console.log('Updated peer node multiaddrs', multiaddrs.map((addr: Multiaddr) => addr.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
@ -183,7 +184,7 @@ export class Peer {
|
||||
this._remotePeerIds = this._remotePeerIds.filter(remotePeerId => remotePeerId.toString() !== disconnectedPeerId.toString());
|
||||
|
||||
// Log disconnected peer
|
||||
console.log(`Disconnected from ${disconnectedPeerId.toString()}`);
|
||||
console.log(`Disconnected to ${disconnectedPeerId.toString()} using multiaddr ${connection.remoteAddr.toString()}`);
|
||||
}
|
||||
|
||||
async _connectPeer (peer: PeerInfo): Promise<void> {
|
||||
@ -207,14 +208,13 @@ export class Peer {
|
||||
// Dial them when we discover them
|
||||
// Attempt to dial all the multiaddrs of the discovered peer (to connect through relay)
|
||||
for (const peerMultiaddr of peer.multiaddrs) {
|
||||
console.log(`Dialling peer ${peer.id.toString()} using multiaddr ${peerMultiaddr.toString()}`);
|
||||
const stream = await this._node.dialProtocol(peerMultiaddr, PROTOCOL).catch(err => {
|
||||
console.log(`Could not dial ${peerMultiaddr.toString()}`, err);
|
||||
});
|
||||
try {
|
||||
console.log(`Dialling peer ${peer.id.toString()} using multiaddr ${peerMultiaddr.toString()}`);
|
||||
const stream = await this._node.dialProtocol(peerMultiaddr, PROTOCOL);
|
||||
|
||||
if (stream) {
|
||||
this._handleStream(peer.id, stream);
|
||||
break;
|
||||
} catch (err) {
|
||||
console.log(`Could not dial ${peerMultiaddr.toString()}`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import { floodsub } from '@libp2p/floodsub';
|
||||
import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery';
|
||||
|
||||
import { DEFAULT_SIGNAL_SERVER_URL } from './index.js';
|
||||
import { PUBSUB_DISCOVERY_INTERVAL } from './constants.js';
|
||||
|
||||
interface Arguments {
|
||||
signalServer: string;
|
||||
@ -40,7 +41,7 @@ async function main (): Promise<void> {
|
||||
pubsub: floodsub(),
|
||||
peerDiscovery: [
|
||||
pubsubPeerDiscovery({
|
||||
interval: 1000
|
||||
interval: PUBSUB_DISCOVERY_INTERVAL
|
||||
})
|
||||
],
|
||||
relay: {
|
||||
|
@ -9,8 +9,8 @@
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||
"@types/chai": "^4.2.18",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"chai": "^4.3.4",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
|
@ -23,8 +23,8 @@
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.19",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"eslint": "^7.27.0",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "^4.3.2"
|
||||
|
@ -24,8 +24,8 @@
|
||||
"yargs": "^17.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "^4.25.0",
|
||||
"@typescript-eslint/parser": "^4.25.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
||||
"@typescript-eslint/parser": "^5.47.1",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-config-semistandard": "^15.0.1",
|
||||
"eslint-config-standard": "^16.0.3",
|
||||
|
74
yarn.lock
74
yarn.lock
@ -5668,7 +5668,7 @@
|
||||
resolved "https://registry.npmjs.org/@types/json-diff/-/json-diff-0.5.2.tgz"
|
||||
integrity sha512-2oqXStJYYLDHCciNAClY277Ti3kXT+JLvPD7lLm/490i+B7g0GR6M4qiW+bd2V5vpB+yMKY8IelbsHMAYX1D0A==
|
||||
|
||||
"@types/json-schema@*", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.7", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9":
|
||||
"@types/json-schema@*", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9":
|
||||
version "7.0.11"
|
||||
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz"
|
||||
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
|
||||
@ -6029,20 +6029,6 @@
|
||||
resolved "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.2.tgz"
|
||||
integrity sha512-HrCIVMLjE1MOozVoD86622S7aunluLb2PJdPfb3nYiEtohm8mIB/vyv0Fd37AdeMFrTUQXEunw78YloMA3Qilg==
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^4.25.0":
|
||||
version "4.33.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.33.0.tgz"
|
||||
integrity sha512-aINiAxGVdOl1eJyVjaWn/YcVAq4Gi/Yo35qHGCnqbWVz61g39D0h23veY/MA0rFFGfxK7TySg2uwDeNv+JgVpg==
|
||||
dependencies:
|
||||
"@typescript-eslint/experimental-utils" "4.33.0"
|
||||
"@typescript-eslint/scope-manager" "4.33.0"
|
||||
debug "^4.3.1"
|
||||
functional-red-black-tree "^1.0.1"
|
||||
ignore "^5.1.8"
|
||||
regexpp "^3.1.0"
|
||||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^5.47.1":
|
||||
version "5.47.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.47.1.tgz#50cc5085578a7fa22cd46a0806c2e5eae858af02"
|
||||
@ -6073,18 +6059,6 @@
|
||||
semver "^7.3.7"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/experimental-utils@4.33.0":
|
||||
version "4.33.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.33.0.tgz"
|
||||
integrity sha512-zeQjOoES5JFjTnAhI5QY7ZviczMzDptls15GFsI6jyUOq0kOf9+WonkhtlIhh0RgHRnqj5gdNxW5j1EvAyYg6Q==
|
||||
dependencies:
|
||||
"@types/json-schema" "^7.0.7"
|
||||
"@typescript-eslint/scope-manager" "4.33.0"
|
||||
"@typescript-eslint/types" "4.33.0"
|
||||
"@typescript-eslint/typescript-estree" "4.33.0"
|
||||
eslint-scope "^5.1.1"
|
||||
eslint-utils "^3.0.0"
|
||||
|
||||
"@typescript-eslint/experimental-utils@^5.0.0":
|
||||
version "5.47.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-5.47.0.tgz"
|
||||
@ -6092,16 +6066,6 @@
|
||||
dependencies:
|
||||
"@typescript-eslint/utils" "5.47.0"
|
||||
|
||||
"@typescript-eslint/parser@^4.25.0":
|
||||
version "4.33.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.33.0.tgz"
|
||||
integrity sha512-ZohdsbXadjGBSK0/r+d87X0SBmKzOq4/S5nzK6SBgJspFo9/CUDJ7hjayuze+JK7CZQLDMroqytp7pOcFKTxZA==
|
||||
dependencies:
|
||||
"@typescript-eslint/scope-manager" "4.33.0"
|
||||
"@typescript-eslint/types" "4.33.0"
|
||||
"@typescript-eslint/typescript-estree" "4.33.0"
|
||||
debug "^4.3.1"
|
||||
|
||||
"@typescript-eslint/parser@^5.47.1":
|
||||
version "5.47.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.47.1.tgz#c4bf16f8c3c7608ce4bf8ff804b677fc899f173f"
|
||||
@ -6122,14 +6086,6 @@
|
||||
"@typescript-eslint/typescript-estree" "5.47.0"
|
||||
debug "^4.3.4"
|
||||
|
||||
"@typescript-eslint/scope-manager@4.33.0":
|
||||
version "4.33.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.33.0.tgz"
|
||||
integrity sha512-5IfJHpgTsTZuONKbODctL4kKuQje/bzBRkwHE8UOZ4f89Zeddg+EGZs8PD8NcN4LdM3ygHWYB3ukPAYjvl/qbQ==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "4.33.0"
|
||||
"@typescript-eslint/visitor-keys" "4.33.0"
|
||||
|
||||
"@typescript-eslint/scope-manager@5.47.0":
|
||||
version "5.47.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.47.0.tgz"
|
||||
@ -6166,11 +6122,6 @@
|
||||
debug "^4.3.4"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/types@4.33.0":
|
||||
version "4.33.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.33.0.tgz"
|
||||
integrity sha512-zKp7CjQzLQImXEpLt2BUw1tvOMPfNoTAfb8l51evhYbOEEzdWyQNmHWWGPR6hwKJDAi+1VXSBmnhL9kyVTTOuQ==
|
||||
|
||||
"@typescript-eslint/types@5.47.0":
|
||||
version "5.47.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.47.0.tgz"
|
||||
@ -6181,19 +6132,6 @@
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.47.1.tgz#459f07428aec5a8c4113706293c2ae876741ac8e"
|
||||
integrity sha512-CmALY9YWXEpwuu6377ybJBZdtSAnzXLSQcxLSqSQSbC7VfpMu/HLVdrnVJj7ycI138EHqocW02LPJErE35cE9A==
|
||||
|
||||
"@typescript-eslint/typescript-estree@4.33.0":
|
||||
version "4.33.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.33.0.tgz"
|
||||
integrity sha512-rkWRY1MPFzjwnEVHsxGemDzqqddw2QbTJlICPD9p9I9LfsO8fdmfQPOX3uKfUaGRDFJbfrtm/sXhVXN4E+bzCA==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "4.33.0"
|
||||
"@typescript-eslint/visitor-keys" "4.33.0"
|
||||
debug "^4.3.1"
|
||||
globby "^11.0.3"
|
||||
is-glob "^4.0.1"
|
||||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/typescript-estree@5.47.0":
|
||||
version "5.47.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.47.0.tgz"
|
||||
@ -6248,14 +6186,6 @@
|
||||
eslint-utils "^3.0.0"
|
||||
semver "^7.3.7"
|
||||
|
||||
"@typescript-eslint/visitor-keys@4.33.0":
|
||||
version "4.33.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.33.0.tgz"
|
||||
integrity sha512-uqi/2aSz9g2ftcHWf8uLPJA70rUv6yuMW5Bohw+bwcuzaxQIHaKFZCKGoGXIrc9vkTJ3+0txM73K0Hq3d5wgIg==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "4.33.0"
|
||||
eslint-visitor-keys "^2.0.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@5.47.0":
|
||||
version "5.47.0"
|
||||
resolved "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.47.0.tgz"
|
||||
@ -12977,7 +12907,7 @@ globby@^11.0.2:
|
||||
merge2 "^1.3.0"
|
||||
slash "^3.0.0"
|
||||
|
||||
globby@^11.0.3, globby@^11.0.4, globby@^11.1.0:
|
||||
globby@^11.0.4, globby@^11.1.0:
|
||||
version "11.1.0"
|
||||
resolved "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz"
|
||||
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
|
||||
|
Loading…
Reference in New Issue
Block a user