Sfoglia il codice sorgente

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

	Fixed possible busy loop if first 20 bytes are not received for 
a few
	minutes.
	* src/MSEHandshake.{h, cc} (identifyHandshakeType)
	* src/ReceiverMSEHandshakeCommand.cc
Tatsuhiro Tsujikawa 17 anni fa
parent
commit
50bb9bd36d
4 ha cambiato i file con 31 aggiunte e 4 eliminazioni
  1. 7 0
      ChangeLog
  2. 14 3
      src/MSEHandshake.cc
  3. 4 0
      src/MSEHandshake.h
  4. 6 1
      src/ReceiverMSEHandshakeCommand.cc

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2008-02-28  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Fixed possible busy loop if first 20 bytes are not received for a few
+	minutes.
+	* src/MSEHandshake.{h, cc} (identifyHandshakeType)
+	* src/ReceiverMSEHandshakeCommand.cc
+
 2008-02-27  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Fixed compilation error

+ 14 - 3
src/MSEHandshake.cc

@@ -91,9 +91,10 @@ MSEHandshake::HANDSHAKE_TYPE MSEHandshake::identifyHandshakeType()
   if(!_socket->isReadable(0)) {
     return HANDSHAKE_NOT_YET;
   }
-  int32_t bufLength = 20;
-  _socket->peekData(_rbuf, bufLength);
-  if(bufLength != 20) {
+  int32_t bufLength = 20-_rbufLength;
+  _socket->readData(_rbuf+_rbufLength, bufLength);
+  _rbufLength += bufLength;
+  if(_rbufLength < 20) {
     return HANDSHAKE_NOT_YET;
   }
   if(_rbuf[0] == BtHandshakeMessage::PSTR_LENGTH &&
@@ -597,4 +598,14 @@ SharedHandle<ARC4Decryptor> MSEHandshake::getDecryptor() const
   return _decryptor;
 }
 
+const unsigned char* MSEHandshake::getBuffer() const
+{
+  return _rbuf;
+}
+
+size_t MSEHandshake::getBufferLength() const
+{
+  return _rbufLength;
+}
+
 } // namespace aria2

+ 4 - 0
src/MSEHandshake.h

@@ -172,6 +172,10 @@ public:
   SharedHandle<ARC4Encryptor> getEncryptor() const;
 
   SharedHandle<ARC4Decryptor> getDecryptor() const;
+
+  const unsigned char* getBuffer() const;
+
+  size_t getBufferLength() const;
 };
 
 } // namespace aria2

+ 6 - 1
src/ReceiverMSEHandshakeCommand.cc

@@ -90,7 +90,12 @@ bool ReceiverMSEHandshakeCommand::executeInternal()
       if(e->option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
 	throw new DlAbortEx("The legacy BitTorrent handshake is not acceptable by the preference.");
       }
-      Command* c = new PeerReceiveHandshakeCommand(cuid, peer, e, socket);
+      SharedHandle<PeerConnection> peerConnection =
+	new PeerConnection(cuid, socket, e->option);
+      peerConnection->presetBuffer(_mseHandshake->getBuffer(),
+				   _mseHandshake->getBufferLength());
+      Command* c = new PeerReceiveHandshakeCommand(cuid, peer, e, socket,
+						   peerConnection);
       e->commands.push_back(c);
       return true;
     }