From 50bb9bd36dca986f8ee0b926c24b3b9bf9b0f8e6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 27 Feb 2008 16:43:52 +0000 Subject: [PATCH] 2008-02-28 Tatsuhiro Tsujikawa Fixed possible busy loop if first 20 bytes are not received for a few minutes. * src/MSEHandshake.{h, cc} (identifyHandshakeType) * src/ReceiverMSEHandshakeCommand.cc --- ChangeLog | 7 +++++++ src/MSEHandshake.cc | 17 ++++++++++++++--- src/MSEHandshake.h | 4 ++++ src/ReceiverMSEHandshakeCommand.cc | 7 ++++++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e724510d..f0758034 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-02-28 Tatsuhiro Tsujikawa + + 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 Fixed compilation error diff --git a/src/MSEHandshake.cc b/src/MSEHandshake.cc index 1b390e95..fe0d9060 100644 --- a/src/MSEHandshake.cc +++ b/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 MSEHandshake::getDecryptor() const return _decryptor; } +const unsigned char* MSEHandshake::getBuffer() const +{ + return _rbuf; +} + +size_t MSEHandshake::getBufferLength() const +{ + return _rbufLength; +} + } // namespace aria2 diff --git a/src/MSEHandshake.h b/src/MSEHandshake.h index 4017186f..13771d95 100644 --- a/src/MSEHandshake.h +++ b/src/MSEHandshake.h @@ -172,6 +172,10 @@ public: SharedHandle getEncryptor() const; SharedHandle getDecryptor() const; + + const unsigned char* getBuffer() const; + + size_t getBufferLength() const; }; } // namespace aria2 diff --git a/src/ReceiverMSEHandshakeCommand.cc b/src/ReceiverMSEHandshakeCommand.cc index b99133e1..e01cf346 100644 --- a/src/ReceiverMSEHandshakeCommand.cc +++ b/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 = + 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; }