Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update build_ppc and ppc_builder #22

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 47 additions & 8 deletions cpp/tools/build_ppc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ sm2_params="sm_sm2.param"
sm_mode="false"
days=36500
rsa_key_length=2048
p2p_connected_conf_name="nodes.json"
file_dir="./"

default_version="v1.1.0"
compatibility_version=${default_version}
Expand Down Expand Up @@ -338,7 +340,7 @@ Usage:
-l <IP list> [Required] "ip1:nodeNum1,ip2:nodeNum2" e.g:"192.168.0.1:2,192.168.0.2:3"
-e <ppc-air-node exec> [Optional] ppc-air-node binary exec
-o <output dir> [Optional] output directory, default ./nodes
-p <Start port> [Optional] Default 40300,10200 means p2p_port start from 40300, rpc_port from 10200
-p <Start port> [Optional] Default 40300,10200,18000 means p2p_port start from 40300, rpc_port from 10200, grpc_port from 18000
-s <SM model> [Optional] SM SSL connection or not, default is false
-d <Disable ra2018> [Optional] Disable ra2018 psi or not, default is false
-h Help
Expand All @@ -350,8 +352,39 @@ EOF
exit 0
}


generate_p2p_connected_conf() {
local output="${1}"
local ip_params="${2}"
local template="${3}"

local p2p_host_list=""
if [[ "${template}" == "true" ]]; then
p2p_host_list="${ip_params}"
else
local ip_array=(${ip_params//,/ })
local ip_length=${#ip_array[@]}

local i=0
for (( ; i < ip_length; i++)); do
local ip=${ip_array[i]}
local delim=""
if [[ $i == $((ip_length - 1)) ]]; then
delim=""
else
delim=","
fi
p2p_host_list="${p2p_host_list}\"${ip}\"${delim}"
done
fi

cat <<EOF >"${output}"
{"nodes":[${p2p_host_list}]}
EOF
}

# generate the config.ini
generate_config_ini() {
generate_node_config_ini() {
local output="${1}"
local gateway_listen_ip="${2}"
local gateway_listen_port="${3}"
Expand All @@ -364,6 +397,7 @@ generate_config_ini() {

local agency_id="${8}"
local index="${9}"
local nodeid="${10}"

cat <<EOF >"${output}"
[agency]
Expand All @@ -389,13 +423,18 @@ generate_config_ini() {
service.gateway_target =
; the components
service.components =
nodeid=${nodeid}

[crypto]
sm_crypto = ${sm_mode}

[gateway]
listen_ip=${gateway_listen_ip}
listen_port=${gateway_listen_port}
;the dir that contains the connected endpoint information, e.g.nodes.json
;nodes_path=${file_dir}
; the file that configure the connected endpoint information
; nodes_file=${p2p_connected_conf_name}
; thread_count = 4
; ssl or sm ssl
sm_ssl=${sm_mode}
Expand All @@ -408,10 +447,6 @@ generate_config_ini() {
;reconnect_time = 10000
; the unreachable distance
;unreachable_distance=10
;the dir that contains the connected endpoint information, e.g.nodes.json
;nodes_path=./
; the file that configure the connected endpoint information
; nodes_path=nodes.json

[rpc]
listen_ip=${rpc_listen_ip}
Expand Down Expand Up @@ -786,6 +821,7 @@ generate_private_key() {
fi
${OPENSSL_CMD} genpkey -paramfile ${sm2_params} -out ${output_path}/node.pem 2>/dev/null
$OPENSSL_CMD ec -in "$output_path/node.pem" -text -noout 2> /dev/null | sed -n '3,5p' | sed 's/://g' | tr "\n" " " | sed 's/ //g' | cat > "$output_path/node.privateKey"
${OPENSSL_CMD} ec -text -noout -in "${output_path}/node.pem" 2>/dev/null | sed -n '7,11p' | tr -d ": \n" | awk '{print substr($0,3);}' | cat >"$output_path"/node.nodeid
private_key=$(cat $output_path/node.privateKey)
echo ${private_key}
}
Expand Down Expand Up @@ -819,6 +855,7 @@ deploy_nodes()
# generate the ca-cert
ca_dir="${output_dir}"/ca
generate_ca_cert "${sm_mode}" "${ca_dir}"
connected_nodes=""
for line in ${ip_array[*]}; do
ip=${line%:*}
num=${line#*:}
Expand Down Expand Up @@ -849,7 +886,7 @@ deploy_nodes()
# generate the node-script
generate_node_scripts "${node_dir}"
local port=$((gateway_listen_port + node_count))
"
connected_nodes=${connected_nodes}"${ip}:${port}, "
((agency_index += 1))
set_value ${ip//./}_count $(($(get_value ${ip//./}_count) + 1))
((++count))
Expand All @@ -875,7 +912,9 @@ deploy_nodes()
local grpc_port=$((grpc_listen_port + node_count))
local agency_id="agency${count}"
private_key=$(generate_private_key "${node_dir}/conf")
generate_config_ini "${node_dir}/config.ini" "${listen_ip}" "${gateway_port}" "${listen_ip}" "${rpc_port}" "${listen_ip}" "${grpc_port}" ${agency_id} "${count}"
node_id=$(cat "${node_dir}/conf/node.nodeid")
generate_node_config_ini "${node_dir}/config.ini" "${listen_ip}" "${gateway_port}" "${listen_ip}" "${rpc_port}" "${listen_ip}" "${grpc_port}" ${agency_id} "${count}" "${node_id}"
generate_p2p_connected_conf "${node_dir}/${p2p_connected_conf_name}" "${connected_nodes}" "false"
set_value ${ip//./}_count $(($(get_value ${ip//./}_count) + 1))
((++count))
done
Expand Down
7 changes: 4 additions & 3 deletions cpp/tools/ppc-builder/build_ppc.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# Note: here can't be refactored by autopep
import sys
sys.path.append("src/")

from controller import commandline_helper
from common import utilities
import traceback
import sys
sys.path.append("src/")


def main():
Expand All @@ -14,6 +14,7 @@ def main():
commandline_helper.execute_command(args)
except Exception as error:
utilities.log_error("%s" % error)
traceback.print_exc()


if __name__ == "__main__":
Expand Down
78 changes: 27 additions & 51 deletions cpp/tools/ppc-builder/conf/config-example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tars]
tars_pkg_dir = "bin/"
app_name = "ppc1"
[env]
binary_path = "bin/"
deploy_dir = "ppc1"

[crypto]
# the gateway-service enable ssl or not, default enable ssl
Expand All @@ -27,25 +27,11 @@ holding_msg_minutes = 30
listen_port=40300
# the thread count
thread_count = 4
# the cache config for the gateway
cache_type = 0
cache_proxy = ""
cache_obServer = ""
cache_cluster = ""
cache_host = "127.0.0.1"
cache_port = 6379
cache_password = ""
cache_database = 1
cache_pool_size = 16
# the redis connection timeout, in ms, default is 500ms
cache_connection_timeout = 500
# the redis socket timeout, in ms, default is 500ms
cache_socket_timeout = 500
# the tars config
# gateway tars server listen ip
tars_listen_ip="0.0.0.0"
# gateway tars server listen start port
tars_listen_port=40600
# the grpc config
# gateway grpc server listen ip
grpc_listen_ip="0.0.0.0"
# gateway grpc server listen start port
grpc_listen_port=40600
# gateway connected peers, should be all of the gateway peers info
[[agency.gateway.peers]]
agency = "agency0"
Expand All @@ -61,10 +47,12 @@ holding_msg_minutes = 30
deploy_ip=["127.0.0.1:2"]
# node name, Notice: node_name in the same agency and group must be unique
node_name = "node0"
# node tars server listen ip
tars_listen_ip="0.0.0.0"
# node tars server listen port
tars_listen_port=40402
# node grpc server listen ip
grpc_listen_ip="0.0.0.0"
# node grpc server listen port
grpc_listen_port=40402
# the components
components = "node"
# the rpc config for the node
[agency.node.rpc]
listen_ip = "0.0.0.0"
Expand Down Expand Up @@ -108,7 +96,7 @@ holding_msg_minutes = 30
token = ""
# the gateway config
[agency.node.gateway]
tars_endpoints = ["127.0.0.1:40600", "127.0.0.1:40601"]
gateway_grpc_target = ["127.0.0.1:40600", "127.0.0.1:40601"]


[[agency]]
Expand All @@ -124,25 +112,11 @@ holding_msg_minutes = 30
listen_port=40320
# the thread count
thread_count = 4
# the cache config for the gateway
cache_type = 0
cache_proxy = ""
cache_obServer = ""
cache_cluster = ""
cache_host = "127.0.0.1"
cache_port = 6379
cache_password = ""
cache_database = 2
cache_pool_size = 16
# the redis connection timeout, in ms, default is 500ms
cache_connection_timeout = 500
# the redis socket timeout, in ms, default is 500ms
cache_socket_timeout = 500
# the tars config
# gateway tars server listen ip
tars_listen_ip="0.0.0.0"
# gateway tars server listen start port
tars_listen_port=40620
# the grpc config
# gateway grpc server listen ip
grpc_listen_ip="0.0.0.0"
# gateway grpc server listen start port
grpc_listen_port=40620
# gateway connected peers, should be all of the gateway peers info
[[agency.gateway.peers]]
agency = "agency0"
Expand All @@ -158,10 +132,12 @@ holding_msg_minutes = 30
deploy_ip=["127.0.0.1:2"]
# node name, Notice: node_name in the same agency and group must be unique
node_name = "node0"
# node tars server listen ip
tars_listen_ip="0.0.0.0"
# node tars server listen port
tars_listen_port=40422
# node grpc server listen ip
grpc_listen_ip="0.0.0.0"
# node grpc server listen port
grpc_listen_port=40422
# the componet
components = "node"
# the rpc config for the node
[agency.node.rpc]
listen_ip = "0.0.0.0"
Expand Down Expand Up @@ -205,4 +181,4 @@ holding_msg_minutes = 30
token = ""
# the gateway config
[agency.node.gateway]
tars_endpoints = ["127.0.0.1:40620", "127.0.0.1:40621"]
gateway_grpc_target = ["127.0.0.1:40620", "127.0.0.1:40621"]
53 changes: 16 additions & 37 deletions cpp/tools/ppc-builder/src/common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ class ServiceInfo:
ssl_file_list = ["ca.crt", "ssl.key", "ssl.crt"]
sm_ssl_file_list = ["sm_ca.crt", "sm_ssl.key",
"sm_ssl.crt", "sm_enssl.key", "sm_enssl.crt"]

node_service_postfix = "NodeService"
gateway_servant = "GatewayService"
gateway_servant_obj = ["GatewayServiceObj"]

node_servant = ["FrontService"]
node_servant_object = ["FrontServiceObj"]

cert_generation_script_path = "src/scripts/gen_cert.sh"
node_service_type = "node"
gateway_service_type = "gateway"
Expand All @@ -31,29 +23,26 @@ class ServiceInfo:

class ConfigInfo:
config_ini_file = "config.ini"
tars_config_file = "tars.conf"

tpl_abs_path = "src/tpl/"
pwd_path = os.getcwd()
node_config_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "config.ini.node")
gateway_config_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "config.ini.gateway")
tars_config_tpl_path = os.path.join(pwd_path, tpl_abs_path, "tars.conf")

tars_start_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "tars_start.sh")
tars_stop_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "tars_stop.sh")

tars_start_all_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "tars_start_all.sh")
tars_stop_all_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "tars_stop_all.sh")

ppc_gateway_binary_name = "ppc-gateway-service"
ppc_node_binary_name = "ppc-pro-node"

start_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "start.sh")
stop_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "stop.sh")

start_all_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "start_all.sh")
stop_all_tpl_path = os.path.join(
pwd_path, tpl_abs_path, "stop_all.sh")


class CommandInfo:
generate_config = "genconfig"
Expand Down Expand Up @@ -123,10 +112,6 @@ def mkfiledir(filepath):
mkdir(parent_dir)


def generate_service_name(prefix, service_name):
return prefix + service_name


def convert_bool_to_str(value):
if value is True:
return "true"
Expand Down Expand Up @@ -162,7 +147,12 @@ def store_config(config_content, config_type, config_path, desc):
mkdir(os.path.dirname(config_path))

with open(config_path, 'w') as configFile:
config_content.write(configFile)
if isinstance(config_content, str):
configFile.write(config_content)
elif isinstance(config_content, bytes):
configFile.write(config_content)
else:
config_content.write(configFile)
log_info("* store %s config for %s success" %
(config_type, desc))
return True
Expand All @@ -176,14 +166,3 @@ def load_config(file_path):
config_content.optionxform = str
config_content.read(file_path)
return config_content


def check_service_name(tag, service_name):
"""
Note: tars service name can only contain letters and numbers
"""
service_name_len = len(service_name)
ret = re.search(r'^[A-Za-z0-9]+', service_name).span()
if ret is None or (ret[0] != 0 or ret[1] != service_name_len):
raise Exception(
"the %s must be letters|numbers, invalid value: %s" % (tag, service_name))
2 changes: 1 addition & 1 deletion cpp/tools/ppc-builder/src/config/cert_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ def generate_private_key(output_path):
"* generate private key error, output_path: %s" % output_path)
return (False, output)
utilities.log_info(
"* generate private_key success, path: %s, private_key: %s" % (output_path, output))
"* generate private_key success, path: %s, public_key: %s" % (output_path, output))
return (True, output)
Loading
Loading