Merge branch 'dscp-support' of https://github.com/iavael/aria2 into iavael-dscp-support

Conflicts:
	src/prefs.cc
	src/prefs.h
	src/usage_text.h
pull/195/head
Tatsuhiro Tsujikawa 2014-02-04 21:42:00 +09:00
commit 1438933c97
9 changed files with 41 additions and 0 deletions

View File

@ -185,6 +185,7 @@ Context::Context(bool standalone,
// when none of network interface has IPv4 address.
setDefaultAIFlags(0);
}
SocketCore::setIpDscp(op->getAsInt(PREF_DSCP));
net::checkAddrconfig();
// Bind interface
if(!op->get(PREF_INTERFACE).empty()) {

View File

@ -739,6 +739,15 @@ std::vector<OptionHandler*> 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,

View File

@ -83,6 +83,7 @@ bool PeerInitiateConnectionCommand::executeInternal() {
createSocket();
getSocket()->establishConnection(getPeer()->getIPAddress(),
getPeer()->getPort(), false);
getSocket()->applyIpDscp();
if(mseHandshakeEnabled_) {
auto c = make_unique<InitiatorMSEHandshakeCommand>
(getCuid(), requestGroup_, getPeer(),

View File

@ -110,6 +110,7 @@ bool PeerListenCommand::execute() {
std::shared_ptr<SocketCore> peerSocket;
try {
peerSocket = socket_->acceptConnection();
peerSocket->applyIpDscp();
std::pair<std::string, uint16_t> peerInfo;
peerSocket->getPeerInfo(peerInfo);

View File

@ -129,6 +129,7 @@ enum TlsState {
} // namespace
int SocketCore::protocolFamily_ = AF_UNSPEC;
int SocketCore::ipDscp_ = 0;
std::vector<std::pair<sockaddr_union, socklen_t> >
SocketCore::bindAddrs_;
@ -532,6 +533,11 @@ void SocketCore::setTcpNodelay(bool f)
setSockOpt(IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
}
void SocketCore::applyIpDscp()
{
setSockOpt(IPPROTO_IP, IP_TOS, &ipDscp_, sizeof(ipDscp_));
}
void SocketCore::setNonBlockingMode()
{
#ifdef __MINGW32__

View File

@ -66,6 +66,7 @@ private:
sock_t sockfd_;
static int protocolFamily_;
static int ipDscp_;
static std::vector<std::pair<sockaddr_union, socklen_t> > bindAddrs_;
@ -120,6 +121,14 @@ public:
// Enables TCP_NODELAY socket option if f == true.
void setTcpNodelay(bool f);
// Set DSCP byte
void applyIpDscp();
static void setIpDscp(int ipDscp)
{
// Here we prepare DSCP value for IPTOS option, which sets whole DS field
ipDscp_ = ipDscp << 2;
}
void create(int family, int protocol = 0);
void bindWithFamily(uint16_t port, int family, int flags = AI_PASSIVE);

View File

@ -361,6 +361,8 @@ PrefPtr PREF_SAVE_SESSION_INTERVAL = makePref("save-session-interval");
PrefPtr PREF_ENABLE_COLOR = makePref("enable-color");
// value: string
PrefPtr PREF_RPC_SECRET = makePref("rpc-secret");
// values: 1*digit
PrefPtr PREF_DSCP = makePref("dscp");
/**
* FTP related preferences

View File

@ -298,6 +298,8 @@ extern PrefPtr PREF_SAVE_SESSION_INTERVAL;
extern PrefPtr PREF_ENABLE_COLOR;
// value: string
extern PrefPtr PREF_RPC_SECRET;
// values: 1*digit
extern PrefPtr PREF_DSCP;
/**
* FTP related preferences

View File

@ -966,3 +966,13 @@
_(" --enable-color[=true|false] Enable color output for a terminal.")
#define TEXT_RPC_SECRET \
_(" --rpc-secret=TOKEN Set RPC secret authorization token.")
#define TEXT_DSCP \
_(" --dscp=DSCP Set DSCP value in outgoing IP packets of\n" \
" BitTorrent traffic for QoS. This parameter sets\n" \
" only DSCP bits in TOS field of IP packets,\n" \
" not the whole field. If you take values\n" \
" from /usr/include/netinet/ip.h divide them by 4\n" \
" (otherwise values would be incorrect, e.g. your CS1\n" \
" class would turn into CS4). If you are take commonly\n" \
" used values from RFC, network vendors' documentation,\n" \
" Wikipedia or any other source, use them as they are.")