Be more tolerant of corrupt peer entries.

This commit is contained in:
David Schwartz
2013-08-21 16:26:02 -07:00
parent c17cfe9ea6
commit 3a2e770e52
2 changed files with 15 additions and 8 deletions

View File

@@ -110,7 +110,7 @@ public:
{
if (!mHello.has_ipv4port() || mIpPortConnect.first.empty())
return false;
connect = boost::str(boost::format("%s:%d") % mIpPortConnect.first % mHello.ipv4port());
connect = boost::str(boost::format("%s %d") % mIpPortConnect.first % mHello.ipv4port());
return true;
}
@@ -1495,7 +1495,6 @@ void PeerImp::recvGetContacts (protocol::TMGetContacts& packet)
// Return a list of your favorite people
// TODO: filter out all the LAN peers
// TODO: filter out the peer you are talking to
void PeerImp::recvGetPeers (protocol::TMGetPeers& packet, Application::ScopedLockType& masterLockHolder)
{
masterLockHolder.unlock ();
@@ -1512,12 +1511,20 @@ void PeerImp::recvGetPeers (protocol::TMGetPeers& packet, Application::ScopedLoc
std::string strIP;
int iPort;
splitIpPort (addrs[n], strIP, iPort);
try
{
splitIpPort (addrs[n], strIP, iPort);
// XXX This should also ipv6
protocol::TMIPv4EndPoint* addr = peers.add_nodes ();
addr->set_ipv4 (inet_addr (strIP.c_str ()));
addr->set_ipv4port (iPort);
}
catch (...)
{
WriteLog (lsWARNING, Peer) << "Bad peer in list: " << addrs[n];
}
// XXX This should also ipv6
protocol::TMIPv4EndPoint* addr = peers.add_nodes ();
addr->set_ipv4 (inet_addr (strIP.c_str ()));
addr->set_ipv4port (iPort);
//WriteLog (lsINFO, Peer) << "Peer: Teaching: " << addressToString(this) << ": " << n << ": " << strIP << " " << iPort;
}

View File

@@ -127,7 +127,7 @@ private:
void splitIpPort (const std::string& strIpPort, std::string& strIp, int& iPort)
{
std::vector<std::string> vIpPort;
boost::split (vIpPort, strIpPort, boost::is_any_of (" "));
boost::split (vIpPort, strIpPort, boost::is_any_of (" :"));
strIp = vIpPort[0];
iPort = lexicalCastThrow <int> (vIpPort[1]);