add missing namespaces

This commit is contained in:
chelovechishko 2018-07-06 23:55:12 +09:00
parent 39c88ea247
commit b3dddeafdf
7 changed files with 133 additions and 118 deletions

View File

@ -89,11 +89,11 @@ static const std::string kConfigKeyProxyServerIpAddrTor = "PROXY_SERVER_IPADDR";
static const std::string kConfigKeyProxyServerPortTor = "PROXY_SERVER_PORT";
static const std::string kConfigKeyProxyServerIpAddrI2P = "PROXY_SERVER_IPADDR_I2P";
static const std::string kConfigKeyProxyServerPortI2P = "PROXY_SERVER_PORT_I2P";
void printConnectState(std::ostream &out, peerState &peer);
peerState::peerState()
:netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0),
:netMode(RS_NET_MODE_UNKNOWN), vs_disc(RS_VS_DISC_FULL), vs_dht(RS_VS_DHT_FULL), lastcontact(0),
hiddenNode(false), hiddenPort(0), hiddenType(RS_HIDDEN_TYPE_NONE)
{
sockaddr_storage_clear(localaddr);
@ -107,13 +107,13 @@ std::string textPeerConnectState(peerState &state)
std::string out = "Id: " + state.id.toStdString() + "\n";
rs_sprintf_append(out, "NetMode: %lu\n", state.netMode);
rs_sprintf_append(out, "VisState: Disc: %u Dht: %u\n", state.vs_disc, state.vs_dht);
out += "laddr: ";
out += sockaddr_storage_tostring(state.localaddr);
out += "\neaddr: ";
out += sockaddr_storage_tostring(state.serveraddr);
out += "\n";
return out;
}
@ -136,7 +136,7 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
mOwnState.netMode = RS_NET_MODE_UPNP; // Default to UPNP.
mOwnState.vs_disc = RS_VS_DISC_FULL;
mOwnState.vs_dht = RS_VS_DHT_FULL;
// setup default ProxyServerAddress.
// Tor
sockaddr_storage_clear(mProxyServerAddressTor);
@ -154,7 +154,7 @@ p3PeerMgrIMPL::p3PeerMgrIMPL(const RsPeerId& ssl_own_id, const RsPgpId& gpg_own_
mProxyServerStatusTor = RS_NET_PROXY_STATUS_UNKNOWN ;
mProxyServerStatusI2P = RS_NET_PROXY_STATUS_UNKNOWN;
}
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgr() Startup" << std::endl;
#endif
@ -222,8 +222,8 @@ bool p3PeerMgrIMPL::forceHiddenNode()
struct sockaddr_storage loopback;
sockaddr_storage_clear(loopback);
sockaddr_storage_ipv4_aton(loopback, "127.0.0.1");
uint16_t port = sockaddr_storage_port(mOwnState.localaddr);
sockaddr_storage_ipv4_setport(loopback, port);
uint16_t port = sockaddr_storage_port(mOwnState.localaddr);
sockaddr_storage_ipv4_setport(loopback, port);
setLocalAddress(AuthSSL::getAuthSSL()->OwnId(), loopback);
@ -254,7 +254,7 @@ bool p3PeerMgrIMPL::setOwnNetworkMode(uint32_t netMode)
changed = true;
}
}
// Pass on Flags to NetMgr.
mNetMgr->setNetworkMode((netMode & RS_NET_MODE_ACTUAL));
return changed;
@ -267,7 +267,7 @@ bool p3PeerMgrIMPL::setOwnVisState(uint16_t vs_disc, uint16_t vs_dht)
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
std::string out;
rs_sprintf(out, "p3PeerMgr::setOwnVisState() Existing vis: %u/%u Input vis: %u/%u",
rs_sprintf(out, "p3PeerMgr::setOwnVisState() Existing vis: %u/%u Input vis: %u/%u",
mOwnState.vs_disc, mOwnState.vs_dht, vs_disc, vs_dht);
rslog(RSL_WARNING, p3peermgrzone, out);
@ -275,7 +275,7 @@ bool p3PeerMgrIMPL::setOwnVisState(uint16_t vs_disc, uint16_t vs_dht)
std::cerr << out.c_str() << std::endl;
#endif
if (mOwnState.vs_disc != vs_disc || mOwnState.vs_dht != vs_dht)
if (mOwnState.vs_disc != vs_disc || mOwnState.vs_dht != vs_dht)
{
mOwnState.vs_disc = vs_disc;
mOwnState.vs_dht = vs_dht;
@ -283,7 +283,7 @@ bool p3PeerMgrIMPL::setOwnVisState(uint16_t vs_disc, uint16_t vs_dht)
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
}
}
// Pass on Flags to NetMgr.
mNetMgr->setVisState(vs_disc, vs_dht);
@ -575,7 +575,7 @@ bool p3PeerMgrIMPL::setHiddenDomainPort(const RsPeerId &ssl_id, const std::strin
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
if (ssl_id == AuthSSL::getAuthSSL()->OwnId())
if (ssl_id == AuthSSL::getAuthSSL()->OwnId())
{
mOwnState.hiddenNode = true;
mOwnState.hiddenDomain = domain;
@ -917,7 +917,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
if (id == AuthSSL::getAuthSSL()->OwnId())
if (id == AuthSSL::getAuthSSL()->OwnId())
{
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::addFriend() cannot add own id as a friend." << std::endl;
@ -973,7 +973,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
/* setup connectivity parameters */
it->second.vs_disc = vs_disc;
it->second.vs_dht = vs_dht;
it->second.netMode = netMode;
it->second.lastcontact = lastContact;
@ -995,7 +995,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
pstate.id = id;
pstate.gpg_id = gpg_id;
pstate.name = AuthGPG::getAuthGPG()->getGPGName(gpg_id);
pstate.vs_disc = vs_disc;
pstate.vs_dht = vs_dht;
pstate.netMode = netMode;
@ -1018,7 +1018,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
mLinkMgr->addFriend(id, vs_dht != RS_VS_DHT_OFF);
}
service_flags &= servicePermissionFlags(gpg_id) ; // Always reduce the permissions.
service_flags &= servicePermissionFlags(gpg_id) ; // Always reduce the permissions.
#ifdef RS_CHATSERVER //Defined by chatserver
setServicePermissionFlags(gpg_id,RS_NODE_PERM_NONE) ;
#else
@ -1029,7 +1029,7 @@ bool p3PeerMgrIMPL::addFriend(const RsPeerId& input_id, const RsPgpId& input_gpg
printPeerLists(std::cerr);
mLinkMgr->printPeerLists(std::cerr);
#endif
return true;
}
@ -1071,10 +1071,10 @@ bool p3PeerMgrIMPL::removeFriend(const RsPgpId &id)
}
for(std::list<RsPeerId>::iterator rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); ++rit)
if (mFriendList.end() != (it = mFriendList.find(*rit)))
if (mFriendList.end() != (it = mFriendList.find(*rit)))
mFriendList.erase(it);
std::map<RsPgpId,ServicePermissionFlags>::iterator it2 = mFriendsPermissionFlags.find(id) ;
std::map<RsPgpId,ServicePermissionFlags>::iterator it2 = mFriendsPermissionFlags.find(id) ;
if(it2 != mFriendsPermissionFlags.end())
mFriendsPermissionFlags.erase(it2);
@ -1146,13 +1146,13 @@ bool p3PeerMgrIMPL::removeFriend(const RsPeerId &id, bool removePgpId)
}
for(std::list<RsPeerId>::iterator rit = sslid_toRemove.begin(); rit != sslid_toRemove.end(); ++rit)
if (mFriendList.end() != (it = mFriendList.find(*rit)))
if (mFriendList.end() != (it = mFriendList.find(*rit)))
mFriendList.erase(it);
std::map<RsPgpId,ServicePermissionFlags>::iterator it2 ;
for(std::list<RsPgpId>::iterator rit = pgpid_toRemove.begin(); rit != pgpid_toRemove.end(); ++rit)
if (mFriendsPermissionFlags.end() != (it2 = mFriendsPermissionFlags.find(*rit)))
if (mFriendsPermissionFlags.end() != (it2 = mFriendsPermissionFlags.find(*rit)))
mFriendsPermissionFlags.erase(it2);
#ifdef PEER_DEBUG
@ -1432,7 +1432,7 @@ bool p3PeerMgrIMPL::setLocalAddress( const RsPeerId &id,
if (changed)
{
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
mNetMgr->setLocalAddress(addr);
mLinkMgr->setLocalAddress(addr);
}
@ -1499,9 +1499,9 @@ bool p3PeerMgrIMPL::setExtAddress( const RsPeerId &id,
changed = true;
}
}
mNetMgr->setExtAddress(addr);
return changed;
}
@ -1584,12 +1584,16 @@ bool p3PeerMgrIMPL::setDynDNS(const RsPeerId &id, const std::string &dyndns)
return changed;
}
namespace pqi {
struct ZeroedInt
{
ZeroedInt() { n=0 ;}
int n ;
};
}
bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, const sockaddr_storage &addr)
{
// The algorithm is the following:
@ -1617,10 +1621,10 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons
// Update a list of own IPs:
// - remove old values for that same peer
// - remove values for non connected peers
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
mReportedOwnAddresses[from] = addr_filtered ;
for(std::map<RsPeerId,sockaddr_storage>::iterator it(mReportedOwnAddresses.begin());it!=mReportedOwnAddresses.end();)
@ -1641,8 +1645,8 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons
std::cerr << "p3PeerMgr:: Current external address is calculated to be: " << sockaddr_storage_iptostring(current_best_ext_address_guess) << " (simultaneously reported by " << count << " peers)." << std::endl;
}
// now current
// now current
sockaddr_storage own_addr ;
@ -1665,7 +1669,7 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons
RsServer::notify()->AddFeedItem(RS_FEED_ITEM_SEC_IP_WRONG_EXTERNAL_IP_REPORTED, from.toStdString(), sockaddr_storage_iptostring(own_addr), sockaddr_storage_iptostring(addr));
}
// we could also sweep over all connected friends and see if some report a different address.
return true ;
@ -1673,46 +1677,46 @@ bool p3PeerMgrIMPL::addCandidateForOwnExternalAddress(const RsPeerId &from, cons
bool p3PeerMgrIMPL::locked_computeCurrentBestOwnExtAddressCandidate(sockaddr_storage& addr, uint32_t& count)
{
std::map<sockaddr_storage,ZeroedInt> addr_counts ;
std::map<sockaddr_storage, pqi::ZeroedInt> addr_counts ;
for(std::map<RsPeerId,sockaddr_storage>::iterator it(mReportedOwnAddresses.begin());it!=mReportedOwnAddresses.end();++it)
++addr_counts[it->second].n ;
#ifdef PEER_DEBUG
std::cerr << "Current ext addr statistics:" << std::endl;
#endif
count = 0 ;
for(std::map<sockaddr_storage,ZeroedInt>::const_iterator it(addr_counts.begin());it!=addr_counts.end();++it)
for(std::map<sockaddr_storage, pqi::ZeroedInt>::const_iterator it(addr_counts.begin());it!=addr_counts.end();++it)
{
if(uint32_t(it->second.n) > count)
{
addr = it->first ;
count = it->second.n ;
}
#ifdef PEER_DEBUG
std::cerr << sockaddr_storage_iptostring(it->first) << " : " << it->second.n << std::endl;
#endif
}
return true ;
}
bool p3PeerMgrIMPL::getExtAddressReportedByFriends(sockaddr_storage &addr, uint8_t& /*isstable*/)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
uint32_t count ;
locked_computeCurrentBestOwnExtAddressCandidate(addr,count) ;
#ifdef PEER_DEBUG
std::cerr << "Estimation count = " << count << ". Trusted? = " << (count>=2) << std::endl;
#endif
return count >= 2 ;// 2 is not conservative enough. 3 should be probably better.
return count >= 2 ;// 2 is not conservative enough. 3 should be probably better.
}
static bool cleanIpList(std::list<pqiIpAddress>& lst,const RsPeerId& pid,p3LinkMgr *link_mgr)
@ -1765,7 +1769,7 @@ bool p3PeerMgrIMPL::updateAddressList(const RsPeerId& id, const pqiIpAddrSet
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* check if it is our own ip */
if (id == getOwnId())
if (id == getOwnId())
{
mOwnState.ipAddrs.updateAddrs(clean_set);
return true;
@ -1811,11 +1815,11 @@ bool p3PeerMgrIMPL::updateCurrentAddress(const RsPeerId& id, const pqiIpAddre
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::updateCurrentAddress() called for id : " << id << std::endl;
#endif
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* cannot be own id */
/* check if it is a friend */
std::map<RsPeerId, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
@ -1846,23 +1850,23 @@ bool p3PeerMgrIMPL::updateCurrentAddress(const RsPeerId& id, const pqiIpAddre
std::cerr << addrstr;
std::cerr << std::endl;
#endif
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
bool p3PeerMgrIMPL::updateLastContact(const RsPeerId& id)
{
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::updateLastContact() called for id : " << id << std::endl;
#endif
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
/* cannot be own id */
/* check if it is a friend */
std::map<RsPeerId, peerState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
@ -1877,7 +1881,7 @@ bool p3PeerMgrIMPL::updateLastContact(const RsPeerId& id)
it->second.lastcontact = time(NULL);
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
}
@ -2061,7 +2065,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
getProxyServerAddress(RS_HIDDEN_TYPE_TOR, proxy_addr_tor);
getProxyServerAddress(RS_HIDDEN_TYPE_I2P, proxy_addr_i2p);
mPeerMtx.lock(); /****** MUTEX LOCKED *******/
mPeerMtx.lock(); /****** MUTEX LOCKED *******/
RsPeerNetItem *item = new RsPeerNetItem();
item->clear();
@ -2088,14 +2092,14 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
item->vs_disc = mOwnState.vs_disc;
item->vs_dht = mOwnState.vs_dht;
item->lastContact = mOwnState.lastcontact;
item->localAddrV4.addr = mOwnState.localaddr;
item->extAddrV4.addr = mOwnState.serveraddr;
sockaddr_storage_clear(item->localAddrV6.addr);
sockaddr_storage_clear(item->extAddrV6.addr);
item->dyndns = mOwnState.dyndns;
mOwnState.ipAddrs.mLocal.loadTlv(item->localAddrList);
mOwnState.ipAddrs.mExt.loadTlv(item->extAddrList);
@ -2125,20 +2129,20 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
item->vs_dht = (it->second).vs_dht;
item->lastContact = (it->second).lastcontact;
item->localAddrV4.addr = (it->second).localaddr;
item->extAddrV4.addr = (it->second).serveraddr;
sockaddr_storage_clear(item->localAddrV6.addr);
sockaddr_storage_clear(item->extAddrV6.addr);
item->dyndns = (it->second).dyndns;
(it->second).ipAddrs.mLocal.loadTlv(item->localAddrList);
(it->second).ipAddrs.mExt.loadTlv(item->extAddrList);
item->domain_addr = (it->second).hiddenDomain;
item->domain_port = (it->second).hiddenPort;
saveData.push_back(item);
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::saveList() Peer Config Item:" << std::endl;
@ -2150,7 +2154,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
RsPeerBandwidthLimitsItem *pblitem = new RsPeerBandwidthLimitsItem ;
pblitem->peers = mPeerBandwidthLimits ;
saveData.push_back(pblitem) ;
RsPeerServicePermissionItem *sitem = new RsPeerServicePermissionItem ;
for(std::map<RsPgpId,ServicePermissionFlags>::const_iterator it(mFriendsPermissionFlags.begin());it!=mFriendsPermissionFlags.end();++it)
@ -2158,11 +2162,11 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
sitem->pgp_ids.push_back(it->first) ;
sitem->service_flags.push_back(it->second) ;
}
saveData.push_back(sitem) ;
// Now save config for network digging strategies
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
RsTlvKeyValue kv;
@ -2199,7 +2203,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
kv.key = kConfigKeyProxyServerPortI2P;
kv.value = sockaddr_storage_porttostring(proxy_addr_i2p);
vitem->tlvkvs.pairs.push_back(kv) ;
saveData.push_back(vitem);
/* save groups */
@ -2213,7 +2217,7 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
return true;
}
bool p3PeerMgrIMPL::getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn)
bool p3PeerMgrIMPL::getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& maxDn)
{
RsPgpId pgp_id ;
@ -2235,7 +2239,7 @@ bool p3PeerMgrIMPL::getMaxRates(const RsPeerId& pid,uint32_t& maxUp,uint32_t& ma
return getMaxRates(pgp_id,maxUp,maxDn) ;
}
bool p3PeerMgrIMPL::getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn)
bool p3PeerMgrIMPL::getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& maxDn)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
@ -2254,25 +2258,25 @@ bool p3PeerMgrIMPL::getMaxRates(const RsPgpId& pid,uint32_t& maxUp,uint32_t& max
return false ;
}
}
bool p3PeerMgrIMPL::setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn)
bool p3PeerMgrIMPL::setMaxRates(const RsPgpId& pid,uint32_t maxUp,uint32_t maxDn)
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
PeerBandwidthLimits& p(mPeerBandwidthLimits[pid]) ;
if(maxUp == p.max_up_rate_kbs && maxDn == p.max_dl_rate_kbs)
return true ;
std::cerr << "Updating max rates for peer " << pid << " to " << maxUp << " kB/s (up), " << maxDn << " kB/s (dn)" << std::endl;
p.max_up_rate_kbs = maxUp ;
p.max_dl_rate_kbs = maxDn ;
IndicateConfigChanged();
return true ;
}
void p3PeerMgrIMPL::saveDone()
{
/* clean up the save List */
@ -2396,7 +2400,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
#ifdef PEER_DEBUG
std::cerr << "setting use_extr_addr_finder to " << useExtAddrFinder << std::endl ;
#endif
}
}
// Tor
else if (kit->key == kConfigKeyProxyServerIpAddrTor)
{
@ -2859,13 +2863,13 @@ bool p3PeerMgrIMPL::removeAllFriendLocations(const RsPgpId &gpgid)
{
return false;
}
std::list<RsPeerId>::iterator it;
for(it = sslIds.begin(); it != sslIds.end(); ++it)
{
removeFriend(*it, true);
}
return true;
}
@ -2877,7 +2881,7 @@ bool p3PeerMgrIMPL::getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::getAssociatedPeers() for id : " << gpg_id << std::endl;
#endif
int count = 0;
std::map<RsPeerId, peerState>::iterator it;
for(it = mFriendList.begin(); it != mFriendList.end(); ++it)
@ -2890,10 +2894,10 @@ bool p3PeerMgrIMPL::getAssociatedPeers(const RsPgpId &gpg_id, std::list<RsPeerId
#ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::getAssociatedPeers() found ssl id : " << it->first << std::endl;
#endif
}
}
return (count > 0);
}
@ -2930,10 +2934,10 @@ bool p3PeerMgrIMPL::removeBannedIps()
return true ;
}
// /* This only removes SSL certs, that are old... Can end up with no Certs per GPG Id
// /* This only removes SSL certs, that are old... Can end up with no Certs per GPG Id
// * We are removing the concept of a "DummyId" - There is no need for it.
// */
//
//
// bool isDummyFriend(RsPeerId id)
// {
// bool ret = (id.substr(0,5) == "dummy");
@ -2974,7 +2978,7 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
{
RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/
// First put a sensible number in all PGP ids
for(std::list<RsPgpId>::const_iterator it = pgpList.begin(); it != pgpList.end(); ++it)
@ -2984,7 +2988,7 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
std::cerr << "p3PeerMgr::removeUnusedLocations()" << std::endl;
#endif
// Then compute the most recently used location for all PGP ids
for( std::map<RsPeerId, peerState>::iterator it = mFriendList.begin(); it != mFriendList.end(); ++it)
{
time_t& bst(mostRecentTime[it->second.gpg_id]) ;
@ -3010,4 +3014,4 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
return true;
}

View File

@ -55,7 +55,7 @@
#define RSBANLIST_DELAY_BETWEEN_TALK_TO_DHT 240 // every 4 mins.
/************ IMPLEMENTATION NOTES *********************************
*
*
* Get Bad Peers passed to us (from DHT mainly).
* we distribute and track the network list of bad peers.
*
@ -113,6 +113,8 @@ void p3BanList::setAutoRangeLimit(int n)
IndicateConfigChanged();
}
namespace services {
class ZeroedInt
{
public:
@ -120,6 +122,8 @@ class ZeroedInt
uint32_t n ;
};
}
BanListPeer::BanListPeer()
{
memset(&addr, 0, sizeof(addr));
@ -220,14 +224,14 @@ void p3BanList::autoFigureOutBanRanges()
std::cerr << "Automatically figuring out IP ranges from banned IPs." << std::endl;
#endif
std::map<sockaddr_storage,ZeroedInt> range_map ;
std::map<sockaddr_storage, services::ZeroedInt> range_map ;
for(std::map<sockaddr_storage,BanListPeer>::iterator it(mBanSet.begin());it!=mBanSet.end();++it)
++range_map[makeBitsRange(it->first,1)].n ;
time_t now = time(NULL) ;
for(std::map<sockaddr_storage,ZeroedInt>::const_iterator it=range_map.begin();it!=range_map.end();++it)
for(std::map<sockaddr_storage, services::ZeroedInt>::const_iterator it=range_map.begin();it!=range_map.end();++it)
{
#ifdef DEBUG_BANLIST
std::cerr << "Ban range: " << sockaddr_storage_iptostring(it->first) << " : " << it->second.n << std::endl;
@ -646,7 +650,7 @@ bool p3BanList::processIncoming()
break;
case RS_PKT_SUBTYPE_BANLIST_ITEM:
{
// Order is important!.
// Order is important!.
updated = (recvBanItem((RsBanListItem *) item) || updated);
}
break;
@ -669,8 +673,8 @@ bool p3BanList::processIncoming()
}
return true ;
}
}
bool p3BanList::recvBanItem(RsBanListItem *item)
{
@ -681,7 +685,7 @@ bool p3BanList::recvBanItem(RsBanListItem *item)
for(it = item->peerList.mList.begin(); it != item->peerList.mList.end(); ++it)
{
// Order is important!.
// Order is important!.
updated = (addBanEntry(item->PeerId(), it->addr.addr, it->level, it->reason, now - it->age) || updated);
}
return updated;
@ -961,7 +965,7 @@ bool p3BanList::addBanEntry( const RsPeerId &peerId,
it = mBanSources.find(peerId);
updated = true;
}
// index is FAMILY + IP - the rest should be Zeros..
struct sockaddr_storage bannedaddr;
sockaddr_storage_clear(bannedaddr);
@ -980,7 +984,7 @@ bool p3BanList::addBanEntry( const RsPeerId &peerId,
blp.level = level;
blp.mTs = time_stamp ;
blp.masked_bytes = 0 ;
it->second.mBanPeers[bannedaddr] = blp;
it->second.mLastUpdate = now;
updated = true;
@ -1036,7 +1040,7 @@ int p3BanList::condenseBanSources_locked()
time_t now = time(NULL);
RsPeerId ownId = mServiceCtrl->getOwnId();
#ifdef DEBUG_BANLIST
std::cerr << "p3BanList::condenseBanSources_locked()";
std::cerr << std::endl;
@ -1062,7 +1066,7 @@ int p3BanList::condenseBanSources_locked()
std::cerr << " Condensing Info from peer: " << it->first;
std::cerr << std::endl;
#endif
std::map<struct sockaddr_storage, BanListPeer>::const_iterator lit;
for(lit = it->second.mBanPeers.begin(); lit != it->second.mBanPeers.end(); ++lit)
{
@ -1135,7 +1139,7 @@ int p3BanList::condenseBanSources_locked()
}
}
#ifdef DEBUG_BANLIST
std::cerr << "p3BanList::condenseBanSources_locked() Printing New Set:";
std::cerr << std::endl;
@ -1280,7 +1284,7 @@ int p3BanList::printBanSet_locked(std::ostream &out)
int p3BanList::printBanSources_locked(std::ostream &out)
{
time_t now = time(NULL);
std::map<RsPeerId, BanList>::const_iterator it;
for(it = mBanSources.begin(); it != mBanSources.end(); ++it)
{

View File

@ -433,7 +433,7 @@ void MainWindow::initStackedPage()
#ifndef RS_RELEASE_VERSION
#ifdef PLUGINMGR
addPage(pluginsPage = new PluginsPage(ui->stackPages), grp, NULL);
addPage(pluginsPage = new gui::PluginsPage(ui->stackPages), grp, NULL);
#endif
#endif
@ -643,10 +643,10 @@ const QList<UserNotify*> &MainWindow::getUserNotifyList()
/*static*/ void MainWindow::displayLobbySystrayMsg(const QString& title,const QString& msg)
{
if (_instance == NULL)
if (_instance == NULL)
return;
if(Settings->getDisplayTrayChatLobby())
if(Settings->getDisplayTrayChatLobby())
_instance->displaySystrayMsg(title,msg) ;
}
@ -1011,7 +1011,7 @@ void SetForegroundWindowInternal(HWND hWnd)
return NULL;
}
switch (page)
switch (page)
{
case Network:
return _instance->friendsDialog->networkDialog;
@ -1457,7 +1457,7 @@ void MainWindow::externalLinkActivated(const QUrl &url)
int res = mb.exec() ;
if (res == QMessageBox::No)
if (res == QMessageBox::No)
return ;
if(dontAsk_CB->isChecked())

View File

@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
@ -39,6 +39,8 @@ class QScriptEngine;
class PluginManager;
namespace gui {
//! A demo widget for showing plugin engine in action :)
@ -46,7 +48,7 @@ class PluginManager;
//! loaded plugin widgets. All specific actions moved to
//! PluginManagerWidget class. It contains a PluginManager instance, but it's
//! supposed that in future a pluginManager will become a global variable
class PluginsPage : public MainPage
class PluginsPage : public MainPage
{
Q_OBJECT
@ -70,10 +72,10 @@ protected:
QVBoxLayout* pluginPageLayout;
QGroupBox* pluginPanel;
QVBoxLayout* pluginPanelLayout;
//! Plugin widgets will be loaded into this tabs
QTabWidget* pluginTabs ;
QVBoxLayout* pmLay;
QFrame* pmFrame;
QSpacerItem* pmSpacer;
@ -82,5 +84,7 @@ protected:
PluginManager* pluginManager;
};
} // namespace gui
#endif

View File

@ -33,7 +33,7 @@
#include "../MainWindow.h"
PluginsPage::PluginsPage(QWidget * parent, Qt::WindowFlags flags)
settings::PluginsPage::PluginsPage(QWidget * parent, Qt::WindowFlags flags)
: ConfigPage(parent, flags)
{
ui.setupUi(this);
@ -123,7 +123,7 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WindowFlags flags)
if(plugin == NULL || plugin->qt_config_panel() == NULL)
item->_configure_PB->hide() ;
if(plugin != NULL){
item->enableButton->hide();
@ -159,7 +159,7 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WindowFlags flags)
QObject::connect(ui.enableAll,SIGNAL(toggled(bool)),this,SLOT(toggleEnableAll(bool))) ;
}
QString PluginsPage::helpText() const
QString settings::PluginsPage::helpText() const
{
return tr("<h1><img width=\"24\" src=\":/icons/help_64.png\">&nbsp;&nbsp;Plugins</h1> \
<p>Plugins are loaded from the directories listed in the bottom list.</p> \
@ -171,11 +171,11 @@ QString PluginsPage::helpText() const
<p>If you want to develop your own plugins, contact the developpers team \
they will be happy to help you out!</p>") ;
}
void PluginsPage::toggleEnableAll(bool b)
void settings::PluginsPage::toggleEnableAll(bool b)
{
rsPlugins->allowAllPlugins(b) ;
}
void PluginsPage::aboutPlugin(int i)
void settings::PluginsPage::aboutPlugin(int i)
{
std::cerr << "Launching about window for plugin " << i << std::endl;
@ -183,7 +183,7 @@ void PluginsPage::aboutPlugin(int i)
if(rsPlugins->plugin(i) != NULL && (dialog = rsPlugins->plugin(i)->qt_about_page()) != NULL)
dialog->exec() ;
}
void PluginsPage::configurePlugin(int i)
void settings::PluginsPage::configurePlugin(int i)
{
std::cerr << "Launching configuration window for plugin " << i << std::endl;
@ -191,14 +191,14 @@ void PluginsPage::configurePlugin(int i)
rsPlugins->plugin(i)->qt_config_panel()->show() ;
}
void PluginsPage::enablePlugin(const QString& hash)
void settings::PluginsPage::enablePlugin(const QString& hash)
{
std::cerr << "Switching status of plugin " << hash.toStdString() << " to enable" << std::endl;
rsPlugins->enablePlugin(RsFileHash(hash.toStdString()) );
}
void PluginsPage::disablePlugin(const QString& hash)
void settings::PluginsPage::disablePlugin(const QString& hash)
{
std::cerr << "Switching status of plugin " << hash.toStdString() << " to disable " << std::endl;
@ -206,11 +206,11 @@ void PluginsPage::disablePlugin(const QString& hash)
}
PluginsPage::~PluginsPage()
settings::PluginsPage::~PluginsPage()
{
}
/** Loads the settings for this page */
void PluginsPage::load()
void settings::PluginsPage::load()
{
}

View File

@ -24,6 +24,8 @@
#include <retroshare-gui/configpage.h>
#include "ui_PluginsPage.h"
namespace settings {
class PluginsPage : public ConfigPage
{
Q_OBJECT
@ -52,3 +54,4 @@ class PluginsPage : public ConfigPage
Ui::PluginsPage ui;
};
} // namespace settings

View File

@ -158,7 +158,7 @@ SettingsPage::initStackedWidget()
addPage(new ForumPage()); // FORUMS
addPage(new PostedPage()); // POSTED RENAME TO LINKS
addPage(new NotifyPage()); // NOTIFY
addPage(new PluginsPage() ); // PLUGINS
addPage(new settings::PluginsPage() ); // PLUGINS
addPage(new AppearancePage()); // APPEARENCE
addPage(new SoundPage() ); // SOUND
addPage(new ServicePermissionsPage() ); // PERMISSIONS