From ec17623400fba55acd01862d968b2636cc3f894d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 8 Aug 2020 17:59:26 -0700 Subject: [PATCH] Test for blocked ports when a stream fails --- app/gui/StreamSegue.qml | 6 ++++- app/streaming/session.cpp | 35 ++++++++++++++++++++++++--- app/streaming/session.h | 5 +++- moonlight-common-c/moonlight-common-c | 2 +- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/gui/StreamSegue.qml b/app/gui/StreamSegue.qml index 0fa62041..391c77e0 100644 --- a/app/gui/StreamSegue.qml +++ b/app/gui/StreamSegue.qml @@ -62,8 +62,12 @@ Item { window.visible = true } - function sessionFinished() + function sessionFinished(portTestResult) { + if (portTestResult !== 0 && streamSegueErrorDialog.text) { + streamSegueErrorDialog.text += "\n\nThis PC's Internet connection is blocking Moonlight. Streaming over the Internet may not work while connected to this network." + } + // Enable GUI gamepad usage now SdlGamepadKeyNavigation.enable() diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 5838432b..5a83d4f7 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -61,12 +61,15 @@ void Session::clStageFailed(int stage, int errorCode) // We know this is called on the same thread as LiStartConnection() // which happens to be the main thread, so it's cool to interact // with the GUI in these callbacks. + s_ActiveSession->m_FailedStageId = stage; emit s_ActiveSession->stageFailed(QString::fromLocal8Bit(LiGetStageName(stage)), errorCode); QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } void Session::clConnectionTerminated(int errorCode) { + s_ActiveSession->m_TerminationErrorCode = errorCode; + // Display the termination dialog if this was not intended switch (errorCode) { case ML_ERROR_GRACEFUL_TERMINATION: @@ -336,6 +339,8 @@ Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *prefere m_InputHandler(nullptr), m_InputHandlerLock(0), m_MouseEmulationRefCount(0), + m_TerminationErrorCode(ML_ERROR_GRACEFUL_TERMINATION), + m_FailedStageId(STAGE_NONE), m_OpusDecoder(nullptr), m_AudioRenderer(nullptr), m_AudioSampleCount(0), @@ -701,12 +706,36 @@ private: !m_Session->m_UnexpectedTermination && m_Session->m_Preferences->quitAppAfter; + + // If the connection terminated due to an error, we may want + // to perform a connection test to ensure our traffic is not + // being blocked. + int portFlags; + unsigned int portTestResult = 0; + if (m_Session->m_FailedStageId != STAGE_NONE) { + portFlags = LiGetPortFlagsFromStage(m_Session->m_FailedStageId); + } + else if (m_Session->m_TerminationErrorCode != ML_ERROR_GRACEFUL_TERMINATION) { + portFlags = LiGetPortFlagsFromTerminationErrorCode(m_Session->m_TerminationErrorCode); + } + else { + portFlags = 0; + } + if (portFlags != 0) { + portTestResult = LiTestClientConnectivity("qt.conntest.moonlight-stream.org", 443, portFlags); + + // Ignore an inconclusive result + if (portTestResult == ML_TEST_RESULT_INCONCLUSIVE) { + portTestResult = 0; + } + } + // Notify the UI if (shouldQuit) { emit m_Session->quitStarting(); } else { - emit m_Session->sessionFinished(); + emit m_Session->sessionFinished(portTestResult); } // Finish cleanup of the connection state @@ -724,7 +753,7 @@ private: } // Session is finished now - emit m_Session->sessionFinished(); + emit m_Session->sessionFinished(portTestResult); } } @@ -922,7 +951,7 @@ void Session::exec(int displayOriginX, int displayOriginY) // calling expensive functions in the constructor (during the // process of loading the StreamSegue). if (!initialize()) { - emit sessionFinished(); + emit sessionFinished(0); return; } diff --git a/app/streaming/session.h b/app/streaming/session.h index 53c6e780..6354fb56 100644 --- a/app/streaming/session.h +++ b/app/streaming/session.h @@ -51,7 +51,7 @@ signals: void quitStarting(); - void sessionFinished(); + void sessionFinished(int portTestResult); private: bool initialize(); @@ -147,6 +147,9 @@ private: SDL_SpinLock m_InputHandlerLock; int m_MouseEmulationRefCount; + int m_TerminationErrorCode; + int m_FailedStageId; + int m_ActiveVideoFormat; int m_ActiveVideoWidth; int m_ActiveVideoHeight; diff --git a/moonlight-common-c/moonlight-common-c b/moonlight-common-c/moonlight-common-c index f6927475..2fdcfb94 160000 --- a/moonlight-common-c/moonlight-common-c +++ b/moonlight-common-c/moonlight-common-c @@ -1 +1 @@ -Subproject commit f6927475cfa290fc301d1916f6e81cfca5fcba76 +Subproject commit 2fdcfb9429be64842d2a730801d2b5700d40d7b9