mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-29 01:16:20 -05:00
34ea22d5f6
Fixed interfaces for UPnP. Some further tweaks to get TCP connections working again: - hiddenNode issue in p3peers.cc - fixed socklen_t for bind() and connect() calls. - initialise addr to IPv4 for netmgr. - change netAssist (Upnp) interfaces. Still todo: tou address functions, test UDP functionality. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-initdev@6755 b45a01b8-16f6-495d-af2f-9b41ad6348cc
111 lines
2.4 KiB
C++
111 lines
2.4 KiB
C++
//windows/osx (miniupnpc) implementation
|
|
#ifndef _RS_UPNP_IFACE_H
|
|
#define _RS_UPNP_IFACE_H
|
|
|
|
#include <string.h>
|
|
|
|
#include <string>
|
|
#include <map>
|
|
|
|
/* platform independent networking... */
|
|
#include "pqi/pqinetwork.h"
|
|
#include "pqi/pqiassist.h"
|
|
|
|
#include "util/rsthreads.h"
|
|
|
|
class upnpentry
|
|
{
|
|
public:
|
|
std::string name;
|
|
std::string id;
|
|
struct sockaddr_in addr;
|
|
unsigned int flags;
|
|
int status;
|
|
int lastTs;
|
|
};
|
|
|
|
class upnpforward
|
|
{
|
|
public:
|
|
std::string name;
|
|
unsigned int flags;
|
|
struct sockaddr_in iaddr;
|
|
struct sockaddr_in eaddr;
|
|
int status;
|
|
int lastTs;
|
|
};
|
|
|
|
|
|
#define RS_UPNP_S_UNINITIALISED 0
|
|
#define RS_UPNP_S_UNAVAILABLE 1
|
|
#define RS_UPNP_S_READY 2
|
|
#define RS_UPNP_S_TCP_FAILED 3
|
|
#define RS_UPNP_S_UDP_FAILED 4
|
|
#define RS_UPNP_S_ACTIVE 5
|
|
|
|
class uPnPConfigData;
|
|
|
|
class upnphandler: public pqiNetAssistFirewall
|
|
{
|
|
public:
|
|
|
|
upnphandler();
|
|
virtual ~upnphandler();
|
|
|
|
/* External Interface (pqiNetAssistFirewall) */
|
|
virtual void enable(bool active);
|
|
virtual void shutdown();
|
|
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; }
|
|
|
|
/* Public functions - for background thread operation,
|
|
* but effectively private from rest of RS, as in derived class
|
|
*/
|
|
|
|
bool start_upnp();
|
|
bool shutdown_upnp();
|
|
|
|
bool initUPnPState();
|
|
bool printUPnPState();
|
|
|
|
private:
|
|
|
|
bool background_setup_upnp(bool, bool);
|
|
bool checkUPnPActive();
|
|
|
|
/* Mutex for data below */
|
|
RsMutex dataMtx;
|
|
|
|
bool toEnable; /* overall on/off switch */
|
|
bool toStart; /* if set start forwarding */
|
|
bool toStop; /* if set stop forwarding */
|
|
|
|
unsigned short iport;
|
|
unsigned short eport; /* config */
|
|
unsigned short eport_curr; /* current forwarded */
|
|
|
|
/* info from upnp */
|
|
unsigned int upnpState;
|
|
uPnPConfigData *upnpConfig;
|
|
|
|
struct sockaddr_in upnp_iaddr;
|
|
struct sockaddr_in upnp_eaddr;
|
|
|
|
/* active port forwarding */
|
|
std::list<upnpforward> activeForwards;
|
|
|
|
};
|
|
|
|
#endif /* _RS_UPNP_IFACE_H */
|