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
pull/1/head
Tatsuhiro Tsujikawa 2008-02-27 16:43:52 +00:00
parent c1fd47809d
commit 50bb9bd36d
4 changed files with 31 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

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

View File

@ -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;
}