mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge friend_connections from NGC fork
This commit is contained in:
parent
24f49fc917
commit
e92a67ed5f
|
@ -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(
|
cc_library(
|
||||||
name = "friend_requests",
|
name = "friend_requests",
|
||||||
srcs = ["friend_requests.c"],
|
srcs = ["friend_requests.c"],
|
||||||
|
|
|
@ -25,7 +25,7 @@ typedef struct Friend_Conn_Callbacks {
|
||||||
int callback_id;
|
int callback_id;
|
||||||
} Friend_Conn_Callbacks;
|
} Friend_Conn_Callbacks;
|
||||||
|
|
||||||
typedef struct Friend_Conn {
|
struct Friend_Conn {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
|
|
||||||
uint8_t real_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
uint8_t real_public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||||
|
@ -50,7 +50,7 @@ typedef struct Friend_Conn {
|
||||||
uint16_t tcp_relay_counter;
|
uint16_t tcp_relay_counter;
|
||||||
|
|
||||||
bool hosting_tcp_relay;
|
bool hosting_tcp_relay;
|
||||||
} Friend_Conn;
|
};
|
||||||
|
|
||||||
|
|
||||||
struct Friend_Connections {
|
struct Friend_Connections {
|
||||||
|
@ -75,11 +75,21 @@ struct Friend_Connections {
|
||||||
bool local_discovery_enabled;
|
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)
|
Net_Crypto *friendconn_net_crypto(const Friend_Connections *fr_c)
|
||||||
{
|
{
|
||||||
return fr_c->net_crypto;
|
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 true if the friendcon_id is valid.
|
||||||
* return false if the friendcon_id is not 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;
|
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)) {
|
if (!friendconn_id_valid(fr_c, friendcon_id)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -262,7 +272,7 @@ static unsigned int send_relays(Friend_Connections *fr_c, int friendcon_id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Node_format nodes[MAX_SHARED_RELAYS];
|
Node_format nodes[MAX_SHARED_RELAYS] = {{{0}}};
|
||||||
uint8_t data[1024];
|
uint8_t data[1024];
|
||||||
|
|
||||||
const int n = copy_connected_tcp_relays(fr_c->net_crypto, nodes, MAX_SHARED_RELAYS);
|
const int n = copy_connected_tcp_relays(fr_c->net_crypto, nodes, MAX_SHARED_RELAYS);
|
||||||
|
|
13
toxcore/friend_connection.cc
Normal file
13
toxcore/friend_connection.cc
Normal 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
|
|
@ -157,4 +157,10 @@ void do_friend_connections(Friend_Connections *fr_c, void *userdata);
|
||||||
/* Free everything related with friend_connections. */
|
/* Free everything related with friend_connections. */
|
||||||
void kill_friend_connections(Friend_Connections *fr_c);
|
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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user