Setting up a constellation network
Now, let's first create four constellation nodes. For development purposes, we will run all four nodes in the same machine. For every constellation node, we have to generate a separate asymmetric key pair. Run the following commands in the raft directory to create the key pairs:
./constellation-node --generatekeys=node1
./constellation-node --generatekeys=node2
./constellation-node --generatekeys=node3
./constellation-node --generatekeys=node4
Here, we are generating a single public key for each constellation node. But, you can have multiple public keys for each constellation node. At the time of running the preceding commands, it will ask you to enter a password to encrypt the keys, but you can skip that by pressing the Enter key. In case you want to encrypt at the time of running the constellation node, you have to provide the password for decryption. To keep things simple, we will not set a password.
While starting a constellation node, you need to pass the various required and optional variables, such as the URL to advertize to other nodes (reachable by them), the local port to listen on, the directory to store the payload, public keys, private keys, TLS settings, and so on. You can pass these variables to the constellation node as options to the command, or else in the form of a configuration file. Let's create a configuration file for each constellation node, which will provide these settings for the constellation nodes to start. Following are the configuration files for the constellation nodes:
Here is the code for constellation1.conf:
url = "http://127.0.0.1:9001/"
port = 9001
storage = "dir:./cnode_data/cnode1/"
socket = "./cnode_data/cnode1/constellation_node1.ipc"
othernodes = ["http://127.0.0.1:9002/", "http://127.0.0.1:9003/", "http://127.0.0.1:9004/"]
publickeys = ["./cnode1.pub"]
privatekeys = ["./cnode1.key"]
tls = "off"
Here is the code for constellation2.conf:
url = "http://127.0.0.1:9002/"
port = 9002
storage = "dir:./cnode_data/cnode2/"
socket = "./cnode_data/cnode1/constellation_node2.ipc"
othernodes = ["http://127.0.0.1:9001/"]
publickeys = ["./cnode2.pub"]
privatekeys = ["./cnode2.key"]
tls = "off"
Here is the code for constellation3.conf:
url = "http://127.0.0.1:9003/"
port = 9003
storage = "dir:./cnode_data/cnode3/"
socket = "./cnode_data/cnode1/constellation_node3.ipc"
othernodes = ["http://127.0.0.1:9001/"]
publickeys = ["./cnode3.pub"]
privatekeys = ["./cnode3.key"]
tls = "off"
Here is the code for constellation4.conf:
url = "http://127.0.0.1:9004/"
port = 9004
storage = "dir:./cnode_data/cnode4/"
socket = "./cnode_data/cnode1/constellation_node4.ipc"
othernodes = ["http://127.0.0.1:9001/"]
publickeys = ["./cnode4.pub"]
privatekeys = ["./cnode4.key"]
tls = "off"
Here, the variable's name reveals what the variable is all about. One important thing to notice here is that we are not providing the other three nodes' URLs in the last three nodes, because constellation has a built-in auto-discovery protocol to find nodes in the network. So, here the first node is pointing to the last three, and the last three have a connection to the first, but in the end all will be able to find each other.
Now, run the following commands in different shell windows to start the constellation nodes:
./constellation-node constellation1.conf
./constellation-node constellation2.conf
./constellation-node constellation3.conf
./constellation-node constellation4.conf