配置简介¶
标签:c-sdk
config
bcos-c-sdk
支持配置对象和配置文件两种方式的初始化:
配置对象初始化:
void* bcos_sdk_create(struct bcos_sdk_c_config* config)
配置文件初始化:
void* bcos_sdk_create_by_config_file(const char* config_file)
本节内容介绍配置对象struct bcos_sdk_c_config
和配置文件config_file
。
配置项¶
源码:
struct bcos_sdk_c_config
{
// common config
int thread_pool_size;
int message_timeout_ms;
int reconnect_period_ms;
int heartbeat_period_ms;
// connected peers
struct bcos_sdk_c_endpoint* peers;
size_t peers_count;
// the switch for disable ssl connection
int disable_ssl;
// ssl or sm_ssl
char* ssl_type;
// cert config items is the content of the cert or the path of the cert file
int is_cert_path;
// ssl connection cert, effective with ssl_type is 'ssl'
struct bcos_sdk_c_cert_config* cert_config;
// sm ssl connection cert, effective with ssl_type is 'sm_ssl'
struct bcos_sdk_c_sm_cert_config* sm_cert_config;
};
struct bcos_sdk_c_endpoint
{
char* host; // c-style string,end with '\0', ipv4、ipv6 support
uint16_t port;
};
struct bcos_sdk_c_cert_config
{
char* ca_cert; // cert and key should be in pem format
char* node_key;
char* node_cert;
};
struct bcos_sdk_c_sm_cert_config
{
char* ca_cert; // cert and key should be in pem format
char* node_key;
char* node_cert;
char* en_node_key;
char* en_node_cert;
};
字段含义:
bcos_sdk_c_endpoint
¶
功能
连接
ip:port
字段
host
: 节点rpc
连接,支持ipv4
、ipv6
格式 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放port
: 节点rpc
端口
bcos_sdk_c_cert_config
¶
功能:
ssl
连接证书配置,ssl_type
为ssl
时有效
字段:
ca_cert
: 根证书配置, 支持文件路径和文件内容两种方式, 参考is_cert_path
字段, 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放node_cert
:sdk
证书, 支持文件路径和文件内容两种方式,参考is_cert_path
字段, 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放node_key
:sdk
私钥, 支持文件路径和文件内容两种方式,参考is_cert_path
字段, 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放
bcos_sdk_c_sm_cert_config
¶
功能:
国密
ssl
连接证书配置,ssl_type
为sm_ssl
时有效
字段:
ca_cert
: 国密根证, 支持文件路径和文件内容两种方式 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放node_cert
:sdk
国密签名证书, 支持文件路径和文件内容两种方式,参考is_cert_path
字段 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放node_key
:sdk
国密签名私钥, 支持文件路径和文件内容两种方式,参考is_cert_path
字段 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放en_node_key
:sdk
国密加密证书, 支持文件路径和文件内容两种方式,参考is_cert_path
字段 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放en_node_crt
:sdk
国密加密私钥, 支持文件路径和文件内容两种方式,参考is_cert_path
字段 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放
bcos_sdk_c_config
¶
字段:
thread_pool_size
: 线程池大小,该线程池用于处理网络消息message_timeout_ms
: 消息超时时间peers
: 连接列表, 注意: 使用malloc
初始化,确保可以使用free
释放peers_count
: 连接列表大小disable_ssl
: 是否屏蔽ssl
, 0: 否, 1: 是ssl_type
:ssl
类型, 支持ssl
和sm_ssl
两种 注意: 使用strdup
或者malloc
初始化,确保可以使用free
释放is_cert_path
:ssl
连接证书的配置项为文件路径或者文件内容, 0:内容, 1:路径bcos_sdk_c_cert_config
:ssl
连接的证书配置,ssl_type
为ssl
时有效 注意: 使用malloc
初始化,确保可以使用free
释放bcos_sdk_c_sm_cert_config
: 国密ssl
连接的证书配置,ssl_type
为sm_ssl
时有效 注意: 使用malloc
初始化,确保可以使用free
释放
配置文件¶
配置文件中的字段与配置对象中的字段对应.
ssl
连接配置文件
[common]
; if ssl connection is disabled, default: false
; disable_ssl = true
; thread pool size for network message sending receiving handing
thread_pool_size = 8
; send message timeout(ms)
message_timeout_ms = 10000
; ssl cert config items,
[cert]
; ssl_type: ssl or sm_ssl, default: ssl
ssl_type = ssl
; directory the certificates located in, default: ./conf
ca_path=./conf
; the ca certificate file
ca_cert=ca.crt
; the node private key file
sdk_key=sdk.key
; the node certificate file
sdk_cert=sdk.crt
[peers]
# supported ipv4 and ipv6
node.0=127.0.0.1:20200
node.1=127.0.0.1:20201
国密
ssl
连接配置文件
[common]
; if ssl connection is disabled, default: false
; disable_ssl = true
; thread pool size for network message sending receiving handing
thread_pool_size = 8
; send message timeout(ms)
message_timeout_ms = 10000
[cert]
; ssl_type: ssl or sm_ssl, default: ssl
ssl_type = sm_ssl
; directory the certificates located in, default: ./conf
ca_path=./conf
; the ca certificate file
sm_ca_cert=sm_ca.crt
; the node private key file
sm_sdk_key=sm_sdk.key
; the node certificate file
sm_sdk_cert=sm_sdk.crt
; the node private key file
sm_ensdk_key=sm_ensdk.key
; the node certificate file
sm_ensdk_cert=sm_ensdk.crt
[peers]
# supported ipv4 and ipv6
node.0=127.0.0.1:20200
node.1=127.0.0.1:20201