Browse Source

dhtput should have a higher cost, as it lacks active limit check.

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
025c061415
  1. 10
      src/dhtproxy.cpp

10
src/dhtproxy.cpp

@ -178,17 +178,17 @@ namespace DhtProxy
} }
} }
bool checkForAbuse(CNode* pfrom) bool checkForAbuse(CNode* pfrom, int cost)
{ {
LOCK(cs_dhtProxy); LOCK(cs_dhtProxy);
// logic inspired/copied from dht_tracker.cpp:incoming_packet // logic inspired/copied from dht_tracker.cpp:incoming_packet
ptime now = time_now(); ptime now = time_now();
PeerBanStats *match = &m_peerBanStats[pfrom->addr]; PeerBanStats *match = &m_peerBanStats[pfrom->addr];
match->count++; match->count+=cost;
if( match->count >= 500 ) { if( match->count >= 500 ) {
if (now < match->limit) { if (now < match->limit) {
if( match->count == 500 ) { if( match->count == 500 ) { // cost may break this 'if' but then we just dont log.
dbgprintf("DhtProxy::checkForAbuse: %s misbehaving, too much requests.\n", dbgprintf("DhtProxy::checkForAbuse: %s misbehaving, too much requests.\n",
pfrom->addr.ToString().c_str()); pfrom->addr.ToString().c_str());
} }
@ -212,7 +212,7 @@ namespace DhtProxy
// we are using proxy ourselves, we can't be proxy to anyone else // we are using proxy ourselves, we can't be proxy to anyone else
pfrom->PushMessage("nodhtproxy"); pfrom->PushMessage("nodhtproxy");
return true; return true;
} else if( !req.stopReq && checkForAbuse(pfrom) ) { } else if( !req.stopReq && checkForAbuse(pfrom, 1) ) {
return false; return false;
} else { } else {
std::string username(req.vchUsername.data(), req.vchUsername.size()); std::string username(req.vchUsername.data(), req.vchUsername.size());
@ -296,7 +296,7 @@ namespace DhtProxy
// we are using proxy ourselves, we can't be proxy to anyone else // we are using proxy ourselves, we can't be proxy to anyone else
pfrom->PushMessage("nodhtproxy"); pfrom->PushMessage("nodhtproxy");
return true; return true;
} else if( checkForAbuse(pfrom) ) { } else if( checkForAbuse(pfrom, 10) ) {
return false; return false;
} else { } else {
std::string username(req.vchUsername.data(), req.vchUsername.size()); std::string username(req.vchUsername.data(), req.vchUsername.size());

Loading…
Cancel
Save