2018-05-28 22:03:39 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/pqi: pqiipset.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2009-2010 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/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2010-07-04 10:15:56 +00:00
|
|
|
#ifndef PQI_IP_SET_H
|
|
|
|
#define PQI_IP_SET_H
|
|
|
|
|
|
|
|
#include "util/rsnet.h"
|
|
|
|
#include "serialiser/rstlvaddrs.h"
|
2018-10-07 01:34:05 +02:00
|
|
|
#include "util/rstime.h"
|
2010-07-04 10:15:56 +00:00
|
|
|
|
2018-02-22 15:38:20 +01:00
|
|
|
#define MAX_ADDRESS_LIST_SIZE 10
|
2010-07-04 10:15:56 +00:00
|
|
|
|
|
|
|
class pqiIpAddress
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool sameAddress(const pqiIpAddress &a) const;
|
|
|
|
bool validAddress() const;
|
|
|
|
|
2013-09-13 14:35:19 +00:00
|
|
|
struct sockaddr_storage mAddr;
|
2018-10-07 01:34:05 +02:00
|
|
|
rstime_t mSeenTime;
|
2010-07-04 10:15:56 +00:00
|
|
|
uint32_t mSrc;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class pqiIpAddrList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// returns true if new address added.
|
|
|
|
bool updateIpAddressList(const pqiIpAddress &addr);
|
2012-04-14 22:38:24 +00:00
|
|
|
void printIpAddressList(std::string &out) const;
|
2010-07-04 10:15:56 +00:00
|
|
|
void extractFromTlv(const RsTlvIpAddrSet &tlvAddrs);
|
2013-09-28 08:09:59 +00:00
|
|
|
void loadTlv(RsTlvIpAddrSet &tlvAddrs) const;
|
2010-07-04 10:15:56 +00:00
|
|
|
|
|
|
|
// sorted list... based on seen time.
|
|
|
|
std::list<pqiIpAddress> mAddrs;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class pqiIpAddrSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool updateLocalAddrs(const pqiIpAddress &addr);
|
|
|
|
bool updateExtAddrs(const pqiIpAddress &addr);
|
|
|
|
bool updateAddrs(const pqiIpAddrSet &addrs);
|
2012-04-14 22:38:24 +00:00
|
|
|
void printAddrs(std::string &out) const;
|
2010-07-04 10:15:56 +00:00
|
|
|
pqiIpAddrList mLocal;
|
|
|
|
pqiIpAddrList mExt;
|
2018-01-03 18:37:43 +01:00
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
mLocal.mAddrs.clear();
|
|
|
|
mExt.mAddrs.clear();
|
|
|
|
}
|
2010-07-04 10:15:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|