add dht and port getter functions

This commit is contained in:
Green Sky 2024-03-10 20:11:41 +01:00
parent 49ab40a1ba
commit 3b75a1c5d3
No known key found for this signature in database
4 changed files with 40 additions and 7 deletions

View File

@ -285,6 +285,32 @@ Tox_Err_Friend_Custom_Packet ToxDefaultImpl::toxFriendSendLosslessPacket(uint32_
return err; return err;
} }
std::vector<uint8_t> ToxDefaultImpl::toxSelfGetDHTID(void) {
std::vector<uint8_t> id(tox_public_key_size());
tox_self_get_dht_id(_tox, id.data());
return id;
}
std::tuple<std::optional<uint16_t>, Tox_Err_Get_Port> ToxDefaultImpl::toxSelfGetUDPPort(void) {
Tox_Err_Get_Port err = TOX_ERR_GET_PORT_OK;
const auto res = tox_self_get_udp_port(_tox, &err);
if (err == TOX_ERR_GET_PORT_OK) {
return {res, err};
} else {
return {std::nullopt, err};
}
}
std::tuple<std::optional<uint16_t>, Tox_Err_Get_Port> ToxDefaultImpl::toxSelfGetTCPPort(void) {
Tox_Err_Get_Port err = TOX_ERR_GET_PORT_OK;
const auto res = tox_self_get_tcp_port(_tox, &err);
if (err == TOX_ERR_GET_PORT_OK) {
return {res, err};
} else {
return {std::nullopt, err};
}
}
uint32_t ToxDefaultImpl::toxGroupMaxTopicLength(void) { uint32_t ToxDefaultImpl::toxGroupMaxTopicLength(void) {
return tox_group_max_topic_length(); return tox_group_max_topic_length();
} }

View File

@ -59,9 +59,10 @@ struct ToxDefaultImpl : public ToxI {
Tox_Err_Friend_Custom_Packet toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) override; Tox_Err_Friend_Custom_Packet toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) override;
Tox_Err_Friend_Custom_Packet toxFriendSendLosslessPacket(uint32_t friend_number, const std::vector<uint8_t>& data) override; Tox_Err_Friend_Custom_Packet toxFriendSendLosslessPacket(uint32_t friend_number, const std::vector<uint8_t>& data) override;
// dht // dht and ports
// udp std::vector<uint8_t> toxSelfGetDHTID(void) override;
// tcp std::tuple<std::optional<uint16_t>, Tox_Err_Get_Port> toxSelfGetUDPPort(void) override;
std::tuple<std::optional<uint16_t>, Tox_Err_Get_Port> toxSelfGetTCPPort(void) override;
// group // group

View File

@ -14,7 +14,7 @@
// defines the full interface for tox // defines the full interface for tox
// HACK: raw // HACK: raw
struct ToxI_raw { struct ToxI_raw {
static constexpr const char* version {"7"}; static constexpr const char* version {"8"};
virtual ~ToxI_raw(void) {} virtual ~ToxI_raw(void) {}
@ -103,9 +103,10 @@ struct ToxI_raw {
virtual Tox_Err_Friend_Custom_Packet toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) = 0; virtual Tox_Err_Friend_Custom_Packet toxFriendSendLossyPacket(uint32_t friend_number, const std::vector<uint8_t>& data) = 0;
virtual Tox_Err_Friend_Custom_Packet toxFriendSendLosslessPacket(uint32_t friend_number, const std::vector<uint8_t>& data) = 0; virtual Tox_Err_Friend_Custom_Packet toxFriendSendLosslessPacket(uint32_t friend_number, const std::vector<uint8_t>& data) = 0;
// dht // dht and ports
// udp virtual std::vector<uint8_t> toxSelfGetDHTID(void) = 0;
// tcp virtual std::tuple<std::optional<uint16_t>, Tox_Err_Get_Port> toxSelfGetUDPPort(void) = 0;
virtual std::tuple<std::optional<uint16_t>, Tox_Err_Get_Port> toxSelfGetTCPPort(void) = 0;
// group // group

View File

@ -159,6 +159,11 @@ enum Tox_Err_Friend_Custom_Packet {
TOX_ERR_FRIEND_CUSTOM_PACKET_SENDQ, TOX_ERR_FRIEND_CUSTOM_PACKET_SENDQ,
}; };
enum Tox_Err_Get_Port {
TOX_ERR_GET_PORT_OK,
TOX_ERR_GET_PORT_NOT_BOUND,
};
enum Tox_Err_Group_New { enum Tox_Err_Group_New {
TOX_ERR_GROUP_NEW_OK, TOX_ERR_GROUP_NEW_OK,
TOX_ERR_GROUP_NEW_TOO_LONG, TOX_ERR_GROUP_NEW_TOO_LONG,