Skip to content
Snippets Groups Projects
Commit a8d44be0 authored by Constantin P.'s avatar Constantin P. 💬
Browse files

Merge branch 'hotfix-vpn-charged-mode-2' into 'master'

Hotfix vpn charged mode 2

See merge request !1229
parents b5add58f 5b72c390
No related branches found
No related tags found
1 merge request!1229Hotfix vpn charged mode 2
Pipeline #29241 passed with stage
in 10 minutes and 7 seconds
...@@ -374,15 +374,12 @@ static void s_grace_period_start(dap_chain_net_srv_grace_t *a_grace) ...@@ -374,15 +374,12 @@ 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); 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; a_grace->usage->is_grace = true;
l_price = DAP_DUP(a_grace->usage->service->pricelist);
l_price = DAP_NEW_Z(dap_chain_net_srv_price_t);
if (!l_price) { if (!l_price) {
log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__);
s_grace_error(a_grace, l_err); s_grace_error(a_grace, l_err);
return; return;
} }
memcpy(l_price, a_grace->usage->service->pricelist, sizeof(*l_price));
a_grace->usage->price = l_price; a_grace->usage->price = l_price;
if (!a_grace->usage->receipt){ if (!a_grace->usage->receipt){
...@@ -662,7 +659,7 @@ static bool s_grace_period_finish(usages_in_grace_t *a_grace_item) ...@@ -662,7 +659,7 @@ static bool s_grace_period_finish(usages_in_grace_t *a_grace_item)
RET_WITH_DEL_A_GRACE; RET_WITH_DEL_A_GRACE;
} }
l_grace_new->request->hdr.net_id = a_grace_item->grace->usage->net->pub.id; l_grace_new->request->hdr.net_id = a_grace_item->grace->usage->net->pub.id;
memcpy(l_grace_new->request->hdr.token, a_grace_item->grace->usage->token_ticker, strlen(a_grace_item->grace->usage->token_ticker)); dap_stpcpy(l_grace_new->request->hdr.token, a_grace_item->grace->usage->token_ticker);
l_grace_new->request->hdr.srv_uid = a_grace_item->grace->usage->service->uid; l_grace_new->request->hdr.srv_uid = a_grace_item->grace->usage->service->uid;
l_grace_new->request->hdr.tx_cond = a_grace_item->grace->usage->tx_cond_hash; l_grace_new->request->hdr.tx_cond = a_grace_item->grace->usage->tx_cond_hash;
l_grace_new->request_size = sizeof(dap_stream_ch_chain_net_srv_pkt_request_t); l_grace_new->request_size = sizeof(dap_stream_ch_chain_net_srv_pkt_request_t);
...@@ -781,12 +778,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg) ...@@ -781,12 +778,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg)
log_it( L_WARNING, "Wrong request size, less than minimum"); log_it( L_WARNING, "Wrong request size, less than minimum");
break; break;
} }
dap_stream_ch_chain_net_srv_pkt_request_t *l_request = DAP_NEW_Z_SIZE(dap_stream_ch_chain_net_srv_pkt_request_t, l_ch_pkt->hdr.data_size); dap_stream_ch_chain_net_srv_pkt_request_t *l_request = (dap_stream_ch_chain_net_srv_pkt_request_t*)l_ch_pkt->data;
if (!l_request) {
log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__);
return;
}
memcpy(l_request, l_ch_pkt->data, l_ch_pkt->hdr.data_size);
l_ch_chain_net_srv->srv_uid.uint64 = l_request->hdr.srv_uid.uint64; l_ch_chain_net_srv->srv_uid.uint64 = l_request->hdr.srv_uid.uint64;
s_service_start(a_ch, l_request, l_ch_pkt->hdr.data_size); s_service_start(a_ch, l_request, l_ch_pkt->hdr.data_size);
} break; /* DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_REQUEST */ } break; /* DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_REQUEST */
...@@ -900,25 +892,23 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg) ...@@ -900,25 +892,23 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg)
// Update actual receipt // Update actual receipt
bool l_is_first_sign = false; bool l_is_first_sign = false;
if (! l_usage->receipt_next && l_usage->receipt){ if (!l_usage->receipt_next && l_usage->receipt) {
DAP_DEL_Z(l_usage->receipt); DAP_DELETE(l_usage->receipt);
l_usage->receipt = DAP_NEW_SIZE(dap_chain_datum_tx_receipt_t,l_receipt_size); l_usage->receipt = DAP_DUP_SIZE(l_receipt, l_receipt_size);
if (!l_usage->receipt_next) { if (!l_usage->receipt) {
log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__);
return; return;
} }
l_is_first_sign = true; l_is_first_sign = true;
l_usage->is_active = true; l_usage->is_active = true;
memcpy( l_usage->receipt, l_receipt, l_receipt_size); } else if (l_usage->receipt_next) {
} else if (l_usage->receipt_next ){ DAP_DELETE(l_usage->receipt_next);
DAP_DEL_Z(l_usage->receipt_next); l_usage->receipt_next = DAP_DUP_SIZE(l_receipt, l_receipt_size);
l_usage->receipt_next = DAP_NEW_SIZE(dap_chain_datum_tx_receipt_t,l_receipt_size);
if (!l_usage->receipt_next) { if (!l_usage->receipt_next) {
log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__); log_it(L_ERROR, "Memory allocation error in %s, line %d", __PRETTY_FUNCTION__, __LINE__);
return; return;
} }
l_usage->is_active = true; l_usage->is_active = true;
memcpy( l_usage->receipt_next, l_receipt, l_receipt_size);
} }
// Store receipt if any problems with transactions // Store receipt if any problems with transactions
...@@ -963,7 +953,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg) ...@@ -963,7 +953,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg)
return; return;
} }
l_grace->request->hdr.net_id = l_usage->net->pub.id; l_grace->request->hdr.net_id = l_usage->net->pub.id;
memcpy(l_grace->request->hdr.token, l_usage->token_ticker, strlen(l_usage->token_ticker)); dap_stpcpy(l_grace->request->hdr.token, l_usage->token_ticker);
l_grace->request->hdr.srv_uid = l_usage->service->uid; l_grace->request->hdr.srv_uid = l_usage->service->uid;
l_grace->request->hdr.tx_cond = l_usage->tx_cond_hash; l_grace->request->hdr.tx_cond = l_usage->tx_cond_hash;
l_ch_chain_net_srv->srv_uid.uint64 = l_grace->request->hdr.srv_uid.uint64; l_ch_chain_net_srv->srv_uid.uint64 = l_grace->request->hdr.srv_uid.uint64;
...@@ -993,7 +983,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg) ...@@ -993,7 +983,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg)
return; return;
} }
l_grace->request->hdr.net_id = l_usage->net->pub.id; l_grace->request->hdr.net_id = l_usage->net->pub.id;
memcpy(l_grace->request->hdr.token, l_usage->token_ticker, strlen(l_usage->token_ticker)); dap_stpcpy(l_grace->request->hdr.token, l_usage->token_ticker);
l_grace->request->hdr.srv_uid = l_usage->service->uid; l_grace->request->hdr.srv_uid = l_usage->service->uid;
l_grace->request->hdr.tx_cond = l_usage->tx_cond_hash; l_grace->request->hdr.tx_cond = l_usage->tx_cond_hash;
l_ch_chain_net_srv->srv_uid.uint64 = l_grace->request->hdr.srv_uid.uint64; l_ch_chain_net_srv->srv_uid.uint64 = l_grace->request->hdr.srv_uid.uint64;
...@@ -1028,30 +1018,26 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg) ...@@ -1028,30 +1018,26 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg)
if (!l_usage->is_grace) if (!l_usage->is_grace)
break; break;
} }
l_success_size = sizeof(dap_stream_ch_chain_net_srv_pkt_success_hdr_t) + DAP_CHAIN_HASH_FAST_STR_SIZE;//sizeof(dap_chain_hash_fast_t); l_success_size = sizeof(dap_stream_ch_chain_net_srv_pkt_success_hdr_t) + DAP_CHAIN_HASH_FAST_STR_SIZE;
} else { } else {
l_success_size = sizeof(dap_stream_ch_chain_net_srv_pkt_success_hdr_t); l_success_size = sizeof(dap_stream_ch_chain_net_srv_pkt_success_hdr_t);
} }
dap_stream_ch_chain_net_srv_pkt_success_t *l_success = DAP_NEW_STACK_SIZE(dap_stream_ch_chain_net_srv_pkt_success_t, dap_stream_ch_chain_net_srv_pkt_success_t *l_success = DAP_NEW_STACK_SIZE(dap_stream_ch_chain_net_srv_pkt_success_t, l_success_size);
l_success_size); l_success->hdr = (dap_stream_ch_chain_net_srv_pkt_success_hdr_t) {
memset(&l_success->hdr, 0, sizeof(l_success->hdr)); .usage_id = l_usage->id,
.net_id = l_usage->net->pub.id,
l_success->hdr.usage_id = l_usage->id; .srv_uid = l_usage->service->uid
l_success->hdr.net_id.uint64 = l_usage->net->pub.id.uint64; };
l_success->hdr.srv_uid.uint64 = l_usage->service->uid.uint64; if (l_usage->is_grace) {
char l_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE] = { '\0' };
if (l_usage->is_grace){ dap_hash_fast_to_str(&l_usage->tx_cond_hash, l_hash_str, sizeof(l_hash_str));
char *l_hash_str = dap_hash_fast_to_str_new(&l_usage->tx_cond_hash);
log_it(L_NOTICE, "Receipt is OK, but tx transaction %s %s. Start the grace period for %d seconds", l_hash_str, log_it(L_NOTICE, "Receipt is OK, but tx transaction %s %s. Start the grace period for %d seconds", l_hash_str,
l_usage->is_waiting_new_tx_cond ? "have no enough funds. New tx cond requested": "can't be found", l_usage->is_waiting_new_tx_cond ? "have no enough funds. New tx cond requested": "can't be found",
l_srv->grace_period); l_srv->grace_period);
DAP_DEL_Z(l_hash_str); } else {
}else { dap_hash_fast_to_str(&l_usage->tx_cond_hash, (char*)l_success->custom_data, DAP_CHAIN_HASH_FAST_STR_SIZE);
char *l_hash_str = dap_hash_fast_to_str_new(&l_usage->tx_cond_hash); log_it(L_NOTICE, "Receipt with client sign is accepted, start service providing");
memcpy(l_success->custom_data, l_hash_str, DAP_CHAIN_HASH_FAST_STR_SIZE);
DAP_DEL_Z(l_hash_str);
log_it(L_NOTICE, "Receipt with remote client sign is acceptible for. Now start the service's usage");
} }
dap_stream_ch_pkt_write_unsafe( a_ch, DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_SUCCESS, dap_stream_ch_pkt_write_unsafe( a_ch, DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_SUCCESS,
...@@ -1095,10 +1081,12 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg) ...@@ -1095,10 +1081,12 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg)
void *l_out_data = l_srv->callbacks.custom_data(l_srv, l_usage, l_pkt->data, l_pkt_size, &l_out_data_size); void *l_out_data = l_srv->callbacks.custom_data(l_srv, l_usage, l_pkt->data, l_pkt_size, &l_out_data_size);
if (l_out_data && l_out_data_size) { if (l_out_data && l_out_data_size) {
pkt_t *l_data = DAP_NEW_STACK_SIZE(pkt_t, sizeof(pkt_t) + l_out_data_size); pkt_t *l_data = DAP_NEW_STACK_SIZE(pkt_t, sizeof(pkt_t) + l_out_data_size);
l_data->hdr.version = 1; l_data->hdr = (dap_stream_ch_chain_net_srv_pkt_data_hdr_t) {
l_data->hdr.srv_uid = l_srv->uid; .version = 1,
l_data->hdr.usage_id = l_pkt->hdr.usage_id; .data_size = l_out_data_size,
l_data->hdr.data_size = l_out_data_size; .usage_id = l_pkt->hdr.usage_id,
.srv_uid = l_srv->uid
};
memcpy(l_data->data, l_out_data, l_out_data_size); memcpy(l_data->data, l_out_data, l_out_data_size);
dap_stream_ch_pkt_write_unsafe(a_ch, DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_DATA, l_data, sizeof(pkt_t) + l_out_data_size); dap_stream_ch_pkt_write_unsafe(a_ch, DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_DATA, l_data, sizeof(pkt_t) + l_out_data_size);
} }
...@@ -1118,11 +1106,9 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg) ...@@ -1118,11 +1106,9 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg)
dap_chain_net_srv_usage_t * l_usage = NULL; dap_chain_net_srv_usage_t * l_usage = NULL;
l_usage = l_srv_session->usage_active; l_usage = l_srv_session->usage_active;
dap_stream_ch_chain_net_srv_pkt_request_t* l_responce = (dap_stream_ch_chain_net_srv_pkt_request_t*)l_ch_pkt->data; dap_stream_ch_chain_net_srv_pkt_request_t* l_responce = (dap_stream_ch_chain_net_srv_pkt_request_t*)l_ch_pkt->data;
char l_tx_in_hash_str[DAP_CHAIN_HASH_FAST_STR_SIZE] = { '\0' };
char *l_tx_in_hash_str = dap_chain_hash_fast_to_str_new(&l_responce->hdr.tx_cond); dap_chain_hash_fast_to_str(&l_responce->hdr.tx_cond, l_tx_in_hash_str, sizeof(l_tx_in_hash_str));
log_it(L_NOTICE, "Received new tx cond %s", l_tx_in_hash_str); log_it(L_NOTICE, "Received new tx cond %s", l_tx_in_hash_str);
DAP_DELETE(l_tx_in_hash_str);
if(!l_usage->is_waiting_new_tx_cond || !l_usage->is_grace) if(!l_usage->is_waiting_new_tx_cond || !l_usage->is_grace)
break; break;
......
...@@ -500,7 +500,7 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply) ...@@ -500,7 +500,7 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply)
dap_cli_server_cmd_set_reply_text(a_str_reply, "The order has not been created. " dap_cli_server_cmd_set_reply_text(a_str_reply, "The order has not been created. "
"Failed to convert string representation of '%s' " "Failed to convert string representation of '%s' "
"to node address.", l_node_addr_str); "to node address.", l_node_addr_str);
DAP_DELETE(l_string_ret); dap_string_free(l_string_ret, true);
return -17; return -17;
} }
} else { } else {
...@@ -522,8 +522,13 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply) ...@@ -522,8 +522,13 @@ static int s_cli_net_srv( int argc, char **argv, char **a_str_reply)
l_price_unit.uint32 = SERV_UNIT_B; l_price_unit.uint32 = SERV_UNIT_B;
} else if (!dap_strcmp(l_price_unit_str, "PCS")){ } else if (!dap_strcmp(l_price_unit_str, "PCS")){
l_price_unit.uint32 = SERV_UNIT_PCS; l_price_unit.uint32 = SERV_UNIT_PCS;
} else } else {
l_price_unit.uint32 = SERV_UNIT_UNDEFINED; //l_price_unit.uint32 = SERV_UNIT_UNDEFINED;
log_it(L_ERROR, "Undefined price unit");
dap_string_free(l_string_ret, true);
dap_cli_server_cmd_set_reply_text(a_str_reply, "Wrong unit type sepcified, possible values: B, KB, MB, SEC, DAY, PCS");
return -18;
}
uint64_t l_units = atoi(l_units_str); uint64_t l_units = atoi(l_units_str);
strncpy(l_price_token, l_price_token_str, DAP_CHAIN_TICKER_SIZE_MAX - 1); strncpy(l_price_token, l_price_token_str, DAP_CHAIN_TICKER_SIZE_MAX - 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment