Skip to content

Commit

Permalink
wip: add send
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Feb 4, 2025
1 parent deaf768 commit a60fb73
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion auto_tests/dht_getnodes_api_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void nodes_response_cb(const Tox_Event_Dht_Nodes_Response *event, void *u

// ask new node to give us their close nodes to every public key
for (size_t i = 0; i < NUM_TOXES; ++i) {
tox_dht_nodes_request(autotox->tox, public_key, ip, port, state->public_key_list[i], nullptr);
tox_dht_send_nodes_request(autotox->tox, public_key, ip, port, state->public_key_list[i], nullptr);
}
}

Expand Down
16 changes: 8 additions & 8 deletions toxcore/tox_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,27 @@ void tox_callback_dht_nodes_response(Tox *tox, tox_dht_nodes_response_cb *callba
tox->dht_nodes_response_callback = callback;
}

bool tox_dht_nodes_request(const Tox *tox, const uint8_t *public_key, const char *ip, uint16_t port,
const uint8_t *target_public_key, Tox_Err_Dht_Nodes_Request *error)
bool tox_dht_send_nodes_request(const Tox *tox, const uint8_t *public_key, const char *ip, uint16_t port,
const uint8_t *target_public_key, Tox_Err_Dht_Send_Nodes_Request *error)
{
assert(tox != nullptr);

tox_lock(tox);

if (tox->m->options.udp_disabled) {
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_NODES_REQUEST_UDP_DISABLED);
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_SEND_NODES_REQUEST_UDP_DISABLED);
tox_unlock(tox);
return false;
}

if (public_key == nullptr || ip == nullptr || target_public_key == nullptr) {
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_NODES_REQUEST_NULL);
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_SEND_NODES_REQUEST_NULL);
tox_unlock(tox);
return false;
}

if (port == 0) {
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_NODES_REQUEST_BAD_PORT);
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_SEND_NODES_REQUEST_BAD_PORT);
tox_unlock(tox);
return false;
}
Expand All @@ -129,7 +129,7 @@ bool tox_dht_nodes_request(const Tox *tox, const uint8_t *public_key, const char
const int32_t count = net_getipport(tox->sys.ns, tox->sys.mem, ip, &root, TOX_SOCK_DGRAM, tox->m->options.dns_enabled);

if (count < 1) {
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_NODES_REQUEST_BAD_IP);
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_SEND_NODES_REQUEST_BAD_IP);
net_freeipport(tox->sys.mem, root);
tox_unlock(tox);
return false;
Expand All @@ -150,11 +150,11 @@ bool tox_dht_nodes_request(const Tox *tox, const uint8_t *public_key, const char
net_freeipport(tox->sys.mem, root);

if (!success) {
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_NODES_REQUEST_FAIL);
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_SEND_NODES_REQUEST_FAIL);
return false;
}

SET_ERROR_PARAMETER(error, TOX_ERR_DHT_NODES_REQUEST_OK);
SET_ERROR_PARAMETER(error, TOX_ERR_DHT_SEND_NODES_REQUEST_OK);

return true;
}
Expand Down
20 changes: 10 additions & 10 deletions toxcore/tox_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,39 +103,39 @@ typedef void tox_dht_nodes_response_cb(Tox *tox, const uint8_t *public_key, cons
*/
void tox_callback_dht_nodes_response(Tox *tox, tox_dht_nodes_response_cb *callback);

typedef enum Tox_Err_Dht_Nodes_Request {
typedef enum Tox_Err_Dht_Send_Nodes_Request {
/**
* The function returned successfully.
*/
TOX_ERR_DHT_NODES_REQUEST_OK,
TOX_ERR_DHT_SEND_NODES_REQUEST_OK,

/**
* UDP is disabled in Tox options; the DHT can only be queried when UDP is
* enabled.
*/
TOX_ERR_DHT_NODES_REQUEST_UDP_DISABLED,
TOX_ERR_DHT_SEND_NODES_REQUEST_UDP_DISABLED,

/**
* One of the arguments to the function was NULL when it was not expected.
*/
TOX_ERR_DHT_NODES_REQUEST_NULL,
TOX_ERR_DHT_SEND_NODES_REQUEST_NULL,

/**
* The supplied port is invalid.
*/
TOX_ERR_DHT_NODES_REQUEST_BAD_PORT,
TOX_ERR_DHT_SEND_NODES_REQUEST_BAD_PORT,

/**
* The supplied IP address is invalid.
*/
TOX_ERR_DHT_NODES_REQUEST_BAD_IP,
TOX_ERR_DHT_SEND_NODES_REQUEST_BAD_IP,

/**
* The nodes request failed. This usually means the packet failed to
* send.
*/
TOX_ERR_DHT_NODES_REQUEST_FAIL,
} Tox_Err_Dht_Nodes_Request;
TOX_ERR_DHT_SEND_NODES_REQUEST_FAIL,
} Tox_Err_Dht_Send_Nodes_Request;

/**
* This function sends a nodes request to a DHT node for its peers that
Expand All @@ -152,8 +152,8 @@ typedef enum Tox_Err_Dht_Nodes_Request {
*
* @return true on success.
*/
bool tox_dht_nodes_request(const Tox *tox, const uint8_t *public_key, const char *ip, uint16_t port,
const uint8_t *target_public_key, Tox_Err_Dht_Nodes_Request *error);
bool tox_dht_send_nodes_request(const Tox *tox, const uint8_t *public_key, const char *ip, uint16_t port,
const uint8_t *target_public_key, Tox_Err_Dht_Send_Nodes_Request *error);

/**
* This function returns the number of DHT nodes in the closelist.
Expand Down

0 comments on commit a60fb73

Please sign in to comment.