From 6c4e918b367f942044abe0258be3c07e31a2faf3 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 3 Oct 2022 18:35:52 +0200 Subject: [PATCH 1/3] fixed compilation on windows --- retroshare-friendserver/src/network.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/retroshare-friendserver/src/network.cc b/retroshare-friendserver/src/network.cc index b5d9e076a..426d54de8 100644 --- a/retroshare-friendserver/src/network.cc +++ b/retroshare-friendserver/src/network.cc @@ -26,7 +26,14 @@ #include #include #include + +#ifdef WINDOWS_SYS +#include +#include +#include +#else #include +#endif #include "util/rsnet.h" #include "util/rsprint.h" From d307b46c1584d3f2e0ecc0afe83fc69f0accf8f0 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 3 Oct 2022 23:06:08 +0200 Subject: [PATCH 2/3] added async testing of friend server --- .../src/gui/FriendServerControl.cpp | 69 ++++++++++++------- retroshare-gui/src/gui/FriendServerControl.h | 3 +- retroshare-gui/src/gui/FriendServerControl.ui | 11 +-- 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/retroshare-gui/src/gui/FriendServerControl.cpp b/retroshare-gui/src/gui/FriendServerControl.cpp index 5842516ed..0a0e286f0 100644 --- a/retroshare-gui/src/gui/FriendServerControl.cpp +++ b/retroshare-gui/src/gui/FriendServerControl.cpp @@ -45,6 +45,7 @@ FriendServerControl::FriendServerControl(QWidget *parent) setupUi(this); friendServerOnOff_CB->setEnabled(false); // until FS is connected. + mCurrentlyCheckingServerAddress = false; if(!rsFriendServer) { @@ -80,13 +81,12 @@ FriendServerControl::FriendServerControl(QWidget *parent) QObject::connect(friendServerOnOff_CB,SIGNAL(toggled(bool)),this,SLOT(onOnOffClick(bool))); QObject::connect(torServerFriendsToRequest_SB,SIGNAL(valueChanged(int)),this,SLOT(onFriendsToRequestChanged(int))); - QObject::connect(torServerAddress_LE,SIGNAL(editingFinished()),this,SLOT(onOnionAddressEdit())); + QObject::connect(torServerAddress_LE,SIGNAL(textEdited(const QString&)),this,SLOT(onOnionAddressEdit(const QString&))); QObject::connect(torServerPort_SB,SIGNAL(valueChanged(int)),this,SLOT(onOnionPortEdit(int))); QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress())); mCheckingServerMovie = new QMovie(":/images/loader/circleball-16.gif"); - serverStatusCheckResult_LB->setMovie(mCheckingServerMovie); updateFriendServerStatusIcon(false); } @@ -130,33 +130,53 @@ void FriendServerControl::onOnionPortEdit(int) } } -void FriendServerControl::onOnionAddressEdit() +void FriendServerControl::onOnionAddressEdit(const QString&) { + while(mCurrentlyCheckingServerAddress) + { + std::cerr << " waiting for free slot" << std::endl; + std::this_thread::sleep_for(std::chrono::milliseconds(500)); // wait for ongoing check to finish. + } + + std::cerr << "Resetting connection proxy timer" << std::endl; + // Setup timer to auto-check the friend server address - mConnectionCheckTimer->stop(); mConnectionCheckTimer->setSingleShot(true); mConnectionCheckTimer->setInterval(5000); // check in 5 secs unless something is changed in the mean time. - mConnectionCheckTimer->start(); - - if(mCheckingServerMovie->fileName() != QString(":/images/loader/circleball-16.gif" )) - { - mCheckingServerMovie->setFileName(":/images/loader/circleball-16.gif"); - mCheckingServerMovie->start(); - } } void FriendServerControl::checkServerAddress() { - rsFriendServer->checkServerAddress_async(torServerAddress_LE->text().toStdString(),torServerPort_SB->value(),5000, - [this](const std::string& address,uint16_t port,bool test_result) - { - if(test_result) - rsFriendServer->setServerAddress(address,port); + std::cerr << "In checkServerAddress() ..." << std::endl; - RsQThreadUtils::postToObject( [=]() { updateFriendServerStatusIcon(test_result); },this); - } - ); + mCurrentlyCheckingServerAddress = true; + + serverStatusCheckResult_LB->setMovie(mCheckingServerMovie); + serverStatusCheckResult_LB->setToolTip(tr("Friend server is currently reachable.")) ; + mCheckingServerMovie->setFileName(":/images/loader/circleball-16.gif"); + mCheckingServerMovie->start(); + + RsThread::async( [this]() + { + auto port = torServerPort_SB->value(); + auto addr = torServerAddress_LE->text().toStdString(); + + std::cerr << "calling sync test..." << std::endl; + bool succeed = rsFriendServer->checkServerAddress(addr,port,5000); + std::cerr << "result is " << succeed << std::endl; + + RsQThreadUtils::postToObject( [addr,port,succeed,this]() + { + if(succeed) + rsFriendServer->setServerAddress(addr,port); + + mCheckingServerMovie->stop(); + updateFriendServerStatusIcon(succeed); + mCurrentlyCheckingServerAddress = false; + + },this); + }); } void FriendServerControl::onNbFriendsToRequestsChanged(int n) @@ -166,23 +186,22 @@ void FriendServerControl::onNbFriendsToRequestsChanged(int n) void FriendServerControl::updateFriendServerStatusIcon(bool ok) { - mCheckingServerMovie->stop(); + std::cerr << "updating proxy status icon" << std::endl; if(ok) { - torServerStatus_LB->setToolTip(tr("Friend server is currently reachable.")) ; - mCheckingServerMovie->setFileName(ICON_STATUS_OK); + serverStatusCheckResult_LB->setToolTip(tr("Friend server is currently reachable.")) ; + serverStatusCheckResult_LB->setPixmap(QPixmap(ICON_STATUS_OK)); friendServerOnOff_CB->setEnabled(true); } else { rsFriendServer->stopServer(); - torServerStatus_LB->setToolTip(tr("The proxy is not enabled or broken.\nAre all services up and running fine??\nAlso check your ports!")) ; - mCheckingServerMovie->setFileName(ICON_STATUS_UNKNOWN); + serverStatusCheckResult_LB->setToolTip(tr("The proxy is not enabled or broken.\nAre all services up and running fine??\nAlso check your ports!")) ; + serverStatusCheckResult_LB->setPixmap(QPixmap(ICON_STATUS_UNKNOWN)); friendServerOnOff_CB->setChecked(false); friendServerOnOff_CB->setEnabled(false); } - mCheckingServerMovie->start(); } diff --git a/retroshare-gui/src/gui/FriendServerControl.h b/retroshare-gui/src/gui/FriendServerControl.h index 832c67f39..fafd26f82 100644 --- a/retroshare-gui/src/gui/FriendServerControl.h +++ b/retroshare-gui/src/gui/FriendServerControl.h @@ -35,7 +35,7 @@ public: protected slots: void onOnOffClick(bool b); - void onOnionAddressEdit(); + void onOnionAddressEdit(const QString &); void onOnionPortEdit(int); void onNbFriendsToRequestsChanged(int n); void checkServerAddress(); @@ -45,4 +45,5 @@ private: QTimer *mConnectionCheckTimer; QMovie *mCheckingServerMovie; + bool mCurrentlyCheckingServerAddress; }; diff --git a/retroshare-gui/src/gui/FriendServerControl.ui b/retroshare-gui/src/gui/FriendServerControl.ui index 4eed774ad..1455de71e 100644 --- a/retroshare-gui/src/gui/FriendServerControl.ui +++ b/retroshare-gui/src/gui/FriendServerControl.ui @@ -59,13 +59,6 @@ - - - - - - - @@ -88,7 +81,7 @@ Qt::NoFocus - + :/icons/help_64.png:/icons/help_64.png @@ -205,7 +198,7 @@ - + From f3ee68411d8c8c3da109a12b526c5183a0f3119f Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 6 Oct 2022 14:26:53 +0200 Subject: [PATCH 3/3] added missing documentation in BinInterface::readdata(), and fixed bug in FdBinInterface not implementing readdata() correctly --- retroshare-friendserver/src/network.cc | 37 +++++++++++++------ .../src/gui/FriendServerControl.cpp | 2 +- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/retroshare-friendserver/src/network.cc b/retroshare-friendserver/src/network.cc index 426d54de8..f28a38de0 100644 --- a/retroshare-friendserver/src/network.cc +++ b/retroshare-friendserver/src/network.cc @@ -113,15 +113,19 @@ void FsNetworkInterface::threadTick() std::list to_close; - RS_STACK_MUTEX(mFsNiMtx); - for(auto& it:mConnections) - if(it.second.bio->isactive() || it.second.bio->moretoread(0)) + { + RS_STACK_MUTEX(mFsNiMtx); + for(auto& it:mConnections) + { it.second.pqi_thread->tick(); - else - to_close.push_back(it.first); - for(const auto& pid:to_close) - locked_closeConnection(pid); + if(!it.second.bio->isactive() && !it.second.bio->moretoread(0)) + to_close.push_back(it.first); + } + + for(const auto& pid:to_close) + locked_closeConnection(pid); + } std::this_thread::sleep_for(std::chrono::milliseconds(200)); } @@ -165,12 +169,17 @@ bool FsNetworkInterface::checkForNewConnections() // Create connection info + RsDbg() << " Creating connection data." ; + ConnectionData c; c.socket = clintConnt; c.client_address = addr; - RsPeerId pid = makePeerId(clintConnt); + RsDbg() << " socket: " << clintConnt; + RsDbg() << " client address: " << sockaddr_storage_tostring(*(sockaddr_storage*)&addr); + RsDbg() << " peer id: " << pid ; + // Setup a pqistreamer to deserialize whatever comes from this connection RsSerialiser *rss = new RsSerialiser ; @@ -183,11 +192,14 @@ bool FsNetworkInterface::checkForNewConnections() c.pqi_thread = pqi; c.bio = bio; - pqi->start(); + { + RS_STACK_MUTEX(mFsNiMtx); + mConnections[pid] = c; - RS_STACK_MUTEX(mFsNiMtx); - mConnections[pid] = c; + pqi->start(); + } + RsDbg() << " streamer has properly started." ; return true; } @@ -195,6 +207,8 @@ bool FsNetworkInterface::RecvItem(RsItem *item) { RS_STACK_MUTEX(mFsNiMtx); + RsDbg() << "FsNetworkInterface: received item " << (void*)item; + auto it = mConnections.find(item->PeerId()); if(it == mConnections.end()) @@ -219,6 +233,7 @@ RsItem *FsNetworkInterface::GetItem() RsItem *item = it.second.incoming_items.front(); it.second.incoming_items.pop_front(); + RsDbg() << "FsNetworkInterface: returning item " << (void*)item << " to caller."; return item; } } diff --git a/retroshare-gui/src/gui/FriendServerControl.cpp b/retroshare-gui/src/gui/FriendServerControl.cpp index 0a0e286f0..5b3fdf994 100644 --- a/retroshare-gui/src/gui/FriendServerControl.cpp +++ b/retroshare-gui/src/gui/FriendServerControl.cpp @@ -153,7 +153,7 @@ void FriendServerControl::checkServerAddress() mCurrentlyCheckingServerAddress = true; serverStatusCheckResult_LB->setMovie(mCheckingServerMovie); - serverStatusCheckResult_LB->setToolTip(tr("Friend server is currently reachable.")) ; + serverStatusCheckResult_LB->setToolTip(tr("Trying to contact friend server\nThis may take up to 1 min.")) ; mCheckingServerMovie->setFileName(":/images/loader/circleball-16.gif"); mCheckingServerMovie->start();