Ver Fonte

2008-02-21 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Fixed abort when peer's ip address is IPv4-mapped address.
	* src/DefaultBtContext.cc (computeFastSet)

	Removed number-and-dots criteria, since 
Util::isNumberAndDotsNotation()
	cannot handle IPv4-mapped addresses.
	* src/DefaultBtInteractive.cc (addPeerExchangeMessage)
Tatsuhiro Tsujikawa há 17 anos atrás
pai
commit
3274b6acc7
3 ficheiros alterados com 15 adições e 9 exclusões
  1. 9 0
      ChangeLog
  2. 4 5
      src/DefaultBtContext.cc
  3. 2 4
      src/DefaultBtInteractive.cc

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2008-02-21  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Fixed abort when peer's ip address is IPv4-mapped address.
+	* src/DefaultBtContext.cc (computeFastSet)
+
+	Removed number-and-dots criteria, since Util::isNumberAndDotsNotation()
+	cannot handle IPv4-mapped addresses.
+	* src/DefaultBtInteractive.cc (addPeerExchangeMessage)
+	
 2008-02-21  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Proper return value handling for OpenSSL functions.

+ 4 - 5
src/DefaultBtContext.cc

@@ -48,6 +48,7 @@
 #include "Logger.h"
 #include "FileEntry.h"
 #include "message.h"
+#include "PeerMessageUtil.h"
 #include <cstring>
 #include <ostream>
 #include <functional>
@@ -385,12 +386,10 @@ std::string DefaultBtContext::getActualBasePath() const
 std::deque<int32_t> DefaultBtContext::computeFastSet(const std::string& ipaddr, int32_t fastSetSize)
 {
   std::deque<int32_t> fastSet;
-  struct in_addr saddr;
-  if(inet_aton(ipaddr.c_str(), &saddr) == 0) {
-    abort();
-  }
+  char compact[6];
+  PeerMessageUtil::createcompact(compact, ipaddr, 0);
   unsigned char tx[24];
-  memcpy(tx, (void*)&saddr.s_addr, 4);
+  memcpy(tx, compact, 4);
   if((tx[0] & 0x80) == 0 || (tx[0] & 0x40) == 0) {
     tx[2] = 0x00;
     tx[3] = 0x00;

+ 2 - 4
src/DefaultBtInteractive.cc

@@ -380,8 +380,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
 	  i != peers.end() && max; ++i) {
 	const PeerHandle& cpeer = *i;
 	if(peer->ipaddr != cpeer->ipaddr &&
-	   !cpeer->getFirstContactTime().elapsed(interval) &&
-	   Util::isNumbersAndDotsNotation(cpeer->ipaddr)) {
+	   !cpeer->getFirstContactTime().elapsed(interval)) {
 	  m->addFreshPeer(cpeer);
 	  --max;
 	}
@@ -393,8 +392,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
 	  i != peers.rend() && max; ++i) {
 	const PeerHandle& cpeer = *i;
 	if(peer->ipaddr != cpeer->ipaddr &&
-	   !cpeer->getBadConditionStartTime().elapsed(interval) &&
-	   Util::isNumbersAndDotsNotation(cpeer->ipaddr)) {
+	   !cpeer->getBadConditionStartTime().elapsed(interval)) {
 	  m->addDroppedPeer(cpeer);
 	  --max;
 	}