r11340 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11339‎ | r11340 | r11341 >
Date:13:10, 13 October 2005
Author:markbergsma
Status:old
Tags:
Comment:
Implement "forwarding rules", i.e. the ability to specify different
destination addresses per source address of the packet sent.
This is useful to support HTCP purge messages in two directions
using only one udpmcast daemon.
Modified paths:
  • /trunk/udpmcast/udpmcast.py (modified) (history)

Diff [purge]

Index: trunk/udpmcast/udpmcast.py
@@ -89,12 +89,18 @@
9090 if debugging:
9191 print msg;
9292
93 -def multicast_diagrams(sock, addresses):
 93+def multicast_diagrams(sock, addrrules):
9494 portnr = sock.getsockname()[1];
9595
9696 while 1:
97 - diagram = sock.recv(2**14)
 97+ diagram, srcaddr = sock.recvfrom(2**14)
9898 if not diagram: break
 99+
 100+ try:
 101+ addresses = addrrules[srcaddr[0]]
 102+ except KeyError:
 103+ addresses = addrrules[0]
 104+
99105 for addr in addresses:
100106 try:
101107 sock.sendto(diagram, 0, (addr, portnr))
@@ -113,7 +119,7 @@
114120 ip_mreq)
115121
116122 def print_help():
117 - print 'Usage:\n\tudpmcast [ options ] { addresses }\n'
 123+ print 'Usage:\n\tudpmcast [ options ] { addresses | forward rules }\n'
118124 print 'Options:'
119125 print '\t-d\tFork into the background (become a daemon)'
120126 print '\t-p {portnr}\tUDP port number to listen on (default is 4827)'
@@ -160,8 +166,20 @@
161167 debug('Joining multicast group ' + multicast_group)
162168 join_multicast_group(sock, multicast_group)
163169
 170+ # Parse the argument list
 171+ addrrules = { 0: [] }
 172+ for argument in arguments:
 173+ if argument[0] == '{':
 174+ # Forward rule
 175+ addrrules.update(eval(argument))
 176+ else:
 177+ # Default forward
 178+ addrrules[0].append(argument)
 179+
 180+ debug('Forward rules: ' + str(addrrules))
 181+
164182 # Multiplex everything that comes in
165 - multicast_diagrams(sock, arguments)
 183+ multicast_diagrams(sock, addrrules)
166184 except socket.error, msg:
167185 print msg[1];
168186 except KeyboardInterrupt:

Status & tagging log