mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-20 04:14:27 -04:00
added logic to stop/start FriendServer from GUI
This commit is contained in:
parent
19e42663a0
commit
d948086b5e
7 changed files with 105 additions and 17 deletions
|
@ -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));
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
|
@ -23,8 +23,8 @@
|
||||||
class RsFriendServer
|
class RsFriendServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void start() =0;
|
virtual void startServer() =0;
|
||||||
virtual void stop() =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 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;
|
virtual void setServerAddress(const std::string&,uint16_t) =0;
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
#include "retroshare/rsversion.h"
|
#include "retroshare/rsversion.h"
|
||||||
#include "rsserver/rsloginhandler.h"
|
#include "rsserver/rsloginhandler.h"
|
||||||
#include "rsserver/rsaccounts.h"
|
#include "rsserver/rsaccounts.h"
|
||||||
|
#include "friend_server/fsmanager.h"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -1170,6 +1171,9 @@ int RsServer::StartupRetroShare()
|
||||||
|
|
||||||
serviceCtrl->setServiceServer(pqih) ;
|
serviceCtrl->setServiceServer(pqih) ;
|
||||||
|
|
||||||
|
// setup friend server
|
||||||
|
rsFriendServer = new FriendServerManager();
|
||||||
|
|
||||||
/****** New Ft Server **** !!! */
|
/****** New Ft Server **** !!! */
|
||||||
ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl);
|
ftServer *ftserver = new ftServer(mPeerMgr, serviceCtrl);
|
||||||
ftserver->setConfigDirectory(RsAccounts::AccountDirectory());
|
ftserver->setConfigDirectory(RsAccounts::AccountDirectory());
|
||||||
|
|
|
@ -61,16 +61,16 @@ int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
|
|
||||||
// send one request for testing to see what happens
|
// // send one request for testing to see what happens
|
||||||
|
//
|
||||||
RsFriendServerClientPublishItem *item = new RsFriendServerClientPublishItem();
|
// RsFriendServerClientPublishItem *item = new RsFriendServerClientPublishItem();
|
||||||
item->long_invite = std::string("[Long Invite]");
|
// item->long_invite = std::string("[Long Invite]");
|
||||||
item->n_requested_friends = 10;
|
// item->n_requested_friends = 10;
|
||||||
|
//
|
||||||
std::cerr << "Sending fake request item for testing..." << std::endl;
|
// std::cerr << "Sending fake request item for testing..." << std::endl;
|
||||||
FsClient(std::string("127.0.0.1")).sendItem(item);
|
// FsClient(std::string("127.0.0.1")).sendItem(item);
|
||||||
|
//
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(4));
|
// std::this_thread::sleep_for(std::chrono::seconds(4));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,6 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
RsFriendServer *rsFriendServer = new RsFriendServer;
|
|
||||||
|
|
||||||
#define ICON_STATUS_UNKNOWN ":/images/ledoff1.png"
|
#define ICON_STATUS_UNKNOWN ":/images/ledoff1.png"
|
||||||
#define ICON_STATUS_OK ":/images/ledon1.png"
|
#define ICON_STATUS_OK ":/images/ledon1.png"
|
||||||
|
|
||||||
|
@ -44,6 +42,7 @@ FriendServerControl::FriendServerControl(QWidget *parent)
|
||||||
|
|
||||||
mConnectionCheckTimer = new QTimer;
|
mConnectionCheckTimer = new QTimer;
|
||||||
|
|
||||||
|
QObject::connect(friendServerOnOff_CB,SIGNAL(toggled(bool)),this,SLOT(onOnOffClick(bool)));
|
||||||
QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress()));
|
QObject::connect(mConnectionCheckTimer,SIGNAL(timeout()),this,SLOT(checkServerAddress()));
|
||||||
QObject::connect(torServerAddress_LE,SIGNAL(textChanged(const QString&)),this,SLOT(onOnionAddressEdit(const QString&)));
|
QObject::connect(torServerAddress_LE,SIGNAL(textChanged(const QString&)),this,SLOT(onOnionAddressEdit(const QString&)));
|
||||||
|
|
||||||
|
@ -62,9 +61,9 @@ FriendServerControl::~FriendServerControl()
|
||||||
void FriendServerControl::onOnOffClick(bool b)
|
void FriendServerControl::onOnOffClick(bool b)
|
||||||
{
|
{
|
||||||
if(b)
|
if(b)
|
||||||
rsFriendServer->start();
|
rsFriendServer->startServer();
|
||||||
else
|
else
|
||||||
rsFriendServer->stop();
|
rsFriendServer->stopServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendServerControl::onOnionAddressEdit(const QString&)
|
void FriendServerControl::onOnionAddressEdit(const QString&)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="torServerOnOff_CB">
|
<widget class="QCheckBox" name="friendServerOnOff_CB">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>On/Off</string>
|
<string>On/Off</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue