diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-02-01 17:36:33 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-02-01 17:36:33 +0000 |
| commit | 0f133632298e31dab0efe6fd36f00c84d2175f33 (patch) | |
| tree | 0e9effc84f05b47e3a6c6ec4a9f7b38391d8be86 /src/SocketCore.h | |
| parent | 0bce06348e3be57c97e246d2a7af71683dc76ede (diff) | |
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}
Diffstat (limited to 'src/SocketCore.h')
| -rw-r--r-- | src/SocketCore.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/SocketCore.h b/src/SocketCore.h index fda3e8a0..262e0d70 100644 --- a/src/SocketCore.h +++ b/src/SocketCore.h @@ -38,6 +38,7 @@ #include "common.h" #include <string> #include <utility> +#include <sys/socket.h> #ifdef HAVE_LIBSSL // for SSL @@ -55,6 +56,8 @@ class SocketCore { friend bool operator!=(const SocketCore& s1, const SocketCore& s2); friend bool operator<(const SocketCore& s1, const SocketCore& s2); private: + // socket type defined in <sys/socket.h> + int _sockType; // socket endpoint descriptor int32_t sockfd; // reference counter for this object. @@ -80,12 +83,12 @@ private: #endif // HAVE_LIBGNUTLS void init(); - SocketCore(int32_t sockfd); + SocketCore(int32_t sockfd, int sockType); static int error(); static const char *errorMsg(); static const char *errorMsg(const int err); public: - SocketCore(); + SocketCore(int sockType = SOCK_STREAM); ~SocketCore(); int32_t getSockfd() const { return sockfd; } @@ -93,11 +96,17 @@ public: bool isOpen() const { return sockfd != -1; } /** - * Creates a socket and listens form connection on it. + * Creates a socket and bind it with locahost's address and port. * @param port port to listen. If 0 is specified, os automaticaly * choose avaiable port. */ - void beginListen(int32_t port = 0); + void bind(uint16_t port); + + /** + * Listens form connection on it. + * Call bind(uint16_t) before calling this function. + */ + void beginListen(); /** * Stores host address and port of this socket to addrinfo. @@ -172,6 +181,8 @@ public: writeData(msg.c_str(), msg.size()); } + void writeData(const char* data, size_t len, const string& host, uint16_t port); + /** * Reads up to len bytes from this socket. * data is a pointer pointing the first @@ -186,6 +197,15 @@ public: */ void readData(char* data, int32_t& len); + ssize_t readDataFrom(char* data, size_t len, struct sockaddr* sender, + socklen_t* senderLength); + + ssize_t readDataFrom(char*, size_t len, + pair<string /* numerichost */, + uint16_t /* port */>& sender); + + ssize_t readDataFrom(char* data, size_t len); + /** * Reads up to len bytes from this socket, but bytes are not removed from * this socket. |
