added option to control TOS byte in peer traffic
This commit is contained in:
parent
5173c7fe31
commit
8132c6aad6
|
@ -2612,6 +2612,7 @@ struct session_settings
|
|||
int cache_size;
|
||||
int cache_expiry;
|
||||
std::pair<int, int> outgoing_ports;
|
||||
char peer_tos;
|
||||
};
|
||||
</pre>
|
||||
<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
|
||||
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>
|
||||
<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 class="section">
|
||||
<h1><a id="pe-settings" name="pe-settings">pe_settings</a></h1>
|
||||
|
|
|
@ -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_expiry;
|
||||
std::pair<int, int> outgoing_ports;
|
||||
char peer_tos;
|
||||
};
|
||||
|
||||
``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
|
||||
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
|
||||
===========
|
||||
|
|
|
@ -101,6 +101,20 @@ public:
|
|||
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
|
||||
void bind(endpoint_type const& endpoint)
|
||||
{
|
||||
|
|
|
@ -127,6 +127,7 @@ namespace libtorrent
|
|||
, cache_size(512)
|
||||
, cache_expiry(60)
|
||||
, outgoing_ports(0,0)
|
||||
, peer_tos(0)
|
||||
{}
|
||||
|
||||
// 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
|
||||
// allow QoS settings based on local port.
|
||||
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
|
||||
|
|
|
@ -185,6 +185,19 @@ namespace libtorrent
|
|||
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
|
||||
|
|
|
@ -256,6 +256,45 @@ namespace aux
|
|||
{ 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 -----------
|
||||
|
||||
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
|
||||
{
|
||||
TORRENT_ASSERT(instantiated());
|
||||
|
|
|
@ -235,6 +235,9 @@ namespace libtorrent
|
|||
(*m_logger) << "*** INCOMING CONNECTION\n";
|
||||
#endif
|
||||
|
||||
if (m_remote.address().is_v4())
|
||||
m_socket->set_option(type_of_service(ses.settings().peer_tos), ec);
|
||||
|
||||
#ifndef NDEBUG
|
||||
piece_failed = false;
|
||||
#endif
|
||||
|
@ -3011,6 +3014,12 @@ namespace libtorrent
|
|||
<< " rtt = " << m_rtt << "\n";
|
||||
#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();
|
||||
setup_send();
|
||||
setup_receive();
|
||||
|
|
Loading…
Reference in New Issue