/usr/share/pyshared/tp/netlib/discover/pyzeroconf_server.py is in python-tp-netlib 0.2.5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | import os, sys
import traceback, socket
import time
globals()['_GLOBAL_DONE'] = False
from pyZeroconf import Zeroconf
from server import ZeroConfServer as ZeroConfServerBase
class ZeroConfServer(ZeroConfServerBase):
def check():
return True
check = staticmethod(check)
def __init__(self):
ZeroConfServerBase.__init__(self)
self.tocall = []
self.services = {}
self.server = Zeroconf.Zeroconf("0.0.0.0")
def ServiceRemove(self, name, type, addr):
self.post(self.__ServiceRemove, (name, type, addr), {})
def __ServiceRemove(self, name, type, addr):
key = (name, type, addr)
if key in self.services:
service = self.services[key]
del self.services[key]
self.server.unregisterService(service)
def ServiceAdd(self, name, type, addr, required, optional):
self.post(self.__ServiceAdd, (name, type, addr, required, optional), {})
def __ServiceAdd(self, name, type, addr, required, optional):
prop = {}
prop.update(optional)
prop.update(required)
stype = "_%s._tcp.local." % type
sname = "%s.%s" % (name, stype)
svc = Zeroconf.ServiceInfo(stype, sname, server=addr[0], address=socket.inet_aton(addr[1]), port=addr[2], properties=prop)
self.server.registerService(svc, 30)
self.services[(name, type, addr)] = svc
######################################
# Callback functions
######################################
def post(self, method, args, kw):
self.tocall.append((method, args, kw))
def run(self):
while not globals()['_GLOBAL_DONE']:
try:
if len(self.tocall) > 0:
method, args, kw = self.tocall.pop(0)
method(*args, **kw)
self.server.run()
except Exception, e:
print e
traceback.print_exc()
globals()['_GLOBAL_DONE'] = True
def exit(self):
globals()['_GLOBAL_DONE'] = True
def main():
from game import Game
game1 = Game("testing 1")
game1.updateRequired({'tp': '0.3', 'server': 'None', 'sertype':'Avahi Testing Script', 'rule': "Testing Avahi!", 'rulever': 'None'})
game1.addLocation("tp", ("mithro.local", "10.1.1.1", 80))
game2 = Game("testing 2")
game2.updateRequired({'tp': '0.3', 'server': 'None', 'sertype':'Avahi Testing Script', 'rule': "Testing Avahi!", 'rulever': 'None'})
game2.addLocation("tp", ("mithro.local", "10.1.1.1", 8080))
# game2.addLocation("tp", ("mithro.local", "10.1.1.1", 443)) -- Can't have to services on the same name and type
game2.addLocation("tps", ("mithro.local", "10.1.1.1", 90))
a = ZeroConfServer()
a.GameAdd(game1)
a.GameAdd(game2)
a.run()
if __name__ == "__main__":
main()
|