Add support for gossipsub (#410)

* Replace floodsub with gossipsub

* Add a pubsub flag to support both floodsub and gossipsub

* Fix deps

* Handle empty string values

* Upgrade @cerc-io/libp2p dependency

* Upgrade package versions
This commit is contained in:
prathamesh0
2023-09-05 17:54:52 +05:30
committed by GitHub
parent f89eea0d2f
commit c80e4d0ab7
24 changed files with 266 additions and 51 deletions
+1 -1
View File
@@ -51,6 +51,6 @@ A basic CLI to pass messages between peers using `stdin`/`stdout`
* `dial-timeout`: timeout for dial to peers (ms)
* `max-relay-connections`: max number of relay node connections for this peer
* `peer-id-file (f)`: file path for peer id to be used (json)
* `enable-debug-info`: Whether to broadcast node's info over floodsub on request
* `enable-debug-info`: Whether to broadcast node's info over pubsub on request
* The process starts reading from `stdin` and outputs messages from others peers over the `/chat/1.0.0` protocol to `stdout`.
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/cli",
"version": "0.2.55",
"version": "0.2.56",
"main": "dist/index.js",
"license": "AGPL-3.0",
"scripts": {
@@ -12,11 +12,11 @@
},
"dependencies": {
"@apollo/client": "^3.7.1",
"@cerc-io/cache": "^0.2.55",
"@cerc-io/ipld-eth-client": "^0.2.55",
"@cerc-io/peer": "^0.2.55",
"@cerc-io/rpc-eth-client": "^0.2.55",
"@cerc-io/util": "^0.2.55",
"@cerc-io/cache": "^0.2.56",
"@cerc-io/ipld-eth-client": "^0.2.56",
"@cerc-io/peer": "^0.2.56",
"@cerc-io/rpc-eth-client": "^0.2.56",
"@cerc-io/util": "^0.2.56",
"@ethersproject/providers": "^5.4.4",
"@graphql-tools/utils": "^9.1.1",
"@ipld/dag-cbor": "^8.0.0",
+8 -1
View File
@@ -14,6 +14,7 @@ import {
PeerIdObj
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1319854183
} from '@cerc-io/peer';
import { PubsubType } from '@cerc-io/util';
import { readPeerId } from './utils';
@@ -26,6 +27,7 @@ interface Arguments {
dialTimeout: number;
maxRelayConnections: number;
peerIdFile: string;
pubsub?: PubsubType;
enableDebugInfo: boolean;
}
@@ -60,6 +62,7 @@ export class PeerCmd {
maxConnections: argv.maxConnections,
dialTimeout: argv.dialTimeout,
maxRelayConnections: argv.maxRelayConnections,
pubsub: argv.pubsub,
enableDebugInfo: argv.enableDebugInfo
};
@@ -112,9 +115,13 @@ function _getArgv (): any {
alias: 'f',
describe: 'Peer id file path (json)'
},
pubsub: {
type: 'string',
describe: "Pubsub to use ('floodsub' | 'gossipsub')"
},
enableDebugInfo: {
type: 'boolean',
describe: 'Whether to participate in exchanging debug info over floodsub',
describe: 'Whether to participate in exchanging debug info over pubsub',
default: false
}
}).argv;
+2
View File
@@ -187,6 +187,7 @@ export class ServerCmd {
redialInterval: relayConfig.redialInterval ?? RELAY_REDIAL_INTERVAL,
maxDialRetry: relayConfig.maxDialRetry ?? RELAY_DEFAULT_MAX_DIAL_RETRY,
peerIdObj,
pubsub: relayConfig.pubsub,
enableDebugInfo: relayConfig.enableDebugInfo
};
await createRelayNode(relayNodeInit);
@@ -212,6 +213,7 @@ export class ServerCmd {
relayRedialInterval: peerConfig.relayRedialInterval,
maxConnections: peerConfig.maxConnections,
dialTimeout: peerConfig.dialTimeout,
pubsub: peerConfig.pubsub,
enableDebugInfo: peerConfig.enableDebugInfo
};
await this._peer.init(peerNodeInit, peerIdObj);