Remove zeroconf deadcode

This commit is contained in:
Gioacchino Mazzurco 2019-04-23 11:57:30 +02:00
parent bff3cd6845
commit 5dda6eb771
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051
8 changed files with 15 additions and 2362 deletions

View File

@ -656,31 +656,6 @@ equals(RS_UPNP_LIB, miniupnpc) {
DEFINES *= RS_USE_LIBUPNP DEFINES *= RS_USE_LIBUPNP
} }
zeroconf {
HEADERS += zeroconf/p3zeroconf.h \
SOURCES += zeroconf/p3zeroconf.cc \
# Disable Zeroconf (we still need the code for zcnatassist
# DEFINES *= RS_ENABLE_ZEROCONF
}
# This is seperated from the above for windows/linux platforms.
# It is acceptable to build in zeroconf and have it not work,
# but unacceptable to rely on Apple's libraries for Upnp when we have alternatives. '
zcnatassist {
HEADERS += zeroconf/p3zcnatassist.h \
SOURCES += zeroconf/p3zcnatassist.cc \
DEFINES *= RS_ENABLE_ZCNATASSIST
}
# new gxs cache system # new gxs cache system
# this should be disabled for releases until further notice. # this should be disabled for releases until further notice.

View File

@ -26,18 +26,16 @@
#include <zlib.h> #include <zlib.h>
#ifdef NO_SQLCIPHER #ifdef NO_SQLCIPHER
#include <sqlite3.h> # include <sqlite3.h>
#else #else
#include <sqlcipher/sqlite3.h> # include <sqlcipher/sqlite3.h>
#endif #endif
#ifndef RS_ENABLE_ZCNATASSIST
#ifdef RS_USE_LIBUPNP #ifdef RS_USE_LIBUPNP
#include "upnp/upnpconfig.h" # include "upnp/upnpconfig.h"
#else #else // def RS_USE_LIBUPNP
#include "miniupnpc/miniupnpc.h" # include "miniupnpc/miniupnpc.h"
#endif // RS_USE_LIBUPNP #endif // def RS_USE_LIBUPNP
#endif // RS_ENABLE_ZCNATASSIST
std::string RsServer::getSQLCipherVersion() std::string RsServer::getSQLCipherVersion()
{ {
@ -88,12 +86,12 @@ void RsServer::getLibraries(std::list<RsLibraryInfo> &libraries)
#ifndef NO_SQLCIPHER #ifndef NO_SQLCIPHER
libraries.push_back(RsLibraryInfo("SQLCipher", getSQLCipherVersion())); libraries.push_back(RsLibraryInfo("SQLCipher", getSQLCipherVersion()));
#endif #endif
#ifndef RS_ENABLE_ZCNATASSIST
#ifdef RS_USE_LIBUPNP #ifdef RS_USE_LIBUPNP
libraries.push_back(RsLibraryInfo("UPnP (libupnp)", UPNP_VERSION_STRING)); libraries.push_back(RsLibraryInfo("UPnP (libupnp)", UPNP_VERSION_STRING));
#else #else // def RS_USE_LIBUPNP
libraries.push_back(RsLibraryInfo("UPnP (MiniUPnP)", MINIUPNPC_VERSION)); libraries.push_back(RsLibraryInfo("UPnP (MiniUPnP)", MINIUPNPC_VERSION));
#endif // RS_USE_LIBUPNP #endif // def RS_USE_LIBUPNP
#endif // RS_ENABLE_ZCNATASSIST
libraries.push_back(RsLibraryInfo("Zlib", ZLIB_VERSION)); libraries.push_back(RsLibraryInfo("Zlib", ZLIB_VERSION));
} }

View File

@ -728,19 +728,11 @@ RsGRouter *rsGRouter = NULL ;
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/rsrandom.h" #include "util/rsrandom.h"
#ifdef RS_ENABLE_ZEROCONF #ifdef RS_USE_LIBUPNP
#include "zeroconf/p3zeroconf.h" # include "upnp/upnphandler_linux.h"
#endif #else // def RS_USE_LIBUPNP
# include "upnp/upnphandler_miniupnp.h"
#ifdef RS_ENABLE_ZCNATASSIST #endif // def RS_USE_LIBUPNP
#include "zeroconf/p3zcnatassist.h"
#else
#ifdef RS_USE_LIBUPNP
#include "upnp/upnphandler_linux.h"
#else
#include "upnp/upnphandler_miniupnp.h"
#endif
#endif
#include "services/autoproxy/p3i2pbob.h" #include "services/autoproxy/p3i2pbob.h"
#include "services/autoproxy/rsautoproxymonitor.h" #include "services/autoproxy/rsautoproxymonitor.h"
@ -1583,23 +1575,9 @@ int RsServer::StartupRetroShare()
mNetMgr->addNetListener(mProxyStack); mNetMgr->addNetListener(mProxyStack);
#endif #endif
#ifdef RS_ENABLE_ZEROCONF
p3ZeroConf *mZeroConf = new p3ZeroConf(
AuthGPG::getAuthGPG()->getGPGOwnId(), ownId,
mLinkMgr, mNetMgr, mPeerMgr);
mNetMgr->addNetAssistConnect(2, mZeroConf);
mNetMgr->addNetListener(mZeroConf);
#endif
#ifdef RS_ENABLE_ZCNATASSIST
// Apple's UPnP & NAT-PMP assistance.
p3zcNatAssist *mZcNatAssist = new p3zcNatAssist();
mNetMgr->addNetAssistFirewall(1, mZcNatAssist);
#else
// Original UPnP Interface. // Original UPnP Interface.
pqiNetAssistFirewall *mUpnpMgr = new upnphandler(); pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
mNetMgr->addNetAssistFirewall(1, mUpnpMgr); mNetMgr->addNetAssistFirewall(1, mUpnpMgr);
#endif
} }
/**************************************************************************/ /**************************************************************************/

View File

@ -1,33 +0,0 @@
The Code in this directory refers to APPLEs ZeroConf Library.
We have two classes: p3ZeroConf & p3ZeroConfNat
The first provides ZeroConf(Bonjour) discovery services.
The second provides UPnP & NAT-PMP Nat Port Forwarding.
OSX
----------------
Both should compile with no problems under OSX.
Both will be compiled by default.
p3ZeroConf is enabled by default.
p3ZeroConfNAT will become the default PortForwarding Service (once tested).
Windows
----------------
Under Windows, you require Apple's header files & library to compile.
If you are missing the libraries, you can disable their compilation in libretroshare.
Furthermore - it'll only work if the Apple DNS Service is running on the Windows PC.
p3ZeroConf will be enabled by default (if included in the compilation).
p3ZeroConfNAT will not be enabled by default.
Linux
----------------
Neither of these classes will compile or be enabled under Linux.
There is another library: Avahi - which provides ZeroConf services.
It is likely to have a totally different interface -
so it will have to be coded up separately.

View File

@ -1,445 +0,0 @@
/*******************************************************************************
* libretroshare/src/zeroconf: p3zcnatassist.cc *
* *
* libretroshare: retroshare core library *
* *
* Copyright 2011-2012 by Robert Fernie <retroshare@lunamutt.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include "zeroconf/p3zeroconf.h"
#include "zeroconf/p3zcnatassist.h"
#include <openssl/sha.h>
#include <iostream>
//#define DEBUG_ZCNATASSIST 1
p3zcNatAssist::p3zcNatAssist()
:mZcMtx("p3zcNatAssist")
{
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::p3zcNatAssist()" << std::endl;
std::cerr << std::endl;
#endif
mMappingStatus = ZC_SERVICE_STOPPED;
mMappingStatusTS = time(NULL);
mLocalPort = 0;
mLocalPortSet = false;
mExternalPort = 0;
mExternalPortSet = false;
mMapped = false;
}
p3zcNatAssist::~p3zcNatAssist()
{
shutdown();
}
/* pqiNetAssist - external interface functions */
void p3zcNatAssist::enable(bool on)
{
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::enable(" << on << ")";
std::cerr << std::endl;
#endif
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
mEnabled = on;
if ((!mEnabled) && (mMappingStatus == ZC_SERVICE_ACTIVE))
{
locked_stopMapping();
}
}
void p3zcNatAssist::shutdown() /* blocking call */
{
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::shutdown()";
std::cerr << std::endl;
#endif
enable(false);
}
void p3zcNatAssist::restart()
{
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::restart()";
std::cerr << std::endl;
#endif
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
if (mMappingStatus == ZC_SERVICE_ACTIVE)
{
locked_stopMapping();
}
}
bool p3zcNatAssist::getEnabled()
{
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::getEnabled() : " << mEnabled;
std::cerr << std::endl;
#endif
return mEnabled;
}
bool p3zcNatAssist::getActive()
{
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::getActive() : " << (mEnabled && mMapped);
std::cerr << std::endl;
#endif
return (mEnabled && mMapped);
}
void p3zcNatAssist::setInternalPort(unsigned short iport_in)
{
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::setInternalPort() : " << iport_in;
std::cerr << std::endl;
#endif
bool changed = false;
{
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
changed = (mEnabled) && (mLocalPort != iport_in);
mLocalPort = iport_in;
mLocalPortSet = true;
}
if (changed)
{
restart();
}
}
void p3zcNatAssist::setExternalPort(unsigned short eport_in)
{
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::setExternalPort() : " << eport_in;
std::cerr << std::endl;
#endif
bool changed = false;
{
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
changed = (mEnabled) && (mExternalPort != eport_in);
mExternalPort = eport_in;
mExternalPortSet = true;
}
if (changed)
{
restart();
}
}
bool p3zcNatAssist::getInternalAddress(struct sockaddr_storage &addr)
{
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::getInternalAddress() always returns false";
std::cerr << std::endl;
#endif
return false;
}
bool p3zcNatAssist::getExternalAddress(struct sockaddr_storage &addr)
{
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
if (mMapped)
{
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::getExternalAddress() mMapped => true";
std::cerr << std::endl;
#endif
addr = mExternalAddress;
return true;
}
#ifdef DEBUG_ZCNATASSIST
std::cerr << "p3zcNatAssist::getExternalAddress() !mMapped => false";
std::cerr << std::endl;
#endif
return false;
}
/***********************************************************************************/
int p3zcNatAssist::tick()
{
{
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
locked_startMapping();
}
checkServiceFDs(); // will cause callbacks - if data is ready.
return 0;
}
void p3zcNatAssist::checkServiceFDs()
{
RsStackMutex stack(mZcMtx); /****** STACK LOCK MUTEX *******/
if (mMappingStatus == ZC_SERVICE_ACTIVE)
{
locked_checkFD(mMappingRef);
}
}
void p3zcNatAssist::locked_checkFD(DNSServiceRef ref)
{
//std::cerr << "p3zcNatAssist::locked_checkFD() Start";
//std::cerr << std::endl;
int sockfd = DNSServiceRefSockFD(ref);
fd_set ReadFDs, WriteFDs, ExceptFDs;
FD_ZERO(&ReadFDs);
FD_ZERO(&WriteFDs);
FD_ZERO(&ExceptFDs);
FD_SET(sockfd, &ReadFDs);
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if (select(sockfd + 1, &ReadFDs, &WriteFDs, &ExceptFDs, &timeout) < 0)
{
std::cerr << "p3zeroconf::checkFD() Select ERROR";
std::cerr << std::endl;
return;
}
if (FD_ISSET(sockfd, &ReadFDs))
{
DNSServiceErrorType err = DNSServiceProcessResult(ref);
switch(err)
{
case 0:
/* ok */
break;
default:
std::cerr << "DNSServiceProcessResult() ERROR: ";
std::cerr << displayDNSServiceError(err);
std::cerr << std::endl;
break;
}
}
//std::cerr << "p3zcNatAssist::locked_checkFD() End";
//std::cerr << std::endl;
return;
}
void p3zcNatAssist_CallbackMapping( DNSServiceRef sdRef, DNSServiceFlags flags,
uint32_t interfaceIndex, DNSServiceErrorType errorCode,
uint32_t externalAddress, DNSServiceProtocol protocol,
uint16_t internalPort, uint16_t externalPort,
uint32_t ttl, void *context )
{
p3zcNatAssist *zc = (p3zcNatAssist *) context;
zc->callbackMapping(sdRef, flags, interfaceIndex, errorCode, externalAddress, protocol, internalPort, externalPort, ttl);
}
int p3zcNatAssist::locked_startMapping()
{
if (!mEnabled)
{
std::cerr << "p3zcNatAssist::locked_startMapping()";
std::cerr << "NatAssist not Enabled";
std::cerr << std::endl;
return 0;
}
if (!mLocalPortSet)
{
std::cerr << "p3zcNatAssist::locked_startMapping()";
std::cerr << "Port Not Set";
std::cerr << std::endl;
return 0;
}
if (mMappingStatus == ZC_SERVICE_ACTIVE)
{
return 0;
}
std::cerr << "p3zcNatAssist::locked_startMapping() Mapping!";
std::cerr << std::endl;
std::cerr << "p3zcNatAssist::locked_startMapping() Local Port: " << mLocalPort;
std::cerr << std::endl;
DNSServiceRef *sdRef = &mMappingRef;
DNSServiceFlags flags = 0; /* no flags, currently reserved */
uint32_t interfaceIndex = 0; /* primary interface */
DNSServiceProtocol protocol = (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP);
uint16_t internalPort = htons(mLocalPort);
uint16_t externalPort = htons(mLocalPort);
if (mExternalPortSet)
{
externalPort = htons(mExternalPort);
}
std::cerr << "p3zcNatAssist::locked_startMapping() External Port: " << ntohs(externalPort);
std::cerr << std::endl;
uint32_t ttl = 0; /* default ttl */
DNSServiceNATPortMappingReply callBack = p3zcNatAssist_CallbackMapping;
void *context = this;
DNSServiceErrorType errcode = DNSServiceNATPortMappingCreate(sdRef, flags, interfaceIndex, protocol,
internalPort, externalPort, ttl, callBack, context);
if (errcode != kDNSServiceErr_NoError)
{
std::cerr << "p3zcNatAssist::locked_startMapping() ERROR: ";
std::cerr << displayDNSServiceError(errcode);
std::cerr << std::endl;
}
else
{
mMappingStatus = ZC_SERVICE_ACTIVE;
mMappingStatusTS = time(NULL);
}
return 1;
}
void p3zcNatAssist::callbackMapping(DNSServiceRef sdRef, DNSServiceFlags flags,
uint32_t interfaceIndex, DNSServiceErrorType errorCode,
uint32_t externalAddress, DNSServiceProtocol protocol,
uint16_t internalPort, uint16_t externalPort, uint32_t ttl)
{
std::cerr << "p3zcNatAssist::callbackMapping()";
std::cerr << std::endl;
/* handle queryIp */
if (errorCode != kDNSServiceErr_NoError)
{
std::cerr << "p3zcNatAssist::callbackMapping() FAILED ERROR: ";
std::cerr << displayDNSServiceError(errorCode);
std::cerr << std::endl;
return;
}
if ((externalAddress == 0) && (externalPort == 0))
{
/* failed :( */
mMapped = false;
std::cerr << "p3zcNatAssist::callbackMapping() ZeroAddress ... Mapping not possible";
std::cerr << std::endl;
return;
}
mMapped = true;
// THIS APPEARS TO BE IPv4 ONLY!.
sockaddr_storage_clear(mExternalAddress);
struct sockaddr_in *addr = (struct sockaddr_in *) &mExternalAddress;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = externalAddress;
addr->sin_port = externalPort;
mTTL = ttl;
std::cerr << "p3zcNatAssist::callbackMapping() Success";
std::cerr << std::endl;
std::cerr << "interfaceIndex: " << interfaceIndex;
std::cerr << std::endl;
std::cerr << "internalPort: " << ntohs(internalPort);
std::cerr << std::endl;
std::cerr << "externalAddress: " << sockaddr_storage_tostring(mExternalAddress);
std::cerr << std::endl;
std::cerr << "protocol: " << protocol;
std::cerr << std::endl;
std::cerr << "ttl: " << ttl;
std::cerr << std::endl;
}
void p3zcNatAssist::locked_stopMapping()
{
std::cerr << "p3zcNatAssist::locked_stopMapping()";
std::cerr << std::endl;
if (mMappingStatus != ZC_SERVICE_ACTIVE)
{
return;
}
DNSServiceRefDeallocate(mMappingRef);
mMappingStatus = ZC_SERVICE_STOPPED;
mMappingStatusTS = time(NULL);
mMapped = false;
}

View File

@ -1,108 +0,0 @@
/*******************************************************************************
* libretroshare/src/zeroconf: p3zcnatassist.h *
* *
* libretroshare: retroshare core library *
* *
* Copyright 2011-2012 by Robert Fernie <retroshare@lunamutt.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef MRK_P3_ZC_NAT_ASSIST_H
#define MRK_P3_ZC_NAT_ASSIST_H
#include "util/rswin.h"
#include "pqi/pqiassist.h"
#include "retroshare/rsdht.h"
#include <string>
#include <map>
#include "pqi/pqinetwork.h"
#include "pqi/pqimonitor.h"
#include "pqi/p3peermgr.h"
#include "util/rsthreads.h"
#include <dns_sd.h>
class p3NetMgr;
class p3zcNatAssist: public pqiNetAssistFirewall
{
public:
p3zcNatAssist();
virtual ~p3zcNatAssist();
/* pqiNetAssist - external interface functions */
virtual int tick();
virtual void enable(bool on);
virtual void shutdown(); /* blocking call */
virtual void restart();
virtual bool getEnabled();
virtual bool getActive();
virtual void setInternalPort(unsigned short iport_in);
virtual void setExternalPort(unsigned short eport_in);
virtual bool getInternalAddress(struct sockaddr_storage &addr);
virtual bool getExternalAddress(struct sockaddr_storage &addr);
/* TO IMPLEMENT: New Port Forward interface to support as many ports as necessary */
virtual bool requestPortForward(const PortForwardParams &params) { return false; }
virtual bool statusPortForward(const uint32_t fwdId, PortForwardParams &params) { return false; }
/* pqiNetAssistConnect - external interface functions */
public:
// Callbacks must be public -> so they can be accessed.
void callbackMapping(DNSServiceRef sdRef, DNSServiceFlags flags,
uint32_t interfaceIndex, DNSServiceErrorType errorCode,
uint32_t externalAddress, DNSServiceProtocol protocol,
uint16_t internalPort, uint16_t externalPort, uint32_t ttl);
private:
/* monitoring fns */
void checkServiceFDs();
void locked_checkFD(DNSServiceRef ref);
int locked_startMapping();
void locked_stopMapping();
/**************** DATA ****************/
RsMutex mZcMtx;
bool mEnabled;
bool mMapped;
uint16_t mLocalPort;
bool mLocalPortSet;
uint16_t mExternalPort;
bool mExternalPortSet;
struct sockaddr_storage mExternalAddress;
int mTTL;
DNSServiceRef mMappingRef;
uint32_t mMappingStatus;
rstime_t mMappingStatusTS;
};
#endif /* MRK_P3_ZC_NAT_ASSIST_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,286 +0,0 @@
/*******************************************************************************
* libretroshare/src/zeroconf: p3zeroconf.h *
* *
* libretroshare: retroshare core library *
* *
* Copyright 2011-2012 by Robert Fernie <retroshare@lunamutt.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef MRK_P3_ZEROCONF_H
#define MRK_P3_ZEROCONF_H
#include "util/rswin.h"
#include "pqi/pqiassist.h"
#include "retroshare/rsdht.h"
#include <string>
#include <map>
#include "pqi/pqinetwork.h"
#include "pqi/pqimonitor.h"
#include "pqi/p3peermgr.h"
#include "util/rsthreads.h"
#include <dns_sd.h>
class zcBrowseResult
{
public:
DNSServiceFlags flags;
uint32_t interfaceIndex;
std::string serviceName;
std::string regtype;
std::string replyDomain;
};
class zcResolveResult
{
public:
zcResolveResult() { return; } // :txtRecord(NULL) { return; }
~zcResolveResult() { return; } //{ if (txtRecord) { free(txtRecord); txtRecord = NULL; } }
DNSServiceFlags flags;
uint32_t interfaceIndex;
std::string fullname;
std::string hosttarget;
uint16_t port;
uint16_t txtLen;
//unsigned char *txtRecord;
// extra results.
std::string gpgId;
std::string sslId;
};
class zcQueryResult
{
public:
zcQueryResult() { return; } //:rdata(NULL) { return; }
~zcQueryResult() {return; } //{ if (rdata) { free(rdata); rdata = NULL; } }
DNSServiceFlags flags;
uint32_t interfaceIndex;
std::string fullname;
uint16_t rrtype;
uint16_t rrclass;
uint16_t rdlen;
//void *rdata;
uint32_t ttl;
// Extra ones.
std::string sslId;
std::string gpgId;
struct sockaddr_storage addr;
};
class zcLocationResult
{
public:
zcLocationResult() { return; }
zcLocationResult(std::string _gpgId, std::string _sslId)
:gpgId(_gpgId), sslId(_sslId) { return; }
std::string gpgId;
std::string sslId;
};
#define ZC_STATUS_NEW_LOCATION 1
#define ZC_STATUS_FOUND 2
#define ZC_STATUS_CONNECTED 4
#define ZC_STATUS_IPADDRESS 8
class zcLocationDetails
{
public:
std::string mSslId;
rstime_t mFoundTs;
uint32_t mStatus;
std::string mHostTarget;
std::string mFullName;
uint16_t mPort;
struct sockaddr_storage mAddress;
rstime_t mAddrTs;
};
class zcPeerDetails
{
public:
std::string gpgId;
std::map<std::string, zcLocationDetails> mLocations;
};
#define ZC_SERVICE_STOPPED 0
#define ZC_SERVICE_ACTIVE 1
// This is used by p3zcNatAssist too.
std::string displayDNSServiceError(DNSServiceErrorType errcode);
class p3NetMgr;
class p3ZeroConf: public pqiNetAssistConnect, public pqiNetListener
{
public:
p3ZeroConf(std::string gpgid, std::string sslid, pqiConnectCb *cb, p3NetMgr *nm, p3PeerMgr *pm);
virtual ~p3ZeroConf();
/*** OVERLOADED from pqiNetListener ***/
virtual bool resetListener(struct sockaddr_in &local);
void start(); /* starts up the thread */
/* pqiNetAssist - external interface functions */
virtual int tick();
virtual void enable(bool on);
virtual void shutdown(); /* blocking call */
virtual void restart();
virtual bool getEnabled();
virtual bool getActive();
virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize);
/* pqiNetAssistConnect - external interface functions */
/* add / remove peers */
virtual bool findPeer(std::string id);
virtual bool dropPeer(std::string id);
virtual int addBadPeer(const struct sockaddr_storage &addr, uint32_t reason, uint32_t flags, uint32_t age);
virtual int addKnownPeer(const std::string &pid, const struct sockaddr_storage &addr, uint32_t flags);
/* feedback on success failure of Connections */
virtual void ConnectionFeedback(std::string pid, int state);
/* extract current peer status */
virtual bool getPeerStatus(std::string id,
struct sockaddr_storage &laddr, struct sockaddr_storage &raddr,
uint32_t &type, uint32_t &mode);
virtual bool setAttachMode(bool on);
/* pqiNetAssistConnect - external interface functions */
public:
// Callbacks must be public -> so they can be accessed.
void callbackRegister(DNSServiceRef sdRef, DNSServiceFlags flags,
DNSServiceErrorType errorCode,
const char *name, const char *regtype, const char *domain);
void callbackBrowse(DNSServiceRef sdRef, DNSServiceFlags flags,
uint32_t interfaceIndex, DNSServiceErrorType errorCode,
const char *serviceName, const char *regtype, const char *replyDomain);
void callbackResolve( DNSServiceRef sdRef, DNSServiceFlags flags,
uint32_t interfaceIndex, DNSServiceErrorType errorCode,
const char *fullname, const char *hosttarget, uint16_t port,
uint16_t txtLen, const unsigned char *txtRecord);
void callbackQueryIp( DNSServiceRef sdRef, DNSServiceFlags flags,
uint32_t interfaceIndex, DNSServiceErrorType errorCode,
const char *fullname, uint16_t rrtype, uint16_t rrclass,
uint16_t rdlen, const void *rdata, uint32_t ttl);
private:
void createTxtRecord();
/* monitoring fns */
void checkServiceFDs();
void locked_checkFD(DNSServiceRef ref);
int checkResolveAction();
int checkLocationResults();
int checkQueryAction();
int checkQueryResults();
/**** THESE ARE MAINLY SEMI LOCKED.... not quite sure when the callback will happen! ***/
int locked_startRegister();
void locked_stopRegister();
int locked_startBrowse();
int locked_stopBrowse();
void locked_startResolve(uint32_t idx, std::string name,
std::string regtype, std::string domain);
int locked_checkResolvedPeer(const zcResolveResult &rr);
int locked_stopResolve();
void locked_startQueryIp(uint32_t idx, std::string fullname,
std::string gpgId, std::string sslId);
int locked_completeQueryResult(zcQueryResult &qr);
int locked_stopQueryIp();
/**************** DATA ****************/
p3NetMgr *mNetMgr;
p3PeerMgr *mPeerMgr;
RsMutex mZcMtx;
std::string mOwnGpgId;
std::string mOwnSslId;
bool mRegistered;
bool mTextOkay;
bool mPortOkay;
uint16_t mLocalPort;
std::string mTextRecord;
DNSServiceRef mRegisterRef;
DNSServiceRef mBrowseRef;
DNSServiceRef mResolveRef;
DNSServiceRef mQueryRef;
uint32_t mRegisterStatus;
uint32_t mBrowseStatus;
uint32_t mResolveStatus;
uint32_t mQueryStatus;
rstime_t mRegisterStatusTS;
rstime_t mBrowseStatusTS;
rstime_t mResolveStatusTS;
rstime_t mQueryStatusTS;
std::string mQuerySslId;
std::string mQueryGpgId;
std::list<zcBrowseResult> mBrowseResults;
std::list<zcResolveResult> mResolveResults;
std::list<zcLocationResult> mLocationResults;
std::list<zcQueryResult> mQueryResults;
rstime_t mMinuteTS;
std::map<std::string, zcPeerDetails> mPeerDetails;
};
#endif /* MRK_P3_ZEROCONF_H */