added logic to stop/start FriendServer from GUI

This commit is contained in:
csoler 2021-10-29 21:44:30 +02:00
parent 19e42663a0
commit d948086b5e
7 changed files with 105 additions and 17 deletions

View File

@ -0,0 +1,44 @@
#include "fsmanager.h"
RsFriendServer *rsFriendServer = nullptr;
void FriendServerManager::startServer()
{
if(!isRunning())
{
std::cerr << "Starting Friend Server Manager." << std::endl;
RsTickingThread::start() ;
}
}
void FriendServerManager::stopServer()
{
if(isRunning() && !shouldStop())
{
std::cerr << "Stopping Friend Server Manager." << std::endl;
RsTickingThread::askForStop() ;
}
}
void FriendServerManager::checkServerAddress_async(const std::string& addr,uint16_t, const std::function<void (const std::string& address,bool result_status)>& callback)
{
#warning TODO
std::this_thread::sleep_for(std::chrono::seconds(1));
callback(addr,true);
}
void FriendServerManager::setServerAddress(const std::string& addr,uint16_t port)
{
mServerAddress = addr;
mServerPort = port;
}
void FriendServerManager::setFriendsToRequest(uint32_t n)
{
mFriendsToRequest = n;
}
void FriendServerManager::threadTick()
{
std::cerr << "Ticking FriendServerManager..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
}

View File

@ -0,0 +1,41 @@
#include <map>
#include "util/rsthreads.h"
#include "retroshare/rsfriendserver.h"
#include "retroshare/rspeers.h"
struct FriendServerPeerInfo
{
enum FriendServerPeerStatus: uint8_t
{
UNKNOWN = 0x00,
LOCALLY_ACCEPTED = 0x01,
HAS_ACCEPTED_ME = 0x02,
ALREADY_CONNECTED = 0x03
};
uint32_t status ;
};
class FriendServerManager: public RsFriendServer, public RsTickingThread
{
public:
virtual void startServer() override ;
virtual void stopServer() override ;
virtual void checkServerAddress_async(const std::string& addr,uint16_t, const std::function<void (const std::string& address,bool result_status)>& callback) override ;
virtual void setServerAddress(const std::string&,uint16_t) override ;
virtual void setFriendsToRequest(uint32_t) override ;
protected:
virtual void threadTick() override;
private:
uint32_t mFriendsToRequest;
// encode the current list of friends obtained through the friendserver and their status
std::map<RsPeerId, FriendServerPeerInfo> mPeers;
std::string mServerAddress ;
uint16_t mServerPort;
};

View File

@ -23,8 +23,8 @@
class RsFriendServer
{
public:
virtual void start() =0;
virtual void stop() =0;
virtual void startServer() =0;
virtual void stopServer() =0;
virtual void checkServerAddress_async(const std::string& addr,uint16_t, const std::function<void (const std::string& address,bool result_status)>& callback) =0;
virtual void setServerAddress(const std::string&,uint16_t) =0;

View File

@ -48,6 +48,7 @@
#include "retroshare/rsversion.h"
#include "rsserver/rsloginhandler.h"
#include "rsserver/rsaccounts.h"
#include "friend_server/fsmanager.h"
#include <list>
#include <string>
@ -1170,6 +1171,9 @@ int RsServer::StartupRetroShare()
serviceCtrl->setServiceServer(pqih) ;
// setup friend server
rsFriendServer = new FriendServerManager();
/****** New Ft Server **** !!! */
ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl);
ftserver->setConfigDirectory(RsAccounts::AccountDirectory());

View File

@ -61,16 +61,16 @@ int main(int argc, char* argv[])
{
std::this_thread::sleep_for(std::chrono::seconds(2));
// send one request for testing to see what happens
RsFriendServerClientPublishItem *item = new RsFriendServerClientPublishItem();
item->long_invite = std::string("[Long Invite]");
item->n_requested_friends = 10;
std::cerr << "Sending fake request item for testing..." << std::endl;
FsClient(std::string("127.0.0.1")).sendItem(item);
std::this_thread::sleep_for(std::chrono::seconds(4));
// // send one request for testing to see what happens
//
// RsFriendServerClientPublishItem *item = new RsFriendServerClientPublishItem();
// item->long_invite = std::string("[Long Invite]");
// item->n_requested_friends = 10;
//
// std::cerr << "Sending fake request item for testing..." << std::endl;
// FsClient(std::string("127.0.0.1")).sendItem(item);
//
// std::this_thread::sleep_for(std::chrono::seconds(4));
}
return 0;
}

View File

@ -31,8 +31,6 @@
#include <iostream>
RsFriendServer *rsFriendServer = new RsFriendServer;
#define ICON_STATUS_UNKNOWN ":/images/ledoff1.png"
#define ICON_STATUS_OK ":/images/ledon1.png"
@ -44,6 +42,7 @@ FriendServerControl::FriendServerControl(QWidget *parent)
mConnectionCheckTimer = new QTimer;
QObject::connect(friendServerOnOff_CB,SIGNAL(toggled(bool)),this,SLOT(onOnOffClick(bool)));
QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress()));
QObject::connect(torServerAddress_LE,SIGNAL(textChanged(const QString&)),this,SLOT(onOnionAddressEdit(const QString&)));
@ -62,9 +61,9 @@ FriendServerControl::~FriendServerControl()
void FriendServerControl::onOnOffClick(bool b)
{
if(b)
rsFriendServer->start();
rsFriendServer->startServer();
else
rsFriendServer->stop();
rsFriendServer->stopServer();
}
void FriendServerControl::onOnionAddressEdit(const QString&)

View File

@ -12,7 +12,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="torServerOnOff_CB">
<widget class="QCheckBox" name="friendServerOnOff_CB">
<property name="text">
<string>On/Off</string>
</property>