mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -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
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue