1.2.4 • Published 4 years ago

@noia-network/node v1.2.4

Weekly downloads
3
License
LGPL-2.1
Repository
github
Last release
4 years ago

README

You would normally want to use noia-node-gui or noia-node-terminal.

Modules

moduledescription
noia-nodecore noia node (this module)
noia-node-contents-clientused to manage contents for noia-node
*noia-node-guinode graphical user interface
*noia-node-terminalheadless (terminal) node

* - example modules how to use noia-node internally and create headless or node with GUI.

Sample code

console.log("[NODE]: Initializing...")
// Initialize node with default values
const node = new Node({
  settingsPath: "settings.json",
  ssl: true,
  privateKeyPath: "path/to/private.key",
  crtPath: "path/to/crt.cert",
  crtBundlePath: "path/to/crt-bundle.cert",
  // One option for test purposes is to use https://ropsten.infura.io infrastructure.
  walletProviderUrl: "https://example-wallet-provider.io/API_KEY"
})
console.log("[NODE]: initialized.")

// Setters take effect after restart
// node.setStorageSpace('/path/to/storage', 1048576)

// Events
node.on("started", () => {
  console.log("[NODE]: started.")
})
node.master.on("connected", () => {
  console.log("[NODE]: connected to master.")
})
node.master.on("closed", (info) => {
  if (info && info.code !== 1000) {
    console.log(`[NODE]: connection with master closed, info =`, info)
    node.restart()
  } else {
    console.log(`[NODE]: connection with master closed, normal exit`, info)
  }
})
node.master.on("cache", (info) => {
  console.log(`[NODE][IN]: cache request, resource = ${info.source.url}`)
})
node.master.on("clear", (info) => {
  console.log(`[NODE][IN]: clear request, infoHashes = ${info.infoHashes}`)
})
node.master.on("seed", (info) => {
  console.log("[NODE][IN]: seed request.")
})
if (node.clientSockets.http) {
  node.clientSockets.http.on("listening", (info) => {
    console.log(`[NODE]: listening for HTTP requests on port ${info.port}.`)
  })
  node.clientSockets.http.on("closed", () => {
  console.log(`[NODE]: closed HTTP server.`)
  })
}
if (node.clientSockets.ws) {
  node.clientSockets.ws.on("listening", (info) => {
    console.log(`[NODE]: listening for ${info.ssl ? "WSS" : "WS"} requests on port ${info.port}.`)
  })
  node.clientSockets.ws.on("closed", () => {
    console.log(`[NODE]: closed WS/WSS server.`)
  })
  node.clientSockets.ws.on("connections", (count) => {
    console.log(`[NODE]: WS Clients connections = ${count}`)
  })
}
node.contentsClient.on("seeding", (infoHashes) => {
  console.log("[NODE]: seeding contents: ", infoHashes)
})
node.clientSockets.on("resourceSent", (info) => {
  const client = `client ${info.ip}`
  const resource = `resource = ${info.resource.infoHash}`
  const url = `url = ${info.resource.url}`
  const size = `size = ${info.resource.size}`
  const sizeMB = `size = ${info.resource.size/1024/1024}`
  if (info.resource.url) {
    console.log(`[NODE]: HTTP sent to ${client} ${resource} ${sizeMB} ${url}`)
  } else {
    console.log(`[NODE]: WS sent to ${client} ${resource} ${sizeMB}`)
  }
})
node.on("destroyed", () => {
  console.log("[NODE]: stopped.")
})
node.on("error", (error) => {
  console.log("[NODE]: error =", error)
})

// Start
node.start()

Configuration

Node configuration can be supplied to Node object or set via settings.json file. settings.json is generated on first run.

*requiredNode options propertysettings.json propertytypedefaultdescription
nosettingsPathN/Astring./settings.jsonPath to settings.json.
nostatisticsPathN/AstatisticsPath./statistics.jsonPath to statistics.json.
nouserDataPathN/AstringemptyPath to user user data folder. If specified, default settings.json and/or statistics.json will be saved to user data folder.
noisHeadlessisHeadlessbooleantrueFalse if node GUI.
nostorageDirstorage.dirstring./storagePath to storage directory.
nostorageSizestorage.sizenumber104857600Size of disk space available to use for caching purposes.
if wsdomaindomainstringemptyDomain SSL is valid for.
if wssslsslbooleanfalseTrue to use secure connections.
if wssslPrivateKeyPathssl.privateKeyPathstringemptyPath to SSL private key.
if wssslCrtPathssl.crtPathstringemptyPath to certificate.
if wssslCrtBundlePathssl.crtBundlePathstringemptyPath to certificate bundle.
nopublicIppublicIpstringemptyPublic IP that master must use. If empty, master must resolve IP by itself.
nonatPmpnatPmpbooleanfalseAutomatic ports mapping using NAT-PMP.
nohttpsockets.httpbooleanfalseTrue to deliver content via HTTP protocol.
nohttpIpsockets.http.ipstring0.0.0.0HTTP listening ip.
nohttpPortsockets.http.portnumber6767HTTP listening port.
nowssockets.wsbooleanfalseTrue to deliver content via WebSockets protocol.
nowsIpsockets.ws.ipstring0.0.0.0WS listening ip.
nowsPortsockets.ws.portnumber7676WS listening port.
yeswrtcsockets.wrtcbooleantrueTrue to deliver content via WebRTC.
yeswrtcControlPortsockets.wrtc.control.portnumber7677Control port to exchange SDP descriptions via HTTP.
yeswrtcControlIpsockets.wrtc.control.ipstring0.0.0.0Control ip to exchange SDP descriptions via HTTP.
yeswrtcDataPortsockets.wrtc.data.portnumber7679WebRTC data port.
nowrtcDataIpsockets.wrtc.data.ipstringundefinedWebRTC data IP.
nowalletMnemonicwallet.mnemonicstringgeneratedWallet mnemonic.
nowalletAddresswallet.addressstringemptyWallet address. If skipBlockchain is turned on this setting takes effect, else walletMnemonic is used to retrieve wallet address.
if not skipBlockchainwalletProviderUrlwallet.providerUrlstringemptyWallet provider url.
noclientclientstringemptyNode client address.
if skipBlockchainmasterAddressmasterAddressstringemptyMaster address to connect to if skipping blockchain.
nowhitelistMasterswhitelist.mastersarray"csl-masters.noia.network"Masters whitelist. If empty array then all masters addresses are available.
nocontrollercontrollerbooleanfalseRESTful node controller. Listens by default on 9000 port when turned on.
nocontrollerIpcontrollerIpstring127.0.0.1Node controller IP
nocontrollerPortcontrollerPortstring9000Node controller port
noskipBlockchainskipBlockchainbooleantrueConnect directy to master using masterAddress (ignores whitelist) if turned on.
nonodeIdnodeIdstringgeneratedNode identifier if skipping blockchain.

* mandatory to make sure configuration is correct to connect to NOIA master and serve content using WebRTC protocol (default setup) or via secure WS (WebSockets). Currently HTTPS is not recommended and poorly supported.

Note: skipBlockchain is turned on by default while we develop blockchain network.

Note: On startup, node is registered on blockchain and client address (client) is saved in settings.json. If any of domain, sockets.ws.port or external IP information property changes, client should be regenerated. To do so, simply remove client property from settings.json and it will registern node client on blockchain with updated values.

SSL

TODO: add SSL docs.

Logging to log file

Node by default doesn't log activiy to file. To log to file noia-node.log, create .env file and add line LOG_TO_FILE=yes to enable it.

1.2.5-rc.1

4 years ago

1.2.5-rc

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.3-rc

5 years ago

1.2.2

5 years ago

1.2.2-rc

5 years ago

1.2.1

5 years ago

1.2.1-rc.4

5 years ago

1.2.1-rc.3

5 years ago

1.2.1-rc.2

5 years ago

1.2.1-rc.1

5 years ago

1.2.1-rc

5 years ago

1.1.5

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-rc.21

5 years ago

1.0.0-rc.20

5 years ago

1.0.0-rc.19

5 years ago

1.0.0-rc.18

5 years ago

1.0.0-rc.17

5 years ago

1.0.0-rc.16

5 years ago

1.0.0-rc.15

5 years ago

1.0.0-rc.14

6 years ago

1.0.0-rc.13

6 years ago

1.0.0-rc.12

6 years ago

1.0.0-rc.11

6 years ago

1.0.0-rc.10

6 years ago

1.0.0-rc.9

6 years ago

1.0.0-rc.8

6 years ago

1.0.0-rc.7

6 years ago

1.0.0-rc.6

6 years ago

1.0.0-rc.5

6 years ago

1.0.0-rc.4

6 years ago

1.0.0-rc.3

6 years ago

1.0.0-rc.2

6 years ago

1.0.0-rc

6 years ago

1.0.0-alpha.3

6 years ago

1.0.0-alpha.2

6 years ago

1.0.0-alpha.1

6 years ago

1.0.0-alpha

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.4.1

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.17

6 years ago

0.3.16

6 years ago

0.3.15

6 years ago

0.3.14

6 years ago

0.3.13

6 years ago

0.3.12

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago