Skip to content

Commit

Permalink
feat: Add Public URL notice (#316)
Browse files Browse the repository at this point in the history
* Add public ws urls

* Add public url notice to logger

* Run linter

* Notify user only if its a public endpoint

* Add clarifying comments about hardcoded ws urls

* Cleanup logger by making terminal isPublicUrl output single line.

* Run linter

* Add warning if on unsecure, and non local url

* Run linter

* Add localhost to isLocal check
  • Loading branch information
TarikGul committed Oct 21, 2020
1 parent ee0a048 commit d1f01ea
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ async function main() {

const { logger } = Log;

/**
* Best effort list of known public nodes that do not encourage high traffic
* sidecar installations connecting to them for non - testing / development purposes.
*/
const publicWsUrls: string[] = [
'wss://rpc.polkadot.io',
'wss://cc1-1.polkadot.network',
'wss://kusama-rpc.polkadot.io',
'wss://cc3-5.kusama.network',
'wss://fullnode.centrifuge.io',
'wss://crab.darwinia.network',
'wss://mainnet-node.dock.io',
'wss://mainnet1.edgewa.re',
'wss://rpc.kulupu.corepaper.org/ws',
'wss://main1.nodleprotocol.io',
'wss://rpc.plasmnet.io/',
'wss://mainnet-rpc.stafi.io',
'wss://rpc.subsocial.network',
];

// Overide console.{log, error, warn, etc}
consoleOverride(logger);

Expand All @@ -54,6 +74,30 @@ async function main() {
}`
);

const isPublicUrl: boolean = publicWsUrls.includes(config.SUBSTRATE.WS_URL);

if (isPublicUrl) {
logger.info(
`${config.SUBSTRATE.WS_URL} is a public node. Too many users will overload this public endpoint. Switch to a privately hosted node when possible.`
);
}

// Split the Url to check for 2 things. Secure connection, and if its a local IP.
const splitUrl: string[] = config.SUBSTRATE.WS_URL.split(':');
// If its 'ws' its not a secure connection.
const isSecure: boolean = splitUrl[0] === 'wss';
// Check if its a local IP.
const isLocal: boolean =
splitUrl[1] === '//0.0.0.0' ||
splitUrl[1] === '//127.0.0.1' ||
splitUrl[1] === '//localhost';

if (!isSecure && !isLocal) {
logger.warn(
`Using unencrypted connection to a public node (${config.SUBSTRATE.WS_URL}); All traffic is sent over the internet in cleartext.`
);
}

// Instantiate v0 controllers (note these will be removed upon the release of v1.0.0)
const claimsController = new controllers.v0.v0Claims(api);
const txArtifactsController = new controllers.v0.v0TransactionMaterial(api);
Expand Down

0 comments on commit d1f01ea

Please sign in to comment.