Skip to content

Commit

Permalink
Support different IPs for node and client listeners.
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Shilov <[email protected]>
  • Loading branch information
Sergey Shilov committed May 28, 2018
1 parent bb29128 commit 3f3f70a
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 64 deletions.
20 changes: 12 additions & 8 deletions build-scripts/ubuntu-1604/postinst_node
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,30 @@ chmod -R ug+rwx $CLI_BASE_DIR
cat <<EOF > /usr/local/bin/init_indy_node
#!/bin/bash
if [ \$# -lt 3 ]; then
if [ \$# -lt 5 ]; then
echo ""
echo "Usage: \$0 name port client_port [seed]";
echo "Usage: \$0 name ip port client_ip client_port [seed]";
echo " name - node name";
echo " ip - node IP";
echo " port - node port";
echo " client_ip - node client IP";
echo " client_port - node client port";
echo " seed - node seed";
echo ""
exit 1;
fi
echo "NODE_NAME=\$1" > $GENERAL_CONFIG_DIR/indy.env
echo "NODE_PORT=\$2" >> $GENERAL_CONFIG_DIR/indy.env
echo "NODE_CLIENT_PORT=\$3" >> $GENERAL_CONFIG_DIR/indy.env
echo "NODE_IP=\$2" >> $GENERAL_CONFIG_DIR/indy.env
echo "NODE_PORT=\$3" >> $GENERAL_CONFIG_DIR/indy.env
echo "NODE_CLIENT_IP=\$4" >> $GENERAL_CONFIG_DIR/indy.env
echo "NODE_CLIENT_PORT=\$5" >> $GENERAL_CONFIG_DIR/indy.env
echo "CLIENT_CONNECTIONS_LIMIT=$CLIENT_CONNECTIONS_LIMIT" >> $GENERAL_CONFIG_DIR/indy.env
if [ -z \$4 ]; then
if [ -z \$6 ]; then
init_indy_keys --name \$1
else
init_indy_keys --name \$1 --seed \$4
init_indy_keys --name \$1 --seed \$6
fi
EOF

Expand All @@ -89,7 +93,7 @@ Requires=indy-node-control.service
[Service]
EnvironmentFile=$GENERAL_CONFIG_DIR/indy.env
ExecStart=/usr/bin/env python3 -O /usr/local/bin/start_indy_node \${NODE_NAME} \${NODE_PORT} \${NODE_CLIENT_PORT}
ExecStart=/usr/bin/env python3 -O /usr/local/bin/start_indy_node \${NODE_NAME} \${NODE_IP} \${NODE_PORT} \${NODE_CLIENT_IP} \${NODE_CLIENT_PORT}
User=indy
Group=indy
Restart=on-failure
Expand Down Expand Up @@ -143,7 +147,7 @@ port = 127.0.0.1:9001
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:indy-node]
command=sh -ac '. $GENERAL_CONFIG_DIR/indy.env;/usr/bin/env python3 -O /usr/local/bin/start_indy_node \${NODE_NAME} \${NODE_PORT} \${NODE_CLIENT_PORT}'
command=sh -ac '. $GENERAL_CONFIG_DIR/indy.env;/usr/bin/env python3 -O /usr/local/bin/start_indy_node \${NODE_NAME} \${NODE_IP} \${NODE_PORT} \${NODE_CLIENT_IP} \${NODE_CLIENT_PORT}'
user=indy
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
Expand Down
8 changes: 4 additions & 4 deletions docs/indy-running-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ At this point you are now ready to start the nodes.

Open up 4 new terminal windows and in each one run one of the following commands (one in each window):
```
start_indy_node Node1 9701 9702
start_indy_node Node2 9703 9704
start_indy_node Node3 9705 9706
start_indy_node Node4 9707 9708
start_indy_node Node1 0.0.0.0 9701 0.0.0.0 9702
start_indy_node Node2 0.0.0.0 9703 0.0.0.0 9704
start_indy_node Node3 0.0.0.0 9705 0.0.0.0 9706
start_indy_node Node4 0.0.0.0 9707 0.0.0.0 9708
```

This will start each node which should connect to each other, do their handshaking and will elect a master and backup.
Expand Down
24 changes: 13 additions & 11 deletions docs/start-nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ There are a number of scripts which can help in generation of keys and running a
###### For deb installation
The following script should be used to generate both ed25519 and BLS keys for a node named `Alpha` with node port `9701` and client port `9702`:
```
init_indy_node Alpha 9701 9702 [--seed 111111111111111111111111111Alpha]
init_indy_node Alpha 0.0.0.0 9701 0.0.0.0 9702 [--seed 111111111111111111111111111Alpha]
```
Also this script generates indy-node environment file needed for systemd service config and indy-node iptables setup script.
Expand Down Expand Up @@ -81,10 +81,12 @@ Instructions related to iptables setup can be found [here](https://github.com/hy
The following script will start a Node process which can communicate with other Nodes and Clients:
```
start_indy_node Alpha 9701 9702
start_indy_node Alpha 0.0.0.0 9701 0.0.0.0 9702
```
The node uses separate TCP channels for communicating with nodes and clients.
The first port number is for the node-to-node communication channel and the second is for node-to-client communication channel.
The first IP/port pair is for the node-to-node communication channel and the second IP/port pair is for node-to-client communication channel.
IP addresses may be changed according to hardware configuration.
Different IP addresses for node-to-node and node-to-client communication may be used.
## Local Test Network Example
Expand All @@ -101,16 +103,16 @@ Node4 will use ports 9707 and 9708 for nodestack and clientstack respectively
Now you can run the 4 nodes as
```
start_indy_node Node1 9701 9702
start_indy_node Node1 0.0.0.0 9701 0.0.0.0 9702
```
```
start_indy_node Node2 9703 9704
start_indy_node Node2 0.0.0.0 9703 0.0.0.0 9704
```
```
start_indy_node Node3 9705 9706
start_indy_node Node3 0.0.0.0 9705 0.0.0.0 9706
```
```
start_indy_node Node4 9707 9708
start_indy_node Node4 0.0.0.0 9707 0.0.0.0 9708
```
## Remote Test Network Example
Expand Down Expand Up @@ -147,14 +149,14 @@ This node with name Node4 will use ports 9707 and 9708 for nodestack and clients
Now you can run the 4 nodes as
```
start_indy_node Node1 9701 9702
start_indy_node Node1 0.0.0.0 9701 0.0.0.0 9702
```
```
start_indy_node Node2 9703 9704
start_indy_node Node2 0.0.0.0 9703 0.0.0.0 9704
```
```
start_indy_node Node3 9705 9706
start_indy_node Node3 0.0.0.0 9705 0.0.0.0 9706
```
```
start_indy_node Node4 9707 9708
start_indy_node Node4 0.0.0.0 9707 0.0.0.0 9708
```
8 changes: 4 additions & 4 deletions environment/docker/getting_started_turnkey/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ info: local

cluster:
@echo -e $(BLUE_COLOR) CLUSTER: Create 4 Nodes at IPS $(IPS) $(NO_COLOR)
docker run --name Node1 -d -p 9701:9701 -p 9702:9702 indy-base /bin/bash -c "create_dirs.sh; init_indy_keys --name Node1; generate_indy_pool_transactions --nodes 4 --clients 5 --nodeNum 1 --ips $(IPS); start_indy_node Node1 9701 9702"
docker run --name Node2 -d -p 9703:9703 -p 9704:9704 indy-base /bin/bash -c "create_dirs.sh; init_indy_keys --name Node2; generate_indy_pool_transactions --nodes 4 --clients 5 --nodeNum 2 --ips $(IPS); start_indy_node Node2 9703 9704"
docker run --name Node3 -d -p 9705:9705 -p 9706:9706 indy-base /bin/bash -c "create_dirs.sh; init_indy_keys --name Node3; generate_indy_pool_transactions --nodes 4 --clients 5 --nodeNum 3 --ips $(IPS); start_indy_node Node3 9705 9706"
docker run --name Node4 -d -p 9707:9707 -p 9708:9708 indy-base /bin/bash -c "create_dirs.sh; init_indy_keys --name Node4; generate_indy_pool_transactions --nodes 4 --clients 5 --nodeNum 4 --ips $(IPS); start_indy_node Node4 9707 9708"
docker run --name Node1 -d -p 9701:9701 -p 9702:9702 indy-base /bin/bash -c "create_dirs.sh; init_indy_keys --name Node1; generate_indy_pool_transactions --nodes 4 --clients 5 --nodeNum 1 --ips $(IPS); start_indy_node Node1 0.0.0.0 9701 0.0.0.0 9702"
docker run --name Node2 -d -p 9703:9703 -p 9704:9704 indy-base /bin/bash -c "create_dirs.sh; init_indy_keys --name Node2; generate_indy_pool_transactions --nodes 4 --clients 5 --nodeNum 2 --ips $(IPS); start_indy_node Node2 0.0.0.0 9703 0.0.0.0 9704"
docker run --name Node3 -d -p 9705:9705 -p 9706:9706 indy-base /bin/bash -c "create_dirs.sh; init_indy_keys --name Node3; generate_indy_pool_transactions --nodes 4 --clients 5 --nodeNum 3 --ips $(IPS); start_indy_node Node3 0.0.0.0 9705 0.0.0.0 9706"
docker run --name Node4 -d -p 9707:9707 -p 9708:9708 indy-base /bin/bash -c "create_dirs.sh; init_indy_keys --name Node4; generate_indy_pool_transactions --nodes 4 --clients 5 --nodeNum 4 --ips $(IPS); start_indy_node Node4 0.0.0.0 9707 0.0.0.0 9708"
@echo -e $(OK_COLOR) SUCCESS: Cluster 4 nodes success at IPS $(IPS) $(NO_COLOR)

indy-cli: info
Expand Down
2 changes: 1 addition & 1 deletion environment/docker/getting_started_turnkey/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ To start the docker image as an Indy node:
```
$ docker run -it --rm indy-base /bin/bash
# init_indy_keys --name Alpha
# start_indy_node Alpha 9701 9702
# start_indy_node Alpha 0.0.0.0 9701 0.0.0.0 9702
```

You can connect to an existing node:
Expand Down
6 changes: 4 additions & 2 deletions environment/docker/pool/node.init.ubuntu.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
FROM indycore

ARG nodename
ARG nip
ARG nport
ARG cip
ARG cport
ARG ips
ARG nodenum
Expand All @@ -18,8 +20,8 @@ RUN echo "logLevel=0" >> /etc/indy/indy_config.py
RUN echo " " >> /etc/indy/indy_config.py

# Init indy-node
RUN init_indy_node $nodename $nport $cport
EXPOSE $nport $cport
RUN init_indy_node $nodename $nip $nport $cip $cport
EXPOSE $nip $nport $cip $cport
RUN if [ ! -z "$ips" ] && [ ! -z "$nodenum" ] && [ ! -z "$nodecnt" ]; then generate_indy_pool_transactions --nodes $nodecnt --clients $clicnt --nodeNum $nodenum --ips "$ips"; fi
USER root
CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"]
6 changes: 4 additions & 2 deletions environment/openshift/scripts/common/initialize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ if [ ! -z "${NODE_SERVICE_HOST_PATTERN}" ]; then
fi
fi

if [ ! -z "${NODE_NAME}" ] && [ ! -z "${NODE_PORT}" ] && [ ! -z "${CLIENT_PORT}" ]; then
if [ ! -z "${NODE_NAME}" ] && [ ! -z "${NODE_IP}" ] && [ ! -z "${NODE_PORT}" ] && [ ! -z "${CLIENT_IP}" ] && [ ! -z "${CLIENT_PORT}" ]; then
echo ===============================================================================
echo "Initializing indy node:"
echo -e "\tName: ${NODE_NAME}"
echo -e "\tNode IP: ${NODE_IP}"
echo -e "\tNode Port: ${NODE_PORT}"
echo -e "\tClient IP: ${CLIENT_IP}"
echo -e "\tClient Port: ${CLIENT_PORT}"
echo -------------------------------------------------------------------------------
init_indy_node ${NODE_NAME} ${NODE_PORT} ${CLIENT_PORT}
init_indy_node ${NODE_NAME} ${NODE_IP} ${NODE_PORT} ${CLIENT_IP} ${CLIENT_PORT}
echo ===============================================================================
echo
fi
Expand Down
4 changes: 2 additions & 2 deletions environment/openshift/scripts/node/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ echo
# sleep 10

echo "Starting indy-node service ..."
echo "/usr/bin/env python3 -O /usr/local/bin/start_indy_node ${NODE_NAME} ${NODE_PORT} ${CLIENT_PORT}"
echo "/usr/bin/env python3 -O /usr/local/bin/start_indy_node ${NODE_NAME} ${NODE_IP} ${NODE_PORT} ${CLIENT_IP} ${CLIENT_PORT}"
echo
exec /usr/bin/env python3 -O /usr/local/bin/start_indy_node ${NODE_NAME} ${NODE_PORT} ${CLIENT_PORT}
exec /usr/bin/env python3 -O /usr/local/bin/start_indy_node ${NODE_NAME} ${NODE_IP} ${NODE_PORT} ${CLIENT_IP} ${CLIENT_PORT}

# echo "Indy node started."
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/bash

HOSTNAME=$1
NODEIP=$2
NODEPORT=$2
CLIENTIP=$3
CLIENTPORT=$3

#--------------------------------------------------------
Expand All @@ -24,7 +26,7 @@ DEBIAN_FRONTEND=noninteractive apt-get install -y dialog figlet python-pip pytho

#--------------------------------------------------------
echo 'Setting Up Indy Node'
su - indy -c "init_indy_node $HOSTNAME $NODEPORT $CLIENTPORT"
su - indy -c "init_indy_node $HOSTNAME $NODEIP $NODEPORT $CLIENTIP $CLIENTPORT"
systemctl start indy-node
systemctl enable indy-node
systemctl status indy-node.service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

/vagrant/scripts/validator.sh Node1 9701 9702
/vagrant/scripts/validator.sh Node1 10.20.30.201 9701 10.20.30.201 9702
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

/vagrant/scripts/validator.sh Node2 9703 9704
/vagrant/scripts/validator.sh Node2 10.20.30.202 9703 10.20.30.202 9704
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

/vagrant/scripts/validator.sh Node3 9705 9706
/vagrant/scripts/validator.sh Node3 10.20.30.203 9705 10.20.30.203 9706
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

/vagrant/scripts/validator.sh Node4 9707 9708
/vagrant/scripts/validator.sh Node4 10.20.30.204 9707 10.20.30.204 9708
16 changes: 9 additions & 7 deletions environment/vagrant/training/vb-multi-vm/scripts/validator.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

display_usage() {
echo -e "Usage:\t$0 <NODENAME> <NODEPORT> <CLIENTPORT> <TIMEZONE>"
echo -e "EXAMPLE: $0 Node1 9701 9702 /usr/share/zoneinfo/America/Denver"
echo -e "Usage:\t$0 <NODENAME> <NODEIP> <NODEPORT> <CLIENTIP> <CLIENTPORT> <TIMEZONE>"
echo -e "EXAMPLE: $0 Node1 0.0.0.0 9701 0.0.0.0 9702 /usr/share/zoneinfo/America/Denver"
}

# if less than one argument is supplied, display usage
Expand All @@ -13,9 +13,11 @@ then
fi

HOSTNAME=$1
NODEPORT=$2
CLIENTPORT=$3
TIMEZONE=$4
NODEIP=$2
NODEPORT=$3
CLIENTIP=$4
CLIENTPORT=$5
TIMEZONE=$6


#--------------------------------------------------------
Expand Down Expand Up @@ -45,7 +47,7 @@ mv /tmp/indy_config.py /etc/indy/indy_config.py
[[ $HOSTNAME =~ [^0-9]*([0-9]*) ]]
NODENUM=${BASH_REMATCH[1]}
echo "Setting Up Indy Node Number $NODENUM"
su - indy -c "init_indy_node $HOSTNAME $NODEPORT $CLIENTPORT" # set up /etc/indy/indy.env
su - indy -c "init_indy_node $HOSTNAME $NODEIP $NODEPORT $CLIENTIP $CLIENTPORT" # set up /etc/indy/indy.env
su - indy -c "generate_indy_pool_transactions --nodes 4 --clients 4 --nodeNum $NODENUM --ips '10.20.30.201,10.20.30.202,10.20.30.203,10.20.30.204'"
systemctl start indy-node
systemctl enable indy-node
Expand All @@ -67,7 +69,7 @@ else
fi
chown indy:indy /etc/indy/indy_config.py
echo "Setting Up Indy Node Number $NODENUM"
su - indy -c "init_indy_node $HOSTNAME $NODEPORT $CLIENTPORT" # set up /etc/indy/indy.env
su - indy -c "init_indy_node $HOSTNAME $NODEIP $NODEPORT $CLIENTIP $CLIENTPORT" # set up /etc/indy/indy.env
su - indy -c "generate_indy_pool_transactions --nodes 4 --clients 4 --nodeNum $NODENUM --ips '10.20.30.201,10.20.30.202,10.20.30.203,10.20.30.204'"
systemctl start indy-node
systemctl enable indy-node
Expand Down
6 changes: 3 additions & 3 deletions indy_node/utils/node_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def integrate(node_config_helper, node, logger):
return node


def run_node(config, name, node_port, client_port):
node_ha = HA("0.0.0.0", node_port)
client_ha = HA("0.0.0.0", client_port)
def run_node(config, name, node_ip, node_port, client_ip, client_port):
node_ha = HA(node_ip, node_port)
client_ha = HA(client_ip, client_port)

node_config_helper = NodeConfigHelper(name, config)

Expand Down
24 changes: 17 additions & 7 deletions scripts/install_indy_node.bat
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
@echo off

SET NODE_NAME=%1
SET NODE_PORT=%2
SET CLI_PORT=%3
SET USER=%4
SET PASSWORD=%5
SET RUN_MODE=%6
SET TEST_MODE=%7
SET NODE_IP=%2
SET NODE_PORT=%3
SET CLI_IP=%4
SET CLI_PORT=%5
SET USER=%6
SET PASSWORD=%7
SET RUN_MODE=%8
SET TEST_MODE=%9

IF NOT DEFINED NODE_NAME (
echo "NODE_NAME argument is required"
exit /B 1
)
IF NOT DEFINED NODE_IP (
echo "NODE_IP argument is required"
exit /B 1
)
IF NOT DEFINED NODE_PORT (
echo "NODE_PORT argument is required"
exit /B 1
)
IF NOT DEFINED CLI_IP (
echo "CLI_IP argument is required"
exit /B 1
)
IF NOT DEFINED CLI_PORT (
echo "CLI_PORT argument is required"
exit /B 1
Expand Down Expand Up @@ -49,7 +59,7 @@ nssm set IndyNodeUpgradeAgent AppParameters "%CURR_DIR%node_control_tool.py %TES
echo "Creating service for node"
nssm install IndyNode "%PYTHONPATH%"
nssm set IndyNode AppDirectory %CURR_DIR%
nssm set IndyNode AppParameters "%CURR_DIR%start_indy_node %NODE_NAME% %NODE_PORT% %CLI_PORT%"
nssm set IndyNode AppParameters "%CURR_DIR%start_indy_node %NODE_NAME% %NODE_IP% %NODE_PORT% %CLI_IP% %CLI_PORT%"
nssm set IndyNode ObjectName ".\%USER%" "%PASSWORD%"
echo "Creating agent restart task"
SchTasks /Create /TN RestartIndyNodeUpgradeAgent /TR "%CURR_DIR%restart_upgrade_agent.bat" /SC ONSTART /F
8 changes: 4 additions & 4 deletions scripts/running_locally/setupEnvironment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ echo Environment setup complete
echo
echo "The nodes can be started using :"
echo
echo "start_indy_node Node1 9701 9702"
echo "start_indy_node Node2 9703 9704"
echo "start_indy_node Node3 9705 9706"
echo "start_indy_node Node4 9707 9708"
echo "start_indy_node Node1 0.0.0.0 9701 0.0.0.0 9702"
echo "start_indy_node Node2 0.0.0.0 9703 0.0.0.0 9704"
echo "start_indy_node Node3 0.0.0.0 9705 0.0.0.0 9706"
echo "start_indy_node Node4 0.0.0.0 9707 0.0.0.0 9708"
echo
10 changes: 6 additions & 4 deletions scripts/start_indy_node
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ from indy_common.config_util import getConfig


if __name__ == "__main__":
if len(sys.argv) < 4:
raise Exception("Provide name and 2 port numbers for running the node "
"and client stacks")
if len(sys.argv) < 6:
raise Exception("Provide name and two pairs of IP/port for running the node "
"and client stacks in form 'node_name node_ip node_port client_ip client_port'")

config = getConfig()
self_name = sys.argv[1]
run_node(config, self_name, int(sys.argv[2]), int(sys.argv[3]))
run_node(config, self_name,
node_ip=sys.argv[2], node_port=int(sys.argv[3]),
client_ip=sys.argv[4], client_port=int(sys.argv[5]))

0 comments on commit 3f3f70a

Please sign in to comment.