rsPeers add few JSON API calls

This commit is contained in:
Gioacchino Mazzurco 2018-10-20 21:13:10 +02:00
parent cfe95a57a0
commit 7a1375ff6f
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
3 changed files with 65 additions and 6 deletions

View File

@ -510,11 +510,55 @@ public:
virtual bool setHiddenNode(const RsPeerId &id, const std::string &address, uint16_t port) = 0;
virtual bool isHiddenNode(const RsPeerId &id) = 0;
virtual bool addPeerLocator(const RsPeerId &ssl_id, const RsUrl& locator) = 0;
virtual bool setLocalAddress(const RsPeerId &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setExtAddress( const RsPeerId &ssl_id, const std::string &addr, uint16_t port) = 0;
virtual bool setDynDNS(const RsPeerId &id, const std::string &addr) = 0;
virtual bool setNetworkMode(const RsPeerId &ssl_id, uint32_t netMode) = 0;
/**
* @brief Add URL locator for given peer
* @jsonapi{development}
* @param[in] sslId SSL id of the peer, own id is accepted too
* @param[in] locator peer url locator
* @return false if error occurred, true otherwise
*/
virtual bool addPeerLocator(const RsPeerId& sslId, const RsUrl& locator) = 0;
/**
* @brief Set local IPv4 address for the given peer
* @jsonapi{development}
* @param[in] sslId SSL id of the peer, own id is accepted too
* @param[in] addr string representation of the local IPv4 address
* @param[in] port local listening port
* @return false if error occurred, true otherwise
*/
virtual bool setLocalAddress(
const RsPeerId& sslId, const std::string& addr, uint16_t port ) = 0;
/**
* @brief Set external IPv4 address for given peer
* @jsonapi{development}
* @param[in] sslId SSL id of the peer, own id is accepted too
* @param[in] addr string representation of the external IPv4 address
* @param[in] port external listening port
* @return false if error occurred, true otherwise
*/
virtual bool setExtAddress(
const RsPeerId& sslId, const std::string &addr, uint16_t port ) = 0;
/**
* @brief Set (dynamical) domain name associated to the given peer
* @jsonapi{development}
* @param[in] sslId SSL id of the peer, own id is accepted too
* @param[in] addr domain name string representation
* @return false if error occurred, true otherwise
*/
virtual bool setDynDNS(const RsPeerId& sslId, const std::string& addr) = 0;
/**
* @brief Set network mode of the given peer
* @jsonapi{development}
* @param[in] sslId SSL id of the peer, own id is accepted too
* @param[in] netMode one of RS_NETMODE_*
* @return false if error occurred, true otherwise
*/
virtual bool setNetworkMode(const RsPeerId &sslId, uint32_t netMode) = 0;
virtual bool setVisState(const RsPeerId &ssl_id, uint16_t vs_disc, uint16_t vs_dht) = 0;
virtual bool getProxyServer(const uint32_t type, std::string &addr, uint16_t &port,uint32_t& status_flags) = 0;

View File

@ -18,6 +18,7 @@
#include "rsurl.h"
#include "serialiser/rstypeserializer.h"
#include <cstdio>
#include <algorithm>
@ -254,6 +255,14 @@ RsUrl& RsUrl::setFragment(const std::string& fragment)
return decoded.str();
}
void RsUrl::serial_process( RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx )
{
std::string urlString = toString();
RS_SERIAL_PROCESS(urlString);
fromString(urlString);
}
/*static*/ const std::string RsUrl::schemeSeparator("://");
/*static*/ const std::string RsUrl::ipv6WrapOpen("[");
/*static*/ const std::string RsUrl::ipv6Separator(":");

View File

@ -20,6 +20,8 @@
#include <string>
#include <map>
#include "serialiser/rsserializable.h"
/**
* Very simplistic and minimal URL helper class for RetroShare, after looking
* for a small and self-contained C/C++ URL parsing and manipulation library,
@ -31,7 +33,7 @@
* Anyway this should support most common URLs of the form
* scheme://host[:port][/path][?query][#fragment]
*/
struct RsUrl
struct RsUrl : RsSerializable
{
RsUrl();
RsUrl(const std::string& urlStr);
@ -78,6 +80,10 @@ struct RsUrl
inline bool operator!=(const RsUrl& rhs) const
{ return toString() != rhs.toString(); }
/// @see RsSerializable
virtual void serial_process(RsGenericSerializer::SerializeJob j,
RsGenericSerializer::SerializeContext& ctx);
static const std::string schemeSeparator;
static const std::string ipv6WrapOpen;
static const std::string ipv6Separator;