Jelajahi Sumber

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

	Added _incoming member to Peer class and made it true if the 
peer
	initiated connection. Don't add those peer to UTPex message.
	If extended handshake is received, assign _incoming to false.
	* src/DefaultBtInteractive.cc
	* src/HandshakeExtensionMessage.cc
	* src/Peer.cc
	* src/Peer.h
	* src/PeerListenCommand.cc
Tatsuhiro Tsujikawa 17 tahun lalu
induk
melakukan
46f0e018d4
6 mengubah file dengan 35 tambahan dan 5 penghapusan
  1. 11 0
      ChangeLog
  2. 1 1
      src/DefaultBtInteractive.cc
  3. 1 0
      src/HandshakeExtensionMessage.cc
  4. 13 2
      src/Peer.cc
  5. 8 1
      src/Peer.h
  6. 1 1
      src/PeerListenCommand.cc

+ 11 - 0
ChangeLog

@@ -1,3 +1,14 @@
+2008-09-02  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Added _incoming member to Peer class and made it true if the peer
+	initiated connection. Don't add those peer to UTPex message.
+	If extended handshake is received, assign _incoming to false.
+	* src/DefaultBtInteractive.cc
+	* src/HandshakeExtensionMessage.cc
+	* src/Peer.cc
+	* src/Peer.h
+	* src/PeerListenCommand.cc
+	
 2008-09-02  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Made files whose name ends with ".gz", ".tgz" not inflated by Content

+ 1 - 1
src/DefaultBtInteractive.cc

@@ -402,7 +402,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
       for(Peers::const_iterator i = peers.begin();
 	  i != peers.end() && max; ++i) {
 	const PeerHandle& cpeer = *i;
-	if(peer->ipaddr != cpeer->ipaddr &&
+	if(peer->ipaddr != cpeer->ipaddr && !cpeer->isIncomingPeer() &&
 	   !cpeer->getFirstContactTime().elapsed(interval)) {
 	  m->addFreshPeer(cpeer);
 	  --max;

+ 1 - 0
src/HandshakeExtensionMessage.cc

@@ -102,6 +102,7 @@ void HandshakeExtensionMessage::doReceivedAction()
 {
   if(_tcpPort > 0) {
     _peer->port = _tcpPort;
+    _peer->setIncomingPeer(false);
   }
   for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin();
       itr != _extensions.end(); ++itr) {

+ 13 - 2
src/Peer.cc

@@ -45,12 +45,13 @@ namespace aria2 {
 
 #define BAD_CONDITION_INTERVAL 10
 
-Peer::Peer(std::string ipaddr, uint16_t port):
+Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
   ipaddr(ipaddr),
   port(port),
   _badConditionStartTime(0),
   _seeder(false),
-  _res(0)
+  _res(0),
+  _incoming(incoming)
 {
   resetStatus();
   std::string idSeed = ipaddr+":"+Util::uitos(port);
@@ -460,4 +461,14 @@ uint64_t Peer::getCompletedLength() const
   return _res->getCompletedLength();
 }
 
+bool Peer::isIncomingPeer() const
+{
+  return _incoming;
+}
+
+void Peer::setIncomingPeer(bool incoming)
+{
+  _incoming = incoming;
+}
+
 } // namespace aria2

+ 8 - 1
src/Peer.h

@@ -69,12 +69,15 @@ private:
 
   PeerSessionResource* _res;
 
+  // If true, port is assumed not to be a listening port.
+  bool _incoming;
+
   // Before calling updateSeeder(),  make sure that
   // allocateSessionResource() is called and _res is created.
   // Otherwise assertion fails.
   void updateSeeder();
 public:
-  Peer(std::string ipaddr, uint16_t port);
+  Peer(std::string ipaddr, uint16_t port, bool incoming = false);
 
   ~Peer();
 
@@ -237,6 +240,10 @@ public:
   const Time& getLastAmUnchoking() const;
 
   uint64_t getCompletedLength() const;
+
+  bool isIncomingPeer() const;
+
+  void setIncomingPeer(bool incoming);
 };
 
 typedef SharedHandle<Peer> PeerHandle;

+ 1 - 1
src/PeerListenCommand.cc

@@ -101,7 +101,7 @@ bool PeerListenCommand::execute() {
       // here.
       peerSocket->setBlockingMode();
 
-      PeerHandle peer(new Peer(peerInfo.first, 0));
+      PeerHandle peer(new Peer(peerInfo.first, peerInfo.second, true));
       int32_t cuid = CUIDCounterSingletonHolder::instance()->newID();
       Command* command =
 	new ReceiverMSEHandshakeCommand(cuid, peer, e, peerSocket);