2006-02-17 14:47:45 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-02-17 14:47:45 +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-02-17 14:47:45 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
2010-10-31 07:23:53 +00:00
|
|
|
#ifndef D_SOCKET_CORE_H
|
|
|
|
#define D_SOCKET_CORE_H
|
2006-02-17 14:47:45 +00:00
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
#include "common.h"
|
2008-09-30 15:16:37 +00:00
|
|
|
|
2006-02-17 14:47:45 +00:00
|
|
|
#include <string>
|
2008-09-30 15:16:37 +00:00
|
|
|
#include <cstdlib>
|
2006-02-21 12:27:17 +00:00
|
|
|
#include <utility>
|
2009-12-06 08:25:41 +00:00
|
|
|
#include <vector>
|
2006-02-17 18:51:12 +00:00
|
|
|
|
2010-04-16 09:25:59 +00:00
|
|
|
#include "a2netcompat.h"
|
|
|
|
|
2006-02-17 18:51:12 +00:00
|
|
|
#ifdef HAVE_LIBSSL
|
|
|
|
// for SSL
|
|
|
|
# include <openssl/ssl.h>
|
2007-07-31 16:45:16 +00:00
|
|
|
# include <openssl/err.h>
|
2006-02-17 18:51:12 +00:00
|
|
|
#endif // HAVE_LIBSSL
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
#ifdef HAVE_LIBGNUTLS
|
|
|
|
# include <gnutls/gnutls.h>
|
|
|
|
#endif // HAVE_LIBGNUTLS
|
2008-09-30 15:16:37 +00:00
|
|
|
|
2008-11-08 10:48:02 +00:00
|
|
|
#include "SharedHandle.h"
|
2008-09-30 15:16:37 +00:00
|
|
|
#include "a2io.h"
|
|
|
|
#include "a2netcompat.h"
|
|
|
|
#include "a2time.h"
|
2006-02-17 14:47:45 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-02-17 14:47:45 +00:00
|
|
|
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_SSL
|
2008-11-08 10:48:02 +00:00
|
|
|
class TLSContext;
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_SSL
|
2008-11-08 10:48:02 +00:00
|
|
|
|
2006-02-17 14:47:45 +00:00
|
|
|
class SocketCore {
|
2006-07-19 17:07:45 +00:00
|
|
|
friend bool operator==(const SocketCore& s1, const SocketCore& s2);
|
|
|
|
friend bool operator!=(const SocketCore& s1, const SocketCore& s2);
|
|
|
|
friend bool operator<(const SocketCore& s1, const SocketCore& s2);
|
2006-02-17 14:47:45 +00:00
|
|
|
private:
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
// socket type defined in <sys/socket.h>
|
2010-06-21 13:51:56 +00:00
|
|
|
int sockType_;
|
2006-02-17 14:47:45 +00:00
|
|
|
// socket endpoint descriptor
|
2010-06-21 13:51:56 +00:00
|
|
|
sock_t sockfd_;
|
2008-05-31 10:31:07 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
static int protocolFamily_;
|
2009-05-06 07:42:59 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
static std::vector<std::pair<struct sockaddr_storage, socklen_t> > bindAddrs_;
|
2009-12-03 14:41:08 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
bool blocking_;
|
|
|
|
int secure_;
|
2008-09-27 16:06:34 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
bool wantRead_;
|
|
|
|
bool wantWrite_;
|
2008-09-27 16:06:34 +00:00
|
|
|
|
2008-11-08 10:48:02 +00:00
|
|
|
#if ENABLE_SSL
|
2010-06-21 13:51:56 +00:00
|
|
|
static SharedHandle<TLSContext> tlsContext_;
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_SSL
|
2008-11-08 10:48:02 +00:00
|
|
|
|
2006-02-17 18:51:12 +00:00
|
|
|
#ifdef HAVE_LIBSSL
|
|
|
|
// for SSL
|
|
|
|
SSL* ssl;
|
2008-09-27 16:06:34 +00:00
|
|
|
|
|
|
|
int sslHandleEAGAIN(int ret);
|
2006-02-17 18:51:12 +00:00
|
|
|
#endif // HAVE_LIBSSL
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
#ifdef HAVE_LIBGNUTLS
|
2010-06-21 13:51:56 +00:00
|
|
|
gnutls_session_t sslSession_;
|
2008-09-27 16:06:34 +00:00
|
|
|
|
|
|
|
void gnutlsRecordCheckDirection();
|
2006-03-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* configure.in: Added gnutls support. Added several CPP macros.
* m4/openssl.m4: Added.
* src/SocketCore.{h,cc}: Drop const quarifier from writeData(),
readData(), peekData(). Added gnutls support.
* src/HttpDownloadCommand.cc: Removed SleepCommand.h
* src/TrackerWatcherCommand.{h,cc}: Added. This command creates
TrackerInitCommand periodicaly(TorrentMan::minInterval).
* src/TorrentMan.cc: Remove downloadedSize == 0 check from
save().
Instead, added a check for whether setup method has executed
successfully.
* src/TorrentMan.h: Added member vaiable setupComplete. Updated
DEFAULT_ANNOUNCE_INTERVAL and DEFAULT_ANNOUNCE_MIN_INTERVAL to
300.
* src/Makefile.am: Updated.
* src/messageDigest.h: Added. This is a macro calculating SHA1
digest
using whether OpenSSL or gcrypt, depending on the result of
configure
script.
* src/ShaVisitor.{h,cc}: Removed direct dependency on OpenSSL by
using
messageDigest.h.
* src/TorrentAutoSaveCommand.h: Removed unused variable cuid.
* src/PeerListenCommand.cc: Added log about port binded
successfully.
Fixed memory leak.
* src/main.cc: Added gnutls support. Replaced LIB_SSL with
ENABLE_BITTORRENT where they are not related to OpenSSL but
BitTorrent.
Removed instantiation of TrackerInitCommand. Instead,
TrackerWatcherCommand is instantiated and pushed to the command
queue.
* src/InitiateConnectionCommandFactory.cc: Replaced HAVE_LIBSSL
with
ENABLE_SSL.
* src/Request.cc: Replaced HAVE_LIBSSL with ENABLE_SSL.
* src/RequestSlotMan.cc:
(deleteCompletedRequestSlot)
If a piece is already acquired by another command, delete the
request
slots for the piece.
* src/TrackerUpdateCommand.cc:
(execute)
Changed log level of MSG_TRACKER_WARNING_MESSAGE from info to
warn.
Added a check whether peer list is null.
Fixed the bug that causes sending completed event to the tracker
several times.
* src/TrackerInitCommand.cc:
(execute)
Fixed the bug that causes sending completed event to the tracker
several times.
* src/AbstractDiskWriter.{h,cc}: Removed direct dependency on
OpenSSL
by using messageDigest.h.
2006-03-26 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* PeerConnection.cc: Replaced log message "keep-alive" with
"keep alive".
* PeerInteractionCommand.{h,cc}: Close connection if peer is
choking
localhost long time.
* TorrentMan.cc: When adding new peer with duplicate = true, if
the
number of peer list is equal to or grater than MAX_PEER_LIST,
delete
at most 100 failure entry from the list. If with duplicate =
false,
MAX_PEER_LIST is not checked.
* PeerListenCommand.cc: Fixed the argument order of log message.
2006-03-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* Logger.h: Moved enum LEVEL from SimpleLogger.h to here.
Added warn().
* SimpleLogger.h: Moved enum LEVEL to Logger.h.
Implemented warn().
Defined 2 macros(WRITE_LOG, WRITE_LOG_EX) to avoid duplicated
code.
2006-03-27 14:47:26 +00:00
|
|
|
#endif // HAVE_LIBGNUTLS
|
|
|
|
|
2006-02-21 12:27:17 +00:00
|
|
|
void init();
|
2008-05-31 10:31:07 +00:00
|
|
|
|
2009-12-03 14:41:08 +00:00
|
|
|
void bind(const struct sockaddr* addr, socklen_t addrlen);
|
|
|
|
|
2010-02-20 14:23:25 +00:00
|
|
|
void setSockOpt(int level, int optname, void* optval, socklen_t optlen);
|
|
|
|
|
2008-06-16 14:01:45 +00:00
|
|
|
SocketCore(sock_t sockfd, int sockType);
|
2006-02-17 14:47:45 +00:00
|
|
|
public:
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
SocketCore(int sockType = SOCK_STREAM);
|
2006-02-17 14:47:45 +00:00
|
|
|
~SocketCore();
|
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
sock_t getSockfd() const { return sockfd_; }
|
2006-07-19 17:07:45 +00:00
|
|
|
|
2010-06-21 13:51:56 +00:00
|
|
|
bool isOpen() const { return sockfd_ != (sock_t) -1; }
|
2006-07-19 17:07:45 +00:00
|
|
|
|
2010-02-22 15:58:05 +00:00
|
|
|
void setMulticastInterface(const std::string& localAddr);
|
|
|
|
|
2010-02-20 14:23:25 +00:00
|
|
|
void setMulticastTtl(unsigned char ttl);
|
|
|
|
|
2010-02-22 15:58:05 +00:00
|
|
|
void setMulticastLoop(unsigned char loop);
|
|
|
|
|
|
|
|
void joinMulticastGroup
|
|
|
|
(const std::string& multicastAddr, uint16_t multicastPort,
|
|
|
|
const std::string& localAddr);
|
2010-02-20 14:23:25 +00:00
|
|
|
|
2010-02-22 15:58:05 +00:00
|
|
|
void create(int family, int protocol = 0);
|
|
|
|
|
2010-02-20 14:23:25 +00:00
|
|
|
void bindWithFamily(uint16_t port, int family, int flags = AI_PASSIVE);
|
|
|
|
|
2006-03-01 07:00:39 +00:00
|
|
|
/**
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
* Creates a socket and bind it with locahost's address and port.
|
2009-08-30 12:25:04 +00:00
|
|
|
* flags is set to struct addrinfo's ai_flags.
|
2006-03-21 14:12:51 +00:00
|
|
|
* @param port port to listen. If 0 is specified, os automaticaly
|
|
|
|
* choose avaiable port.
|
2006-03-01 07:00:39 +00:00
|
|
|
*/
|
2009-08-30 12:25:04 +00:00
|
|
|
void bind(uint16_t port, int flags = AI_PASSIVE);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
2010-08-07 14:15:21 +00:00
|
|
|
void bind
|
|
|
|
(const std::string& addr, uint16_t port, int family, int flags = AI_PASSIVE);
|
|
|
|
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
/**
|
|
|
|
* Listens form connection on it.
|
|
|
|
* Call bind(uint16_t) before calling this function.
|
|
|
|
*/
|
|
|
|
void beginListen();
|
2006-03-01 07:00:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores host address and port of this socket to addrinfo.
|
|
|
|
* @param addrinfo placeholder to store host address and port.
|
|
|
|
*/
|
2008-03-09 12:24:01 +00:00
|
|
|
void getAddrInfo(std::pair<std::string, uint16_t>& addrinfo) const;
|
2009-06-02 03:18:07 +00:00
|
|
|
|
2010-07-30 14:45:35 +00:00
|
|
|
/**
|
|
|
|
* Stores address of this socket to sockaddr. len must be
|
|
|
|
* initialized to the size of sockaddr. On success, address data is
|
|
|
|
* stored in sockaddr and actual size of address structure is stored
|
|
|
|
* in len.
|
|
|
|
*/
|
|
|
|
void getAddrInfo
|
|
|
|
(struct sockaddr_storage& sockaddr, socklen_t& len) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns address family of this socket.
|
|
|
|
* The socket must be connected or bounded to address.
|
|
|
|
*/
|
|
|
|
int getAddressFamily() const;
|
|
|
|
|
2006-03-21 14:12:51 +00:00
|
|
|
/**
|
|
|
|
* Stores peer's address and port to peerinfo.
|
|
|
|
* @param peerinfo placeholder to store peer's address and port.
|
|
|
|
*/
|
2008-03-09 12:24:01 +00:00
|
|
|
void getPeerInfo(std::pair<std::string, uint16_t>& peerinfo) const;
|
2006-03-01 07:00:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Accepts incoming connection on this socket.
|
|
|
|
* You must call beginListen() before calling this method.
|
|
|
|
* @return accepted socket. The caller must delete it after using it.
|
|
|
|
*/
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
SocketCore* acceptConnection() const;
|
2006-03-01 07:00:39 +00:00
|
|
|
|
2006-02-17 14:47:45 +00:00
|
|
|
/**
|
|
|
|
* Connects to the server named host and the destination port is port.
|
2006-03-01 07:00:39 +00:00
|
|
|
* This method makes socket non-blocking mode.
|
|
|
|
* To make the socket blocking mode again, call setBlockingMode() after
|
2006-02-17 14:47:45 +00:00
|
|
|
* the connection is established.
|
2006-03-01 07:00:39 +00:00
|
|
|
* @param host hostname or ip address to connect to
|
|
|
|
* @param port service port number to connect to
|
2006-02-17 14:47:45 +00:00
|
|
|
*/
|
2008-03-09 12:24:01 +00:00
|
|
|
void establishConnection(const std::string& host, uint16_t port);
|
2006-02-17 14:47:45 +00:00
|
|
|
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
void setNonBlockingMode();
|
2006-06-22 15:26:18 +00:00
|
|
|
|
2006-03-01 07:00:39 +00:00
|
|
|
/**
|
|
|
|
* Makes this socket blocking mode.
|
|
|
|
*/
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
void setBlockingMode();
|
2006-02-17 14:47:45 +00:00
|
|
|
|
2006-03-01 07:00:39 +00:00
|
|
|
/**
|
|
|
|
* Closes the connection of this socket.
|
|
|
|
*/
|
2006-02-17 14:47:45 +00:00
|
|
|
void closeConnection();
|
|
|
|
|
2006-03-01 07:00:39 +00:00
|
|
|
/**
|
|
|
|
* Checks whether this socket is available for writing.
|
|
|
|
* @param timeout the amount of time elapsed before the checking are timed
|
|
|
|
* out.
|
|
|
|
* @return true if the socket is available for writing,
|
|
|
|
* otherwise returns false.
|
|
|
|
*/
|
2008-05-31 10:31:07 +00:00
|
|
|
bool isWritable(time_t timeout);
|
2006-02-17 14:47:45 +00:00
|
|
|
|
2006-03-01 07:00:39 +00:00
|
|
|
/**
|
|
|
|
* Checks whether this socket is available for reading.
|
|
|
|
* @param timeout the amount of time elapsed before the checking are timed
|
|
|
|
* out.
|
|
|
|
* @return true if the socket is available for reading,
|
|
|
|
* otherwise returns false.
|
|
|
|
*/
|
2008-05-31 10:31:07 +00:00
|
|
|
bool isReadable(time_t timeout);
|
2006-02-17 14:47:45 +00:00
|
|
|
|
2006-03-01 07:00:39 +00:00
|
|
|
/**
|
2008-09-27 16:06:34 +00:00
|
|
|
* Writes data into this socket. data is a pointer pointing the first
|
2006-03-01 07:00:39 +00:00
|
|
|
* byte of the data and len is the length of data.
|
2008-09-27 16:06:34 +00:00
|
|
|
* If the underlying socket is in blocking mode, this method may block until
|
|
|
|
* all data is sent.
|
|
|
|
* If the underlying socket is in non-blocking mode, this method may return
|
|
|
|
* even if all data is sent. The size of written data is returned. If
|
2010-06-21 13:51:56 +00:00
|
|
|
* underlying socket gets EAGAIN, wantRead_ or wantWrite_ is set accordingly.
|
|
|
|
* This method sets wantRead_ and wantWrite_ to false before do anything else.
|
2006-03-01 07:00:39 +00:00
|
|
|
* @param data data to write
|
|
|
|
* @param len length of data
|
|
|
|
*/
|
2008-09-13 16:32:47 +00:00
|
|
|
ssize_t writeData(const char* data, size_t len);
|
|
|
|
ssize_t writeData(const std::string& msg)
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2008-09-13 16:32:47 +00:00
|
|
|
return writeData(msg.c_str(), msg.size());
|
2007-10-11 16:58:24 +00:00
|
|
|
}
|
2008-09-13 16:32:47 +00:00
|
|
|
ssize_t writeData(const unsigned char* data, size_t len)
|
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-13 16:32:47 +00:00
|
|
|
return writeData(reinterpret_cast<const char*>(data), len);
|
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
|
|
|
}
|
2006-02-17 14:47:45 +00:00
|
|
|
|
2008-10-05 13:21:14 +00:00
|
|
|
ssize_t writeData(const char* data, size_t len,
|
2010-01-05 16:01:46 +00:00
|
|
|
const std::string& host, uint16_t port);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
2008-10-05 13:21:14 +00:00
|
|
|
ssize_t writeData(const unsigned char* data, size_t len,
|
2010-01-05 16:01:46 +00:00
|
|
|
const std::string& host,
|
|
|
|
uint16_t port)
|
2008-03-07 12:05:50 +00:00
|
|
|
{
|
2008-10-05 13:21:14 +00:00
|
|
|
return writeData(reinterpret_cast<const char*>(data), len, host, port);
|
2008-03-07 12:05:50 +00:00
|
|
|
}
|
|
|
|
|
2006-03-01 07:00:39 +00:00
|
|
|
/**
|
|
|
|
* Reads up to len bytes from this socket.
|
|
|
|
* data is a pointer pointing the first
|
|
|
|
* byte of the data, which must be allocated before this method is called.
|
|
|
|
* len is the size of the allocated memory. When this method returns
|
|
|
|
* successfully, len is replaced by the size of the read data.
|
2008-09-27 16:06:34 +00:00
|
|
|
* If the underlying socket is in blocking mode, this method may block until
|
|
|
|
* at least 1byte is received.
|
|
|
|
* If the underlying socket is in non-blocking mode, this method may return
|
|
|
|
* even if no single byte is received. If the underlying socket gets EAGAIN,
|
2010-06-21 13:51:56 +00:00
|
|
|
* wantRead_ or wantWrite_ is set accordingly.
|
|
|
|
* This method sets wantRead_ and wantWrite_ to false before do anything else.
|
2006-03-01 07:00:39 +00:00
|
|
|
* @param data holder to store data.
|
|
|
|
* @param len the maximum size data can store. This method assigns
|
|
|
|
* the number of bytes read to len.
|
|
|
|
*/
|
2008-03-09 12:24:01 +00:00
|
|
|
void readData(char* data, size_t& len);
|
2006-03-01 07:00:39 +00:00
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void readData(unsigned char* data, size_t& len)
|
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
|
|
|
{
|
|
|
|
readData(reinterpret_cast<char*>(data), len);
|
|
|
|
}
|
|
|
|
|
2008-03-07 12:05:50 +00:00
|
|
|
ssize_t readDataFrom(char* data, size_t len,
|
2010-01-05 16:01:46 +00:00
|
|
|
std::pair<std::string /* numerichost */,
|
|
|
|
uint16_t /* port */>& sender);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
2008-03-07 12:05:50 +00:00
|
|
|
ssize_t readDataFrom(unsigned char* data, size_t len,
|
2010-01-05 16:01:46 +00:00
|
|
|
std::pair<std::string /* numerichost */,
|
|
|
|
uint16_t /* port */>& sender)
|
2008-03-07 12:05:50 +00:00
|
|
|
{
|
|
|
|
return readDataFrom(reinterpret_cast<char*>(data), len, sender);
|
|
|
|
}
|
2009-06-02 03:18:07 +00:00
|
|
|
|
2006-02-17 18:51:12 +00:00
|
|
|
/**
|
2006-02-17 19:04:22 +00:00
|
|
|
* Makes this socket secure.
|
|
|
|
* If the system has not OpenSSL, then this method do nothing.
|
2006-03-01 07:00:39 +00:00
|
|
|
* connection must be established before calling this method.
|
2008-11-09 07:36:44 +00:00
|
|
|
*
|
|
|
|
* If you are going to verify peer's certificate, hostname must be supplied.
|
2006-02-17 18:51:12 +00:00
|
|
|
*/
|
2008-11-09 07:36:44 +00:00
|
|
|
bool initiateSecureConnection(const std::string& hostname="");
|
2008-09-27 16:06:34 +00:00
|
|
|
|
|
|
|
void prepareSecureConnection();
|
2006-07-28 14:06:47 +00:00
|
|
|
|
|
|
|
bool operator==(const SocketCore& s) {
|
2010-06-21 13:51:56 +00:00
|
|
|
return sockfd_ == s.sockfd_;
|
2006-07-28 14:06:47 +00:00
|
|
|
}
|
2009-06-02 03:18:07 +00:00
|
|
|
|
2006-07-28 14:06:47 +00:00
|
|
|
bool operator!=(const SocketCore& s) {
|
|
|
|
return !(*this == s);
|
|
|
|
}
|
2009-06-02 03:18:07 +00:00
|
|
|
|
2006-07-28 14:06:47 +00:00
|
|
|
bool operator<(const SocketCore& s) {
|
2010-06-21 13:51:56 +00:00
|
|
|
return sockfd_ < s.sockfd_;
|
2006-07-28 14:06:47 +00:00
|
|
|
}
|
2008-09-14 14:26:35 +00:00
|
|
|
|
|
|
|
std::string getSocketError() const;
|
2008-09-27 16:06:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the underlying socket gets EAGAIN in the previous
|
|
|
|
* readData() or writeData() and the socket needs more incoming data to
|
|
|
|
* continue the operation.
|
|
|
|
*/
|
|
|
|
bool wantRead() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the underlying socket gets EAGAIN in the previous
|
|
|
|
* readData() or writeData() and the socket needs to write more data.
|
|
|
|
*/
|
|
|
|
bool wantWrite() const;
|
2008-11-08 10:48:02 +00:00
|
|
|
|
2008-11-13 15:08:52 +00:00
|
|
|
#ifdef ENABLE_SSL
|
2008-11-08 10:48:02 +00:00
|
|
|
static void setTLSContext(const SharedHandle<TLSContext>& tlsContext);
|
2008-11-13 15:08:52 +00:00
|
|
|
#endif // ENABLE_SSL
|
2009-05-06 07:42:59 +00:00
|
|
|
|
|
|
|
static void setProtocolFamily(int protocolFamily)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
protocolFamily_ = protocolFamily;
|
2009-05-06 07:42:59 +00:00
|
|
|
}
|
2009-12-03 14:41:08 +00:00
|
|
|
|
|
|
|
// Bind socket to interface. interface may be specified as a
|
|
|
|
// hostname, IP address or interface name like eth0. If the given
|
|
|
|
// interface is not found or binding socket is failed, exception
|
2010-06-21 13:51:56 +00:00
|
|
|
// will be thrown. Set protocolFamily_ before calling this function
|
2009-12-03 14:41:08 +00:00
|
|
|
// if you limit protocol family.
|
2010-01-09 13:06:45 +00:00
|
|
|
//
|
|
|
|
// We cannot use interface as an argument because it is a reserved
|
|
|
|
// keyword in MSVC.
|
|
|
|
static void bindAddress(const std::string& iface);
|
2010-02-21 15:21:21 +00:00
|
|
|
|
|
|
|
friend void getInterfaceAddress
|
|
|
|
(std::vector<std::pair<struct sockaddr_storage, socklen_t> >& ifAddrs,
|
2010-02-23 13:50:35 +00:00
|
|
|
const std::string& iface, int family, int aiFlags);
|
2006-02-17 14:47:45 +00:00
|
|
|
};
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2009-12-24 14:59:47 +00:00
|
|
|
// Set default ai_flags. hints.ai_flags is initialized with this
|
|
|
|
// value.
|
|
|
|
void setDefaultAIFlags(int flags);
|
|
|
|
|
|
|
|
// Wrapper function for getaddrinfo(). The value
|
|
|
|
// flags|DEFAULT_AI_FLAGS is used as ai_flags. You can override
|
|
|
|
// DEFAULT_AI_FLAGS value by calling setDefaultAIFlags() with new
|
|
|
|
// flags.
|
|
|
|
int callGetaddrinfo
|
|
|
|
(struct addrinfo** resPtr, const char* host, const char* service, int family,
|
|
|
|
int sockType, int flags, int protocol);
|
|
|
|
|
2010-02-21 15:21:21 +00:00
|
|
|
// Collects IP addresses of given inteface iface and stores in
|
|
|
|
// ifAddres. iface may be specified as a hostname, IP address or
|
|
|
|
// interface name like eth0. You can limit the family of IP addresses
|
2010-02-23 13:50:35 +00:00
|
|
|
// to collect using family argument. aiFlags is passed to
|
|
|
|
// getaddrinfo() as hints.ai_flags. No throw.
|
2010-02-21 15:21:21 +00:00
|
|
|
void getInterfaceAddress
|
|
|
|
(std::vector<std::pair<struct sockaddr_storage, socklen_t> >& ifAddrs,
|
2010-02-23 13:50:35 +00:00
|
|
|
const std::string& iface, int family = AF_UNSPEC, int aiFlags = 0);
|
2010-02-21 15:21:21 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|
|
|
|
|
2010-10-31 07:23:53 +00:00
|
|
|
#endif // D_SOCKET_CORE_H
|