Merge friend_connections from NGC fork

This commit is contained in:
jfreegman 2021-12-21 10:51:17 -05:00
parent 24f49fc917
commit e92a67ed5f
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 43 additions and 4 deletions

View File

@ -282,6 +282,16 @@ cc_library(
],
)
cc_test(
name = "friend_connection_test",
size = "small",
srcs = ["friend_connection.cc"],
deps = [
":friend_connection",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "friend_requests",
srcs = ["friend_requests.c"],

View File

@ -25,7 +25,7 @@ typedef struct Friend_Conn_Callbacks {
int callback_id;
} Friend_Conn_Callbacks;
typedef struct Friend_Conn {
struct Friend_Conn {
uint8_t status;
uint8_t real_public_key[CRYPTO_PUBLIC_KEY_SIZE];
@ -50,7 +50,7 @@ typedef struct Friend_Conn {
uint16_t tcp_relay_counter;
bool hosting_tcp_relay;
} Friend_Conn;
};
struct Friend_Connections {
@ -75,11 +75,21 @@ struct Friend_Connections {
bool local_discovery_enabled;
};
int friend_conn_get_onion_friendnum(const Friend_Conn *fc)
{
return fc->onion_friendnum;
}
Net_Crypto *friendconn_net_crypto(const Friend_Connections *fr_c)
{
return fr_c->net_crypto;
}
const IP_Port *friend_conn_get_dht_ip_port(const Friend_Conn *fc)
{
return &fc->dht_ip_port;
}
/* return true if the friendcon_id is valid.
* return false if the friendcon_id is not valid.
@ -168,7 +178,7 @@ static int wipe_friend_conn(Friend_Connections *fr_c, int friendcon_id)
return 0;
}
static Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id)
Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id)
{
if (!friendconn_id_valid(fr_c, friendcon_id)) {
return nullptr;
@ -262,7 +272,7 @@ static unsigned int send_relays(Friend_Connections *fr_c, int friendcon_id)
return 0;
}
Node_format nodes[MAX_SHARED_RELAYS];
Node_format nodes[MAX_SHARED_RELAYS] = {{{0}}};
uint8_t data[1024];
const int n = copy_connected_tcp_relays(fr_c->net_crypto, nodes, MAX_SHARED_RELAYS);

View File

@ -0,0 +1,13 @@
#include "friend_connection.h"
#include <gtest/gtest.h>
namespace {
// TODO(Jfreegman) make this useful or remove it after NGC is merged
TEST(friend_connection, NullTest) {
(void)friend_conn_get_onion_friendnum;
(void)friend_conn_get_dht_ip_port;
}
} // namespace

View File

@ -157,4 +157,10 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata);
/* Free everything related with friend_connections. */
void kill_friend_connections(Friend_Connections *fr_c);
typedef struct Friend_Conn Friend_Conn;
Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id);
int friend_conn_get_onion_friendnum(const Friend_Conn *fc);
const IP_Port *friend_conn_get_dht_ip_port(const Friend_Conn *fc);
#endif