Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-chain-net-srv-vpn
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap-chain-net-srv-vpn
Commits
72ad71ba
Commit
72ad71ba
authored
4 years ago
by
alexander.lysikov
Browse files
Options
Downloads
Patches
Plain Diff
updated response for node_list http request
parent
276eca97
No related branches found
No related tags found
1 merge request
!21
Feature 3281
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dap_chain_net_srv_vpn_cdb_server_list.c
+136
-27
136 additions, 27 deletions
dap_chain_net_srv_vpn_cdb_server_list.c
with
136 additions
and
27 deletions
dap_chain_net_srv_vpn_cdb_server_list.c
+
136
−
27
View file @
72ad71ba
...
...
@@ -26,6 +26,7 @@
#include
<time.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<unistd.h>
...
...
@@ -83,9 +84,15 @@ void dap_chain_net_srv_vpn_cdb_server_list_deinit(void)
{
}
static
void
order_info_print
(
dap_string_t
*
a_reply_str
,
dap_chain_net_t
*
a_net
,
dap_chain_net_srv_order_t
*
a_orders
)
/**
* @brief order_info_print
* @param a_server_location for server name, NULL not used
* @param a_node_number for server name, <0 not use
*/
static
int
order_info_print
(
dap_string_t
*
a_reply_str
,
dap_chain_net_t
*
a_net
,
dap_chain_net_srv_order_t
*
a_order
,
const
char
*
a_server_name
,
int
a_node_number
)
{
dap_chain_node_info_t
*
l_node_info
=
dap_chain_node_info_read
(
a_net
,
&
a_order
s
->
node_addr
);
dap_chain_node_info_t
*
l_node_info
=
dap_chain_node_info_read
(
a_net
,
&
a_order
->
node_addr
);
if
(
l_node_info
)
{
char
l_node_ext_ipv4_str
[
INET_ADDRSTRLEN
]
=
{
0
};
char
l_node_ext_ipv6_str
[
INET6_ADDRSTRLEN
]
=
{
0
};
...
...
@@ -93,27 +100,47 @@ static void order_info_print(dap_string_t *a_reply_str, dap_chain_net_t * a_net,
inet_ntop
(
AF_INET
,
&
l_node_info
->
hdr
.
ext_addr_v4
,
l_node_ext_ipv4_str
,
sizeof
(
l_node_ext_ipv4_str
));
if
(
*
((
uint128_t
*
)
l_node_info
->
hdr
.
ext_addr_v6
.
s6_addr
))
inet_ntop
(
AF_INET6
,
&
l_node_info
->
hdr
.
ext_addr_v6
,
l_node_ext_ipv6_str
,
sizeof
(
l_node_ext_ipv6_str
));
uint8_t
l_continent_num
=
0
;
char
*
l_region
=
NULL
;
dap_chain_net_srv_order_get_continent_region
(
a_order
,
&
l_continent_num
,
&
l_region
);
const
char
*
l_continent_str
=
dap_chain_net_srv_order_continent_to_str
(
l_continent_num
);
// ext_out in hex view
char
*
l_ext_out
=
a_order
->
ext_size
?
DAP_NEW_Z_SIZE
(
char
,
a_order
->
ext_size
*
2
+
1
)
:
NULL
;
dap_bin2hex
(
l_ext_out
,
a_order
->
ext
,
a_order
->
ext_size
);
dap_string_append_printf
(
a_reply_str
,
" {
\n
"
);
const
char
*
l_continent_str
=
dap_chain_net_srv_order_get_continent_str
(
a_orders
->
continent
);
dap_string_append_printf
(
a_reply_str
,
"
\"
Locations
\"
:
\"
%s-%s
\"
,
\n
"
,
l_continent_str
?
l_continent_str
:
"None"
,
a_orders
->
region
[
0
]
?
a_orders
->
region
:
"None"
);
//NETHERLANDS
l_continent_str
?
l_continent_str
:
"None"
,
l_region
?
l_region
:
"None"
);
//NETHERLANDS
dap_string_append_printf
(
a_reply_str
,
"
\"
ChainNet
\"
:
\"
%s
\"
,
\n
"
,
a_net
->
pub
.
name
);
dap_string_append_printf
(
a_reply_str
,
"
\"
Name
\"
:
\"
%s.Cell-%lu.%zd
\"
,
\n
"
,
a_net
->
pub
.
name
,
l_node_info
->
hdr
.
cell_id
.
uint64
,
0
);
//dap_string_append_printf(a_reply_str, " \"Name\":\"%s.Cell-%lu.%zd\",\n", a_net->pub.name, l_node_info->hdr.cell_id.uint64, 0);
if
(
a_server_name
)
dap_string_append_printf
(
a_reply_str
,
"
\"
Name
\"
:
\"
%s
\"
,
\n
"
,
a_server_name
);
else
dap_string_append_printf
(
a_reply_str
,
"
\"
Name
\"
:
\"
%s.%s.%zd
\"
,
\n
"
,
l_continent_str
?
l_continent_str
:
""
,
l_region
?
l_region
:
""
,
a_node_number
+
1
);
//dap_string_append_printf(a_reply_str, " \"Name\":\"%s.%s.Cell-%lu.%zd\",\n", l_continent_str ? l_continent_str : "", l_region ? l_region : "", l_node_info->hdr.cell_id.uint64, a_node_number + 1);
if
(
l_node_ext_ipv4_str
[
0
])
dap_string_append_printf
(
a_reply_str
,
"
\"
Address
\"
:
\"
%s
\"
,
\n
"
,
l_node_ext_ipv4_str
);
if
(
l_node_ext_ipv6_str
[
0
])
dap_string_append_printf
(
a_reply_str
,
"
\"
Address6
\"
:
\"
%s
\"
,
\n
"
,
l_node_ext_ipv6_str
);
dap_string_append_printf
(
a_reply_str
,
"
\"
Port
\"
:%hu,
\n
"
,
l_node_info
->
hdr
.
ext_port
?
l_node_info
->
hdr
.
ext_port
:
80
);
dap_string_append_printf
(
a_reply_str
,
"
\"
Ext
\"
:
\"
%s
\"
,
\n
"
,
a_orders
->
ext
);
dap_string_append_printf
(
a_reply_str
,
"
\"
Price
\"
:%lu,
\n
"
,
a_orders
->
price
);
dap_string_append_printf
(
a_reply_str
,
"
\"
PriceUnits
\"
:%u,
\n
"
,
a_orders
->
price_unit
.
uint32
);
dap_string_append_printf
(
a_reply_str
,
"
\"
PriceToken
\"
:
\"
%s
\"\n
"
,
a_orders
->
price_ticker
);
dap_string_append_printf
(
a_reply_str
,
"
\"
Port
\"
:%hu,
\n
"
,
l_node_info
->
hdr
.
ext_port
?
l_node_info
->
hdr
.
ext_port
:
80
);
//dap_string_append_printf(a_reply_str, " \"Ext\":\"%s-%s\",\n", l_continent_str ? l_continent_str : "", l_region ? l_region : "");
dap_string_append_printf
(
a_reply_str
,
"
\"
Ext
\"
:0x%s,
\n
"
,
l_ext_out
?
l_ext_out
:
""
);
dap_string_append_printf
(
a_reply_str
,
"
\"
Price
\"
:%lu,
\n
"
,
a_order
->
price
);
dap_string_append_printf
(
a_reply_str
,
"
\"
PriceUnits
\"
:%u,
\n
"
,
a_order
->
price_unit
.
uint32
);
dap_string_append_printf
(
a_reply_str
,
"
\"
PriceToken
\"
:
\"
%s
\"\n
"
,
a_order
->
price_ticker
);
dap_string_append_printf
(
a_reply_str
,
" }"
);
DAP_DELETE
(
l_region
);
DAP_DELETE
(
l_ext_out
);
}
else
}
else
{
log_it
(
L_WARNING
,
"Order in
\"
%s
\"
network issued by node without ext_ipv4 field"
,
a_net
->
pub
.
name
);
return
-
1
;
}
return
0
;
}
...
...
@@ -129,24 +156,106 @@ static void s_http_simple_proc(dap_http_simple_t *a_http_simple, void *a_arg)
dap_chain_net_t
*
l_net
=
s_cdb_net
[
i
];
if
(
l_net
)
{
dap_chain_net_srv_order_t
*
l_orders
=
NULL
;
size_t
l_orders_
count
=
0
;
size_t
l_orders_
num
=
0
;
dap_chain_net_srv_price_unit_uid_t
l_unit_uid
=
{{
0
}};
dap_chain_net_srv_uid_t
l_srv_uid
=
{
.
uint64
=
DAP_CHAIN_NET_SRV_VPN_ID
};
dap_chain_net_srv_order_find_all_by
(
l_net
,
SERV_DIR_SELL
,
l_srv_uid
,
l_unit_uid
,
NULL
,
0
,
0
,
&
l_orders
,
&
l_orders_count
);
log_it
(
L_DEBUG
,
"Found %zd orders in
\"
%s
\"
network"
,
l_orders_count
,
l_net
->
pub
.
name
);
char
*
l_node_name
;
// first random node
for
(
size_t
j
=
0
;
j
<
l_orders_count
;
j
++
)
{
///!!!l_node_name =
//!!!order_info_print(l_reply_str, l_net, &l_orders[j], l_node_name);
if
(
j
!=
l_orders_count
-
1
)
dap_string_append_printf
(
l_reply_str
,
" },
\n
"
);
else
dap_string_append_printf
(
l_reply_str
,
" }
\n
"
);
NULL
,
0
,
0
,
&
l_orders
,
&
l_orders_num
);
log_it
(
L_DEBUG
,
"Found %zd orders in
\"
%s
\"
network"
,
l_orders_num
,
l_net
->
pub
.
name
);
// node numbering
// list of node numbers
//int *l_node_numbering = DAP_NEW_Z_SIZE(int, l_orders_num * sizeof(int));
size_t
l_continents_count
=
dap_chain_net_srv_order_continents_count
();
// list of the number of nodes in each continent
int
*
l_continents_numbers
=
DAP_NEW_Z_SIZE
(
int
,
l_continents_count
*
sizeof
(
int
));
int
l_node_numbering
[
l_continents_count
][
l_orders_num
];
for
(
size_t
m1
=
0
;
m1
<=
l_continents_count
;
m1
++
)
for
(
size_t
m2
=
0
;
m2
<=
l_orders_num
;
m2
++
)
l_node_numbering
[
m1
][
m2
]
=
0
;
{
size_t
l_orders_size
=
0
;
// filling l_continents_numbers and l_node_numbering
for
(
size_t
j
=
0
;
j
<
l_orders_num
;
j
++
)
{
dap_chain_net_srv_order_t
*
l_order
=
(
dap_chain_net_srv_order_t
*
)
((
char
*
)
l_orders
+
l_orders_size
);
l_orders_size
+=
dap_chain_net_srv_order_get_size
(
l_order
);
uint8_t
l_continent_num
;
if
(
!
dap_chain_net_srv_order_get_continent_region
(
l_order
,
&
l_continent_num
,
NULL
))
continue
;
l_node_numbering
[
l_continent_num
][
j
]
=
l_continents_numbers
[
l_continent_num
]
++
;
}
}
// random node
int
l_count
=
0
;
while
(
l_orders_num
>
0
)
{
// first random node
size_t
k
=
rand
()
%
l_orders_num
;
// find orded pos
size_t
l_orders_size
=
0
;
dap_chain_net_srv_order_t
*
l_order
=
l_orders
;
for
(
size_t
j
=
0
;
j
<=
k
;
j
++
)
{
l_order
=
(
dap_chain_net_srv_order_t
*
)((
char
*
)
l_orders
+
l_orders_size
);
l_orders_size
+=
dap_chain_net_srv_order_get_size
(
l_order
);
}
if
(
!
order_info_print
(
l_reply_str
,
l_net
,
l_order
,
"Random server"
,
-
1
)){
dap_string_append_printf
(
l_reply_str
,
",
\n
"
);
break
;
}
if
(
l_count
>
20
)
break
;
l_count
++
;
}
// random nodes for continents
for
(
size_t
l_c
=
0
;
l_c
<
l_continents_count
;
l_c
++
)
{
while
(
l_continents_numbers
[
l_c
]
>
0
)
{
// random node for continent
size_t
k
=
rand
()
%
l_continents_numbers
[
l_c
];
size_t
l_node_pos
=
0
;
for
(
size_t
j2
=
0
;
j2
<=
l_orders_num
;
j2
++
)
{
if
(
k
==
l_node_numbering
[
l_c
][
j2
])
{
l_node_pos
=
j2
;
break
;
}
}
// find orded pos
size_t
l_orders_size
=
0
;
dap_chain_net_srv_order_t
*
l_order
=
l_orders
;
for
(
size_t
j
=
0
;
j
<=
l_node_pos
;
j
++
)
{
l_order
=
(
dap_chain_net_srv_order_t
*
)
((
char
*
)
l_orders
+
l_orders_size
);
l_orders_size
+=
dap_chain_net_srv_order_get_size
(
l_order
);
}
char
*
l_server_name
=
dap_strdup_printf
(
"Random server: %s"
,
dap_chain_net_srv_order_continent_to_str
(
l_c
));
if
(
!
order_info_print
(
l_reply_str
,
l_net
,
l_order
,
l_server_name
,
-
1
))
{
dap_string_append_printf
(
l_reply_str
,
",
\n
"
);
DAP_DELETE
(
l_server_name
);
break
;
}
else
DAP_DELETE
(
l_server_name
);
if
(
l_count
>
20
)
break
;
l_count
++
;
}
}
DAP_DELETE
(
l_continents_numbers
);
size_t
l_orders_size
=
0
;
for
(
size_t
j
=
0
;
j
<
l_orders_num
;
j
++
)
{
dap_chain_net_srv_order_t
*
l_order
=
(
dap_chain_net_srv_order_t
*
)((
char
*
)
l_orders
+
l_orders_size
);
l_orders_size
+=
dap_chain_net_srv_order_get_size
(
l_order
);
uint8_t
l_continent_num
=
0
;
dap_chain_net_srv_order_get_continent_region
(
l_order
,
&
l_continent_num
,
NULL
);
if
(
!
order_info_print
(
l_reply_str
,
l_net
,
l_order
,
NULL
,
l_node_numbering
[
l_continent_num
][
j
]))
{
if
(
j
!=
l_orders_num
-
1
)
dap_string_append_printf
(
l_reply_str
,
",
\n
"
);
else
dap_string_append_printf
(
l_reply_str
,
"
\n
"
);
}
}
//DAP_DELETE(l_node_numbering);
}
}
dap_string_append_printf
(
l_reply_str
,
"]
\n\n
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment