Merge pull request #1659 from G10h4ck/netmgr_calmer

Calm down p3netmgr at least when internet connection is not available
This commit is contained in:
G10h4ck 2019-10-25 18:42:45 +02:00 committed by GitHub
commit 63861ba942
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 120 additions and 2288 deletions

View File

@ -404,9 +404,7 @@ HEADERS += pqi/authssl.h \
pqi/pqiqosstreamer.h \
pqi/sslfns.h \
pqi/pqinetstatebox.h \
pqi/p3servicecontrol.h \
# pqi/p3dhtmgr.h \
pqi/p3servicecontrol.h
HEADERS += rsserver/p3face.h \
rsserver/p3history.h \
@ -653,8 +651,8 @@ equals(RS_UPNP_LIB, miniupnpc) {
contains(RS_UPNP_LIB, upnp) {
HEADERS += rs_upnp/upnp18_retrocompat.h
HEADERS += rs_upnp/UPnPBase.h rs_upnp/upnphandler_linux.h
SOURCES += rs_upnp/UPnPBase.cpp rs_upnp/upnphandler_linux.cc
HEADERS += rs_upnp/UPnPBase.h rs_upnp/upnphandler_libupnp.h
SOURCES += rs_upnp/UPnPBase.cpp rs_upnp/upnphandler_libupnp.cc
}
# new gxs cache system

File diff suppressed because it is too large Load Diff

View File

@ -1,246 +0,0 @@
/*******************************************************************************
* libretroshare/src/pqi: p3dhtmgr.h *
* *
* libretroshare: retroshare core library *
* *
* Copyright 2004-2008 by Robert Fernie. *
* *
* 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_DHT_MANAGER_HEADER
#define MRK_P3_DHT_MANAGER_HEADER
/* Interface class for DHT data */
#include <string>
#include <map>
#include "pqi/pqinetwork.h"
#include "util/rsthreads.h"
#include "pqi/pqimonitor.h"
#include "pqi/pqiassist.h"
/* All other #defs are in .cc */
#define DHT_ADDR_INVALID 0xff
#define DHT_ADDR_TCP 0x01
#define DHT_ADDR_UDP 0x02
/* for DHT peer STATE */
#define DHT_PEER_OFF 0
#define DHT_PEER_INIT 1
#define DHT_PEER_SEARCH 2
#define DHT_PEER_FOUND 3
/* for DHT peer STATE (ownEntry) */
#define DHT_PEER_ADDR_KNOWN 4
#define DHT_PEER_PUBLISHED 5
/* Interface with Real DHT Implementation */
#define DHT_MODE_SEARCH 1
#define DHT_MODE_PUBLISH 1
#define DHT_MODE_NOTIFY 2
#define DHT_MODE_BOOTSTRAP 3
/* TIMEOUTS: Reference Values are set here... */
#define DHT_SEARCH_PERIOD 1800 /* PeerKeys: if we haven't found them: 30 min */
#define DHT_CHECK_PERIOD 1800 /* PeerKeys: re-lookup peer: 30 min */
#define DHT_PUBLISH_PERIOD 1800 /* OwnKey: 30 min */
#define DHT_NOTIFY_PERIOD 300 /* 5 min - Notify Check period */
/* TTLs for DHTs posts */
#define DHT_TTL_PUBLISH (DHT_PUBLISH_PERIOD + 120) // for a little overlap.
#define DHT_TTL_NOTIFY (DHT_NOTIFY_PERIOD + 60) // for time to find it...
#define DHT_TTL_BOOTSTRAP (DHT_PUBLISH_PERIOD) // To start with.
class dhtPeerEntry
{
public:
dhtPeerEntry();
RsPeerId id;
uint32_t state;
rstime_t lastTS;
uint32_t notifyPending;
rstime_t notifyTS;
struct sockaddr_in laddr, raddr;
uint32_t type; /* ADDR_TYPE as defined above */
std::string hash1; /* SHA1 Hash of id */
std::string hash2; /* SHA1 Hash of reverse Id */
};
class p3DhtMgr: public pqiNetAssistConnect, public RsThread
{
/*
*/
public:
p3DhtMgr(RsPeerId id, pqiConnectCb *cb);
/********** External DHT Interface ************************
* These Functions are the external interface
* for the DHT, and must be non-blocking and return quickly
*/
/* OVERLOADED From pqiNetAssistConnect. */
virtual void enable(bool on);
virtual void shutdown();
virtual void restart();
virtual bool getEnabled(); /* on */
virtual bool getActive(); /* actually working */
virtual void setBootstrapAllowed(bool on);
virtual bool getBootstrapAllowed();
/* set key data */
virtual bool setExternalInterface(struct sockaddr_in laddr,
struct sockaddr_in raddr, uint32_t type);
/* add / remove peers */
virtual bool findPeer(const RsPeerId& id);
virtual bool dropPeer(const RsPeerId& id);
/* post DHT key saying we should connect (callback when done) */
virtual bool notifyPeer(const RsPeerId& id);
/* extract current peer status */
virtual bool getPeerStatus(const RsPeerId& id,
struct sockaddr_storage &laddr, struct sockaddr_storage &raddr,
uint32_t &type, uint32_t &mode);
/* stun */
virtual bool enableStun(bool on);
virtual bool addStun(std::string id);
//doneStun();
/********** Higher Level DHT Work Functions ************************
* These functions translate from the strings/addresss to
* key/value pairs.
*/
public:
/* results from DHT proper */
virtual bool dhtResultNotify(std::string id);
virtual bool dhtResultSearch(std::string id,
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
uint32_t type, std::string sign);
virtual bool dhtResultBootstrap(std::string idhash);
protected:
/* can block briefly (called only from thread) */
virtual bool dhtPublish(std::string idhash,
struct sockaddr_in &laddr,
struct sockaddr_in &raddr,
uint32_t type, std::string sign);
virtual bool dhtNotify(std::string idhash, std::string ownIdHash,
std::string sign);
virtual bool dhtSearch(std::string idhash, uint32_t mode);
virtual bool dhtBootstrap(std::string idhash, std::string ownIdHash,
std::string sign); /* to publish bootstrap */
/********** Actual DHT Work Functions ************************
* These involve a very simple LOW-LEVEL interface ...
*
* publish
* search
* result
*
*/
public:
/* Feedback callback (handled here) */
virtual bool resultDHT(std::string key, std::string value);
protected:
virtual bool dhtInit();
virtual bool dhtShutdown();
virtual bool dhtActive();
virtual int status(std::ostream &out);
virtual bool publishDHT(std::string key, std::string value, uint32_t ttl);
virtual bool searchDHT(std::string key);
/********** Internal DHT Threading ************************
*
*/
public:
virtual void run();
private:
/* search scheduling */
void checkDHTStatus();
int checkStunState();
int checkStunState_Active(); /* when in active state */
int doStun();
int checkPeerDHTKeys();
int checkOwnDHTKeys();
int checkNotifyDHT();
void clearDhtData();
/* IP Bootstrap */
bool getDhtBootstrapList();
std::string BootstrapId(uint32_t bin);
std::string randomBootstrapId();
/* other feedback through callback */
// use pqiNetAssistConnect.. version pqiConnectCb *connCb;
/* protected by Mutex */
RsMutex dhtMtx;
bool mDhtOn; /* User desired state */
bool mDhtModifications; /* any user requests? */
dhtPeerEntry ownEntry;
rstime_t ownNotifyTS;
std::map<RsPeerId, dhtPeerEntry> peers;
std::list<std::string> stunIds;
bool mStunRequired;
uint32_t mDhtState;
rstime_t mDhtActiveTS;
bool mBootstrapAllowed;
rstime_t mLastBootstrapListTS;
};
#endif // MRK_P3_DHT_MANAGER_HEADER

View File

@ -28,7 +28,6 @@
#include "rsserver/p3face.h"
#include "pqi/authssl.h"
#include "pqi/p3dhtmgr.h" // Only need it for constants.
#include "tcponudp/tou.h"
#include "util/extaddrfinder.h"
#include "util/dnsresolver.h"

View File

@ -79,16 +79,12 @@ const uint32_t MAX_UPNP_COMPLETE = 600; /* 10 min... seems to take a while */
// #define NETMGR_DEBUG_TICK 1
// #define NETMGR_DEBUG_STATEBOX 1
pqiNetStatus::pqiNetStatus()
:mLocalAddrOk(false), mExtAddrOk(false), mExtAddrStableOk(false),
mUpnpOk(false), mDhtOk(false), mResetReq(false)
pqiNetStatus::pqiNetStatus() :
mExtAddrOk(false), mExtAddrStableOk(false), mUpnpOk(false), mDhtOk(false),
mDhtNetworkSize(0), mDhtRsNetworkSize(0), mResetReq(false)
{
mDhtNetworkSize = 0;
mDhtRsNetworkSize = 0;
sockaddr_storage_clear(mLocalAddr);
sockaddr_storage_clear(mExtAddr);
return;
}
@ -96,7 +92,6 @@ pqiNetStatus::pqiNetStatus()
void pqiNetStatus::print(std::ostream &out)
{
out << "pqiNetStatus: ";
out << "mLocalAddrOk: " << mLocalAddrOk;
out << " mExtAddrOk: " << mExtAddrOk;
out << " mExtAddrStableOk: " << mExtAddrStableOk;
out << std::endl;
@ -108,14 +103,13 @@ void pqiNetStatus::print(std::ostream &out)
out << std::endl;
out << "mLocalAddr: " << sockaddr_storage_tostring(mLocalAddr) << " ";
out << "mExtAddr: " << sockaddr_storage_tostring(mExtAddr) << " ";
out << " NetOk: " << NetOk();
out << std::endl;
}
p3NetMgrIMPL::p3NetMgrIMPL()
:mPeerMgr(NULL), mLinkMgr(NULL), mNetMtx("p3NetMgr"),
mNetStatus(RS_NET_UNKNOWN), mStatusChanged(false)
p3NetMgrIMPL::p3NetMgrIMPL() : mPeerMgr(nullptr), mLinkMgr(nullptr),
mNetMtx("p3NetMgr"), mNetStatus(RS_NET_UNKNOWN), mStatusChanged(false),
mDoNotNetCheckUntilTs(0)
{
{
@ -130,7 +124,6 @@ p3NetMgrIMPL::p3NetMgrIMPL()
mNetFlags = pqiNetStatus();
mOldNetFlags = pqiNetStatus();
mLastSlowTickTime = 0;
mOldNatType = RSNET_NATTYPE_UNKNOWN;
mOldNatHole = RSNET_NATHOLE_UNKNOWN;
sockaddr_storage_clear(mLocalAddr);
@ -415,47 +408,37 @@ void p3NetMgrIMPL::netStartup()
void p3NetMgrIMPL::tick()
{
rstime_t now = time(NULL);
bool doSlowTick = false;
{
RsStackMutex stack(mNetMtx); /************** LOCK MUTEX ***************/
if (now > mLastSlowTickTime)
{
mLastSlowTickTime = now;
doSlowTick = true;
}
}
rstime_t now = time(nullptr);
rstime_t dontCheckNetUntil;
{ RS_STACK_MUTEX(mNetMtx); dontCheckNetUntil = mDoNotNetCheckUntilTs; }
if (doSlowTick)
{
slowTick();
}
}
if(now >= dontCheckNetUntil) netStatusTick();
void p3NetMgrIMPL::slowTick()
uint32_t netStatus; { RS_STACK_MUTEX(mNetMtx); netStatus = mNetStatus; }
switch (netStatus)
{
netTick();
case RS_NET_LOOPBACK:
if(dontCheckNetUntil <= now)
{
RS_STACK_MUTEX(mNetMtx);
mDoNotNetCheckUntilTs = now + 30;
}
break;
default:
netAssistTick();
updateNetStateBox_temporal();
#ifdef RS_USE_DHT_STUNNER
if (mDhtStunner)
{
mDhtStunner->tick();
}
if (mProxyStunner)
{
mProxyStunner->tick();
}
if (mDhtStunner) mDhtStunner->tick();
if (mProxyStunner) mProxyStunner->tick();
#endif // RS_USE_DHT_STUNNER
break;
}
}
#define STARTUP_DELAY 5
void p3NetMgrIMPL::netTick()
void p3NetMgrIMPL::netStatusTick()
{
#ifdef NETMGR_DEBUG_TICK
@ -986,10 +969,9 @@ bool p3NetMgrIMPL::checkNetAddress()
if (mNetMode & RS_NET_MODE_TRY_LOOPBACK)
{
#if defined(NETMGR_DEBUG_TICK) || defined(NETMGR_DEBUG_RESET)
std::cerr << "p3NetMgrIMPL::checkNetAddress() LOOPBACK ... forcing to 127.0.0.1";
std::cerr << std::endl;
#endif
RsInfo() << __PRETTY_FUNCTION__ <<" network mode set to LOOPBACK,"
<< " forcing address to 127.0.0.1" << std::endl;
sockaddr_storage_ipv4_aton(prefAddr, "127.0.0.1");
validAddr = true;
}
@ -1034,137 +1016,77 @@ bool p3NetMgrIMPL::checkNetAddress()
break;
}
}
/* If no satisfactory local address has been found yet relax and
* accept also loopback addresses */
if(!validAddr) for (auto it = addrs.begin(); it!=addrs.end(); ++it)
{
sockaddr_storage& addr(*it);
if( sockaddr_storage_isValidNet(addr) &&
sockaddr_storage_ipv6_to_ipv4(addr) )
{
prefAddr = addr;
validAddr = true;
break;
}
}
}
}
if (!validAddr)
{
Dbg3() << __PRETTY_FUNCTION__ << " no valid local network address found"
<< std::endl;
RsErr() << __PRETTY_FUNCTION__ << " no valid local network address "
<<" found. Report to developers." << std::endl;
print_stacktrace();
return false;
}
/* check addresses */
{
RS_STACK_MUTEX(mNetMtx);
{ RS_STACK_MUTEX(mNetMtx);
sockaddr_storage_copy(mLocalAddr, oldAddr);
addrChanged = !sockaddr_storage_sameip(prefAddr, mLocalAddr);
#ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgrIMPL::checkNetAddress()";
std::cerr << std::endl;
std::cerr << "Current Local: " << sockaddr_storage_tostring(mLocalAddr);
std::cerr << std::endl;
std::cerr << "Current Preferred: " << sockaddr_storage_iptostring(prefAddr);
std::cerr << std::endl;
#endif
#ifdef NETMGR_DEBUG_RESET
if (addrChanged)
{
std::cerr << "p3NetMgrIMPL::checkNetAddress() Address Changed!";
std::cerr << std::endl;
std::cerr << "Current Local: " << sockaddr_storage_tostring(mLocalAddr);
std::cerr << std::endl;
std::cerr << "Current Preferred: " << sockaddr_storage_iptostring(prefAddr);
std::cerr << std::endl;
}
#endif
// update address.
sockaddr_storage_copyip(mLocalAddr, prefAddr);
sockaddr_storage_copy(mLocalAddr, mNetFlags.mLocalAddr);
if(sockaddr_storage_isLoopbackNet(mLocalAddr))
{
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgrIMPL::checkNetAddress() laddr: Loopback" << std::endl;
#endif
mNetFlags.mLocalAddrOk = false;
mNetStatus = RS_NET_LOOPBACK;
}
else if (!sockaddr_storage_isValidNet(mLocalAddr))
{
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgrIMPL::checkNetAddress() laddr: invalid" << std::endl;
#endif
mNetFlags.mLocalAddrOk = false;
}
else
{
#ifdef NETMGR_DEBUG_TICK
std::cerr << "p3NetMgrIMPL::checkNetAddress() laddr okay" << std::endl;
#endif
mNetFlags.mLocalAddrOk = true;
}
int port = sockaddr_storage_port(mLocalAddr);
if ((port < PQI_MIN_PORT) || (port > PQI_MAX_PORT))
// Check if local port is valid, reset it if not
if (!sockaddr_storage_port(mLocalAddr))
{
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgrIMPL::checkNetAddress() Correcting Port to DEFAULT" << std::endl;
#endif
uint16_t new_port = htons(PQI_MIN_PORT_RNG + (RSRandom::random_u32() % (PQI_MAX_PORT - PQI_MIN_PORT_RNG)));
sockaddr_storage_setport(mLocalAddr, new_port);
/* Using same port as external may make some NAT happier */
uint16_t port = sockaddr_storage_port(mExtAddr);
/* Avoid to automatically set a local port to a reserved one < 1024
* that needs special permissions or root access.
* This do not impede the user to set a reserved port manually,
* which make sense in some cases. */
while (port < 1025)
port = static_cast<uint16_t>(RsRandom::random_u32());
sockaddr_storage_setport(mLocalAddr, htons(port));
addrChanged = true;
RsWarn() << __PRETTY_FUNCTION__ << " local port was 0, corrected "
<<"to: " << port << std::endl;
}
#if DEAD_CODE
/* Enabling this piece of code breaks setup where an additional BOFH
* overlooked port like 80 or 443 is manually forwarded to RetroShare to
* avoid restrictive firewals.
* In the case of a real mismatch, it is not really problematic, as our
* peers would get and then attempt to connect also to the right port.
*/
/* if localaddr == serveraddr, then ensure that the ports
* are the same (modify server)... this mismatch can
* occur when the local port is changed....
*/
if ( sockaddr_storage_sameip(mLocalAddr, mExtAddr)
&& sockaddr_storage_port(mLocalAddr) != sockaddr_storage_port(mExtAddr) )
{
#ifdef NETMGR_DEBUG_RESET
std::cerr << __PRETTY_FUNCTION__ << " local and external ports are"
<< " not the same. Setting external port to "
<< sockaddr_storage_port(mLocalAddr) << std::endl;
#endif
sockaddr_storage_setport(mExtAddr, sockaddr_storage_port(mLocalAddr));
addrChanged = true;
}
#endif // DEAD_CODE
#ifdef NETMGR_DEBUG_TICK
std::cerr << __PRETTY_FUNCTION__ << " Final Local Address: "
<< sockaddr_storage_tostring(mLocalAddr) << std::endl;
#endif
}
} // RS_STACK_MUTEX(mNetMtx);
if (addrChanged)
{
#ifdef NETMGR_DEBUG_RESET
std::cerr << "p3NetMgrIMPL::checkNetAddress() local address changed, resetting network." << std::endl;
std::cerr << std::endl;
#endif
RsInfo() << __PRETTY_FUNCTION__ << " local address changed, resetting"
<<" network." << std::endl;
if (mPeerMgr)
{
mPeerMgr->UpdateOwnAddress(mLocalAddr, mExtAddr);
}
std::cerr << __PRETTY_FUNCTION__
<< " local address changed, resetting network" << std::endl;
if (mPeerMgr) mPeerMgr->UpdateOwnAddress(mLocalAddr, mExtAddr);
netReset();
}
return 1;
return true;
}
@ -2051,3 +1973,6 @@ void p3NetMgrIMPL::updateNetStateBox_reset()
}
p3NetMgr::~p3NetMgr() = default;
pqiNetAssist::~pqiNetAssist() = default;
pqiNetAssistPeerShare::~pqiNetAssistPeerShare() = default;
pqiNetAssistConnect::~pqiNetAssistConnect() = default;

View File

@ -44,13 +44,10 @@ class DNSResolver ;
class pqiNetStatus
struct pqiNetStatus
{
public:
pqiNetStatus();
bool mLocalAddrOk; // Local address is not loopback.
bool mExtAddrOk; // have external address.
bool mExtAddrStableOk; // stable external address.
bool mUpnpOk; // upnp is ok.
@ -65,11 +62,6 @@ class pqiNetStatus
bool mResetReq; // Not Used yet!.
void print(std::ostream &out);
bool NetOk() // minimum to believe network is okay.`
{
return (mLocalAddrOk && mExtAddrOk);
}
};
class p3PeerMgr;
@ -211,11 +203,6 @@ void addNetListener(pqiNetListener *listener);
// SHOULD MAKE THIS PROTECTED.
bool checkNetAddress(); /* check our address is sensible */
protected:
void slowTick();
protected:
/****************** Internal Interface *******************/
bool enableNetAssistFirewall(bool on);
@ -248,7 +235,7 @@ bool netAssistAttach(bool on);
void netReset();
void statusTick();
void netTick();
void netStatusTick();
void netStartup();
/* startup the bits */
@ -335,7 +322,7 @@ void netStatusReset_locked();
// Improved NetStatusBox, which uses the Stunners!
pqiNetStateBox mNetStateBox;
rstime_t mLastSlowTickTime;
rstime_t mDoNotNetCheckUntilTs;
uint32_t mOldNatType;
uint32_t mOldNatHole;

View File

@ -34,11 +34,6 @@
#include "pqi/p3historymgr.h"
#include "pqi/pqinetwork.h" // for getLocalAddresses
//#include "pqi/p3dhtmgr.h" // Only need it for constants.
//#include "tcponudp/tou.h"
//#include "util/extaddrfinder.h"
//#include "util/dnsresolver.h"
#include "util/rsprint.h"
#include "util/rsstring.h"
#include "util/rsdebug.h"

View File

@ -37,12 +37,6 @@ struct RSTrafficClue;
#include "serialiser/rsserial.h"
#include "retroshare/rstypes.h"
#define PQI_MIN_PORT 10 // TO ALLOW USERS TO HAVE PORT 80! - was 1024
#define PQI_MIN_PORT_RNG 1024
#define PQI_MAX_PORT 65535
#define PQI_DEFAULT_PORT 7812
int getPQIsearchId();
int fixme(char *str, int n);

View File

@ -19,8 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef MRK_PQI_ASSIST_H
#define MRK_PQI_ASSIST_H
#pragma once
#include <string>
#include <map>
@ -28,26 +27,16 @@
#include "pqi/pqinetwork.h"
#include "pqi/pqimonitor.h"
/**********
* This header file provides two interfaces for assisting
* the connections to friends.
*
* pqiNetAssistFirewall - which will provides interfaces
* to functionality like upnp and apple's equivalent.
*
* pqiNetAssistConnect - which will provides interfaces
* to other networks (DHT) etc that can provide information.
* These classes would be expected to use the pqiMonitor
* callback system to notify the connectionMgr.
*
***/
/**
* @file
* This header file provides interfaces for assisting the connections to
* friends.
*/
class pqiNetAssist
{
public:
virtual ~pqiNetAssist() { return; }
/* External Interface */
virtual void enable(bool on) = 0;
virtual void shutdown() = 0; /* blocking call */
@ -58,28 +47,24 @@ virtual bool getActive() = 0;
virtual int tick() { return 0; } /* for internal accounting */
virtual ~pqiNetAssist();
};
#define PFP_TYPE_UDP 0x0001
#define PFP_TYPE_TCP 0x0002
class PortForwardParams
struct PortForwardParams
{
public:
uint32_t fwdId;
uint32_t status;
uint32_t typeFlags;
struct sockaddr_storage intAddr;
struct sockaddr_storage extaddr;
sockaddr_storage intAddr;
sockaddr_storage extaddr;
};
/**
* Provides interfaces to functionality like upnp and apple's equivalent.
*/
class pqiNetAssistFirewall: public pqiNetAssist
{
public:
virtual ~pqiNetAssistFirewall() { return; }
/* the address that the listening port is on */
virtual void setInternalPort(unsigned short iport_in) = 0;
virtual void setExternalPort(unsigned short eport_in) = 0;
@ -103,10 +88,12 @@ virtual bool statusPortForward(const uint32_t fwdId, PortForwardParams &param
class pqiNetAssistPeerShare
{
public:
/** share Addresses for various reasons (bad peers, etc) */
virtual void updatePeer(
const RsPeerId& id, const struct sockaddr_storage &addr,
int type, int reason, int age ) = 0;
/* share Addresses for various reasons (bad peers, etc) */
virtual void updatePeer(const RsPeerId& id, const struct sockaddr_storage &addr, int type, int reason, int age) = 0;
virtual ~pqiNetAssistPeerShare();
};
@ -141,20 +128,22 @@ virtual int tick() = 0; /* for internal accounting */
#define NETASSIST_KNOWN_PEER_TYPE_MASK 0xff00
/**
* Provides interfaces to other networks like DHT that can provide information.
* These classes would be expected to use the pqiMonitor callback system to
* notify the connectionMgr.
*/
class pqiNetAssistConnect: public pqiNetAssist
{
/*
*/
public:
pqiNetAssistConnect(const RsPeerId& id, pqiConnectCb *cb)
:mPeerId(id), mConnCb(cb) { return; }
pqiNetAssistConnect(const RsPeerId& id, pqiConnectCb *cb) :
mPeerId(id), mConnCb(cb) {}
/********** External DHT Interface ************************
* These Functions are the external interface
* for the DHT, and must be non-blocking and return quickly
*/
/* add / remove peers */
virtual bool findPeer(const RsPeerId& id) = 0;
virtual bool dropPeer(const RsPeerId& id) = 0;
@ -175,11 +164,9 @@ virtual bool setAttachMode(bool on) = 0; // FIXUP.
/***** Stats for Network / DHT *****/
virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize) = 0; // DEPRECIATE.
~pqiNetAssistConnect() override;
protected:
RsPeerId mPeerId;
pqiConnectCb *mConnCb;
};
#endif /* MRK_PQI_ASSIST_H */

View File

@ -63,10 +63,6 @@ const uint32_t RS_STUN_FRIEND = 0x0020;
const uint32_t RS_STUN_FRIEND_OF_FRIEND = 0x0040;
// for the old p3dhtmgr - amazed it still compiles ;)
#define RS_CONNECT_PASSIVE 1
#define RS_CONNECT_ACTIVE 2
#define RS_CB_DHT 0x0001 /* from dht */
#define RS_CB_DISC 0x0002 /* from peers */
#define RS_CB_PERSON 0x0003 /* from connection */

View File

@ -206,11 +206,11 @@ struct RSTrafficClue : RsSerializable
struct RsConfigNetStatus : RsSerializable
{
RsConfigNetStatus()
RsConfigNetStatus() : netLocalOk(true)
{
localPort = extPort = 0 ;
firewalled = forwardPort = false ;
DHTActive = uPnPActive = netLocalOk = netUpnpOk = netDhtOk = netStunOk = netExtAddressOk = false ;
DHTActive = uPnPActive = netUpnpOk = netDhtOk = netStunOk = netExtAddressOk = false ;
uPnPState = 0 ;
//DHTPeers = 0 ;
netDhtNetSize = netDhtRsNetSize = 0;
@ -235,7 +235,8 @@ struct RsConfigNetStatus : RsSerializable
int uPnPState;
/* Flags for Network Status */
bool netLocalOk; /* That we've talked to someone! */
RS_DEPRECATED
bool netLocalOk; /// As of today it's meaningless
bool netUpnpOk; /* upnp is enabled and active */
bool netDhtOk; /* response from dht */
bool netStunOk; /* recvd stun / udp packets */

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* libretroshare/src/upnp: upnphandler_linux.cc *
* libretroshare/src/upnp: upnphandler_libupnp.cc *
* *
* libretroshare: retroshare core library *
* *
@ -28,7 +28,7 @@ extern "C" {
#endif
/* This stuff is actually C */
#include "rs_upnp/upnphandler_linux.h"
#include "rs_upnp/upnphandler_libupnp.h"
#include "util/rsnet.h"

View File

@ -1,5 +1,5 @@
/*******************************************************************************
* libretroshare/src/upnp: upnphandler_linux.h *
* libretroshare/src/upnp: upnphandler_libupnp.h *
* *
* libretroshare: retroshare core library *
* *
@ -19,8 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef _RS_UPNP_IFACE_H
#define _RS_UPNP_IFACE_H
#pragma once
#include <string.h>
@ -99,5 +98,3 @@ class upnphandler: public pqiNetAssistFirewall
/* info from upnp */
int CtrlPointCallbackEventHandler(Upnp_EventType ,void* , void*);
#endif /* _RS_UPNP_IFACE_H */

View File

@ -19,12 +19,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
//windows/osx (miniupnpc) implementation
#ifndef _RS_UPNP_IFACE_H
#define _RS_UPNP_IFACE_H
#pragma once
#include <string.h>
#include <string>
#include <map>
@ -127,5 +124,3 @@ bool checkUPnPActive();
std::list<upnpforward> activeForwards;
};
#endif /* _RS_UPNP_IFACE_H */

View File

@ -160,7 +160,6 @@ int p3ServerConfig::getConfigNetStatus(RsConfigNetStatus &status)
pqiNetStatus nstatus;
mNetMgr->getNetStatus(nstatus);
status.netLocalOk = nstatus.mLocalAddrOk;
status.netUpnpOk = nstatus.mUpnpOk;
status.netStunOk = false;
status.netExtAddressOk = nstatus.mExtAddrOk;

View File

@ -702,7 +702,7 @@ RsGRouter *rsGRouter = NULL ;
#include "util/rsrandom.h"
#ifdef RS_USE_LIBUPNP
# include "rs_upnp/upnphandler_linux.h"
# include "rs_upnp/upnphandler_libupnp.h"
#else // def RS_USE_LIBUPNP
# include "rs_upnp/upnphandler_miniupnp.h"
#endif // def RS_USE_LIBUPNP