Skip to content

Commit

Permalink
Resend requests to ps until 1st response received + set ps5 to false …
Browse files Browse the repository at this point in the history
…for ps4 in list devices
  • Loading branch information
streetpea committed May 15, 2024
1 parent 58f1d85 commit fc682b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
6 changes: 3 additions & 3 deletions gui/src/qmlbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ void QmlBackend::updatePsnHosts()
ChiakiHolepunchDeviceInfo *device_info_ps4 = NULL;
size_t num_devices_ps4 = 0;
ChiakiLog backend_log;
chiaki_log_init(&backend_log, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, chiaki_log_cb_print, NULL);
chiaki_log_init(&backend_log, settings->GetLogLevelMask(), chiaki_log_cb_print, NULL);
for(int i = 0; i < PSN_DEVICES_TRIES; i++)
{
ChiakiErrorCode err = chiaki_holepunch_list_devices(psn_token.toUtf8().constData(), CHIAKI_HOLEPUNCH_CONSOLE_TYPE_PS5, &device_info_ps5, &num_devices_ps5, &backend_log);
Expand Down Expand Up @@ -1121,7 +1121,7 @@ void QmlBackend::updatePsnHosts()
QString name = QString(dev.device_name);
if(!settings->GetNicknameRegisteredHostRegistered(name))
continue;
bool ps5 = CHIAKI_HOLEPUNCH_CONSOLE_TYPE_PS5 ? true : false;
bool ps5 = true;
PsnHost psn_host(duid, name, ps5);
if(!psn_hosts.contains(duid))
psn_hosts.insert(duid, psn_host);
Expand All @@ -1136,7 +1136,7 @@ void QmlBackend::updatePsnHosts()
QString name = QString(dev.device_name);
if(!settings->GetNicknameRegisteredHostRegistered(name))
continue;
bool ps5 = CHIAKI_HOLEPUNCH_CONSOLE_TYPE_PS5 ? true : false;
bool ps5 = false;
PsnHost psn_host(duid, name, ps5);
if(!psn_hosts.contains(duid))
psn_hosts.insert(duid, psn_host);
Expand Down
44 changes: 38 additions & 6 deletions lib/src/remote/holepunch.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
#define SESSION_CREATION_TIMEOUT_SEC 30
#define SESSION_START_TIMEOUT_SEC 30
#define SESSION_DELETION_TIMEOUT_SEC 3
#define SELECT_CANDIDATE_TIMEOUT_SEC 10
#define SELECT_CANDIDATE_TIMEOUT_SEC 0.5F
#define SELECT_CANDIDATE_TRIES 20
#define SELECT_CANDIDATE_CONNECTION_SEC 5
#define WAIT_RESPONSE_TIMEOUT_SEC 1
#define MSG_TYPE_REQ 0x06000000
#define MSG_TYPE_RESP 0x07000000
Expand Down Expand Up @@ -2699,11 +2701,14 @@ static ChiakiErrorCode check_candidates(
maxfd = maxfd + 1;

struct timeval tv;
tv.tv_sec = SELECT_CANDIDATE_TIMEOUT_SEC;
tv.tv_usec = 0;
tv.tv_sec = 0;
tv.tv_usec = SELECT_CANDIDATE_TIMEOUT_SEC * SECOND_US;

chiaki_socket_t selected_sock = CHIAKI_INVALID_SOCKET;
Candidate *selected_candidate = NULL;
bool received_response = false;
bool connecting = false;
int retry_counter = 0;

while (!selected_candidate)
{
Expand All @@ -2719,9 +2724,36 @@ static ChiakiErrorCode check_candidates(
goto cleanup_sockets;
} else if (ret == 0)
{
// No responsive candidate within timeout, terminate with error
if (CHIAKI_SOCKET_IS_INVALID(selected_sock))
{
if(retry_counter < SELECT_CANDIDATE_TRIES && !received_response)
{
retry_counter++;
tv.tv_sec = 0;
tv.tv_usec = SELECT_CANDIDATE_TIMEOUT_SEC * SECOND_US;
Candidate *candidate = NULL;
chiaki_socket_t sock = CHIAKI_INVALID_SOCKET;
CHIAKI_LOGI(session->log, "Resending requests to all candidates TRY %d... waiting for 1st response", retry_counter);
for (int i=0; i < num_candidates; i++)
{
sock = sockets[i];
candidate = &candidates[i];
if (send(sock, (CHIAKI_SOCKET_BUF_TYPE) request_buf[0], sizeof(request_buf[0]), 0) < 0)
{
CHIAKI_LOGE(session->log, "check_candidate: Sending request failed for %s:%d with error: " CHIAKI_SOCKET_ERROR_FMT, candidate->addr, candidate->port, CHIAKI_SOCKET_ERROR_VALUE);
continue;
}
}
continue;
}
else if(received_response && !connecting)
{
connecting = true;
tv.tv_sec = SELECT_CANDIDATE_CONNECTION_SEC;
tv.tv_usec = 0;
continue;
}
// No responsive candidate within timeout, terminate with error
CHIAKI_LOGE(session->log, "check_candidate: Select timed out");
err = CHIAKI_ERR_TIMEOUT;
goto cleanup_sockets;
Expand Down Expand Up @@ -2784,9 +2816,9 @@ static ChiakiErrorCode check_candidates(
{
CHIAKI_LOGE(session->log, "check_candidate: Received response with unexpected request ID %lu from %s:%d", request_id, candidate->addr, candidate->port);
chiaki_log_hexdump(session->log, CHIAKI_LOG_ERROR, response_buf, 88);
err = CHIAKI_ERR_UNKNOWN;
goto cleanup_sockets;
continue;
}
received_response = true;
responses_received[i]++;
responses = responses_received[i];
if(responses > 2)
Expand Down

0 comments on commit fc682b4

Please sign in to comment.