diff --git a/modules/channel/chain-net-srv/dap_stream_ch_chain_net_srv.c b/modules/channel/chain-net-srv/dap_stream_ch_chain_net_srv.c index 9db68b80a12c372b6de57355da877ad311050de1..c89a35590e48b85a1042d72dba315a8669d3e0ef 100644 --- a/modules/channel/chain-net-srv/dap_stream_ch_chain_net_srv.c +++ b/modules/channel/chain-net-srv/dap_stream_ch_chain_net_srv.c @@ -372,11 +372,26 @@ static void s_grace_period_start(dap_chain_net_srv_grace_t *a_grace) } l_tx = a_grace->usage->is_waiting_new_tx_cond ? NULL : dap_chain_ledger_tx_find_by_hash(l_ledger, &a_grace->usage->tx_cond_hash); - if ( ! l_tx ){ // No tx cond transaction, start grace-period + if (!l_tx) { // No tx cond transaction, start grace-period a_grace->usage->is_grace = true; - l_price = DAP_DUP(a_grace->usage->service->pricelist); + DL_FOREACH(a_grace->usage->service->pricelist, l_price) { + switch (l_price->units_uid.enm) { + case SERV_UNIT_MB: + case SERV_UNIT_SEC: + case SERV_UNIT_DAY: + case SERV_UNIT_KB: + case SERV_UNIT_B: + log_it(L_MSG, "Proper unit type %s found among available prices", + dap_chain_srv_unit_enum_to_str(l_price->units_uid.enm)); + break; + default: + continue; + } + break; // proper price found, thus we exit from the loop + } if (!l_price) { - log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); + log_it(L_ERROR, "Price with proper unit type not found, check available orders and/or pricelists"); + l_err.code = DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_ERROR_CODE_CANT_ADD_USAGE; s_grace_error(a_grace, l_err); return; } @@ -425,12 +440,17 @@ static void s_grace_period_start(dap_chain_net_srv_grace_t *a_grace) return; } - const char * l_ticker = NULL; - l_ticker = dap_chain_ledger_tx_get_token_ticker_by_hash(l_ledger, &a_grace->usage->tx_cond_hash); + const char *l_ticker = dap_chain_ledger_tx_get_token_ticker_by_hash(l_ledger, &a_grace->usage->tx_cond_hash); + if (!l_ticker) { + char l_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE] = { '\0' }; + dap_hash_fast_to_str(&a_grace->usage->tx_cond_hash, l_hash_str, sizeof(l_hash_str)); + log_it( L_ERROR, "Token ticker not found for tx cond hash %s", l_hash_str); + l_err.code = DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_ERROR_CODE_TX_COND_NOT_FOUND; + s_grace_error(a_grace, l_err); + return; + } dap_stpcpy(a_grace->usage->token_ticker, l_ticker); - - dap_chain_net_srv_price_t *l_price_tmp; DL_FOREACH(a_grace->usage->service->pricelist, l_price_tmp) { if (l_price_tmp && l_price_tmp->net->pub.id.uint64 == a_grace->usage->net->pub.id.uint64 @@ -500,7 +520,8 @@ static bool s_grace_period_finish(usages_in_grace_t *a_grace_item) } if (l_grace->usage->price && !l_grace->usage->receipt_next){ // if first grace delete price and set actual - DAP_DEL_Z(l_grace->usage->price); + l_grace->usage->price = NULL; + } if (l_grace->usage->is_waiting_new_tx_cond){ diff --git a/modules/service/vpn/dap_chain_net_srv_vpn.c b/modules/service/vpn/dap_chain_net_srv_vpn.c index 78b816991304cffddbc4708c6689f7498262d642..bf8c5871a6bea4967f8b53d955173ab029151a13 100644 --- a/modules/service/vpn/dap_chain_net_srv_vpn.c +++ b/modules/service/vpn/dap_chain_net_srv_vpn.c @@ -962,14 +962,12 @@ static int s_callback_response_success(dap_chain_net_srv_t * a_srv, uint32_t a_u l_usage_client->usage_id = a_usage_id; if (!l_usage_active->is_free){ - l_usage_client->receipt = DAP_NEW_SIZE(dap_chain_datum_tx_receipt_t,l_receipt_size); + l_usage_client->receipt = DAP_DUP_SIZE(l_receipt, l_receipt_size); if (!l_usage_client->receipt) { log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); DAP_DEL_Z(l_usage_client); return -1; } - - memcpy(l_usage_client->receipt, l_receipt, l_receipt_size); } pthread_rwlock_wrlock(&s_clients_rwlock); HASH_ADD(hh, s_clients,usage_id,sizeof(a_usage_id),l_usage_client);