summaryrefslogtreecommitdiff
path: root/src/InitiateConnectionCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-04-01 00:12:27 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2013-04-01 00:12:27 +0900
commit597e1a5c1b10aa3668f91bcae02a864dcd0c045b (patch)
tree4437c2896b410b441013452b7385dfa303441772 /src/InitiateConnectionCommand.cc
parentd671d8bf3672cbefc06f3727f82b77872abe6120 (diff)
Implement simple Happy Eyeballs for HTTP/FTP downloads
Diffstat (limited to 'src/InitiateConnectionCommand.cc')
-rw-r--r--src/InitiateConnectionCommand.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/InitiateConnectionCommand.cc b/src/InitiateConnectionCommand.cc
index baee1f74..c4d084fa 100644
--- a/src/InitiateConnectionCommand.cc
+++ b/src/InitiateConnectionCommand.cc
@@ -51,6 +51,7 @@
#include "RecoverableException.h"
#include "fmt.h"
#include "SocketRecvBuffer.h"
+#include "BackupIPv4ConnectCommand.h"
namespace aria2 {
@@ -127,4 +128,36 @@ void InitiateConnectionCommand::setConnectedAddrInfo
req->setConnectedAddrInfo(hostname, peerAddr.first, peerAddr.second);
}
+SharedHandle<BackupConnectInfo>
+InitiateConnectionCommand::createBackupIPv4ConnectCommand
+(const std::string& hostname, const std::string& ipaddr, uint16_t port,
+ Command* mainCommand)
+{
+ // Prepare IPv4 backup connection attemp in "Happy Eyeballs"
+ // fashion.
+ SharedHandle<BackupConnectInfo> info;
+ char buf[sizeof(in6_addr)];
+ if(inetPton(AF_INET6, ipaddr.c_str(), &buf) == -1) {
+ return info;
+ }
+ A2_LOG_INFO("Searching IPv4 address for backup connection attempt");
+ std::vector<std::string> addrs;
+ getDownloadEngine()->findAllCachedIPAddresses(std::back_inserter(addrs),
+ hostname, port);
+ for(std::vector<std::string>::const_iterator i = addrs.begin(),
+ eoi = addrs.end(); i != eoi; ++i) {
+ if(inetPton(AF_INET, (*i).c_str(), &buf) == 0) {
+ info.reset(new BackupConnectInfo());
+ BackupIPv4ConnectCommand* command = new BackupIPv4ConnectCommand
+ (getDownloadEngine()->newCUID(), *i, port, info, mainCommand,
+ getRequestGroup(), getDownloadEngine());
+ A2_LOG_INFO(fmt("Issue backup connection command CUID#%"PRId64
+ ", addr=%s", command->getCuid(), (*i).c_str()));
+ getDownloadEngine()->addCommand(command);
+ return info;
+ }
+ }
+ return info;
+}
+
} // namespace aria2