Skip to content

Commit

Permalink
[chainmaker][#1330]add BoATChainmaker_FreeNetworkContext interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Cavalierliu committed Dec 15, 2022
1 parent 278d5ad commit a27be09
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 25 deletions.
1 change: 0 additions & 1 deletion include/network/network_chainmaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
//!< set to 1.
//!< @note This macro is reserved for future.

#define BOAT_CHAINMAKER_NODE_INFO_MAX_LEN 127 //!< Maxmum length of node's URL
#define BOAT_CHAINMAKER_CERT_MAX_LEN 1024 //!< Maxmum length of certificate

//!@brief chainmaker certificate information config structure
Expand Down
125 changes: 101 additions & 24 deletions sdk/network/chainmaker/network_chainmaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,24 @@ __BOATSTATIC BOAT_RESULT BoATChainmaker_getNetworkFromProto(BoatChainmakerNetwor
Networkdata->ca_tls_cert_content.length = strlen(network_proto->ca_tls_cert_content);
strcpy((BCHAR *)Networkdata->ca_tls_cert_content.content, network_proto->ca_tls_cert_content);

#if (BOAT_CHAINMAKER_TLS_IDENTIFY_CLIENT == 1)
if (strlen(network_proto->client_tls_cert_content) - 1 > sizeof(Networkdata->client_tls_cert_content.content))
{
BoatLog(BOAT_LOG_NORMAL, "client tls cert len exceed");
return BOAT_ERROR_COMMON_OUT_OF_MEMORY;
}
#if (BOAT_CHAINMAKER_TLS_IDENTIFY_CLIENT == 1)
if (strlen(network_proto->client_tls_cert_content) - 1 > sizeof(Networkdata->client_tls_cert_content.content))
{
BoatLog(BOAT_LOG_NORMAL, "client tls cert len exceed");
return BOAT_ERROR_COMMON_OUT_OF_MEMORY;
}

Networkdata->client_tls_cert_content.length = strlen(network_proto->client_tls_cert_content);
strcpy((BCHAR *)Networkdata->client_tls_cert_content.content, network_proto->client_tls_cert_content);
Networkdata->client_tls_cert_content.length = strlen(network_proto->client_tls_cert_content);
strcpy((BCHAR *)Networkdata->client_tls_cert_content.content, network_proto->client_tls_cert_content);

if (strlen(network_proto->client_tls_privkey_data) - 1 > sizeof(Networkdata->client_tls_privkey_data.value))
{
BoatLog(BOAT_LOG_NORMAL, "client tls prikey len exceed");
return BOAT_ERROR_COMMON_OUT_OF_MEMORY;
}
Networkdata->client_tls_privkey_data.value_len = strlen(network_proto->client_tls_privkey_data);
strcpy((BCHAR *)Networkdata->client_tls_privkey_data.value, network_proto->client_tls_privkey_data);
#endif
if (strlen(network_proto->client_tls_privkey_data) - 1 > sizeof(Networkdata->client_tls_privkey_data.value))
{
BoatLog(BOAT_LOG_NORMAL, "client tls prikey len exceed");
return BOAT_ERROR_COMMON_OUT_OF_MEMORY;
}
Networkdata->client_tls_privkey_data.value_len = strlen(network_proto->client_tls_privkey_data);
strcpy((BCHAR *)Networkdata->client_tls_privkey_data.value, network_proto->client_tls_privkey_data);
#endif
#endif

return result;
Expand Down Expand Up @@ -472,10 +472,10 @@ __BOATSTATIC BOAT_RESULT BoATChainmaker_Get_Network_Data(BoatChainmakerNetworkDa

#if (BOAT_CHAINMAKER_TLS_SUPPORT == 1)
protobuf_network.ca_tls_cert_content = (BCHAR *)networkData->ca_tls_cert_content.content;
#if (BOAT_CHAINMAKER_TLS_IDENTIFY_CLIENT == 1)
protobuf_network.client_tls_privkey_data = (BCHAR *)networkData->client_tls_privkey_data.value;
protobuf_network.client_tls_cert_content = (BCHAR *)networkData->client_tls_cert_content.content;
#endif
#if (BOAT_CHAINMAKER_TLS_IDENTIFY_CLIENT == 1)
protobuf_network.client_tls_privkey_data = (BCHAR *)networkData->client_tls_privkey_data.value;
protobuf_network.client_tls_cert_content = (BCHAR *)networkData->client_tls_cert_content.content;
#endif
#endif

networkLength = common__chainmaker_network_data__get_packed_size(&protobuf_network);
Expand Down Expand Up @@ -732,10 +732,10 @@ BOAT_RESULT BoatChainmakerNetworkCreate(BoatChainmakerNetworkData *networkConfig

#if (BOAT_CHAINMAKER_TLS_SUPPORT == 1)
mNetworkDataCtx.ca_tls_cert_content = networkConfig->ca_tls_cert_content;
#if (BOAT_CHAINMAKER_TLS_IDENTIFY_CLIENT == 1)
mNetworkDataCtx.client_tls_cert_content = networkConfig->client_tls_cert_content;
mNetworkDataCtx.client_tls_privkey_data = networkConfig->client_tls_privkey_data;
#endif
#if (BOAT_CHAINMAKER_TLS_IDENTIFY_CLIENT == 1)
mNetworkDataCtx.client_tls_cert_content = networkConfig->client_tls_cert_content;
mNetworkDataCtx.client_tls_privkey_data = networkConfig->client_tls_privkey_data;
#endif
#endif

result = BoATChainmaker_NetworkDataCtx_Store(&mNetworkDataCtx, storeType);
Expand Down Expand Up @@ -1055,4 +1055,81 @@ BOAT_RESULT BoATChainmaker_GetNetworkByIndex(BoatChainmakerNetworkData *networkD
}
}
return BOAT_ERROR_NETWORK_INEXISTENCE;
}

/**
* @description:
* This function reset every param in BoatChainmakerNetworkData;
* if someone have malloced memory , free the memory;
* @param {BoatChainmakerNetworkData} networkData
* @return {*}
* This function returns BOAT_SUCCESS if successfully executed.
* Otherwise it returns one of the error codes. Refer to header file boaterrcode.h
* for details.
* @author: aitos
*/
BOAT_RESULT BoATChainmaker_FreeNetworkData(BoatChainmakerNetworkData *networkData)
{
BOAT_RESULT result = BOAT_SUCCESS;

networkData->networkIndex = 0;
networkData->client_member_type = 0;
networkData->client_sign_cert_content.length = 0;

#if (BOAT_CHAINMAKER_TLS_SUPPORT == 1)
networkData->ca_tls_cert_content.length = 0;
#if (BOAT_CHAINMAKER_TLS_IDENTIFY_CLIENT == 1)
networkData->client_tls_privkey_data.value_len = 0;
networkData->client_tls_cert_content.length = 0;
#endif
#endif

if (NULL != networkData->node_url)
{
BoatFree(networkData->node_url);
}

if (NULL != networkData->host_name)
{
BoatFree(networkData->host_name);
}

if (NULL != networkData->chain_id)
{
BoatFree(networkData->chain_id);
}

if (NULL != networkData->org_id)
{
BoatFree(networkData->org_id);
}

return result;
}



/**
* @description:
* This function use to free BoatChainmakerNetworkContext param.
* @param[in] {BoatChainmakerNetworkContext} networkList
* @return {*}
* This function returns BOAT_SUCCESS if successfully executed.
* Otherwise it returns one of the error codes. Refer to header file boaterrcode.h
* for details.
* @author: aitos
*/
BOAT_RESULT BoATChainmaker_FreeNetworkContext(BoatChainmakerNetworkContext networkList)
{
if (networkList.networkNum == 0)
{
return BOAT_SUCCESS;
}
for (int i = 0; i < networkList.networkNum; i++)
{
/* code */
BoATChainmaker_FreeNetworkData(&networkList.networks[i]);
}
networkList.networkNum = 0;
return BOAT_SUCCESS;
}

0 comments on commit a27be09

Please sign in to comment.