2018-05-28 16:03:39 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/pqi: pqinetstatebox.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2018 Retroshare Team <retroshare.team@gmail.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/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2011-07-09 20:41:39 -04:00
|
|
|
#ifndef PQI_NET_STATUS_BOX_H
|
|
|
|
#define PQI_NET_STATUS_BOX_H
|
|
|
|
|
|
|
|
/* a little state box to determine network status */
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
/*** Network state
|
|
|
|
* Want this to be all encompassing.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class pqiNetStateBox
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pqiNetStateBox();
|
|
|
|
|
2011-07-12 10:16:46 -04:00
|
|
|
void reset();
|
|
|
|
|
2011-07-09 20:41:39 -04:00
|
|
|
/* input network bits */
|
2013-09-13 10:35:19 -04:00
|
|
|
void setAddressStunDht(const struct sockaddr_storage &addr, bool stable);
|
|
|
|
void setAddressStunProxy(const struct sockaddr_storage &addr, bool stable);
|
2011-07-09 20:41:39 -04:00
|
|
|
|
2013-09-13 10:35:19 -04:00
|
|
|
void setAddressUPnP(bool active, const struct sockaddr_storage &addr);
|
|
|
|
void setAddressNatPMP(bool active, const struct sockaddr_storage &addr);
|
|
|
|
void setAddressWebIP(bool active, const struct sockaddr_storage &addr);
|
2011-07-09 20:41:39 -04:00
|
|
|
|
2011-07-30 12:57:40 -04:00
|
|
|
void setPortForwarded(bool active, uint16_t port);
|
|
|
|
|
2011-07-09 20:41:39 -04:00
|
|
|
void setDhtState(bool dhtOn, bool dhtActive);
|
|
|
|
|
|
|
|
uint32_t getNetStateMode();
|
|
|
|
uint32_t getNetworkMode();
|
|
|
|
uint32_t getNatTypeMode();
|
|
|
|
uint32_t getNatHoleMode();
|
|
|
|
uint32_t getConnectModes();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/* calculate network state */
|
|
|
|
void clearOldNetworkData();
|
|
|
|
void determineNetworkState();
|
|
|
|
int statusOkay();
|
|
|
|
int updateNetState();
|
|
|
|
|
|
|
|
/* more internal fns */
|
|
|
|
void workoutNetworkMode();
|
|
|
|
|
|
|
|
bool mStatusOkay;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mStatusTS;
|
2011-07-09 20:41:39 -04:00
|
|
|
|
|
|
|
uint32_t mNetworkMode;
|
|
|
|
uint32_t mNatTypeMode;
|
|
|
|
uint32_t mNatHoleMode;
|
|
|
|
uint32_t mConnectModes;
|
|
|
|
uint32_t mNetStateMode;
|
|
|
|
|
|
|
|
/* Parameters set externally */
|
|
|
|
|
|
|
|
bool mStunDhtSet;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mStunDhtTS;
|
2011-07-09 20:41:39 -04:00
|
|
|
bool mStunDhtStable;
|
2013-09-13 10:35:19 -04:00
|
|
|
struct sockaddr_storage mStunDhtAddr;
|
2011-07-09 20:41:39 -04:00
|
|
|
|
|
|
|
bool mStunProxySet;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mStunProxyTS;
|
2011-07-09 20:41:39 -04:00
|
|
|
bool mStunProxyStable;
|
2011-07-13 07:41:25 -04:00
|
|
|
bool mStunProxySemiStable;
|
2013-09-13 10:35:19 -04:00
|
|
|
struct sockaddr_storage mStunProxyAddr;
|
2011-07-09 20:41:39 -04:00
|
|
|
|
|
|
|
bool mDhtSet;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mDhtTS;
|
2011-07-09 20:41:39 -04:00
|
|
|
bool mDhtOn;
|
|
|
|
bool mDhtActive;
|
|
|
|
|
|
|
|
bool mUPnPSet;
|
2013-09-13 10:35:19 -04:00
|
|
|
struct sockaddr_storage mUPnPAddr;
|
2011-07-09 20:41:39 -04:00
|
|
|
bool mUPnPActive;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mUPnPTS;
|
2011-07-09 20:41:39 -04:00
|
|
|
|
|
|
|
bool mNatPMPSet;
|
2013-09-13 10:35:19 -04:00
|
|
|
struct sockaddr_storage mNatPMPAddr;
|
2011-07-09 20:41:39 -04:00
|
|
|
bool mNatPMPActive;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mNatPMPTS;
|
2011-07-09 20:41:39 -04:00
|
|
|
|
|
|
|
bool mWebIPSet;
|
2013-09-13 10:35:19 -04:00
|
|
|
struct sockaddr_storage mWebIPAddr;
|
2011-07-09 20:41:39 -04:00
|
|
|
bool mWebIPActive;
|
2018-10-06 19:34:05 -04:00
|
|
|
rstime_t mWebIPTS;
|
2011-07-09 20:41:39 -04:00
|
|
|
|
2011-07-30 12:57:40 -04:00
|
|
|
bool mPortForwardSet;
|
2011-07-09 20:41:39 -04:00
|
|
|
uint16_t mPortForwarded;
|
|
|
|
};
|
|
|
|
|
2011-07-12 10:16:46 -04:00
|
|
|
|
|
|
|
|
|
|
|
std::string NetStateNetStateString(uint32_t netstate);
|
|
|
|
std::string NetStateConnectModesString(uint32_t connect);
|
|
|
|
std::string NetStateNatHoleString(uint32_t natHole);
|
|
|
|
std::string NetStateNatTypeString(uint32_t natType);
|
|
|
|
std::string NetStateNetworkModeString(uint32_t netMode);
|
|
|
|
|
|
|
|
|
2011-07-09 20:41:39 -04:00
|
|
|
#endif
|