Re: IP_TOS setting wrong
"voo6evoo" <[email protected]>
| Newsgroups | gmane.network.bit-torrent.general |
|---|---|
| Message-ID | <[email protected]> |
--- In [email protected], "Gregory P. Smith" <gpsmith@g...> wrote: > In RawServer.py it looks like someone attempted to set the IP_TOS > bits. However it is set very oddly: > > in the bind() method: > > server.setsockopt(socket.IPPROTO_IP, socket.IP_TOS, 32) > > What does 32 mean? > > Its diffserv "IPTOS_PREC_PRIORITY 0x20" > > A more appropriate value would be "IPTOS_THROUGHPUT 0x08" > > Also, it needs to be set on outgoing connections for it to matter. > Not just the server socket. Looks like yahoo rejected my normal mail (grumble). Resubmitting. The TOS value of 32 equates to the DSCP value of 8, which is used by the scavenger service. Instead of indicating that throughput matters more than latency for this application, it indicates that the traffic is low priority, but can consume much bandwidth, and thus should be throttled unless there is "excess" capacity. For example, at work I am on a university campus where capacity is high, but where unfettered consumption will draw the attention of the network administrators. As long as their routers are configured to shape scavenger traffic, I should not need to cap my usage to a fixed rate. At home I control the router and configure my own traffic shaping to prevent bittorrent and kazaa from drowning out my ssh and web sessions. At least, that's my take on it. See http://qbone.internet2.edu/qbss/ for general info on the scavenger service and http://www.aarnet.edu.au/engineering/networkdesign/qos/ for details on the history and use of these fields ("Precedence and DSCP" and "Using the Scavenger service"). As for the code, I agree that it is both abstruse and incorrect. I offer the patch below in the name of clarity and correctness. Without a modification such as this, bittorrent traffic is not properly shaped, and can get people (me) in trouble. It was only today that I dug out ethereal to find out why my policy wasn't being enforced as I expected. Be advised that the default queuing disciplines in linux respect the old RFC 791 TOS values IPTOS_THROUGHPUT and IPTOS_LOWDELAY and do not make use of newer DSCP values. So you need to install your own policy if you wish to use this feature. Even wondershaper appears to ignore the scavenger service. ----------------------------- bittorrent-scavenge-all.patch ----------------------------- diff -ru BitTorrent-3.4.2.orig/BitTorrent/RawServer.py BitTorrent-3.4.2/BitTorrent/RawServer.py --- BitTorrent-3.4.2.orig/BitTorrent/RawServer.py 2004-04-02 23:10:44.000000000 -0500 +++ BitTorrent-3.4.2/BitTorrent/RawServer.py 2004-12-12 23:35:56.385056021 -0500 @@ -78,6 +78,16 @@ def default_error_handler(x): print x +def scavenger_socket(sock): + # DSCP of 8 signifies scavenger service (low priority traffic) + scavenger_dscp = 8 + # DSCP occupies the upper 6 bits of the 8-bit TOS field + scavenger_tos = scavenger_dscp << 2 + try: + sock.setsockopt(socket.IPPROTO_IP, socket.IP_TOS, scavenger_tos) + except: + pass + class RawServer: def __init__(self, doneflag, timeout_check_interval, timeout, noisy = True, errorfunc = default_error_handler, maxconnects = 55): @@ -115,10 +125,7 @@ if reuse: server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.setblocking(0) - try: - server.setsockopt(socket.IPPROTO_IP, socket.IP_TOS, 32) - except: - pass + scavenger_socket(server) server.bind((bind, port)) server.listen(5) self.poll.register(server, POLLIN) @@ -136,6 +143,7 @@ raise except Exception, e: raise socket.error(str(e)) + scavenger_socket(sock) self.poll.register(sock, POLLIN) s = SingleSocket(self, sock, handler) self.single_sockets[sock.fileno()] = s ------------------------ Yahoo! Groups Sponsor --------------------~--> $4.98 domain names from Yahoo!. Register anything. http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/dkFolB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/BitTorrent/ <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/