added option to control TOS byte in peer traffic

This commit is contained in:
Arvid Norberg
2008-03-12 16:58:23 +00:00
parent 5173c7fe31
commit 8132c6aad6
7 changed files with 112 additions and 0 deletions

View File

@@ -2612,6 +2612,7 @@ struct session_settings
int cache_size; int cache_size;
int cache_expiry; int cache_expiry;
std::pair<int, int> outgoing_ports; std::pair<int, int> outgoing_ports;
char peer_tos;
}; };
</pre> </pre>
<p><tt class="docutils literal"><span class="pre">user_agent</span></tt> this is the client identification to the tracker. <p><tt class="docutils literal"><span class="pre">user_agent</span></tt> this is the client identification to the tracker.
@@ -2768,6 +2769,10 @@ used to bind outgoing sockets to. This may be useful for users whose router
allows them to assign QoS classes to traffic based on its local port. It is allows them to assign QoS classes to traffic based on its local port. It is
a range instead of a single port because of the problems with failing to reconnect a range instead of a single port because of the problems with failing to reconnect
to peers if a previous socket to that peer and port is in <tt class="docutils literal"><span class="pre">TIME_WAIT</span></tt> state.</p> to peers if a previous socket to that peer and port is in <tt class="docutils literal"><span class="pre">TIME_WAIT</span></tt> state.</p>
<p><tt class="docutils literal"><span class="pre">peer_tos</span></tt> determines the TOS byte set in the IP header of every packet
sent to peers (including web seeds). The default value for this is <tt class="docutils literal"><span class="pre">0x0</span></tt>
(no marking). One potentially useful TOS mark is <tt class="docutils literal"><span class="pre">0x20</span></tt>, this represents
the <em>QBone scavenger service</em>. For more details, see <a class="reference" href="http://qbone.internet2.edu/qbss/">QBSS</a>.</p>
</div> </div>
<div class="section"> <div class="section">
<h1><a id="pe-settings" name="pe-settings">pe_settings</a></h1> <h1><a id="pe-settings" name="pe-settings">pe_settings</a></h1>

View File

@@ -2605,6 +2605,7 @@ that will be sent to the tracker. The user-agent is a good way to identify your
int cache_size; int cache_size;
int cache_expiry; int cache_expiry;
std::pair<int, int> outgoing_ports; std::pair<int, int> outgoing_ports;
char peer_tos;
}; };
``user_agent`` this is the client identification to the tracker. ``user_agent`` this is the client identification to the tracker.
@@ -2800,6 +2801,13 @@ allows them to assign QoS classes to traffic based on its local port. It is
a range instead of a single port because of the problems with failing to reconnect a range instead of a single port because of the problems with failing to reconnect
to peers if a previous socket to that peer and port is in ``TIME_WAIT`` state. to peers if a previous socket to that peer and port is in ``TIME_WAIT`` state.
``peer_tos`` determines the TOS byte set in the IP header of every packet
sent to peers (including web seeds). The default value for this is ``0x0``
(no marking). One potentially useful TOS mark is ``0x20``, this represents
the *QBone scavenger service*. For more details, see QBSS_.
.. _`QBSS`: http://qbone.internet2.edu/qbss/
pe_settings pe_settings
=========== ===========

View File

@@ -101,6 +101,20 @@ public:
m_sock.async_write_some(buffers, handler); m_sock.async_write_some(buffers, handler);
} }
#ifndef BOOST_NO_EXCEPTIONS
template <class SettableSocketOption>
void set_option(SettableSocketOption const& opt)
{
m_sock.set_option(opt);
}
#endif
template <class SettableSocketOption>
asio::error_code set_option(SettableSocketOption const& opt, asio::error_code& ec)
{
return m_sock.set_option(opt, ec);
}
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
void bind(endpoint_type const& endpoint) void bind(endpoint_type const& endpoint)
{ {

View File

@@ -127,6 +127,7 @@ namespace libtorrent
, cache_size(512) , cache_size(512)
, cache_expiry(60) , cache_expiry(60)
, outgoing_ports(0,0) , outgoing_ports(0,0)
, peer_tos(0)
{} {}
// this is the user agent that will be sent to the tracker // this is the user agent that will be sent to the tracker
@@ -339,6 +340,13 @@ namespace libtorrent
// is useful for users that have routers that // is useful for users that have routers that
// allow QoS settings based on local port. // allow QoS settings based on local port.
std::pair<int, int> outgoing_ports; std::pair<int, int> outgoing_ports;
// the TOS byte of all peer traffic (including
// web seeds) is set to this value. The default
// is the QBSS scavenger service
// http://qbone.internet2.edu/qbss/
// For unmarked packets, set to 0
char peer_tos;
}; };
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT

View File

@@ -185,6 +185,19 @@ namespace libtorrent
int m_value; int m_value;
}; };
struct type_of_service
{
type_of_service(char val): m_value(val) {}
template<class Protocol>
int level(Protocol const&) const { return IPPROTO_IP; }
template<class Protocol>
int name(Protocol const&) const { return IP_TOS; }
template<class Protocol>
char const* data(Protocol const&) const { return &m_value; }
template<class Protocol>
size_t size(Protocol const&) const { return sizeof(m_value); }
char m_value;
};
} }
#endif // TORRENT_SOCKET_HPP_INCLUDED #endif // TORRENT_SOCKET_HPP_INCLUDED

View File

@@ -256,6 +256,45 @@ namespace aux
{ return EndpointType(); } { return EndpointType(); }
}; };
// -------------- set_option -----------
template <class SettableSocketOption>
struct set_option_visitor
: boost::static_visitor<>
{
set_option_visitor(SettableSocketOption const& opt)
: opt_(opt)
{}
template <class T>
void operator()(T* p) const
{ p->set_option(opt_); }
std::size_t operator()(boost::blank) const {}
SettableSocketOption const& opt_;
};
template <class SettableSocketOption>
struct set_option_visitor_ec
: boost::static_visitor<asio::error_code>
{
set_option_visitor_ec(SettableSocketOption const& opt, asio::error_code& ec)
: opt_(opt)
, ec_(ec)
{}
template <class T>
asio::error_code operator()(T* p) const
{ return p->set_option(opt_, ec_); }
asio::error_code operator()(boost::blank) const
{ return ec_; }
SettableSocketOption const& opt_;
asio::error_code& ec_;
};
// -------------- local_endpoint ----------- // -------------- local_endpoint -----------
template <class EndpointType> template <class EndpointType>
@@ -657,6 +696,22 @@ public:
); );
} }
template <class SettableSocketOption>
void set_option(SettableSocketOption const& opt)
{
TORRENT_ASSERT(instantiated());
boost::apply_visitor(aux::set_option_visitor<SettableSocketOption>(opt)
, m_variant);
}
template <class SettableSocketOption>
asio::error_code set_option(SettableSocketOption const& opt, asio::error_code& ec)
{
TORRENT_ASSERT(instantiated());
return boost::apply_visitor(aux::set_option_visitor_ec<SettableSocketOption>(opt, ec)
, m_variant);
}
endpoint_type local_endpoint() const endpoint_type local_endpoint() const
{ {
TORRENT_ASSERT(instantiated()); TORRENT_ASSERT(instantiated());

View File

@@ -235,6 +235,9 @@ namespace libtorrent
(*m_logger) << "*** INCOMING CONNECTION\n"; (*m_logger) << "*** INCOMING CONNECTION\n";
#endif #endif
if (m_remote.address().is_v4())
m_socket->set_option(type_of_service(ses.settings().peer_tos), ec);
#ifndef NDEBUG #ifndef NDEBUG
piece_failed = false; piece_failed = false;
#endif #endif
@@ -3011,6 +3014,12 @@ namespace libtorrent
<< " rtt = " << m_rtt << "\n"; << " rtt = " << m_rtt << "\n";
#endif #endif
if (m_remote.address().is_v4())
{
asio::error_code ec;
m_socket->set_option(type_of_service(m_ses.settings().peer_tos), ec);
}
on_connected(); on_connected();
setup_send(); setup_send();
setup_receive(); setup_receive();