watcher-ts/packages/peer/src/constants.ts

73 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

Implement peer package to send messages between peers (#279) * Initial implementation of class and discoving other peers * Implement peer connection and sending messages between peers * Add react app and use peer package for broadcasting * Maintain stream for each remote peer * Refactor code in peer package * Add serve package for react-app * Add readme for running react app * Add peer package readme * Add logs for events with details * Add a chat CLI using peer package (#280) * Add a flag to instantiate Peer for nodejs * Add a basic chat CLI using peer * Add a signal server arg to chat CLI * Add instructions for chat CLI * Fix typescript and ESM issues after adding peer package (#282) * Fix build issues in util package * Update eslint TS plugins * Scope react app package name * Convert cli package back to CJS and dynamically import ESM * Upgrade ts-node version * Fix tests * Setup a relay node and pubsub based discovery (#284) * Add a script to setup a relay node * Use pubsub based peer discovery * Add peer multiaddr to connection log * Catch relay node dial errors * Increase discovery interval and dial all mutiaddr * Add UI to display self peer ID and multiaddrs * Add UI for displaying live remote connections * Send js objects in peer broadcast messages * Add react-peer package for using peer in react app * Reduce disconnect frequency between peers (#287) * Restrict number of max concurrent dials per peer * Increase hop relay timeout to 1 day * Self review changes * Review changes * Increase pubsub discovery interval and add steps to create a peer id (#290) * Increase pubsub discovery interval * Disable autodial to avoid peer dials without protocol on a reconnect * Add steps to create a peer id and use for relay node * Add back dependency to run signalling server * Avoid bootstrapping and dial to relay node directly Co-authored-by: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
2023-01-10 14:40:27 +00:00
//
// Copyright 2023 Vulcanize, Inc.
//
export const P2P_WEBRTC_STAR_ID = 'p2p-webrtc-star';
export const P2P_CIRCUIT_ID = 'p2p-circuit';
export const CHAT_PROTOCOL = '/chat/1.0.0';
export const DEBUG_INFO_TOPIC = 'debug-info';
// How often a peer should broadcast it's peer data over pubsub discovery topic
// (interval at which other peers get corresponding discovery event)
Implement peer package to send messages between peers (#279) * Initial implementation of class and discoving other peers * Implement peer connection and sending messages between peers * Add react app and use peer package for broadcasting * Maintain stream for each remote peer * Refactor code in peer package * Add serve package for react-app * Add readme for running react app * Add peer package readme * Add logs for events with details * Add a chat CLI using peer package (#280) * Add a flag to instantiate Peer for nodejs * Add a basic chat CLI using peer * Add a signal server arg to chat CLI * Add instructions for chat CLI * Fix typescript and ESM issues after adding peer package (#282) * Fix build issues in util package * Update eslint TS plugins * Scope react app package name * Convert cli package back to CJS and dynamically import ESM * Upgrade ts-node version * Fix tests * Setup a relay node and pubsub based discovery (#284) * Add a script to setup a relay node * Use pubsub based peer discovery * Add peer multiaddr to connection log * Catch relay node dial errors * Increase discovery interval and dial all mutiaddr * Add UI to display self peer ID and multiaddrs * Add UI for displaying live remote connections * Send js objects in peer broadcast messages * Add react-peer package for using peer in react app * Reduce disconnect frequency between peers (#287) * Restrict number of max concurrent dials per peer * Increase hop relay timeout to 1 day * Self review changes * Review changes * Increase pubsub discovery interval and add steps to create a peer id (#290) * Increase pubsub discovery interval * Disable autodial to avoid peer dials without protocol on a reconnect * Add steps to create a peer id and use for relay node * Add back dependency to run signalling server * Avoid bootstrapping and dial to relay node directly Co-authored-by: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
2023-01-10 14:40:27 +00:00
export const PUBSUB_DISCOVERY_INTERVAL = 10000; // 10 seconds
// Use StrictSign signature policy to pass signed pubsub messages
// (includes source peer's id with a signature in the message)
export const PUBSUB_SIGNATURE_POLICY = 'StrictSign';
// Relayed connections between peers drop after hop timeout
// (redialled on discovery)
Implement peer package to send messages between peers (#279) * Initial implementation of class and discoving other peers * Implement peer connection and sending messages between peers * Add react app and use peer package for broadcasting * Maintain stream for each remote peer * Refactor code in peer package * Add serve package for react-app * Add readme for running react app * Add peer package readme * Add logs for events with details * Add a chat CLI using peer package (#280) * Add a flag to instantiate Peer for nodejs * Add a basic chat CLI using peer * Add a signal server arg to chat CLI * Add instructions for chat CLI * Fix typescript and ESM issues after adding peer package (#282) * Fix build issues in util package * Update eslint TS plugins * Scope react app package name * Convert cli package back to CJS and dynamically import ESM * Upgrade ts-node version * Fix tests * Setup a relay node and pubsub based discovery (#284) * Add a script to setup a relay node * Use pubsub based peer discovery * Add peer multiaddr to connection log * Catch relay node dial errors * Increase discovery interval and dial all mutiaddr * Add UI to display self peer ID and multiaddrs * Add UI for displaying live remote connections * Send js objects in peer broadcast messages * Add react-peer package for using peer in react app * Reduce disconnect frequency between peers (#287) * Restrict number of max concurrent dials per peer * Increase hop relay timeout to 1 day * Self review changes * Review changes * Increase pubsub discovery interval and add steps to create a peer id (#290) * Increase pubsub discovery interval * Disable autodial to avoid peer dials without protocol on a reconnect * Add steps to create a peer id and use for relay node * Add back dependency to run signalling server * Avoid bootstrapping and dial to relay node directly Co-authored-by: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Co-authored-by: prathamesh0 <prathamesh.musale0@gmail.com>
2023-01-10 14:40:27 +00:00
export const HOP_TIMEOUT = 24 * 60 * 60 * 1000; // 1 day
// Connected peers can be given tags according to their priority
// Create a high value tag for prioritizing primary relay node connection
export const RELAY_TAG = {
tag: 'laconic:relay-primary',
value: 100
};
// Interval in ms to check peer connections using ping
export const DEFAULT_PING_INTERVAL = 10000; // 10 seconds
// Ping timeout used to check if connection is alive
// Should be less than DEFAULT_PING_INTERVAL
export const DEFAULT_PING_TIMEOUT = 3000; // 3 seconds
// Redial interval (in ms) to relay node on connection failure
export const RELAY_REDIAL_INTERVAL = 5000; // 5 seconds
// Max number of relay node connections for a peer after which it starts igoring them
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
// Number of max concurrent dials per peer
export const MAX_CONCURRENT_DIALS_PER_PEER = 3;
// Max number of connections for a peer after which it starts pruning connections
export const MAX_CONNECTIONS = 10;
// Min number of connections for a peer below which autodial triggers (if enabled)
export const MIN_CONNECTIONS = 0;
// How long a dial is allowed to take before it's aborted
export const DIAL_TIMEOUT = 10000; // 10 seconds
// Relay node defaults
// Default host to bind relay server to
export const RELAY_DEFAULT_HOST = '127.0.0.1';
// Default port to start listening on
export const RELAY_DEFAULT_PORT = 9090;
// Default max number of dial retries to a relay peer
export const RELAY_DEFAULT_MAX_DIAL_RETRY = 10;