Fran Villalba Segarra
Oct 7 · 5 min read

Hi there!

We launched X Core a few months ago. The number of nodes is growing exponentially, so we’re extremely thankful for that. The X Core app can already be ran on macOS, Linux, and Windows. Today, we’re unleashing a feature many of you have been requesting; a headless version of X Core.

This can be run on any OS and is to be installed via command-line interface. It is only to be used by advanced users who want to run a lighter version of X Core and manage it all via CLI. This version of X Core also allows the node operator to set up as many nodes as desired (the X Core app limits this to 1).

To install X Core Headless, simply follow this tutorial:

TL;DR

sudo apt update
sudo apt install git python
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bashexport NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install 8.15git clone https://github.com/internxt/xcore-daemon
cd xcore-daemon
npm i && npm link

Create a new node

Parameters needed (examples):

  • Wallet address (0x0000000000000000000000000000000000000000)
  • Public IP (81.81.81.81)
  • Public port (12345)
  • Path of folder to share (/home/user/xcore)
  • Size of storage to share (10GB)
xcore create --inxt 0x0000000000000000000000000000000000000000 --storage /home/user/xcore --size 10TB --rpcport 12345 --rpcaddress 81.81.81.81 --noedit

This command will only generate a new node configuration file on /home/user/.xcore/configs

Filename is [your node id].json

To start this new node, enter:

xcore daemon
xcore start --config /home/user/.xcore/configs/your_node_id.json

Installation

Make sure you have the following prerequisites installed:

  • Git
  • Node.js LTS (8.x.x)
  • NPM
  • Python 2.7
  • GCC/G++/Make

Node.js + NPM

GNU+Linux & Mac OSX

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

Close your shell and open an new one. Now that you can call the nvm program, install Node.js (which comes with NPM):

nvm install --lts

Windows

Download Node.js LTS for Windows, launch the installer and follow the setup instructions. Restart your PC, then test it from the command prompt:

node --version
npm --version

Build Dependencies

GNU+Linux

Debian based (like Ubuntu)

apt install git python build-essential

Red Hat / Centos

yum groupinstall 'Development Tools'

You might also find yourself lacking a C++11 compiler — see this

Mac OS X

xcode-select --install

Windows

npm install --global windows-build-tools

Install

Once build dependencies have been installed for your platform, install the package globally using Node Package Manager:

npm install --global internxt/xcore-daemon

Usage (CLI)

Once installed, you will have access to the xcore program, so start by asking it for some help.

xcore --help  Usage: xcore [options] [command]
Commands: start start a farming node
stop stop a farming node
restart restart a farming node
status check status of node(s)
logs tail the logs for a node
create create a new configuration
destroy kills the farming node
killall kills all shares and stops the daemon
daemon starts the daemon
help [cmd] display help for [cmd]
Options: -h, --help output usage information
-V, --version output the version number

You can also get more detailed help for a specific command.

xcore help create  Usage: xcore-create [options]  generates a new share configuration  Options:    -h, --help                 output usage information
--inxt <addr> specify the INXT address (required)
--key <privkey> specify the private key
--storage <path> specify the storage path
--size <maxsize> specify share size (ex: 10GB, 1TB)
--rpcport <port> specify the rpc port number
--rpcaddress <addr> specify the rpc address
--maxtunnels <tunnels> specify the max tunnels
--tunnelportmin <port> specify min gateway port
--tunnelportmax <port> specify max gateway port
--manualforwarding do not use nat traversal strategies
--logdir <path> specify the log directory
--noedit do not open generated config in editor
-o, --outfile <writepath> write config to path

Usage (Programmatic)

The X Core daemon uses a local dnode server to handle RPC message from the CLI and other applications. Assuming the daemon is running, your program can communicate with it using this interface. The example that follows is using Node.js, but dnode is implemented in many other languages.

const dnode = require('dnode');
const daemon = dnode.connect(45015);
daemon.on('remote', (rpc) => {
// rpc.start(configPath, callback);
// rpc.stop(nodeId, callback);
// rpc.restart(nodeId, callback);
// rpc.status(callback);
// rpc.destroy(nodeId, callback);
// rpc.save(snapshotPath, callback);
// rpc.load(snapshotPath, callback);
// rpc.killall(callback);
});

You can also easily start the daemon from your program by creating a dnode server and passing it an instance of the RPC class exposed from this package.

const xcore = require('xcore-daemon');
const dnode = require('dnode');
const api = new xcore.RPC();
dnode(api.methods).listen(45015, '127.0.0.1');

Configuring the Daemon

The X Core daemon loads configuration from anywhere the rc package can read it. The first time you run the daemon, it will create a directory in $HOME/.xcore, so the simplest way to change the daemon's behavior is to create a file at $HOME/.xcore/config containing the following:

{
"daemonRpcPort": 45015,
"daemonRpcAddress": "127.0.0.1",
"daemonLogFilePath": "",
"daemonLogVerbosity": 3
}

Modify these parameters to your liking, see example/daemon.config.json for detailed explanation of these properties.

Debugging the Daemon

The daemon logs activity to the configured log file, which by default is $HOME/.xcore/logs/daemon.log. However if you find yourself needing to frequently restart the daemon and check the logs during development, you can run the daemon as a foreground process for a tighter feedback loop.

xcore killall
xcore daemon --foreground

Connecting to a remote Daemon

Note: Exposing your xcore-daemon to the Internet is a bad idea as everybody could read your Private Key!

To connect to a remote running daemon instance you will first need to ensure this daemon is running on a different address than the default 127.0.0.1. This can be achieved by configuring the Daemon.

After your xcore-daemon is reachable (eg. within your home network) you can use -r or --remote option (on supported commands) to use the specified IP/hostname and port to connect to, instead of 127.0.0.1.

Note that this option does not support to start the xcore-daemon on a different system, only connect to an already running one!

Example to connect to remote daemon running on 192.168.0.10 on the default port (45015) and show the status:

xcore status --remote 192.168.0.10

If the port is changed, just append it like so:

xcore status --remote 192.168.0.10:51000

Internxt

Internxt is excitement, ambition, innovation. Join the revolution. The future is now.

Fran Villalba Segarra

Written by

Internxt

Internxt

Internxt is excitement, ambition, innovation. Join the revolution. The future is now.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade