mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
commit
b17d2a3aca
@ -41,7 +41,7 @@ addons:
|
|||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- if [ $TRAVIS_OS_NAME == linux ]; then qmake QMAKE_CC=$CC QMAKE_CXX=$CXX; fi
|
- if [ $TRAVIS_OS_NAME == linux ]; then qmake QMAKE_CC=$CC QMAKE_CXX=$CXX; fi
|
||||||
- if [ $TRAVIS_OS_NAME == osx ]; then qmake QMAKE_CC=$CC QMAKE_CXX=$CXX CONFIG+=rs_macos10.12 INCLUDEPATH+=/usr/local/opt/openssl/include/ QMAKE_LIBDIR+=/usr/local/opt/openssl/lib/; fi
|
- if [ $TRAVIS_OS_NAME == osx ]; then echo TEMPORARILY DISABLED qmake QMAKE_CC=$CC QMAKE_CXX=$CXX CONFIG+=rs_macos10.12 INCLUDEPATH+=/usr/local/opt/openssl/include/ QMAKE_LIBDIR+=/usr/local/opt/openssl/lib/; fi
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- if [ $TRAVIS_OS_NAME == linux ] && [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make -j2; fi
|
- if [ $TRAVIS_OS_NAME == linux ] && [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make -j2; fi
|
||||||
|
@ -45,6 +45,10 @@ registerHandler("$%apiPath%$",
|
|||||||
if(jReq.HasMember(kcd))
|
if(jReq.HasMember(kcd))
|
||||||
jAns.AddMember(kcd, jReq[kcd], jAns.GetAllocator());
|
jAns.AddMember(kcd, jReq[kcd], jAns.GetAllocator());
|
||||||
|
|
||||||
|
if( !checkRsServicePtrReady(
|
||||||
|
$%instanceName%$, "$%instanceName%$", cAns, session ) )
|
||||||
|
return;
|
||||||
|
|
||||||
$%paramsDeclaration%$
|
$%paramsDeclaration%$
|
||||||
|
|
||||||
$%inputParamsDeserialization%$
|
$%inputParamsDeserialization%$
|
||||||
|
@ -78,12 +78,12 @@ int main(int argc, char *argv[])
|
|||||||
QString headerFileName(hfi.fileName());
|
QString headerFileName(hfi.fileName());
|
||||||
headerFileName.replace(QString("_8h.xml"), QString(".h"));
|
headerFileName.replace(QString("_8h.xml"), QString(".h"));
|
||||||
|
|
||||||
QDomNodeList sectiondefs = hDoc.elementsByTagName("sectiondef");
|
QDomNodeList sectiondefs = hDoc.elementsByTagName("memberdef");
|
||||||
for(int j = 0; j < sectiondefs.size(); ++j)
|
for(int j = 0; j < sectiondefs.size(); ++j)
|
||||||
{
|
{
|
||||||
QDomElement sectDef = sectiondefs.item(j).toElement();
|
QDomElement sectDef = sectiondefs.item(j).toElement();
|
||||||
|
|
||||||
if( sectDef.attributes().namedItem("kind").nodeValue() != "var"
|
if( sectDef.attributes().namedItem("kind").nodeValue() != "variable"
|
||||||
|| sectDef.elementsByTagName("jsonapi").isEmpty() )
|
|| sectDef.elementsByTagName("jsonapi").isEmpty() )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -112,7 +112,6 @@ int main(int argc, char *argv[])
|
|||||||
QDomNode member = members.item(i);
|
QDomNode member = members.item(i);
|
||||||
QString refid(member.attributes().namedItem("refid").nodeValue());
|
QString refid(member.attributes().namedItem("refid").nodeValue());
|
||||||
QString methodName(member.firstChildElement("name").toElement().text());
|
QString methodName(member.firstChildElement("name").toElement().text());
|
||||||
QString wrapperName(instanceName+methodName+"Wrapper");
|
|
||||||
QString defFilePath(doxPrefix + refid.split('_')[0] + ".xml");
|
QString defFilePath(doxPrefix + refid.split('_')[0] + ".xml");
|
||||||
|
|
||||||
qDebug() << "Looking for" << typeName << methodName << "into"
|
qDebug() << "Looking for" << typeName << methodName << "into"
|
||||||
@ -325,7 +324,7 @@ int main(int argc, char *argv[])
|
|||||||
substitutionsMap.insert("paramsDeclaration", paramsDeclaration);
|
substitutionsMap.insert("paramsDeclaration", paramsDeclaration);
|
||||||
substitutionsMap.insert("inputParamsDeserialization", inputParamsDeserialization);
|
substitutionsMap.insert("inputParamsDeserialization", inputParamsDeserialization);
|
||||||
substitutionsMap.insert("outputParamsSerialization", outputParamsSerialization);
|
substitutionsMap.insert("outputParamsSerialization", outputParamsSerialization);
|
||||||
substitutionsMap.insert("wrapperName", wrapperName);
|
substitutionsMap.insert("instanceName", instanceName);
|
||||||
substitutionsMap.insert("headerFileName", headerFileName);
|
substitutionsMap.insert("headerFileName", headerFileName);
|
||||||
substitutionsMap.insert("functionCall", functionCall);
|
substitutionsMap.insert("functionCall", functionCall);
|
||||||
substitutionsMap.insert("apiPath", apiPath);
|
substitutionsMap.insert("apiPath", apiPath);
|
||||||
|
@ -38,6 +38,10 @@ registerHandler("$%apiPath%$",
|
|||||||
if(jReq.HasMember(kcd))
|
if(jReq.HasMember(kcd))
|
||||||
jAns.AddMember(kcd, jReq[kcd], jAns.GetAllocator());
|
jAns.AddMember(kcd, jReq[kcd], jAns.GetAllocator());
|
||||||
|
|
||||||
|
if( !checkRsServicePtrReady(
|
||||||
|
$%instanceName%$, "$%instanceName%$", cAns, session ) )
|
||||||
|
return;
|
||||||
|
|
||||||
$%paramsDeclaration%$
|
$%paramsDeclaration%$
|
||||||
|
|
||||||
// deserialize input parameters from JSON
|
// deserialize input parameters from JSON
|
||||||
|
@ -30,13 +30,42 @@
|
|||||||
// Generated at compile time
|
// Generated at compile time
|
||||||
#include "jsonapi-includes.inl"
|
#include "jsonapi-includes.inl"
|
||||||
|
|
||||||
|
static bool checkRsServicePtrReady(
|
||||||
|
void* serviceInstance, const std::string& serviceName,
|
||||||
|
RsGenericSerializer::SerializeContext& ctx,
|
||||||
|
const std::shared_ptr<restbed::Session> session)
|
||||||
|
{
|
||||||
|
if(serviceInstance) return true;
|
||||||
|
|
||||||
|
std::string jsonApiError;
|
||||||
|
jsonApiError += "Service: ";
|
||||||
|
jsonApiError += serviceName;
|
||||||
|
jsonApiError += " not initialized! Are you sure you logged in already?";
|
||||||
|
|
||||||
|
RsGenericSerializer::SerializeJob j(RsGenericSerializer::TO_JSON);
|
||||||
|
RS_SERIAL_PROCESS(jsonApiError);
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << ctx.mJson;
|
||||||
|
std::string&& ans(ss.str());
|
||||||
|
const std::multimap<std::string, std::string> headers
|
||||||
|
{
|
||||||
|
{ "Content-Type", "text/json" },
|
||||||
|
{ "Content-Length", std::to_string(ans.length()) }
|
||||||
|
};
|
||||||
|
session->close(rb::CONFLICT, ans, headers);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
JsonApiServer::JsonApiServer(
|
JsonApiServer::JsonApiServer(
|
||||||
uint16_t port, const std::function<void(int)> shutdownCallback) :
|
uint16_t port, const std::string& bindAddress,
|
||||||
mPort(port), mShutdownCallback(shutdownCallback)
|
const std::function<void(int)> shutdownCallback ) :
|
||||||
|
mPort(port), mBindAddress(bindAddress), mShutdownCallback(shutdownCallback)
|
||||||
{
|
{
|
||||||
registerHandler("/jsonApiServer/shutdown",
|
registerHandler("/jsonApiServer/shutdown",
|
||||||
[this](const std::shared_ptr<rb::Session>)
|
[this](const std::shared_ptr<rb::Session> session)
|
||||||
{
|
{
|
||||||
|
session->close(rb::OK);
|
||||||
shutdown();
|
shutdown();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -62,6 +91,9 @@ JsonApiServer::JsonApiServer(
|
|||||||
if(jReq.HasMember(kcd))
|
if(jReq.HasMember(kcd))
|
||||||
jAns.AddMember(kcd, jReq[kcd], jAns.GetAllocator());
|
jAns.AddMember(kcd, jReq[kcd], jAns.GetAllocator());
|
||||||
|
|
||||||
|
if(!checkRsServicePtrReady(rsFiles, "rsFiles", cAns, session))
|
||||||
|
return;
|
||||||
|
|
||||||
RsFileHash hash;
|
RsFileHash hash;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
uint32_t requested_size;
|
uint32_t requested_size;
|
||||||
@ -122,7 +154,7 @@ void JsonApiServer::run()
|
|||||||
{
|
{
|
||||||
std::shared_ptr<rb::Settings> settings(new rb::Settings);
|
std::shared_ptr<rb::Settings> settings(new rb::Settings);
|
||||||
settings->set_port(mPort);
|
settings->set_port(mPort);
|
||||||
// settings->set_default_header("Connection", "close");
|
settings->set_bind_address(mBindAddress);
|
||||||
settings->set_default_header("Cache-Control", "no-cache");
|
settings->set_default_header("Cache-Control", "no-cache");
|
||||||
mService.start(settings);
|
mService.start(settings);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ namespace rb = restbed;
|
|||||||
struct JsonApiServer : RsSingleJobThread
|
struct JsonApiServer : RsSingleJobThread
|
||||||
{
|
{
|
||||||
JsonApiServer(
|
JsonApiServer(
|
||||||
uint16_t port,
|
uint16_t port = 9092,
|
||||||
|
const std::string& bindAddress = "127.0.0.1",
|
||||||
const std::function<void(int)> shutdownCallback = [](int){} );
|
const std::function<void(int)> shutdownCallback = [](int){} );
|
||||||
|
|
||||||
/// @see RsSingleJobThread
|
/// @see RsSingleJobThread
|
||||||
@ -66,7 +67,8 @@ struct JsonApiServer : RsSingleJobThread
|
|||||||
void shutdown(int exitCode = 0);
|
void shutdown(int exitCode = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t mPort;
|
const uint16_t mPort;
|
||||||
|
const std::string mBindAddress;
|
||||||
rb::Service mService;
|
rb::Service mService;
|
||||||
const std::function<void(int)> mShutdownCallback;
|
const std::function<void(int)> mShutdownCallback;
|
||||||
};
|
};
|
||||||
|
@ -56,6 +56,11 @@ public:
|
|||||||
/* Real Startup Fn */
|
/* Real Startup Fn */
|
||||||
virtual int StartupRetroShare() = 0;
|
virtual int StartupRetroShare() = 0;
|
||||||
|
|
||||||
|
/** Check if core is fully ready, true only after
|
||||||
|
* StartupRetroShare() finish and before rsGlobalShutDown() begin
|
||||||
|
*/
|
||||||
|
virtual bool isReady() = 0;
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
/* Config */
|
/* Config */
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ struct RsLoginHelper;
|
|||||||
*/
|
*/
|
||||||
extern RsLoginHelper* rsLoginHelper;
|
extern RsLoginHelper* rsLoginHelper;
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Initialisation Class (not publicly disclosed to RsIFace)
|
* Initialisation Class (not publicly disclosed to RsIFace)
|
||||||
*/
|
*/
|
||||||
@ -132,25 +133,30 @@ private:
|
|||||||
|
|
||||||
/* Seperate static Class for dealing with Accounts */
|
/* Seperate static Class for dealing with Accounts */
|
||||||
|
|
||||||
class RsAccountsDetail ;
|
class RsAccountsDetail;
|
||||||
|
|
||||||
class RsAccounts
|
class RsAccounts
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Should be called once before everything else.
|
/// Should be called once before everything else.
|
||||||
|
|
||||||
static bool init(const std::string &opt_base_dir, int& error_code);
|
static bool init(const std::string &opt_base_dir, int& error_code);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ConfigDirectory (normally ~/.retroshare) you can call this method
|
* @brief ConfigDirectory (usually ~/.retroshare) you can call this method
|
||||||
* even before initialisation (you can't with some other methods)
|
* even before initialisation (you can't with some other methods)
|
||||||
*
|
|
||||||
* On linux: ~/.retroshare/
|
|
||||||
*
|
|
||||||
* @see RsAccountsDetail::PathBaseDirectory()
|
* @see RsAccountsDetail::PathBaseDirectory()
|
||||||
*/
|
*/
|
||||||
static std::string ConfigDirectory();
|
static std::string ConfigDirectory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get current account id. Beware that an account may be selected
|
||||||
|
* without actually logging in.
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[out] id storage for current account id
|
||||||
|
* @return false if account hasn't been selected yet, true otherwise
|
||||||
|
*/
|
||||||
|
static bool getCurrentAccountId(RsPeerId &id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DataDirectory
|
* @brief DataDirectory
|
||||||
* you can call this method even before initialisation (you can't with some other methods)
|
* you can call this method even before initialisation (you can't with some other methods)
|
||||||
@ -207,9 +213,17 @@ public:
|
|||||||
static void unlockPreferredAccount() ;
|
static void unlockPreferredAccount() ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static RsAccountsDetail *rsAccounts ;
|
static RsAccountsDetail* rsAccountsDetails;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pointer to global instance of RsAccounts needed to expose JSON API, as all
|
||||||
|
* the members of this class are static you should call them directly without
|
||||||
|
* using this pointer in the other parts of the code
|
||||||
|
* @jsonapi{development}
|
||||||
|
*/
|
||||||
|
extern RsAccounts* rsAccounts;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This helper class have been implemented because there was not reasonable way
|
* This helper class have been implemented because there was not reasonable way
|
||||||
@ -263,6 +277,14 @@ struct RsLoginHelper
|
|||||||
const std::string& password, bool makeHidden,
|
const std::string& password, bool makeHidden,
|
||||||
bool makeAutoTor, std::string& errorMessage );
|
bool makeAutoTor, std::string& errorMessage );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if RetroShare is already logged in, this usually return true
|
||||||
|
* after a successfull attemptLogin() and before closeSession()
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @return true if already logged in, false otherwise
|
||||||
|
*/
|
||||||
|
bool isLoggedIn();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Close RetroShare session
|
* @brief Close RetroShare session
|
||||||
* @jsonapi{development}
|
* @jsonapi{development}
|
||||||
|
@ -19,25 +19,25 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
#ifndef RETROSHARE_PEER_GUI_INTERFACE_H
|
#pragma once
|
||||||
#define RETROSHARE_PEER_GUI_INTERFACE_H
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#include <retroshare/rstypes.h>
|
#include "retroshare/rstypes.h"
|
||||||
#include <retroshare/rsfiles.h>
|
#include "retroshare/rsfiles.h"
|
||||||
#include <retroshare/rsids.h>
|
#include "retroshare/rsids.h"
|
||||||
#include "util/rsurl.h"
|
#include "util/rsurl.h"
|
||||||
|
#include "util/rsdeprecate.h"
|
||||||
|
|
||||||
/* The Main Interface Class - for information about your Peers
|
|
||||||
* A peer is another RS instance, means associated with an SSL certificate
|
|
||||||
* A same GPG person can have multiple peer running with different SSL certs signed by the same GPG key
|
|
||||||
* Thus a peer have SSL cert details, and also the parent GPG details
|
|
||||||
*/
|
|
||||||
class RsPeers;
|
class RsPeers;
|
||||||
extern RsPeers *rsPeers;
|
|
||||||
|
/**
|
||||||
|
* Pointer to global instance of RsPeers service implementation
|
||||||
|
* @jsonapi{development}
|
||||||
|
*/
|
||||||
|
extern RsPeers* rsPeers;
|
||||||
|
|
||||||
/* TODO: 2015/12/31 As for type safetyness all those constant must be declared as enum!
|
/* TODO: 2015/12/31 As for type safetyness all those constant must be declared as enum!
|
||||||
* C++ now supports typed enum so there is no ambiguity in serialization size
|
* C++ now supports typed enum so there is no ambiguity in serialization size
|
||||||
@ -203,11 +203,8 @@ std::string RsPeerNetModeString(uint32_t netModel);
|
|||||||
std::string RsPeerLastConnectString(uint32_t lastConnect);
|
std::string RsPeerLastConnectString(uint32_t lastConnect);
|
||||||
|
|
||||||
|
|
||||||
/* Details class */
|
struct RsPeerDetails : RsSerializable
|
||||||
class RsPeerDetails
|
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
|
|
||||||
RsPeerDetails();
|
RsPeerDetails();
|
||||||
|
|
||||||
/* Auth details */
|
/* Auth details */
|
||||||
@ -279,13 +276,61 @@ class RsPeerDetails
|
|||||||
|
|
||||||
/* linkType */
|
/* linkType */
|
||||||
uint32_t linkType;
|
uint32_t linkType;
|
||||||
|
|
||||||
|
/// @see RsSerializable
|
||||||
|
virtual void serial_process( RsGenericSerializer::SerializeJob j,
|
||||||
|
RsGenericSerializer::SerializeContext& ctx )
|
||||||
|
{
|
||||||
|
RS_SERIAL_PROCESS(isOnlyGPGdetail);
|
||||||
|
RS_SERIAL_PROCESS(id);
|
||||||
|
RS_SERIAL_PROCESS(gpg_id);
|
||||||
|
RS_SERIAL_PROCESS(name);
|
||||||
|
RS_SERIAL_PROCESS(email);
|
||||||
|
RS_SERIAL_PROCESS(location);
|
||||||
|
RS_SERIAL_PROCESS(org);
|
||||||
|
RS_SERIAL_PROCESS(issuer);
|
||||||
|
RS_SERIAL_PROCESS(fpr);
|
||||||
|
RS_SERIAL_PROCESS(authcode);
|
||||||
|
RS_SERIAL_PROCESS(gpgSigners);
|
||||||
|
RS_SERIAL_PROCESS(trustLvl);
|
||||||
|
RS_SERIAL_PROCESS(validLvl);
|
||||||
|
RS_SERIAL_PROCESS(ownsign);
|
||||||
|
RS_SERIAL_PROCESS(hasSignedMe);
|
||||||
|
RS_SERIAL_PROCESS(accept_connection);
|
||||||
|
RS_SERIAL_PROCESS(service_perm_flags);
|
||||||
|
RS_SERIAL_PROCESS(state);
|
||||||
|
RS_SERIAL_PROCESS(actAsServer);
|
||||||
|
RS_SERIAL_PROCESS(connectAddr);
|
||||||
|
RS_SERIAL_PROCESS(connectPort);
|
||||||
|
RS_SERIAL_PROCESS(isHiddenNode);
|
||||||
|
RS_SERIAL_PROCESS(hiddenNodeAddress);
|
||||||
|
RS_SERIAL_PROCESS(hiddenNodePort);
|
||||||
|
RS_SERIAL_PROCESS(hiddenType);
|
||||||
|
RS_SERIAL_PROCESS(localAddr);
|
||||||
|
RS_SERIAL_PROCESS(localPort);
|
||||||
|
RS_SERIAL_PROCESS(extAddr);
|
||||||
|
RS_SERIAL_PROCESS(extPort);
|
||||||
|
RS_SERIAL_PROCESS(dyndns);
|
||||||
|
RS_SERIAL_PROCESS(ipAddressList);
|
||||||
|
RS_SERIAL_PROCESS(netMode);
|
||||||
|
RS_SERIAL_PROCESS(vs_disc);
|
||||||
|
RS_SERIAL_PROCESS(vs_dht);
|
||||||
|
RS_SERIAL_PROCESS(lastConnect);
|
||||||
|
RS_SERIAL_PROCESS(lastUsed);
|
||||||
|
RS_SERIAL_PROCESS(connectState);
|
||||||
|
RS_SERIAL_PROCESS(connectStateString);
|
||||||
|
RS_SERIAL_PROCESS(connectPeriod);
|
||||||
|
RS_SERIAL_PROCESS(foundDHT);
|
||||||
|
RS_SERIAL_PROCESS(wasDeniedConnection);
|
||||||
|
RS_SERIAL_PROCESS(deniedTS);
|
||||||
|
RS_SERIAL_PROCESS(linkType);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class is used to get info about crytographic algorithms used with a
|
// This class is used to get info about crytographic algorithms used with a
|
||||||
// particular peer.
|
// particular peer.
|
||||||
class RsPeerCryptoParams
|
struct RsPeerCryptoParams
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
int connexion_state;
|
int connexion_state;
|
||||||
std::string cipher_name;
|
std::string cipher_name;
|
||||||
int cipher_bits_1;
|
int cipher_bits_1;
|
||||||
@ -293,9 +338,8 @@ public:
|
|||||||
std::string cipher_version;
|
std::string cipher_version;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsGroupInfo : RsSerializable
|
struct RsGroupInfo : RsSerializable
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
RsGroupInfo();
|
RsGroupInfo();
|
||||||
|
|
||||||
RsNodeGroupId id;
|
RsNodeGroupId id;
|
||||||
@ -304,9 +348,11 @@ public:
|
|||||||
|
|
||||||
std::set<RsPgpId> peerIds;
|
std::set<RsPgpId> peerIds;
|
||||||
|
|
||||||
// RsSerializable interface
|
/// @see RsSerializable
|
||||||
public:
|
void serial_process(
|
||||||
void serial_process(RsGenericSerializer::SerializeJob j, RsGenericSerializer::SerializeContext &ctx) {
|
RsGenericSerializer::SerializeJob j,
|
||||||
|
RsGenericSerializer::SerializeContext &ctx)
|
||||||
|
{
|
||||||
RS_SERIAL_PROCESS(id);
|
RS_SERIAL_PROCESS(id);
|
||||||
RS_SERIAL_PROCESS(name);
|
RS_SERIAL_PROCESS(name);
|
||||||
RS_SERIAL_PROCESS(flag);
|
RS_SERIAL_PROCESS(flag);
|
||||||
@ -316,8 +362,11 @@ public:
|
|||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);
|
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);
|
||||||
|
|
||||||
/* TODO: 2015/12/31 this class seems foundamental for RetroShare code
|
/** The Main Interface Class - for information about your Peers
|
||||||
* understanding must document it as soon as possible
|
* A peer is another RS instance, means associated with an SSL certificate
|
||||||
|
* A same GPG person can have multiple peer running with different SSL certs
|
||||||
|
* signed by the same GPG key
|
||||||
|
* Thus a peer have SSL cert details, and also the parent GPG details
|
||||||
*/
|
*/
|
||||||
class RsPeers
|
class RsPeers
|
||||||
{
|
{
|
||||||
@ -326,32 +375,86 @@ public:
|
|||||||
RsPeers() {}
|
RsPeers() {}
|
||||||
virtual ~RsPeers() {}
|
virtual ~RsPeers() {}
|
||||||
|
|
||||||
// TODO: 2015/12/31 is this dead code?
|
/**
|
||||||
/* Updates ... */
|
* @brief Get own SSL peer id
|
||||||
// not implemented
|
* @return own peer id
|
||||||
//virtual bool FriendsChanged() = 0;
|
*/
|
||||||
//virtual bool OthersChanged() = 0;
|
|
||||||
|
|
||||||
/* Peer Details (Net & Auth) */
|
|
||||||
virtual const RsPeerId& getOwnId() = 0;
|
virtual const RsPeerId& getOwnId() = 0;
|
||||||
|
|
||||||
virtual bool haveSecretKey(const RsPgpId& gpg_id) = 0 ;
|
virtual bool haveSecretKey(const RsPgpId& gpg_id) = 0 ;
|
||||||
|
|
||||||
virtual bool getOnlineList(std::list<RsPeerId> &ssl_ids) = 0;
|
/**
|
||||||
virtual bool getFriendList(std::list<RsPeerId> &ssl_ids) = 0;
|
* @brief Get trusted peers list
|
||||||
virtual bool getPeerCount (unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0;
|
* @jsonapi{development}
|
||||||
|
* @param[out] sslIds storage for the trusted peers
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool getFriendList(std::list<RsPeerId>& sslIds) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get connected peers list
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[out] sslIds storage for the peers
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool getOnlineList(std::list<RsPeerId> &sslIds) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get peers count
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[out] peersCount storage for trusted peers count
|
||||||
|
* @param[out] onlinePeersCount storage for online peers count
|
||||||
|
* @param[in] countLocations true to count multiple locations of same owner
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool getPeersCount(
|
||||||
|
uint32_t& peersCount, uint32_t& onlinePeersCount,
|
||||||
|
bool countLocations = true ) = 0;
|
||||||
|
|
||||||
|
RS_DEPRECATED
|
||||||
|
virtual bool getPeerCount(unsigned int *pnFriendCount, unsigned int *pnnOnlineCount, bool ssl) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if there is an established connection to the given peer
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] sslId id of the peer to check
|
||||||
|
* @return true if the connection is establisced, false otherwise
|
||||||
|
*/
|
||||||
|
virtual bool isOnline(const RsPeerId &sslId) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if given peer is a trusted node
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] sslId id of the peer to check
|
||||||
|
* @return true if the node is trusted, false otherwise
|
||||||
|
*/
|
||||||
|
virtual bool isFriend(const RsPeerId &sslId) = 0;
|
||||||
|
|
||||||
virtual bool isOnline(const RsPeerId &ssl_id) = 0;
|
|
||||||
virtual bool isFriend(const RsPeerId &ssl_id) = 0;
|
|
||||||
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend) = 0;
|
virtual bool isGPGAccepted(const RsPgpId &gpg_id_is_friend) = 0;
|
||||||
virtual std::string getPeerName(const RsPeerId &ssl_id) = 0;
|
virtual std::string getPeerName(const RsPeerId &ssl_id) = 0;
|
||||||
virtual std::string getGPGName(const RsPgpId& gpg_id) = 0;
|
virtual std::string getGPGName(const RsPgpId& gpg_id) = 0;
|
||||||
virtual bool getPeerDetails(const RsPeerId& ssl_id, RsPeerDetails &d) = 0;
|
|
||||||
|
/**
|
||||||
|
* @brief Get details details of the given peer
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] sslId id of the peer
|
||||||
|
* @param[out] det storage for the details of the peer
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool getPeerDetails(const RsPeerId& sslId, RsPeerDetails& det) = 0;
|
||||||
|
|
||||||
virtual bool getGPGDetails(const RsPgpId& gpg_id, RsPeerDetails &d) = 0;
|
virtual bool getGPGDetails(const RsPgpId& gpg_id, RsPeerDetails &d) = 0;
|
||||||
|
|
||||||
/* Using PGP Ids */
|
/* Using PGP Ids */
|
||||||
virtual const RsPgpId& getGPGOwnId() = 0;
|
virtual const RsPgpId& getGPGOwnId() = 0;
|
||||||
virtual RsPgpId getGPGId(const RsPeerId& sslid) = 0; //return the gpg id of the given ssl id
|
|
||||||
|
/**
|
||||||
|
* @brief Get PGP id for the given peer
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] sslId SSL id of the peer
|
||||||
|
* @return PGP id of the peer
|
||||||
|
*/
|
||||||
|
virtual RsPgpId getGPGId(const RsPeerId& sslId) = 0;
|
||||||
virtual bool isKeySupported(const RsPgpId& gpg_ids) = 0;
|
virtual bool isKeySupported(const RsPgpId& gpg_ids) = 0;
|
||||||
virtual bool getGPGAcceptedList(std::list<RsPgpId> &gpg_ids) = 0;
|
virtual bool getGPGAcceptedList(std::list<RsPgpId> &gpg_ids) = 0;
|
||||||
virtual bool getGPGSignedList(std::list<RsPgpId> &gpg_ids) = 0;//friends that we accpet to connect with but we don't want to sign their gpg key
|
virtual bool getGPGSignedList(std::list<RsPgpId> &gpg_ids) = 0;//friends that we accpet to connect with but we don't want to sign their gpg key
|
||||||
@ -360,16 +463,49 @@ public:
|
|||||||
virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list<RsPeerId>& ids) = 0;
|
virtual bool getAssociatedSSLIds(const RsPgpId& gpg_id, std::list<RsPeerId>& ids) = 0;
|
||||||
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") = 0;
|
virtual bool gpgSignData(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen, std::string reason = "") = 0;
|
||||||
|
|
||||||
/* Add/Remove Friends */
|
/**
|
||||||
virtual bool addFriend(const RsPeerId &ssl_id, const RsPgpId &gpg_id,ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT) = 0;
|
* @brief Add trusted node
|
||||||
virtual bool removeFriend(const RsPgpId& pgp_id) = 0;
|
* @jsonapi{development}
|
||||||
|
* @param[in] sslId SSL id of the node to add
|
||||||
|
* @param[in] gpgId PGP id of the node to add
|
||||||
|
* @param[in] flags service permissions flag
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool addFriend( const RsPeerId &sslId, const RsPgpId& gpgId,
|
||||||
|
ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Revoke connection trust from to node
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] pgpId PGP id of the node
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool removeFriend(const RsPgpId& pgpId) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove location of a trusted node, useful to prune old unused
|
||||||
|
* locations of a trusted peer without revoking trust
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] sslId SSL id of the location to remove
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
virtual bool removeFriendLocation(const RsPeerId& sslId) = 0;
|
virtual bool removeFriendLocation(const RsPeerId& sslId) = 0;
|
||||||
|
|
||||||
/* keyring management */
|
/* keyring management */
|
||||||
virtual bool removeKeysFromPGPKeyring(const std::set<RsPgpId>& pgp_ids,std::string& backup_file,uint32_t& error_code) = 0;
|
virtual bool removeKeysFromPGPKeyring(
|
||||||
|
const std::set<RsPgpId>& pgpIds, std::string& backupFile,
|
||||||
|
uint32_t& errorCode ) = 0;
|
||||||
|
|
||||||
/* Network Stuff */
|
/* Network Stuff */
|
||||||
virtual bool connectAttempt(const RsPeerId& ssl_id) = 0;
|
|
||||||
|
/**
|
||||||
|
* @brief Trigger connection attempt to given node
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] sslId SSL id of the node to connect
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool connectAttempt(const RsPeerId& sslId) = 0;
|
||||||
|
|
||||||
virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location) = 0; // location is shown in the gui to differentiate ssl certs
|
virtual bool setLocation(const RsPeerId &ssl_id, const std::string &location) = 0; // location is shown in the gui to differentiate ssl certs
|
||||||
|
|
||||||
virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address) = 0;
|
virtual bool setHiddenNode(const RsPeerId &id, const std::string &hidden_node_address) = 0;
|
||||||
@ -393,6 +529,7 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get RetroShare invite of the given peer
|
* @brief Get RetroShare invite of the given peer
|
||||||
|
* @jsonapi{development}
|
||||||
* @param[in] sslId Id of the peer of which we want to generate an invite
|
* @param[in] sslId Id of the peer of which we want to generate an invite
|
||||||
* @param[in] includeSignatures true to add key signatures to the invite
|
* @param[in] includeSignatures true to add key signatures to the invite
|
||||||
* @param[in] includeExtraLocators false to avoid to add extra locators
|
* @param[in] includeExtraLocators false to avoid to add extra locators
|
||||||
@ -402,6 +539,17 @@ public:
|
|||||||
const RsPeerId& sslId, bool includeSignatures = false,
|
const RsPeerId& sslId, bool includeSignatures = false,
|
||||||
bool includeExtraLocators = true ) = 0;
|
bool includeExtraLocators = true ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add trusted node from invite
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] invite invite string being it in cert or URL format
|
||||||
|
* @param[in] flags service permissions flag
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool acceptInvite(
|
||||||
|
const std::string& invite,
|
||||||
|
ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT ) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get RetroShare invite of our own peer
|
* @brief Get RetroShare invite of our own peer
|
||||||
* @param[in] includeSignatures true to add key signatures to the invite
|
* @param[in] includeSignatures true to add key signatures to the invite
|
||||||
@ -417,11 +565,31 @@ public:
|
|||||||
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0;
|
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum) = 0;
|
||||||
virtual bool hasExportMinimal() = 0;
|
virtual bool hasExportMinimal() = 0;
|
||||||
|
|
||||||
// Add keys to the keyring
|
/**
|
||||||
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string) = 0;
|
* @brief Import certificate into the keyring
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] cert string representation of the certificate
|
||||||
|
* @param[out] sslId storage for the SSL id of the certificate
|
||||||
|
* @param[out] pgpId storage for the PGP id of the certificate
|
||||||
|
* @param[out] errorString storage for the possible error string
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool loadCertificateFromString(
|
||||||
|
const std::string& cert, RsPeerId& sslId, RsPgpId& pgpId,
|
||||||
|
std::string& errorString) = 0;
|
||||||
|
|
||||||
// Gets the GPG details, but does not add the key to the keyring.
|
/**
|
||||||
virtual bool loadDetailsFromStringCert(const std::string& certGPG, RsPeerDetails &pd,uint32_t& error_code) = 0;
|
* @brief Examine certificate and get details without importing into
|
||||||
|
* the keyring
|
||||||
|
* @jsonapi{development}
|
||||||
|
* @param[in] cert string representation of the certificate
|
||||||
|
* @param[out] certDetails storage for the certificate details
|
||||||
|
* @param[out] errorCode storage for possible error number
|
||||||
|
* @return false if error occurred, true otherwise
|
||||||
|
*/
|
||||||
|
virtual bool loadDetailsFromStringCert(
|
||||||
|
const std::string& cert, RsPeerDetails& certDetails,
|
||||||
|
uint32_t& errorCode ) = 0;
|
||||||
|
|
||||||
// Certificate utils
|
// Certificate utils
|
||||||
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) = 0;
|
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert,int& error_code) = 0;
|
||||||
@ -468,4 +636,5 @@ public:
|
|||||||
virtual bool getPeerMaximumRates(const RsPgpId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate) =0;
|
virtual bool getPeerMaximumRates(const RsPgpId& pid,uint32_t& maxUploadRate,uint32_t& maxDownloadRate) =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ void RsServer::startServiceThread(RsTickingThread *t, const std::string &threadN
|
|||||||
|
|
||||||
void RsServer::rsGlobalShutDown()
|
void RsServer::rsGlobalShutDown()
|
||||||
{
|
{
|
||||||
|
coreReady = false;
|
||||||
// TODO: cache should also clean up old files
|
// TODO: cache should also clean up old files
|
||||||
|
|
||||||
ConfigFinalSave(); // save configuration before exit
|
ConfigFinalSave(); // save configuration before exit
|
||||||
|
@ -79,8 +79,8 @@ const double RsServer::maxTimeDelta = 0.2;
|
|||||||
const double RsServer::kickLimit = 0.15;
|
const double RsServer::kickLimit = 0.15;
|
||||||
|
|
||||||
|
|
||||||
RsServer::RsServer()
|
RsServer::RsServer() :
|
||||||
: coreMutex("RsServer")
|
coreMutex("RsServer"), coreReady(false)
|
||||||
{
|
{
|
||||||
// This is needed asap.
|
// This is needed asap.
|
||||||
//
|
//
|
||||||
|
@ -82,6 +82,9 @@ class RsServer: public RsControl, public RsTickingThread
|
|||||||
/****************************************/
|
/****************************************/
|
||||||
/* p3face.cc: main loop / util fns / locking. */
|
/* p3face.cc: main loop / util fns / locking. */
|
||||||
|
|
||||||
|
/// @see RsControl::isReady()
|
||||||
|
virtual bool isReady() { return coreReady; }
|
||||||
|
|
||||||
RsServer() ;
|
RsServer() ;
|
||||||
virtual ~RsServer();
|
virtual ~RsServer();
|
||||||
|
|
||||||
@ -126,7 +129,7 @@ class RsServer: public RsControl, public RsTickingThread
|
|||||||
* This function is responsible for ensuring Retroshare exits in a legal state:
|
* This function is responsible for ensuring Retroshare exits in a legal state:
|
||||||
* i.e. releases all held resources and saves current configuration
|
* i.e. releases all held resources and saves current configuration
|
||||||
*/
|
*/
|
||||||
virtual void rsGlobalShutDown( );
|
virtual void rsGlobalShutDown();
|
||||||
|
|
||||||
/****************************************/
|
/****************************************/
|
||||||
|
|
||||||
@ -198,6 +201,11 @@ class RsServer: public RsControl, public RsTickingThread
|
|||||||
static const double minTimeDelta; // 25;
|
static const double minTimeDelta; // 25;
|
||||||
static const double maxTimeDelta;
|
static const double maxTimeDelta;
|
||||||
static const double kickLimit;
|
static const double kickLimit;
|
||||||
|
|
||||||
|
/** Keep track of the core being fully ready, true only after
|
||||||
|
* StartupRetroShare() finish and before rsGlobalShutDown() begin
|
||||||
|
*/
|
||||||
|
bool coreReady;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Helper function to convert windows paths
|
/* Helper function to convert windows paths
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "pqi/authgpg.h"
|
#include "pqi/authgpg.h"
|
||||||
#include "retroshare/rsinit.h"
|
#include "retroshare/rsinit.h"
|
||||||
#include "retroshare/rsfiles.h"
|
#include "retroshare/rsfiles.h"
|
||||||
|
#include "util/rsurl.h"
|
||||||
|
|
||||||
#include "pgp/rscertificate.h"
|
#include "pgp/rscertificate.h"
|
||||||
|
|
||||||
@ -200,6 +201,15 @@ bool p3Peers::getFriendList(std::list<RsPeerId> &ids)
|
|||||||
// return true;
|
// return true;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
bool p3Peers::getPeersCount(
|
||||||
|
uint32_t& peersCount, uint32_t& onlinePeersCount,
|
||||||
|
bool countLocations )
|
||||||
|
{
|
||||||
|
peersCount = mPeerMgr->getFriendCount(countLocations, false);
|
||||||
|
onlinePeersCount = mPeerMgr->getFriendCount(countLocations, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool p3Peers::getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl)
|
bool p3Peers::getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl)
|
||||||
{
|
{
|
||||||
#ifdef P3PEERS_DEBUG
|
#ifdef P3PEERS_DEBUG
|
||||||
@ -1099,6 +1109,72 @@ bool p3Peers::GetPGPBase64StringAndCheckSum( const RsPgpId& gpg_id,
|
|||||||
return true ;
|
return true ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool p3Peers::acceptInvite( const std::string& invite,
|
||||||
|
ServicePermissionFlags flags )
|
||||||
|
{
|
||||||
|
if(invite.empty()) return false;
|
||||||
|
|
||||||
|
const std::string* radixPtr(&invite);
|
||||||
|
|
||||||
|
RsUrl url(invite);
|
||||||
|
std::map<std::string, std::string> query(url.query());
|
||||||
|
|
||||||
|
if(query.find("radix") != query.end())
|
||||||
|
radixPtr = &query["radix"];
|
||||||
|
|
||||||
|
const std::string& radix(*radixPtr);
|
||||||
|
if(radix.empty()) return false;
|
||||||
|
|
||||||
|
RsPgpId pgpId;
|
||||||
|
RsPeerId sslId;
|
||||||
|
std::string errorString;
|
||||||
|
|
||||||
|
if(!loadCertificateFromString(radix, sslId, pgpId, errorString))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
RsPeerDetails peerDetails;
|
||||||
|
uint32_t errorCode;
|
||||||
|
|
||||||
|
if(!loadDetailsFromStringCert(radix, peerDetails, errorCode))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(peerDetails.gpg_id.isNull())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
addFriend(peerDetails.id, peerDetails.gpg_id, flags);
|
||||||
|
|
||||||
|
if (!peerDetails.location.empty())
|
||||||
|
setLocation(peerDetails.id, peerDetails.location);
|
||||||
|
|
||||||
|
// Update new address even the peer already existed.
|
||||||
|
if (peerDetails.isHiddenNode)
|
||||||
|
{
|
||||||
|
setHiddenNode( peerDetails.id,
|
||||||
|
peerDetails.hiddenNodeAddress,
|
||||||
|
peerDetails.hiddenNodePort );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//let's check if there is ip adresses in the certificate.
|
||||||
|
if (!peerDetails.extAddr.empty() && peerDetails.extPort)
|
||||||
|
setExtAddress( peerDetails.id,
|
||||||
|
peerDetails.extAddr,
|
||||||
|
peerDetails.extPort );
|
||||||
|
if (!peerDetails.localAddr.empty() && peerDetails.localPort)
|
||||||
|
setLocalAddress( peerDetails.id,
|
||||||
|
peerDetails.localAddr,
|
||||||
|
peerDetails.localPort );
|
||||||
|
if (!peerDetails.dyndns.empty())
|
||||||
|
setDynDNS(peerDetails.id, peerDetails.dyndns);
|
||||||
|
for(auto&& ipr : peerDetails.ipAddressList)
|
||||||
|
addPeerLocator(
|
||||||
|
peerDetails.id,
|
||||||
|
RsUrl(ipr.substr(0, ipr.find(' '))) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::string p3Peers::GetRetroshareInvite(
|
std::string p3Peers::GetRetroshareInvite(
|
||||||
const RsPeerId& ssl_id, bool include_signatures,
|
const RsPeerId& ssl_id, bool include_signatures,
|
||||||
bool includeExtraLocators )
|
bool includeExtraLocators )
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "retroshare/rspeers.h"
|
#include "retroshare/rspeers.h"
|
||||||
#include "util/rsurl.h"
|
#include "util/rsurl.h"
|
||||||
|
#include "util/rsdeprecate.h"
|
||||||
|
|
||||||
class p3LinkMgr;
|
class p3LinkMgr;
|
||||||
class p3PeerMgr;
|
class p3PeerMgr;
|
||||||
@ -56,6 +57,11 @@ public:
|
|||||||
|
|
||||||
virtual bool getOnlineList(std::list<RsPeerId> &ids);
|
virtual bool getOnlineList(std::list<RsPeerId> &ids);
|
||||||
virtual bool getFriendList(std::list<RsPeerId> &ids);
|
virtual bool getFriendList(std::list<RsPeerId> &ids);
|
||||||
|
virtual bool getPeersCount(
|
||||||
|
uint32_t& peersCount, uint32_t& onlinePeersCount,
|
||||||
|
bool countLocations );
|
||||||
|
|
||||||
|
RS_DEPRECATED
|
||||||
virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl);
|
virtual bool getPeerCount (unsigned int *friendCount, unsigned int *onlineCount, bool ssl);
|
||||||
|
|
||||||
virtual bool isOnline(const RsPeerId &id);
|
virtual bool isOnline(const RsPeerId &id);
|
||||||
@ -121,6 +127,11 @@ public:
|
|||||||
bool includeExtraLocators = true );
|
bool includeExtraLocators = true );
|
||||||
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum);
|
virtual bool GetPGPBase64StringAndCheckSum(const RsPgpId& gpg_id,std::string& gpg_base64_string,std::string& gpg_base64_checksum);
|
||||||
|
|
||||||
|
/// @see RsPeers::acceptInvite
|
||||||
|
virtual bool acceptInvite(
|
||||||
|
const std::string& invite,
|
||||||
|
ServicePermissionFlags flags = RS_NODE_PERM_DEFAULT );
|
||||||
|
|
||||||
virtual bool hasExportMinimal();
|
virtual bool hasExportMinimal();
|
||||||
|
|
||||||
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string);
|
virtual bool loadCertificateFromString(const std::string& cert, RsPeerId& ssl_id,RsPgpId& pgp_id, std::string& error_string);
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
// Global singleton declaration of data.
|
// Global singleton declaration of data.
|
||||||
RsAccountsDetail *RsAccounts::rsAccounts;
|
RsAccountsDetail* RsAccounts::rsAccountsDetails = nullptr;
|
||||||
|
|
||||||
/* Uses private class - so must be hidden */
|
/* Uses private class - so must be hidden */
|
||||||
static bool checkAccount(const std::string &accountdir, AccountDetails &account,std::map<std::string,std::vector<std::string> >& unsupported_keys);
|
static bool checkAccount(const std::string &accountdir, AccountDetails &account,std::map<std::string,std::vector<std::string> >& unsupported_keys);
|
||||||
@ -1267,17 +1267,18 @@ bool RsInit::LoadPassword(const std::string& id, const std::string& inPwd)
|
|||||||
|
|
||||||
bool RsAccounts::init(const std::string& opt_base_dir,int& error_code)
|
bool RsAccounts::init(const std::string& opt_base_dir,int& error_code)
|
||||||
{
|
{
|
||||||
rsAccounts = new RsAccountsDetail ;
|
rsAccountsDetails = new RsAccountsDetail;
|
||||||
|
rsAccounts = new RsAccounts;
|
||||||
|
|
||||||
// first check config directories, and set bootstrap values.
|
// first check config directories, and set bootstrap values.
|
||||||
if(!rsAccounts->setupBaseDirectory(opt_base_dir))
|
if(!rsAccountsDetails->setupBaseDirectory(opt_base_dir))
|
||||||
{
|
{
|
||||||
error_code = RS_INIT_BASE_DIR_ERROR ;
|
error_code = RS_INIT_BASE_DIR_ERROR ;
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup PGP stuff.
|
// Setup PGP stuff.
|
||||||
std::string pgp_dir = rsAccounts->PathPGPDirectory();
|
std::string pgp_dir = rsAccountsDetails->PathPGPDirectory();
|
||||||
|
|
||||||
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
||||||
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
|
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
|
||||||
@ -1288,7 +1289,7 @@ bool RsAccounts::init(const std::string& opt_base_dir,int& error_code)
|
|||||||
pgp_dir + "/lock");
|
pgp_dir + "/lock");
|
||||||
|
|
||||||
// load Accounts.
|
// load Accounts.
|
||||||
if (!rsAccounts->loadAccounts())
|
if (!rsAccountsDetails->loadAccounts())
|
||||||
{
|
{
|
||||||
error_code = RS_INIT_NO_KEYRING ;
|
error_code = RS_INIT_NO_KEYRING ;
|
||||||
return false ;
|
return false ;
|
||||||
@ -1299,75 +1300,75 @@ bool RsAccounts::init(const std::string& opt_base_dir,int& error_code)
|
|||||||
// Directories.
|
// Directories.
|
||||||
std::string RsAccounts::ConfigDirectory() { return RsAccountsDetail::PathBaseDirectory(); }
|
std::string RsAccounts::ConfigDirectory() { return RsAccountsDetail::PathBaseDirectory(); }
|
||||||
std::string RsAccounts::systemDataDirectory(bool check) { return RsAccountsDetail::PathDataDirectory(check); }
|
std::string RsAccounts::systemDataDirectory(bool check) { return RsAccountsDetail::PathDataDirectory(check); }
|
||||||
std::string RsAccounts::PGPDirectory() { return rsAccounts->PathPGPDirectory(); }
|
std::string RsAccounts::PGPDirectory() { return rsAccountsDetails->PathPGPDirectory(); }
|
||||||
std::string RsAccounts::AccountDirectory() { return rsAccounts->getCurrentAccountPathAccountDirectory(); }
|
std::string RsAccounts::AccountDirectory() { return rsAccountsDetails->getCurrentAccountPathAccountDirectory(); }
|
||||||
std::string RsAccounts::AccountKeysDirectory() { return rsAccounts->getCurrentAccountPathAccountKeysDirectory(); }
|
std::string RsAccounts::AccountKeysDirectory() { return rsAccountsDetails->getCurrentAccountPathAccountKeysDirectory(); }
|
||||||
std::string RsAccounts::AccountPathCertFile() { return rsAccounts->getCurrentAccountPathCertFile(); }
|
std::string RsAccounts::AccountPathCertFile() { return rsAccountsDetails->getCurrentAccountPathCertFile(); }
|
||||||
std::string RsAccounts::AccountPathKeyFile() { return rsAccounts->getCurrentAccountPathKeyFile(); }
|
std::string RsAccounts::AccountPathKeyFile() { return rsAccountsDetails->getCurrentAccountPathKeyFile(); }
|
||||||
std::string RsAccounts::AccountLocationName() { return rsAccounts->getCurrentAccountLocationName(); }
|
std::string RsAccounts::AccountLocationName() { return rsAccountsDetails->getCurrentAccountLocationName(); }
|
||||||
|
|
||||||
bool RsAccounts::lockPreferredAccount() { return rsAccounts->lockPreferredAccount();} // are these methods any useful??
|
bool RsAccounts::lockPreferredAccount() { return rsAccountsDetails->lockPreferredAccount();} // are these methods any useful??
|
||||||
void RsAccounts::unlockPreferredAccount() { rsAccounts->unlockPreferredAccount(); }
|
void RsAccounts::unlockPreferredAccount() { rsAccountsDetails->unlockPreferredAccount(); }
|
||||||
|
|
||||||
bool RsAccounts::checkCreateAccountDirectory() { return rsAccounts->checkAccountDirectory(); }
|
bool RsAccounts::checkCreateAccountDirectory() { return rsAccountsDetails->checkAccountDirectory(); }
|
||||||
|
|
||||||
// PGP Accounts.
|
// PGP Accounts.
|
||||||
int RsAccounts::GetPGPLogins(std::list<RsPgpId> &pgpIds)
|
int RsAccounts::GetPGPLogins(std::list<RsPgpId> &pgpIds)
|
||||||
{
|
{
|
||||||
return rsAccounts->GetPGPLogins(pgpIds);
|
return rsAccountsDetails->GetPGPLogins(pgpIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
int RsAccounts::GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email)
|
int RsAccounts::GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email)
|
||||||
{
|
{
|
||||||
return rsAccounts->GetPGPLoginDetails(id, name, email);
|
return rsAccountsDetails->GetPGPLoginDetails(id, name, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsAccounts::GeneratePGPCertificate(const std::string &name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString)
|
bool RsAccounts::GeneratePGPCertificate(const std::string &name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString)
|
||||||
{
|
{
|
||||||
return rsAccounts->GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString);
|
return rsAccountsDetails->GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PGP Support Functions.
|
// PGP Support Functions.
|
||||||
bool RsAccounts::ExportIdentity(const std::string& fname,const RsPgpId& pgp_id)
|
bool RsAccounts::ExportIdentity(const std::string& fname,const RsPgpId& pgp_id)
|
||||||
{
|
{
|
||||||
return rsAccounts->exportIdentity(fname,pgp_id);
|
return rsAccountsDetails->exportIdentity(fname,pgp_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsAccounts::ImportIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error)
|
bool RsAccounts::ImportIdentity(const std::string& fname,RsPgpId& imported_pgp_id,std::string& import_error)
|
||||||
{
|
{
|
||||||
return rsAccounts->importIdentity(fname,imported_pgp_id,import_error);
|
return rsAccountsDetails->importIdentity(fname,imported_pgp_id,import_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsAccounts::ImportIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error)
|
bool RsAccounts::ImportIdentityFromString(const std::string& data,RsPgpId& imported_pgp_id,std::string& import_error)
|
||||||
{
|
{
|
||||||
return rsAccounts->importIdentityFromString(data,imported_pgp_id,import_error);
|
return rsAccountsDetails->importIdentityFromString(data,imported_pgp_id,import_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsAccounts::GetUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys)
|
void RsAccounts::GetUnsupportedKeys(std::map<std::string,std::vector<std::string> > &unsupported_keys)
|
||||||
{
|
{
|
||||||
return rsAccounts->getUnsupportedKeys(unsupported_keys);
|
return rsAccountsDetails->getUnsupportedKeys(unsupported_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsAccounts::CopyGnuPGKeyrings()
|
bool RsAccounts::CopyGnuPGKeyrings()
|
||||||
{
|
{
|
||||||
return rsAccounts->copyGnuPGKeyrings();
|
return rsAccountsDetails->copyGnuPGKeyrings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsAccounts::storeSelectedAccount() { rsAccounts->storePreferredAccount() ;}
|
void RsAccounts::storeSelectedAccount() { rsAccountsDetails->storePreferredAccount() ;}
|
||||||
// Rs Accounts
|
// Rs Accounts
|
||||||
bool RsAccounts::SelectAccount(const RsPeerId &id)
|
bool RsAccounts::SelectAccount(const RsPeerId &id)
|
||||||
{
|
{
|
||||||
return rsAccounts->selectId(id);
|
return rsAccountsDetails->selectId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsAccounts::GetPreferredAccountId(RsPeerId &id)
|
bool RsAccounts::GetPreferredAccountId(RsPeerId &id)
|
||||||
{
|
{
|
||||||
return rsAccounts->getCurrentAccountId(id);
|
return rsAccountsDetails->getCurrentAccountId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsAccounts::getCurrentAccountOptions(bool& is_hidden,bool& is_tor_auto,bool& is_first_time)
|
bool RsAccounts::getCurrentAccountOptions(bool& is_hidden,bool& is_tor_auto,bool& is_first_time)
|
||||||
{
|
{
|
||||||
return rsAccounts->getCurrentAccountOptions(is_hidden,is_tor_auto,is_first_time);
|
return rsAccountsDetails->getCurrentAccountOptions(is_hidden,is_tor_auto,is_first_time);
|
||||||
}
|
}
|
||||||
bool RsAccounts::isHiddenNode()
|
bool RsAccounts::isHiddenNode()
|
||||||
{
|
{
|
||||||
@ -1400,14 +1401,14 @@ bool RsAccounts::isTorAuto()
|
|||||||
|
|
||||||
bool RsAccounts::GetAccountIds(std::list<RsPeerId> &ids)
|
bool RsAccounts::GetAccountIds(std::list<RsPeerId> &ids)
|
||||||
{
|
{
|
||||||
return rsAccounts->getAccountIds(ids);
|
return rsAccountsDetails->getAccountIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsAccounts::GetAccountDetails(const RsPeerId &id,
|
bool RsAccounts::GetAccountDetails(const RsPeerId &id,
|
||||||
RsPgpId &pgpId, std::string &pgpName,
|
RsPgpId &pgpId, std::string &pgpName,
|
||||||
std::string &pgpEmail, std::string &location)
|
std::string &pgpEmail, std::string &location)
|
||||||
{
|
{
|
||||||
return rsAccounts->getCurrentAccountDetails(id, pgpId, pgpName, pgpEmail, location);
|
return rsAccountsDetails->getCurrentAccountDetails(id, pgpId, pgpName, pgpEmail, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsAccounts::createNewAccount(
|
bool RsAccounts::createNewAccount(
|
||||||
@ -1415,7 +1416,7 @@ bool RsAccounts::createNewAccount(
|
|||||||
const std::string& country, bool ishiddenloc, bool isautotor,
|
const std::string& country, bool ishiddenloc, bool isautotor,
|
||||||
const std::string& passwd, RsPeerId &sslId, std::string &errString )
|
const std::string& passwd, RsPeerId &sslId, std::string &errString )
|
||||||
{
|
{
|
||||||
return rsAccounts->GenerateSSLCertificate(pgp_id, org, loc, country, ishiddenloc, isautotor, passwd, sslId, errString);
|
return rsAccountsDetails->GenerateSSLCertificate(pgp_id, org, loc, country, ishiddenloc, isautotor, passwd, sslId, errString);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************
|
/*********************************************************************************
|
||||||
|
@ -101,7 +101,9 @@ RsDht *rsDht = NULL ;
|
|||||||
|
|
||||||
//std::map<std::string,std::vector<std::string> > RsInit::unsupported_keys ;
|
//std::map<std::string,std::vector<std::string> > RsInit::unsupported_keys ;
|
||||||
|
|
||||||
RsLoginHelper* rsLoginHelper;
|
RsLoginHelper* rsLoginHelper = nullptr;
|
||||||
|
|
||||||
|
RsAccounts* rsAccounts = nullptr;
|
||||||
|
|
||||||
class RsInitConfig
|
class RsInitConfig
|
||||||
{
|
{
|
||||||
@ -1931,6 +1933,7 @@ int RsServer::StartupRetroShare()
|
|||||||
std::cerr << "== RsInit:: Retroshare core started ==" << std::endl;
|
std::cerr << "== RsInit:: Retroshare core started ==" << std::endl;
|
||||||
std::cerr << "========================================================================" << std::endl;
|
std::cerr << "========================================================================" << std::endl;
|
||||||
|
|
||||||
|
coreReady = true;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2006,6 +2009,11 @@ bool RsLoginHelper::createLocation(
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RsLoginHelper::isLoggedIn()
|
||||||
|
{
|
||||||
|
return RsControl::instance()->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
void RsLoginHelper::closeSession()
|
void RsLoginHelper::closeSession()
|
||||||
{
|
{
|
||||||
RsControl::instance()->rsGlobalShutDown();
|
RsControl::instance()->rsGlobalShutDown();
|
||||||
@ -2020,3 +2028,8 @@ void RsLoginHelper::Location::serial_process(
|
|||||||
RS_SERIAL_PROCESS(mLocationName);
|
RS_SERIAL_PROCESS(mLocationName);
|
||||||
RS_SERIAL_PROCESS(mPpgName);
|
RS_SERIAL_PROCESS(mPpgName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static*/ bool RsAccounts::getCurrentAccountId(RsPeerId& id)
|
||||||
|
{
|
||||||
|
return rsAccountsDetails->getCurrentAccountId(id);
|
||||||
|
}
|
||||||
|
@ -11,7 +11,9 @@ android-*:CONFIG += dll
|
|||||||
android-*:TEMPLATE = lib
|
android-*:TEMPLATE = lib
|
||||||
!android-*:TEMPLATE = app
|
!android-*:TEMPLATE = app
|
||||||
|
|
||||||
!include("../../libresapi/src/use_libresapi.pri"):error("Including")
|
libresapilocalserver {
|
||||||
|
!include("../../libresapi/src/use_libresapi.pri"):error("Including")
|
||||||
|
}
|
||||||
|
|
||||||
!include("../../libretroshare/src/use_libretroshare.pri"):error("Including")
|
!include("../../libretroshare/src/use_libretroshare.pri"):error("Including")
|
||||||
|
|
||||||
|
@ -17,36 +17,37 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDebug>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
# include "util/androiddebug.h"
|
# include "util/androiddebug.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "api/ApiServer.h"
|
#ifdef LIBRESAPI_LOCAL_SERVER
|
||||||
#include "api/ApiServerLocal.h"
|
# include <QDir>
|
||||||
#include "api/RsControlModule.h"
|
# include <QTimer>
|
||||||
|
# include <QDebug>
|
||||||
|
|
||||||
|
# include "api/ApiServer.h"
|
||||||
|
# include "api/ApiServerLocal.h"
|
||||||
|
# include "api/RsControlModule.h"
|
||||||
|
#else // ifdef LIBRESAPI_LOCAL_SERVER
|
||||||
|
# include <QObject>
|
||||||
|
|
||||||
|
# include "retroshare/rsinit.h"
|
||||||
|
# include "retroshare/rsiface.h"
|
||||||
|
#endif // ifdef LIBRESAPI_LOCAL_SERVER
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
# include "jsonapi/jsonapi.h"
|
# include "jsonapi/jsonapi.h"
|
||||||
# include "retroshare/rsiface.h"
|
# include "util/rsnet.h"
|
||||||
|
# include "util/rsurl.h"
|
||||||
|
|
||||||
JsonApiServer jas(9092, [](int ec)
|
# include <cstdint>
|
||||||
{
|
# include <QCommandLineParser>
|
||||||
RsControl::instance()->rsGlobalShutDown();
|
# include <QString>
|
||||||
QCoreApplication::exit(ec);
|
# include <iostream>
|
||||||
});
|
#endif // def RS_JSONAPI
|
||||||
|
|
||||||
void exitGracefully(int ec) { jas.shutdown(ec); }
|
|
||||||
|
|
||||||
#else // ifdef RS_JSONAPI
|
|
||||||
void exitGracefully(int ec) { QCoreApplication::exit(ec); }
|
|
||||||
#endif // ifdef RS_JSONAPI
|
|
||||||
|
|
||||||
using namespace resource_api;
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -56,13 +57,15 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
|
|
||||||
signal(SIGINT, exitGracefully);
|
signal(SIGINT, QCoreApplication::exit);
|
||||||
signal(SIGTERM, exitGracefully);
|
signal(SIGTERM, QCoreApplication::exit);
|
||||||
#ifdef SIGBREAK
|
#ifdef SIGBREAK
|
||||||
signal(SIGBREAK, exitGracefully);
|
signal(SIGBREAK, QCoreApplication::exit);
|
||||||
#endif // ifdef SIGBREAK
|
#endif // ifdef SIGBREAK
|
||||||
|
|
||||||
#ifdef LIBRESAPI_LOCAL_SERVER
|
#ifdef LIBRESAPI_LOCAL_SERVER
|
||||||
|
using namespace resource_api;
|
||||||
|
|
||||||
ApiServer api;
|
ApiServer api;
|
||||||
RsControlModule ctrl_mod(argc, argv, api.getStateTokenServer(), &api, true);
|
RsControlModule ctrl_mod(argc, argv, api.getStateTokenServer(), &api, true);
|
||||||
api.addResourceHandler(
|
api.addResourceHandler(
|
||||||
@ -81,15 +84,84 @@ int main(int argc, char *argv[])
|
|||||||
shouldExitTimer.setTimerType(Qt::VeryCoarseTimer);
|
shouldExitTimer.setTimerType(Qt::VeryCoarseTimer);
|
||||||
shouldExitTimer.setInterval(1000);
|
shouldExitTimer.setInterval(1000);
|
||||||
QObject::connect( &shouldExitTimer, &QTimer::timeout, [&]()
|
QObject::connect( &shouldExitTimer, &QTimer::timeout, [&]()
|
||||||
{ if(ctrl_mod.processShouldExit()) exitGracefully(0); } );
|
{ if(ctrl_mod.processShouldExit()) QCoreApplication::exit(0); } );
|
||||||
shouldExitTimer.start();
|
shouldExitTimer.start();
|
||||||
#else
|
#else // ifdef LIBRESAPI_LOCAL_SERVER
|
||||||
# error retroshare-android-service need CONFIG+=libresapilocalserver to build
|
RsInit::InitRsConfig();
|
||||||
#endif
|
RsInit::InitRetroShare(argc, argv, true);
|
||||||
|
RsControl::earlyInitNotificationSystem();
|
||||||
|
QObject::connect(
|
||||||
|
&app, &QCoreApplication::aboutToQuit,
|
||||||
|
[](){
|
||||||
|
if(RsControl::instance()->isReady())
|
||||||
|
RsControl::instance()->rsGlobalShutDown(); } );
|
||||||
|
#endif // ifdef LIBRESAPI_LOCAL_SERVER
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
|
uint16_t jsonApiPort = 9092;
|
||||||
|
std::string jsonApiBindAddress = "127.0.0.1";
|
||||||
|
|
||||||
|
{
|
||||||
|
QCommandLineOption jsonApiPortOpt(
|
||||||
|
"jsonApiPort", "JSON API listening port.", "port", "9092");
|
||||||
|
QCommandLineOption jsonApiBindAddressOpt(
|
||||||
|
"jsonApiBindAddress", "JSON API Bind Address.",
|
||||||
|
"IP Address", "127.0.0.1");
|
||||||
|
|
||||||
|
QCommandLineParser cmdParser;
|
||||||
|
cmdParser.addHelpOption();
|
||||||
|
cmdParser.addOption(jsonApiPortOpt);
|
||||||
|
cmdParser.addOption(jsonApiBindAddressOpt);
|
||||||
|
|
||||||
|
cmdParser.parse(app.arguments());
|
||||||
|
|
||||||
|
if(cmdParser.isSet(jsonApiPortOpt))
|
||||||
|
{
|
||||||
|
QString jsonApiPortStr = cmdParser.value(jsonApiPortOpt);
|
||||||
|
bool portOk;
|
||||||
|
jsonApiPort = jsonApiPortStr.toUShort(&portOk);
|
||||||
|
if(!portOk)
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR: jsonApiPort option value must be a valid "
|
||||||
|
<< "TCP port!" << std::endl;
|
||||||
|
cmdParser.showHelp();
|
||||||
|
QCoreApplication::exit(EINVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cmdParser.isSet(jsonApiBindAddressOpt))
|
||||||
|
{
|
||||||
|
sockaddr_storage tmp;
|
||||||
|
jsonApiBindAddress =
|
||||||
|
cmdParser.value(jsonApiBindAddressOpt).toStdString();
|
||||||
|
if(!sockaddr_storage_inet_pton(tmp, jsonApiBindAddress))
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR: jsonApiBindAddress option value must "
|
||||||
|
<< "be a valid IP address!" << std::endl;
|
||||||
|
cmdParser.showHelp();
|
||||||
|
QCoreApplication::exit(EINVAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonApiServer jas( jsonApiPort, jsonApiBindAddress,
|
||||||
|
[](int ec) { QCoreApplication::exit(ec); } );
|
||||||
jas.start();
|
jas.start();
|
||||||
#endif
|
|
||||||
|
{
|
||||||
|
sockaddr_storage tmp;
|
||||||
|
sockaddr_storage_inet_pton(tmp, jsonApiBindAddress);
|
||||||
|
sockaddr_storage_setport(tmp, jsonApiPort);
|
||||||
|
sockaddr_storage_ipv6_to_ipv4(tmp);
|
||||||
|
RsUrl tmpUrl(sockaddr_storage_tostring(tmp));
|
||||||
|
tmpUrl.setScheme("http");
|
||||||
|
|
||||||
|
std::cerr << "JSON API listening on "
|
||||||
|
<< tmpUrl.toString()
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ifdef RS_JSONAPI
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,12 @@ resource_api::ApiServerMHD* WebuiPage::apiServerMHD = 0;
|
|||||||
resource_api::ApiServerLocal* WebuiPage::apiServerLocal = 0;
|
resource_api::ApiServerLocal* WebuiPage::apiServerLocal = 0;
|
||||||
#endif
|
#endif
|
||||||
resource_api::RsControlModule* WebuiPage::controlModule = 0;
|
resource_api::RsControlModule* WebuiPage::controlModule = 0;
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
|
# include <csignal>
|
||||||
|
|
||||||
JsonApiServer* WebuiPage::jsonApiServer = nullptr;
|
JsonApiServer* WebuiPage::jsonApiServer = nullptr;
|
||||||
#endif
|
#endif // ifdef RS_JSONAPI
|
||||||
|
|
||||||
WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
|
WebuiPage::WebuiPage(QWidget */*parent*/, Qt::WindowFlags /*flags*/)
|
||||||
{
|
{
|
||||||
@ -109,11 +112,16 @@ QString WebuiPage::helpText() const
|
|||||||
#ifdef LIBRESAPI_LOCAL_SERVER
|
#ifdef LIBRESAPI_LOCAL_SERVER
|
||||||
apiServerLocal = new resource_api::ApiServerLocal(apiServer, resource_api::ApiServerLocal::serverPath());
|
apiServerLocal = new resource_api::ApiServerLocal(apiServer, resource_api::ApiServerLocal::serverPath());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
// Use same port of libresapi + 2
|
// Use same port of libresapi + 2
|
||||||
jsonApiServer = new JsonApiServer(Settings->getWebinterfacePort() + 2);
|
jsonApiServer = new JsonApiServer(
|
||||||
|
Settings->getWebinterfacePort() + 2,
|
||||||
|
Settings->getWebinterfaceAllowAllIps() ? "::" : "127.0.0.1",
|
||||||
|
[](int /*ec*/) { std::raise(SIGTERM); } );
|
||||||
jsonApiServer->start("WebuiPage::jsonApiServer");
|
jsonApiServer->start("WebuiPage::jsonApiServer");
|
||||||
#endif
|
#endif // ifdef RS_JSONAPI
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,12 +68,16 @@ int main(int argc, char **argv)
|
|||||||
#ifdef RS_JSONAPI
|
#ifdef RS_JSONAPI
|
||||||
JsonApiServer* jsonApiServer = nullptr;
|
JsonApiServer* jsonApiServer = nullptr;
|
||||||
uint16_t jsonApiPort = 0;
|
uint16_t jsonApiPort = 0;
|
||||||
|
std::string jsonApiBindAddress = "127.0.0.1";
|
||||||
|
|
||||||
{
|
{
|
||||||
argstream jsonApiArgs(argc, argv);
|
argstream jsonApiArgs(argc, argv);
|
||||||
jsonApiArgs >> parameter(
|
jsonApiArgs >> parameter(
|
||||||
"jsonApiPort", jsonApiPort, "jsonApiPort",
|
"jsonApiPort", jsonApiPort, "jsonApiPort",
|
||||||
"Enable JSON API on the specified port", false );
|
"Enable JSON API on the specified port", false );
|
||||||
|
jsonApiArgs >> parameter(
|
||||||
|
"jsonApiBindAddress", jsonApiBindAddress,
|
||||||
|
"jsonApiBindAddress", "JSON API Bind Address.", false);
|
||||||
jsonApiArgs >> help('h', "help", "Display this Help");
|
jsonApiArgs >> help('h', "help", "Display this Help");
|
||||||
|
|
||||||
if (jsonApiArgs.helpRequested())
|
if (jsonApiArgs.helpRequested())
|
||||||
@ -82,10 +86,9 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if(jsonApiPort)
|
if(jsonApiPort)
|
||||||
{
|
{
|
||||||
jsonApiServer = new JsonApiServer( jsonApiPort, [](int /*ec*/)
|
jsonApiServer = new JsonApiServer(
|
||||||
{
|
jsonApiPort, jsonApiBindAddress,
|
||||||
std::raise(SIGTERM);
|
[](int /*ec*/) { std::raise(SIGTERM); } );
|
||||||
} );
|
|
||||||
|
|
||||||
jsonApiServer->start("JSON API Server");
|
jsonApiServer->start("JSON API Server");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user