mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 14:16:16 -04:00
Added basic ZeroConf interface.
- registers oneself, browses and resolves services. - Lots still TODO: - parse TxtRecords. - Track peers. - feedback to libretroshare - etc, etc. Enabled ZeroConf in libretroshare.pro & rsinit.cc. Compiles and runs on OSX. Added RelayHandler to Dht, to enable external control of Relays. Marked pqiAssist Interface for changes... will be revamped with ZeroConf. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4727 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2048bb5e47
commit
4d2175636e
9 changed files with 1488 additions and 19 deletions
33
libretroshare/src/zeroconf/NOTES.txt
Normal file
33
libretroshare/src/zeroconf/NOTES.txt
Normal file
|
@ -0,0 +1,33 @@
|
|||
|
||||
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.
|
||||
|
||||
|
||||
|
1091
libretroshare/src/zeroconf/p3zeroconf.cc
Normal file
1091
libretroshare/src/zeroconf/p3zeroconf.cc
Normal file
File diff suppressed because it is too large
Load diff
231
libretroshare/src/zeroconf/p3zeroconf.h
Normal file
231
libretroshare/src/zeroconf/p3zeroconf.h
Normal file
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* libretroshare/src/zeroconf: p3zeroconf.h
|
||||
*
|
||||
* ZeroConf interface for RetroShare.
|
||||
*
|
||||
* Copyright 2011-2011 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MRK_P3_ZEROCONF_H
|
||||
#define MRK_P3_ZEROCONF_H
|
||||
|
||||
#include "pqi/pqiassist.h"
|
||||
#include "retroshare/rsdht.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "pqi/pqinetwork.h"
|
||||
#include "pqi/pqimonitor.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;
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class zcPeerDetails
|
||||
{
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
class p3NetMgr;
|
||||
|
||||
class p3ZeroConf: public pqiNetAssistConnect, public pqiNetListener
|
||||
{
|
||||
public:
|
||||
p3ZeroConf(std::string gpgid, std::string sslid, pqiConnectCb *cb, p3NetMgr *nm);
|
||||
virtual ~p3ZeroConf();
|
||||
|
||||
/*** OVERLOADED from pqiNetListener ***/
|
||||
|
||||
virtual bool resetListener(struct sockaddr_in &local);
|
||||
|
||||
void start(); /* starts up the bitdht 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_in &addr, uint32_t reason, uint32_t flags, uint32_t age);
|
||||
virtual int addKnownPeer(const std::string &pid, const struct sockaddr_in &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_in &laddr, struct sockaddr_in &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 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_stopResolve();
|
||||
|
||||
void locked_startQueryIp(uint32_t idx, std::string fullname);
|
||||
int locked_stopQueryIp();
|
||||
|
||||
std::string displayDNSServiceError(DNSServiceErrorType errcode);
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
std::list<zcBrowseResult> mBrowseResults;
|
||||
std::list<zcResolveResult> mResolveResults;
|
||||
std::list<zcQueryResult> mQueryResults;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
p3NetMgr *mNetMgr;
|
||||
|
||||
RsMutex mZcMtx;
|
||||
|
||||
std::string mOwnGpgId;
|
||||
std::string mOwnSslId;
|
||||
|
||||
time_t mMinuteTS;
|
||||
|
||||
/* translation maps */
|
||||
|
||||
};
|
||||
|
||||
#endif /* MRK_P3_ZEROCONF_H */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue