Add an option to use a domain name for a announce address (#320)

* Add an option to use a domain name for a announce address

* Update chat CLI readme

* Set port range for relay node

* Add descriptive comment

* Upgrade webrtc-direct version
This commit is contained in:
prathamesh0 2023-02-15 18:09:21 +05:30 committed by GitHub
parent b91f904f14
commit e47f864966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 17 deletions

View File

@ -30,11 +30,12 @@ A basic CLI to pass messages between peers using `stdin`/`stdout`
```bash ```bash
# In packages/peer # In packages/peer
yarn relay-node --host [LISTEN_HOST] --port [LISTEN_PORT] --peer-id-file [PEER_ID_FILE_PATH] --relay-peers [RELAY_PEERS_FILE_PATH] yarn relay-node --host [LISTEN_HOST] --port [LISTEN_PORT] --announce [ANNOUNCE_DOMAIN] --peer-id-file [PEER_ID_FILE_PATH] --relay-peers [RELAY_PEERS_FILE_PATH]
``` ```
* `host (h)`: Host to bind to (default: `127.0.0.1`) * `host (h)`: host to bind to (default: `127.0.0.1`)
* `port (p)`: Port to start listening on (default: `9090`) * `port (p)`: port to start listening on (default: `9090`)
* `announce (a)`: domain name to be used in the announce address
* `peer-id-file (f)`: file path for peer id to be used (json) * `peer-id-file (f)`: file path for peer id to be used (json)
* `relay-peers (r)`: file path for relay peer multiaddr(s) to dial on startup (json) * `relay-peers (r)`: file path for relay peer multiaddr(s) to dial on startup (json)

View File

@ -27,7 +27,7 @@
}, },
"dependencies": { "dependencies": {
"@cerc-io/libp2p": "0.42.2-laconic-0.1.1", "@cerc-io/libp2p": "0.42.2-laconic-0.1.1",
"@cerc-io/webrtc-direct": "^5.0.0-laconic-0.1.2", "@cerc-io/webrtc-direct": "^5.0.0-laconic-0.1.3",
"@chainsafe/libp2p-noise": "^11.0.0", "@chainsafe/libp2p-noise": "^11.0.0",
"@libp2p/floodsub": "^6.0.0", "@libp2p/floodsub": "^6.0.0",
"@libp2p/mplex": "^7.1.1", "@libp2p/mplex": "^7.1.1",

View File

@ -35,6 +35,13 @@ export const RELAY_REDIAL_DELAY = 5000; // 5 sconds
// Max number of relay node connections for a peer after which it starts igoring them // Max number of relay node connections for a peer after which it starts igoring them
export const DEFAULT_MAX_RELAY_CONNECTIONS = 2; export const DEFAULT_MAX_RELAY_CONNECTIONS = 2;
// Range of ports to be used for WebRTC connections
// (option only availabe when running in nodejs)
export const WEBRTC_PORT_RANGE = {
min: 10000,
max: 11000
};
// Peer connection manager config constants // Peer connection manager config constants
// Number of max concurrent dials per peer // Number of max concurrent dials per peer

View File

@ -20,7 +20,7 @@ import type { Connection } from '@libp2p/interface-connection';
import { multiaddr } from '@multiformats/multiaddr'; import { multiaddr } from '@multiformats/multiaddr';
import type { PeerId } from '@libp2p/interface-peer-id'; import type { PeerId } from '@libp2p/interface-peer-id';
import { HOP_TIMEOUT, PUBSUB_DISCOVERY_INTERVAL, PUBSUB_SIGNATURE_POLICY } from './constants.js'; import { HOP_TIMEOUT, PUBSUB_DISCOVERY_INTERVAL, PUBSUB_SIGNATURE_POLICY, WEBRTC_PORT_RANGE } from './constants.js';
import { PeerHearbeatChecker } from './peer-heartbeat-checker.js'; import { PeerHearbeatChecker } from './peer-heartbeat-checker.js';
const log = debug('laconic:relay'); const log = debug('laconic:relay');
@ -28,6 +28,7 @@ const log = debug('laconic:relay');
interface Arguments { interface Arguments {
host: string; host: string;
port: number; port: number;
announce: string;
peerIdFile: string; peerIdFile: string;
relayPeers: string; relayPeers: string;
} }
@ -47,18 +48,26 @@ async function main (): Promise<void> {
console.log('Creating a new peer id'); console.log('Creating a new peer id');
} }
const listenMultiaddr = `/ip4/${argv.host}/tcp/${argv.port}/http/p2p-webrtc-direct`; const listenMultiaddrs = [`/ip4/${argv.host}/tcp/${argv.port}/http/p2p-webrtc-direct`];
const announceMultiaddrs = [];
if (argv.announce) {
announceMultiaddrs.push(`/dns4/${argv.announce}/tcp/443/https/p2p-webrtc-direct`);
}
const node = await createLibp2p({ const node = await createLibp2p({
peerId, peerId,
addresses: { addresses: {
listen: [listenMultiaddr] listen: listenMultiaddrs,
announce: announceMultiaddrs
}, },
transports: [ transports: [
webRTCDirect({ webRTCDirect({
wrtc, wrtc,
enableSignalling: true, enableSignalling: true,
nodeType: WebRTCDirectNodeType.Relay nodeType: WebRTCDirectNodeType.Relay,
initiatorOptions: { webRTCPortRange: WEBRTC_PORT_RANGE },
receiverOptions: { webRTCPortRange: WEBRTC_PORT_RANGE }
}) })
], ],
connectionEncryption: [noise()], connectionEncryption: [noise()],
@ -144,6 +153,11 @@ function _getArgv (): any {
default: '9090', default: '9090',
describe: 'Port to start listening on' describe: 'Port to start listening on'
}, },
announce: {
type: 'string',
alias: 'a',
describe: 'Domain name to be used in the announce address'
},
peerIdFile: { peerIdFile: {
type: 'string', type: 'string',
alias: 'f', alias: 'f',

View File

@ -373,12 +373,12 @@
wherearewe "^2.0.0" wherearewe "^2.0.0"
xsalsa20 "^1.1.0" xsalsa20 "^1.1.0"
"@cerc-io/webrtc-direct@^5.0.0-laconic-0.1.2": "@cerc-io/webrtc-direct@^5.0.0-laconic-0.1.3":
version "5.0.0-laconic-0.1.2" version "5.0.0-laconic-0.1.3"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fwebrtc-direct/-/5.0.0-laconic-0.1.2/webrtc-direct-5.0.0-laconic-0.1.2.tgz#b0697f3efe297ce7ccccadd537a36b012425df61" resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fwebrtc-direct/-/5.0.0-laconic-0.1.3/webrtc-direct-5.0.0-laconic-0.1.3.tgz#14802ba88899c904bddc327082d96cb541523ffb"
integrity sha512-SSHpUHDjyTwFX1bYL+cMjKqbAiEJQRd0N5bVMQGl86hWmmVXu+09vtpHxO6VTUZNNpnYkOisQPvn9CUyAsfWng== integrity sha512-HiRn2eoXbOFM2Dklecr+H76BB0H1H/k4I59Hnjj7tppdlr6wwts9MuA/SX0draXYEiRA5Ft4vXrfo469fGS68A==
dependencies: dependencies:
"@cerc-io/webrtc-peer" "^2.0.2-laconic-0.1.3" "@cerc-io/webrtc-peer" "^2.0.2-laconic-0.1.4"
"@libp2p/interface-transport" "^2.0.0" "@libp2p/interface-transport" "^2.0.0"
"@libp2p/interfaces" "^3.0.3" "@libp2p/interfaces" "^3.0.3"
"@libp2p/logger" "^2.0.1" "@libp2p/logger" "^2.0.1"
@ -399,10 +399,10 @@
undici "^5.2.0" undici "^5.2.0"
wherearewe "^2.0.1" wherearewe "^2.0.1"
"@cerc-io/webrtc-peer@^2.0.2-laconic-0.1.3": "@cerc-io/webrtc-peer@^2.0.2-laconic-0.1.4":
version "2.0.2-laconic-0.1.3" version "2.0.2-laconic-0.1.4"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fwebrtc-peer/-/2.0.2-laconic-0.1.3/webrtc-peer-2.0.2-laconic-0.1.3.tgz#decfc53539f206d70f7250b8f913a5d74da5c505" resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fwebrtc-peer/-/2.0.2-laconic-0.1.4/webrtc-peer-2.0.2-laconic-0.1.4.tgz#9ce10477ad4f6391de61a3f6f9a6063b09c0e196"
integrity sha512-B0fcADAeU8W0EfdLp/ju6wBDrd/WOXnsqZuGAk+EVTXqvm2cSJiA/TzttmiKQIAvYuWTsLvmRUQ14KHCbtMdSA== integrity sha512-tCXLCmDW1NKjn9m2ymgh6GbN3YWvEHMIsupW27L2Xt3q02DmWM7acZB04mjvuCDtQt5FC7ok0B6yTQ8a1liXnQ==
dependencies: dependencies:
"@libp2p/interfaces" "^3.0.2" "@libp2p/interfaces" "^3.0.2"
"@libp2p/logger" "^2.0.0" "@libp2p/logger" "^2.0.0"