diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index aa0c9e32..e97b3894 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -730,6 +730,15 @@ std::vector OptionHandlerFactory::createOptionHandlers() op->addTag(TAG_ADVANCED); handlers.push_back(op); } + { + OptionHandler* op(new NumberOptionHandler + (PREF_DSCP, + TEXT_DSCP, + "0", + 0)); + op->addTag(TAG_ADVANCED); + handlers.push_back(op); + } { OptionHandler* op(new BooleanOptionHandler (PREF_SELECT_LEAST_USED_HOST, diff --git a/src/PeerInitiateConnectionCommand.cc b/src/PeerInitiateConnectionCommand.cc index 384af239..d785d88a 100644 --- a/src/PeerInitiateConnectionCommand.cc +++ b/src/PeerInitiateConnectionCommand.cc @@ -41,6 +41,7 @@ #include "prefs.h" #include "SocketCore.h" #include "Logger.h" +#include "Option.h" #include "LogFactory.h" #include "Peer.h" #include "BtRuntime.h" @@ -83,6 +84,7 @@ bool PeerInitiateConnectionCommand::executeInternal() { createSocket(); getSocket()->establishConnection(getPeer()->getIPAddress(), getPeer()->getPort(), false); + getSocket()->setIpDscp(requestGroup_->getOption()->getAsInt(PREF_DSCP)); if(mseHandshakeEnabled_) { auto c = make_unique (getCuid(), requestGroup_, getPeer(), diff --git a/src/PeerListenCommand.cc b/src/PeerListenCommand.cc index 4c137e55..4d730100 100644 --- a/src/PeerListenCommand.cc +++ b/src/PeerListenCommand.cc @@ -44,6 +44,7 @@ #include "message.h" #include "ReceiverMSEHandshakeCommand.h" #include "Logger.h" +#include "Option.h" #include "LogFactory.h" #include "SocketCore.h" #include "SimpleRandomizer.h" @@ -110,6 +111,7 @@ bool PeerListenCommand::execute() { std::shared_ptr peerSocket; try { peerSocket = socket_->acceptConnection(); + peerSocket->setIpDscp(e_->getOption()->getAsInt(PREF_DSCP)); std::pair peerInfo; peerSocket->getPeerInfo(peerInfo); diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 74ebdb5c..8022e2ff 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -532,6 +532,11 @@ void SocketCore::setTcpNodelay(bool f) setSockOpt(IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val)); } +void SocketCore::setIpDscp(int32_t dscp) +{ + setSockOpt(IPPROTO_IP, IP_TOS, &dscp, sizeof(dscp)); +} + void SocketCore::setNonBlockingMode() { #ifdef __MINGW32__ diff --git a/src/SocketCore.h b/src/SocketCore.h index de7065d4..4d2a70dd 100644 --- a/src/SocketCore.h +++ b/src/SocketCore.h @@ -120,6 +120,9 @@ public: // Enables TCP_NODELAY socket option if f == true. void setTcpNodelay(bool f); + // Set DSCP byte + void setIpDscp(int32_t); + void create(int family, int protocol = 0); void bindWithFamily(uint16_t port, int family, int flags = AI_PASSIVE); diff --git a/src/prefs.cc b/src/prefs.cc index e3572990..9e5b39c9 100644 --- a/src/prefs.cc +++ b/src/prefs.cc @@ -358,6 +358,8 @@ PrefPtr PREF_DISK_CACHE = makePref("disk-cache"); PrefPtr PREF_GID = makePref("gid"); // values: 1*digit PrefPtr PREF_SAVE_SESSION_INTERVAL = makePref("save-session-interval"); +// values: 1*digit +PrefPtr PREF_DSCP = makePref("dscp"); /** * FTP related preferences diff --git a/src/prefs.h b/src/prefs.h index 0dbc1bc7..8f7bfafb 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -294,6 +294,8 @@ extern PrefPtr PREF_DISK_CACHE; extern PrefPtr PREF_GID; // values: 1*digit extern PrefPtr PREF_SAVE_SESSION_INTERVAL; +// values: 1*digit +extern PrefPtr PREF_DSCP; /** * FTP related preferences diff --git a/src/usage_text.h b/src/usage_text.h index 4a93ed89..9ef13d90 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -958,3 +958,5 @@ " specified by --save-session option every SEC\n" \ " seconds. If 0 is given, file will be saved only\n" \ " when aria2 exits.") +#define TEXT_DSCP \ + _(" --dscp=DSCP Set DSCP code")