forked from Green-Sky/tomato
Squashed 'external/toxcore/c-toxcore/' changes from adbd5b32d8..e29e185c03
e29e185c03 feat: add ngc events 2b0dc0f46b add ngc related unpack functions b2315c50e0 Add groupchat API function that returns an IP address string for a peer 5f863a5492 feat: Add `to_string` functions for all public enums. 0c998a7598 add real timeout test 68c827609a chore: Move s390x build to post-merge. 028b017d79 perf: Slightly reduce bandwidth usage when there are few nodes. 90f7496819 feat: Enable ubsan on bootstrap nodes. 89b6450d66 test: Add check-c run to bazel build. REVERT: adbd5b32d8 feat: add ngc events git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: e29e185c03fea7337036e5ef4d1d9080a6cee721
This commit is contained in:
@ -3517,6 +3517,63 @@ int gc_get_peer_public_key_by_peer_id(const GC_Chat *chat, uint32_t peer_id, uin
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @brief Puts a string of the IP associated with `ip_port` in `ip_str` if the
|
||||
* connection is direct, otherwise puts a placeholder in the buffer indicating that
|
||||
* the IP cannot be displayed.
|
||||
*/
|
||||
non_null()
|
||||
static void get_gc_ip_ntoa(const IP_Port *ip_port, Ip_Ntoa *ip_str)
|
||||
{
|
||||
net_ip_ntoa(&ip_port->ip, ip_str);
|
||||
|
||||
if (!ip_str->ip_is_valid) {
|
||||
ip_str->buf[0] = '-';
|
||||
ip_str->buf[1] = '\0';
|
||||
ip_str->length = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int gc_get_peer_ip_address_size(const GC_Chat *chat, uint32_t peer_id)
|
||||
{
|
||||
const int peer_number = get_peer_number_of_peer_id(chat, peer_id);
|
||||
const GC_Connection *gconn = get_gc_connection(chat, peer_number);
|
||||
|
||||
if (gconn == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const IP_Port *ip_port = peer_number == 0 ? &chat->self_ip_port : &gconn->addr.ip_port;
|
||||
|
||||
Ip_Ntoa ip_str;
|
||||
get_gc_ip_ntoa(ip_port, &ip_str);
|
||||
|
||||
return ip_str.length;
|
||||
}
|
||||
|
||||
int gc_get_peer_ip_address(const GC_Chat *chat, uint32_t peer_id, uint8_t *ip_addr)
|
||||
{
|
||||
const int peer_number = get_peer_number_of_peer_id(chat, peer_id);
|
||||
const GC_Connection *gconn = get_gc_connection(chat, peer_number);
|
||||
|
||||
if (gconn == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ip_addr == nullptr) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
const IP_Port *ip_port = peer_number == 0 ? &chat->self_ip_port : &gconn->addr.ip_port;
|
||||
|
||||
Ip_Ntoa ip_str;
|
||||
get_gc_ip_ntoa(ip_port, &ip_str);
|
||||
|
||||
assert(ip_str.length <= IP_NTOA_LEN);
|
||||
memcpy(ip_addr, ip_str.buf, ip_str.length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int gc_get_peer_connection_status(const GC_Chat *chat, uint32_t peer_id)
|
||||
{
|
||||
const int peer_number = get_peer_number_of_peer_id(chat, peer_id);
|
||||
|
Reference in New Issue
Block a user