Merge pull request #2636 from csoler/v0.6-TorControl3

fixed compilation on windows
This commit is contained in:
csoler 2022-10-06 20:30:19 +02:00 committed by GitHub
commit 0eda08f881
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 46 deletions

View File

@ -26,7 +26,14 @@
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#ifdef WINDOWS_SYS
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <netinet/tcp.h>
#endif
#include "util/rsnet.h"
#include "util/rsprint.h"
@ -106,15 +113,19 @@ void FsNetworkInterface::threadTick()
std::list<RsPeerId> 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));
}
@ -158,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 ;
@ -176,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;
}
@ -188,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())
@ -212,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;
}
}

View File

@ -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("Trying to contact friend server\nThis may take up to 1 min.")) ;
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();
}

View File

@ -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;
};

View File

@ -59,13 +59,6 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="torServerStatus_LB">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -88,7 +81,7 @@
<enum>Qt::NoFocus</enum>
</property>
<property name="icon">
<iconset resource="icons.qrc">
<iconset resource="images.qrc">
<normaloff>:/icons/help_64.png</normaloff>:/icons/help_64.png</iconset>
</property>
<property name="checkable">
@ -205,7 +198,7 @@
</layout>
</widget>
<resources>
<include location="icons.qrc"/>
<include location="images.qrc"/>
</resources>
<connections/>
</ui>