Browse Source

don't immediately reply to the request, wait a random time [0, MX]

before repling as per draft-goland-http-udp-04.txt

[git-p4: depot-paths = "//depot/": change = 720]
replace/5b80aeb26dc425aaddcd5182126c969e5cc04cbb
John-Mark Gurney 19 years ago
parent
commit
82eba4cbcc
1 changed files with 7 additions and 4 deletions
  1. +7
    -4
      SSDP.py

+ 7
- 4
SSDP.py View File

@@ -7,10 +7,12 @@
# Implementation of SSDP server under Twisted Python.
#

import random
import string

from twisted.python import log
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor

# TODO: Is there a better way of hooking the SSDPServer into a reactor
# without having to know the default SSDP port and multicast address?
@@ -45,7 +47,7 @@ class SSDPServer(DatagramProtocol):
lines = map(lambda x: x.replace(': ', ':', 1), lines[1:])
lines = filter(lambda x: len(x) > 0, lines)

headers = [string.split(x, ':', 1) for x in lines[1:]]
headers = [string.split(x, ':', 1) for x in lines]
headers = dict(map(lambda x: (x[0].lower(), x[1]), headers))

if cmd[0] == 'M-SEARCH' and cmd[1] == '*':
@@ -82,11 +84,12 @@ class SSDPServer(DatagramProtocol):
for k, v in self.known[headers['st']].items():
response.append('%s: %s' % (k, v))

log.msg('responding with: %s' % response)
delay = random.randint(0, int(headers['mx']))
log.msg('responding in %d with: %s' % (delay, response))

# TODO: we should wait random(headers['mx'])
self.transport.write(
string.join(response, '\r\n') + '\r\n\r\n', (host, port))
reactor.callLater(delay, self.transport.write,
string.join(response, '\r\n') + '\r\n\r\n', (host, port))

def register(self, usn, st, location):
"""Register a service or device that this SSDP server will


Loading…
Cancel
Save