Refactored DSCP-related code a bit

pull/188/merge^2
Alexander Amanuel 2014-01-28 23:09:21 +04:00
parent 924feb12b0
commit 46a251e346
5 changed files with 12 additions and 7 deletions

View File

@ -184,6 +184,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

@ -41,7 +41,6 @@
#include "prefs.h"
#include "SocketCore.h"
#include "Logger.h"
#include "Option.h"
#include "LogFactory.h"
#include "Peer.h"
#include "BtRuntime.h"
@ -84,7 +83,7 @@ bool PeerInitiateConnectionCommand::executeInternal() {
createSocket();
getSocket()->establishConnection(getPeer()->getIPAddress(),
getPeer()->getPort(), false);
getSocket()->setIpDscp(requestGroup_->getOption()->getAsInt(PREF_DSCP));
getSocket()->applyIpDscp();
if(mseHandshakeEnabled_) {
auto c = make_unique<InitiatorMSEHandshakeCommand>
(getCuid(), requestGroup_, getPeer(),

View File

@ -44,7 +44,6 @@
#include "message.h"
#include "ReceiverMSEHandshakeCommand.h"
#include "Logger.h"
#include "Option.h"
#include "LogFactory.h"
#include "SocketCore.h"
#include "SimpleRandomizer.h"
@ -111,7 +110,7 @@ bool PeerListenCommand::execute() {
std::shared_ptr<SocketCore> peerSocket;
try {
peerSocket = socket_->acceptConnection();
peerSocket->setIpDscp(e_->getOption()->getAsInt(PREF_DSCP));
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,9 +533,9 @@ void SocketCore::setTcpNodelay(bool f)
setSockOpt(IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
}
void SocketCore::setIpDscp(int32_t dscp)
void SocketCore::applyIpDscp()
{
setSockOpt(IPPROTO_IP, IP_TOS, &dscp, sizeof(dscp));
setSockOpt(IPPROTO_IP, IP_TOS, &ipDscp_, sizeof(ipDscp_));
}
void SocketCore::setNonBlockingMode()

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_;
@ -121,7 +122,11 @@ public:
void setTcpNodelay(bool f);
// Set DSCP byte
void setIpDscp(int32_t);
void applyIpDscp();
static void setIpDscp(int ipDscp)
{
ipDscp_ = ipDscp;
}
void create(int family, int protocol = 0);