Skip to content

Commit

Permalink
Move offer message and local candidates to inside holepunch session
Browse files Browse the repository at this point in the history
  • Loading branch information
streetpea committed Oct 28, 2024
1 parent 4dc2858 commit d5db9d6
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 116 deletions.
2 changes: 1 addition & 1 deletion gui/src/qmlbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,7 @@ void QmlBackend::updateDiscoveryHosts()
continue;
auto registered = settings->GetRegisteredHost(host.GetHostMAC());
if (registered.GetRPRegistKey() == session_info.regist_key) {
if(wakeup_start && host.host_name == wakeup_nickname && host.state == CHIAKI_DISCOVERY_HOST_STATE_READY)
if(wakeup_start && session && host.host_name == wakeup_nickname && host.state == CHIAKI_DISCOVERY_HOST_STATE_READY)
{
wakeup_nickname.clear();
wakeup_start = false;
Expand Down
12 changes: 2 additions & 10 deletions gui/src/streamsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,9 +1914,7 @@ ChiakiErrorCode StreamSession::ConnectPsnConnection(QString duid, bool ps5)
return CHIAKI_ERR_INVALID_DATA;
}
ChiakiHolepunchConsoleType console_type = ps5 ? CHIAKI_HOLEPUNCH_CONSOLE_TYPE_PS5 : CHIAKI_HOLEPUNCH_CONSOLE_TYPE_PS4;
ChiakiHolepunchCandidate local_candidates = NULL;
ChiakiHolepunchMessage our_offer_msg = NULL;
ChiakiErrorCode err = holepunch_session_create_offer(holepunch_session, &local_candidates, &our_offer_msg);
ChiakiErrorCode err = holepunch_session_create_offer(holepunch_session);
if (err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(log, "!! Failed to create offer msg for ctrl connection");
Expand All @@ -1927,23 +1925,17 @@ ChiakiErrorCode StreamSession::ConnectPsnConnection(QString duid, bool ps5)
if (err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(log, "!! Failed to start session");
if(local_candidates)
free(local_candidates);
return err;
}
CHIAKI_LOGI(log, ">> Started session");

err = chiaki_holepunch_session_punch_hole(holepunch_session, local_candidates, our_offer_msg, CHIAKI_HOLEPUNCH_PORT_TYPE_CTRL);
err = chiaki_holepunch_session_punch_hole(holepunch_session, CHIAKI_HOLEPUNCH_PORT_TYPE_CTRL);
if (err != CHIAKI_ERR_SUCCESS)
{
CHIAKI_LOGE(log, "!! Failed to punch hole for control connection.");
if(local_candidates)
free(local_candidates);
return err;
}
CHIAKI_LOGI(log, ">> Punched hole for control connection!");
if(local_candidates)
free(local_candidates);
return err;
}

Expand Down
13 changes: 3 additions & 10 deletions lib/include/chiaki/remote/holepunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ extern "C" {
/** Handle to holepunching session state */
typedef struct session_t* ChiakiHolepunchSession;

/** Handle to session message */
typedef struct session_message_t* ChiakiHolepunchMessage;

/** Handle to candidate */
typedef struct candidate_t* ChiakiHolepunchCandidate;

/** Info for Remote Registration */
typedef struct holepunch_regist_info_t
{
Expand Down Expand Up @@ -216,11 +210,10 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_holepunch_session_start(
/** Creates an OFFER session message to send via PSN.
*
* @param session The Session instance.
* @param local_candidates The local candidates found while creating the offer
* @param out the created SessionMessage
* @param type The type of offer message to create
* @return CHIAKI_ERR_SUCCESS on success, or an error code on failure.
*/
CHIAKI_EXPORT ChiakiErrorCode holepunch_session_create_offer(ChiakiHolepunchSession session, ChiakiHolepunchCandidate *local_candidates, ChiakiHolepunchMessage *our_offer_msg);
CHIAKI_EXPORT ChiakiErrorCode holepunch_session_create_offer(ChiakiHolepunchSession session);

/**
* Punch a hole in the NAT for the control or data socket.
Expand All @@ -233,7 +226,7 @@ CHIAKI_EXPORT ChiakiErrorCode holepunch_session_create_offer(ChiakiHolepunchSess
* @return CHIAKI_ERR_SUCCESS on success, otherwise another error code
*/
CHIAKI_EXPORT ChiakiErrorCode chiaki_holepunch_session_punch_hole(
ChiakiHolepunchSession session, ChiakiHolepunchCandidate local_candidate, ChiakiHolepunchMessage our_offer_msg, ChiakiHolepunchPortType port_type);
ChiakiHolepunchSession session, ChiakiHolepunchPortType port_type);

/**
* Cancel initial psn connection steps (i.e., session create, session start and session punch hole)
Expand Down
Loading

0 comments on commit d5db9d6

Please sign in to comment.