2006-03-21 14:12:51 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-03-21 14:12:51 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-09-21 15:31:24 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-03-21 14:12:51 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "PeerConnection.h"
|
2009-05-13 14:50:48 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <cassert>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
#include "message.h"
|
|
|
|
#include "DlAbortEx.h"
|
2006-04-17 16:17:20 +00:00
|
|
|
#include "LogFactory.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "BtHandshakeMessage.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Socket.h"
|
2007-07-23 13:04:48 +00:00
|
|
|
#include "a2netcompat.h"
|
2008-02-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Message Stream Encryption(MSE) support.
Currently, aria2 accepts incoming connections with Obfuscation Header
and legacy BitTorrent Header and establishes connections with
Obfuscation Header first and if failed then retry with legacy
BitTorrent header. If plain text and ARC4 is provided, aria2 always
choose ARC4. The new option to change the default behavior is planned.
For tracker extension, "supportcrypto=1" is added statically.
* src/PeerInitiateConnectionCommand.{h, cc}
* src/PeerConnection.{h, cc}
* src/HandleRegistry.h
* src/SocketCore.h
* src/PeerReceiveHandshakeCommand.{h, cc}
* src/BtRegistry.{h, cc}
* src/PeerListenCommand.cc
* src/InitiatorMSEHandshakeCommand.{h, cc}
* src/ReceiverMSEHandshakeCommand.{h, cc}
* src/MSEHandshake.{h, cc}
* src/ARC4Encryptor.h
* src/ARC4Decryptor.h
* src/LibgcryptARC4Encryptor.h
* src/LibgcryptARC4Decryptor.h
* src/LibgcryptARC4Context.h
* src/LibsslARC4Encryptor.h
* src/LibsslARC4Decryptor.h
* src/LibsslARC4Context.h
* src/DHKeyExchange.h
* src/LibgcryptDHKeyExchange.h
* src/LibsslDHKeyExchange.h
* src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter.
* test/DefaultBtAnnounceTest.cc
* test/ARC4Test.cc
* test/DHKeyExchangeTest.cc
Removed prepareForRetry() because it is not used.
* src/PeerAbstractCommand.{h, cc}
* src/PeerInteractionCommand.{h, cc}
* src/PeerInitiateConnectionCommand.{h, cc}
2008-02-17 15:56:47 +00:00
|
|
|
#include "ARC4Encryptor.h"
|
|
|
|
#include "ARC4Decryptor.h"
|
2010-11-20 08:21:36 +00:00
|
|
|
#include "fmt.h"
|
2010-03-21 07:05:49 +00:00
|
|
|
#include "util.h"
|
2010-08-04 15:00:38 +00:00
|
|
|
#include "Peer.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2010-08-04 15:00:38 +00:00
|
|
|
PeerConnection::PeerConnection
|
|
|
|
(cuid_t cuid, const SharedHandle<Peer>& peer, const SocketHandle& socket)
|
2010-11-20 08:21:36 +00:00
|
|
|
: cuid_(cuid),
|
|
|
|
peer_(peer),
|
|
|
|
socket_(socket),
|
|
|
|
resbuf_(new unsigned char[MAX_PAYLOAD_LEN]),
|
|
|
|
resbufLength_(0),
|
|
|
|
currentPayloadLength_(0),
|
|
|
|
lenbufLength_(0),
|
|
|
|
socketBuffer_(socket),
|
|
|
|
encryptionEnabled_(false),
|
|
|
|
prevPeek_(false)
|
2008-02-08 15:53:45 +00:00
|
|
|
{}
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2010-03-04 16:24:03 +00:00
|
|
|
PeerConnection::~PeerConnection()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
delete [] resbuf_;
|
2010-03-04 16:24:03 +00:00
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
|
2010-03-04 16:24:03 +00:00
|
|
|
void PeerConnection::pushStr(const std::string& data)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(encryptionEnabled_) {
|
2010-03-04 16:24:03 +00:00
|
|
|
const size_t len = data.size();
|
|
|
|
unsigned char* chunk = new unsigned char[len];
|
|
|
|
try {
|
2010-06-21 13:51:56 +00:00
|
|
|
encryptor_->encrypt
|
2010-03-04 16:24:03 +00:00
|
|
|
(chunk, len, reinterpret_cast<const unsigned char*>(data.data()), len);
|
|
|
|
} catch(RecoverableException& e) {
|
|
|
|
delete [] chunk;
|
|
|
|
throw;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
socketBuffer_.pushBytes(chunk, len);
|
2010-03-04 16:24:03 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
socketBuffer_.pushStr(data);
|
2010-03-04 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PeerConnection::pushBytes(unsigned char* data, size_t len)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(encryptionEnabled_) {
|
2010-03-04 16:24:03 +00:00
|
|
|
unsigned char* chunk = new unsigned char[len];
|
|
|
|
try {
|
2010-06-21 13:51:56 +00:00
|
|
|
encryptor_->encrypt(chunk, len, data, len);
|
2010-03-04 16:24:03 +00:00
|
|
|
} catch(RecoverableException& e) {
|
|
|
|
delete [] data;
|
|
|
|
delete [] chunk;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
delete [] data;
|
2010-06-21 13:51:56 +00:00
|
|
|
socketBuffer_.pushBytes(chunk, len);
|
2010-03-04 16:24:03 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
socketBuffer_.pushBytes(data, len);
|
2010-03-04 16:24:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength) {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(resbufLength_ == 0 && 4 > lenbufLength_) {
|
2008-01-10 15:12:32 +00:00
|
|
|
// read payload size, 32bit unsigned integer
|
2010-06-21 13:51:56 +00:00
|
|
|
size_t remaining = 4-lenbufLength_;
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t temp = remaining;
|
2010-06-21 13:51:56 +00:00
|
|
|
readData(lenbuf_+lenbufLength_, remaining, encryptionEnabled_);
|
2008-01-10 15:12:32 +00:00
|
|
|
if(remaining == 0) {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(socket_->wantRead() || socket_->wantWrite()) {
|
2010-01-05 16:01:46 +00:00
|
|
|
return false;
|
2008-09-27 16:06:34 +00:00
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
// we got EOF
|
2010-11-20 12:12:06 +00:00
|
|
|
A2_LOG_DEBUG(fmt("CUID#%lld - In PeerConnection::receiveMessage(),"
|
2010-06-12 12:29:11 +00:00
|
|
|
" remain=%lu",
|
2010-11-20 12:12:06 +00:00
|
|
|
cuid_,
|
2010-11-20 08:21:36 +00:00
|
|
|
static_cast<unsigned long>(temp)));
|
2010-08-04 15:00:38 +00:00
|
|
|
peer_->setDisconnectedGracefully(true);
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(EX_EOF_FROM_PEER);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
lenbufLength_ += remaining;
|
|
|
|
if(4 > lenbufLength_) {
|
|
|
|
// still 4-lenbufLength_ bytes to go
|
2006-05-09 15:54:14 +00:00
|
|
|
return false;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2009-05-23 15:48:20 +00:00
|
|
|
uint32_t payloadLength;
|
2010-06-21 13:51:56 +00:00
|
|
|
memcpy(&payloadLength, lenbuf_, sizeof(payloadLength));
|
2009-05-23 15:48:20 +00:00
|
|
|
payloadLength = ntohl(payloadLength);
|
2008-01-10 15:12:32 +00:00
|
|
|
if(payloadLength > MAX_PAYLOAD_LEN) {
|
2010-11-20 09:36:14 +00:00
|
|
|
throw DL_ABORT_EX(fmt(EX_TOO_LONG_PAYLOAD, payloadLength));
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
currentPayloadLength_ = payloadLength;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(!socket_->isReadable(0)) {
|
2007-01-11 16:32:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
// we have currentPayloadLen-resbufLen bytes to read
|
2010-06-21 13:51:56 +00:00
|
|
|
size_t remaining = currentPayloadLength_-resbufLength_;
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t temp = remaining;
|
2006-03-21 14:12:51 +00:00
|
|
|
if(remaining > 0) {
|
2010-06-21 13:51:56 +00:00
|
|
|
readData(resbuf_+resbufLength_, remaining, encryptionEnabled_);
|
2006-03-21 14:12:51 +00:00
|
|
|
if(remaining == 0) {
|
2010-06-21 13:51:56 +00:00
|
|
|
if(socket_->wantRead() || socket_->wantWrite()) {
|
2010-01-05 16:01:46 +00:00
|
|
|
return false;
|
2008-09-27 16:06:34 +00:00
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
// we got EOF
|
2010-11-20 12:12:06 +00:00
|
|
|
A2_LOG_DEBUG(fmt("CUID#%lld - In PeerConnection::receiveMessage(),"
|
2010-06-12 12:29:11 +00:00
|
|
|
" payloadlen=%lu, remaining=%lu",
|
2010-11-20 12:12:06 +00:00
|
|
|
cuid_,
|
2010-06-21 13:51:56 +00:00
|
|
|
static_cast<unsigned long>(currentPayloadLength_),
|
2010-11-20 08:21:36 +00:00
|
|
|
static_cast<unsigned long>(temp)));
|
2010-08-04 15:00:38 +00:00
|
|
|
peer_->setDisconnectedGracefully(true);
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(EX_EOF_FROM_PEER);
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
resbufLength_ += remaining;
|
|
|
|
if(currentPayloadLength_ > resbufLength_) {
|
2006-05-09 15:54:14 +00:00
|
|
|
return false;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// we got whole payload.
|
2010-06-21 13:51:56 +00:00
|
|
|
resbufLength_ = 0;
|
|
|
|
lenbufLength_ = 0;
|
2010-03-04 16:24:03 +00:00
|
|
|
if(data) {
|
2010-06-21 13:51:56 +00:00
|
|
|
memcpy(data, resbuf_, currentPayloadLength_);
|
2010-03-04 16:24:03 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
dataLength = currentPayloadLength_;
|
2006-05-09 15:54:14 +00:00
|
|
|
return true;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
bool PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength,
|
2010-01-05 16:01:46 +00:00
|
|
|
bool peek) {
|
2011-01-08 13:51:48 +00:00
|
|
|
if(BtHandshakeMessage::MESSAGE_LENGTH < resbufLength_) {
|
|
|
|
throw DL_ABORT_EX
|
|
|
|
("More than BtHandshakeMessage::MESSAGE_LENGTH bytes are buffered.");
|
|
|
|
}
|
2008-01-10 15:12:32 +00:00
|
|
|
bool retval = true;
|
2011-01-09 14:57:07 +00:00
|
|
|
size_t remaining = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength_;
|
|
|
|
if(remaining > 0) {
|
|
|
|
size_t temp = remaining;
|
|
|
|
readData(resbuf_+resbufLength_, remaining, encryptionEnabled_);
|
|
|
|
if(remaining == 0 && !socket_->wantRead() && !socket_->wantWrite()) {
|
|
|
|
// we got EOF
|
|
|
|
A2_LOG_DEBUG
|
|
|
|
(fmt("CUID#%lld - In PeerConnection::receiveHandshake(), remain=%lu",
|
|
|
|
cuid_,
|
|
|
|
static_cast<unsigned long>(temp)));
|
|
|
|
peer_->setDisconnectedGracefully(true);
|
|
|
|
throw DL_ABORT_EX(EX_EOF_FROM_PEER);
|
|
|
|
}
|
|
|
|
resbufLength_ += remaining;
|
|
|
|
if(BtHandshakeMessage::MESSAGE_LENGTH > resbufLength_) {
|
|
|
|
retval = false;
|
2008-01-10 15:12:32 +00:00
|
|
|
}
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
size_t writeLength = std::min(resbufLength_, dataLength);
|
|
|
|
memcpy(data, resbuf_, writeLength);
|
2006-12-24 06:25:21 +00:00
|
|
|
dataLength = writeLength;
|
2007-10-11 16:58:24 +00:00
|
|
|
if(retval && !peek) {
|
2010-06-21 13:51:56 +00:00
|
|
|
resbufLength_ = 0;
|
2006-06-22 15:26:18 +00:00
|
|
|
}
|
|
|
|
return retval;
|
2006-03-21 14:12:51 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2010-06-12 12:29:11 +00:00
|
|
|
void PeerConnection::readData
|
|
|
|
(unsigned char* data, size_t& length, bool encryption)
|
2008-02-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Message Stream Encryption(MSE) support.
Currently, aria2 accepts incoming connections with Obfuscation Header
and legacy BitTorrent Header and establishes connections with
Obfuscation Header first and if failed then retry with legacy
BitTorrent header. If plain text and ARC4 is provided, aria2 always
choose ARC4. The new option to change the default behavior is planned.
For tracker extension, "supportcrypto=1" is added statically.
* src/PeerInitiateConnectionCommand.{h, cc}
* src/PeerConnection.{h, cc}
* src/HandleRegistry.h
* src/SocketCore.h
* src/PeerReceiveHandshakeCommand.{h, cc}
* src/BtRegistry.{h, cc}
* src/PeerListenCommand.cc
* src/InitiatorMSEHandshakeCommand.{h, cc}
* src/ReceiverMSEHandshakeCommand.{h, cc}
* src/MSEHandshake.{h, cc}
* src/ARC4Encryptor.h
* src/ARC4Decryptor.h
* src/LibgcryptARC4Encryptor.h
* src/LibgcryptARC4Decryptor.h
* src/LibgcryptARC4Context.h
* src/LibsslARC4Encryptor.h
* src/LibsslARC4Decryptor.h
* src/LibsslARC4Context.h
* src/DHKeyExchange.h
* src/LibgcryptDHKeyExchange.h
* src/LibsslDHKeyExchange.h
* src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter.
* test/DefaultBtAnnounceTest.cc
* test/ARC4Test.cc
* test/DHKeyExchangeTest.cc
Removed prepareForRetry() because it is not used.
* src/PeerAbstractCommand.{h, cc}
* src/PeerInteractionCommand.{h, cc}
* src/PeerInitiateConnectionCommand.{h, cc}
2008-02-17 15:56:47 +00:00
|
|
|
{
|
|
|
|
if(encryption) {
|
|
|
|
unsigned char temp[MAX_PAYLOAD_LEN];
|
|
|
|
assert(MAX_PAYLOAD_LEN >= length);
|
2010-06-21 13:51:56 +00:00
|
|
|
socket_->readData(temp, length);
|
|
|
|
decryptor_->decrypt(data, length, temp, length);
|
2008-02-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Message Stream Encryption(MSE) support.
Currently, aria2 accepts incoming connections with Obfuscation Header
and legacy BitTorrent Header and establishes connections with
Obfuscation Header first and if failed then retry with legacy
BitTorrent header. If plain text and ARC4 is provided, aria2 always
choose ARC4. The new option to change the default behavior is planned.
For tracker extension, "supportcrypto=1" is added statically.
* src/PeerInitiateConnectionCommand.{h, cc}
* src/PeerConnection.{h, cc}
* src/HandleRegistry.h
* src/SocketCore.h
* src/PeerReceiveHandshakeCommand.{h, cc}
* src/BtRegistry.{h, cc}
* src/PeerListenCommand.cc
* src/InitiatorMSEHandshakeCommand.{h, cc}
* src/ReceiverMSEHandshakeCommand.{h, cc}
* src/MSEHandshake.{h, cc}
* src/ARC4Encryptor.h
* src/ARC4Decryptor.h
* src/LibgcryptARC4Encryptor.h
* src/LibgcryptARC4Decryptor.h
* src/LibgcryptARC4Context.h
* src/LibsslARC4Encryptor.h
* src/LibsslARC4Decryptor.h
* src/LibsslARC4Context.h
* src/DHKeyExchange.h
* src/LibgcryptDHKeyExchange.h
* src/LibsslDHKeyExchange.h
* src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter.
* test/DefaultBtAnnounceTest.cc
* test/ARC4Test.cc
* test/DHKeyExchangeTest.cc
Removed prepareForRetry() because it is not used.
* src/PeerAbstractCommand.{h, cc}
* src/PeerInteractionCommand.{h, cc}
* src/PeerInitiateConnectionCommand.{h, cc}
2008-02-17 15:56:47 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
socket_->readData(data, length);
|
2008-02-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Message Stream Encryption(MSE) support.
Currently, aria2 accepts incoming connections with Obfuscation Header
and legacy BitTorrent Header and establishes connections with
Obfuscation Header first and if failed then retry with legacy
BitTorrent header. If plain text and ARC4 is provided, aria2 always
choose ARC4. The new option to change the default behavior is planned.
For tracker extension, "supportcrypto=1" is added statically.
* src/PeerInitiateConnectionCommand.{h, cc}
* src/PeerConnection.{h, cc}
* src/HandleRegistry.h
* src/SocketCore.h
* src/PeerReceiveHandshakeCommand.{h, cc}
* src/BtRegistry.{h, cc}
* src/PeerListenCommand.cc
* src/InitiatorMSEHandshakeCommand.{h, cc}
* src/ReceiverMSEHandshakeCommand.{h, cc}
* src/MSEHandshake.{h, cc}
* src/ARC4Encryptor.h
* src/ARC4Decryptor.h
* src/LibgcryptARC4Encryptor.h
* src/LibgcryptARC4Decryptor.h
* src/LibgcryptARC4Context.h
* src/LibsslARC4Encryptor.h
* src/LibsslARC4Decryptor.h
* src/LibsslARC4Context.h
* src/DHKeyExchange.h
* src/LibgcryptDHKeyExchange.h
* src/LibsslDHKeyExchange.h
* src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter.
* test/DefaultBtAnnounceTest.cc
* test/ARC4Test.cc
* test/DHKeyExchangeTest.cc
Removed prepareForRetry() because it is not used.
* src/PeerAbstractCommand.{h, cc}
* src/PeerInteractionCommand.{h, cc}
* src/PeerInitiateConnectionCommand.{h, cc}
2008-02-17 15:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-12 12:29:11 +00:00
|
|
|
void PeerConnection::enableEncryption
|
|
|
|
(const SharedHandle<ARC4Encryptor>& encryptor,
|
|
|
|
const SharedHandle<ARC4Decryptor>& decryptor)
|
2008-02-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Message Stream Encryption(MSE) support.
Currently, aria2 accepts incoming connections with Obfuscation Header
and legacy BitTorrent Header and establishes connections with
Obfuscation Header first and if failed then retry with legacy
BitTorrent header. If plain text and ARC4 is provided, aria2 always
choose ARC4. The new option to change the default behavior is planned.
For tracker extension, "supportcrypto=1" is added statically.
* src/PeerInitiateConnectionCommand.{h, cc}
* src/PeerConnection.{h, cc}
* src/HandleRegistry.h
* src/SocketCore.h
* src/PeerReceiveHandshakeCommand.{h, cc}
* src/BtRegistry.{h, cc}
* src/PeerListenCommand.cc
* src/InitiatorMSEHandshakeCommand.{h, cc}
* src/ReceiverMSEHandshakeCommand.{h, cc}
* src/MSEHandshake.{h, cc}
* src/ARC4Encryptor.h
* src/ARC4Decryptor.h
* src/LibgcryptARC4Encryptor.h
* src/LibgcryptARC4Decryptor.h
* src/LibgcryptARC4Context.h
* src/LibsslARC4Encryptor.h
* src/LibsslARC4Decryptor.h
* src/LibsslARC4Context.h
* src/DHKeyExchange.h
* src/LibgcryptDHKeyExchange.h
* src/LibsslDHKeyExchange.h
* src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter.
* test/DefaultBtAnnounceTest.cc
* test/ARC4Test.cc
* test/DHKeyExchangeTest.cc
Removed prepareForRetry() because it is not used.
* src/PeerAbstractCommand.{h, cc}
* src/PeerInteractionCommand.{h, cc}
* src/PeerInitiateConnectionCommand.{h, cc}
2008-02-17 15:56:47 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
encryptor_ = encryptor;
|
|
|
|
decryptor_ = decryptor;
|
2008-02-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Message Stream Encryption(MSE) support.
Currently, aria2 accepts incoming connections with Obfuscation Header
and legacy BitTorrent Header and establishes connections with
Obfuscation Header first and if failed then retry with legacy
BitTorrent header. If plain text and ARC4 is provided, aria2 always
choose ARC4. The new option to change the default behavior is planned.
For tracker extension, "supportcrypto=1" is added statically.
* src/PeerInitiateConnectionCommand.{h, cc}
* src/PeerConnection.{h, cc}
* src/HandleRegistry.h
* src/SocketCore.h
* src/PeerReceiveHandshakeCommand.{h, cc}
* src/BtRegistry.{h, cc}
* src/PeerListenCommand.cc
* src/InitiatorMSEHandshakeCommand.{h, cc}
* src/ReceiverMSEHandshakeCommand.{h, cc}
* src/MSEHandshake.{h, cc}
* src/ARC4Encryptor.h
* src/ARC4Decryptor.h
* src/LibgcryptARC4Encryptor.h
* src/LibgcryptARC4Decryptor.h
* src/LibgcryptARC4Context.h
* src/LibsslARC4Encryptor.h
* src/LibsslARC4Decryptor.h
* src/LibsslARC4Context.h
* src/DHKeyExchange.h
* src/LibgcryptDHKeyExchange.h
* src/LibsslDHKeyExchange.h
* src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter.
* test/DefaultBtAnnounceTest.cc
* test/ARC4Test.cc
* test/DHKeyExchangeTest.cc
Removed prepareForRetry() because it is not used.
* src/PeerAbstractCommand.{h, cc}
* src/PeerInteractionCommand.{h, cc}
* src/PeerInitiateConnectionCommand.{h, cc}
2008-02-17 15:56:47 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
encryptionEnabled_ = true;
|
2008-02-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Message Stream Encryption(MSE) support.
Currently, aria2 accepts incoming connections with Obfuscation Header
and legacy BitTorrent Header and establishes connections with
Obfuscation Header first and if failed then retry with legacy
BitTorrent header. If plain text and ARC4 is provided, aria2 always
choose ARC4. The new option to change the default behavior is planned.
For tracker extension, "supportcrypto=1" is added statically.
* src/PeerInitiateConnectionCommand.{h, cc}
* src/PeerConnection.{h, cc}
* src/HandleRegistry.h
* src/SocketCore.h
* src/PeerReceiveHandshakeCommand.{h, cc}
* src/BtRegistry.{h, cc}
* src/PeerListenCommand.cc
* src/InitiatorMSEHandshakeCommand.{h, cc}
* src/ReceiverMSEHandshakeCommand.{h, cc}
* src/MSEHandshake.{h, cc}
* src/ARC4Encryptor.h
* src/ARC4Decryptor.h
* src/LibgcryptARC4Encryptor.h
* src/LibgcryptARC4Decryptor.h
* src/LibgcryptARC4Context.h
* src/LibsslARC4Encryptor.h
* src/LibsslARC4Decryptor.h
* src/LibsslARC4Context.h
* src/DHKeyExchange.h
* src/LibgcryptDHKeyExchange.h
* src/LibsslDHKeyExchange.h
* src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter.
* test/DefaultBtAnnounceTest.cc
* test/ARC4Test.cc
* test/DHKeyExchangeTest.cc
Removed prepareForRetry() because it is not used.
* src/PeerAbstractCommand.{h, cc}
* src/PeerInteractionCommand.{h, cc}
* src/PeerInitiateConnectionCommand.{h, cc}
2008-02-17 15:56:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PeerConnection::presetBuffer(const unsigned char* data, size_t length)
|
|
|
|
{
|
|
|
|
size_t nwrite = std::min((size_t)MAX_PAYLOAD_LEN, length);
|
2010-06-21 13:51:56 +00:00
|
|
|
memcpy(resbuf_, data, nwrite);
|
|
|
|
resbufLength_ = length;
|
2008-02-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added Message Stream Encryption(MSE) support.
Currently, aria2 accepts incoming connections with Obfuscation Header
and legacy BitTorrent Header and establishes connections with
Obfuscation Header first and if failed then retry with legacy
BitTorrent header. If plain text and ARC4 is provided, aria2 always
choose ARC4. The new option to change the default behavior is planned.
For tracker extension, "supportcrypto=1" is added statically.
* src/PeerInitiateConnectionCommand.{h, cc}
* src/PeerConnection.{h, cc}
* src/HandleRegistry.h
* src/SocketCore.h
* src/PeerReceiveHandshakeCommand.{h, cc}
* src/BtRegistry.{h, cc}
* src/PeerListenCommand.cc
* src/InitiatorMSEHandshakeCommand.{h, cc}
* src/ReceiverMSEHandshakeCommand.{h, cc}
* src/MSEHandshake.{h, cc}
* src/ARC4Encryptor.h
* src/ARC4Decryptor.h
* src/LibgcryptARC4Encryptor.h
* src/LibgcryptARC4Decryptor.h
* src/LibgcryptARC4Context.h
* src/LibsslARC4Encryptor.h
* src/LibsslARC4Decryptor.h
* src/LibsslARC4Context.h
* src/DHKeyExchange.h
* src/LibgcryptDHKeyExchange.h
* src/LibsslDHKeyExchange.h
* src/DefaultBtAnnounce.cc: Just added "supportcrypto=1" parameter.
* test/DefaultBtAnnounceTest.cc
* test/ARC4Test.cc
* test/DHKeyExchangeTest.cc
Removed prepareForRetry() because it is not used.
* src/PeerAbstractCommand.{h, cc}
* src/PeerInteractionCommand.{h, cc}
* src/PeerInitiateConnectionCommand.{h, cc}
2008-02-17 15:56:47 +00:00
|
|
|
}
|
|
|
|
|
2008-09-28 10:55:17 +00:00
|
|
|
bool PeerConnection::sendBufferIsEmpty() const
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
return socketBuffer_.sendBufferIsEmpty();
|
2008-09-28 10:55:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t PeerConnection::sendPendingData()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
ssize_t writtenLength = socketBuffer_.send();
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_DEBUG(fmt("sent %ld byte(s).", static_cast<long int>(writtenLength)));
|
2008-09-28 10:55:17 +00:00
|
|
|
return writtenLength;
|
|
|
|
}
|
|
|
|
|
2010-11-14 07:17:55 +00:00
|
|
|
unsigned char* PeerConnection::detachBuffer()
|
|
|
|
{
|
|
|
|
unsigned char* detachbuf = resbuf_;
|
|
|
|
resbuf_ = new unsigned char[MAX_PAYLOAD_LEN];
|
|
|
|
return detachbuf;
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|