Cleanup the service stuff for the multicast case
This commit is contained in:
parent
2fdedc751e
commit
f6d9916b4a
@ -25,8 +25,7 @@ class Owner(Buddy):
|
||||
if not nick or not len(nick):
|
||||
nick = "n00b"
|
||||
|
||||
service = Service(nick, PRESENCE_SERVICE_TYPE,
|
||||
PRESENCE_SERVICE_PORT)
|
||||
service = Service(nick, PRESENCE_SERVICE_TYPE, PRESENCE_SERVICE_PORT)
|
||||
|
||||
Buddy.__init__(self, service, nick)
|
||||
|
||||
|
@ -105,13 +105,14 @@ class LocalGroup(Group):
|
||||
|
||||
def _on_service_resolved(self, interface, protocol, name, stype, domain,
|
||||
host, aprotocol, address, port, txt, flags):
|
||||
multicast = None
|
||||
service = Service(name, stype, port)
|
||||
service.set_address(address)
|
||||
|
||||
for prop in avahi.txt_array_to_string_array(txt):
|
||||
(key, value) = prop.split('=')
|
||||
if key == 'multicast':
|
||||
multicast = value
|
||||
service.set_group_address(value)
|
||||
|
||||
service = Service(name, stype, port, multicast)
|
||||
if stype == PRESENCE_SERVICE_TYPE:
|
||||
self._add_buddy(Buddy(service, name))
|
||||
elif stype.startswith("_olpc"):
|
||||
|
@ -10,7 +10,7 @@ class Notifier:
|
||||
service = Service(name, Notifier.TYPE, Notifier.PORT, Notifier.ADDRESS)
|
||||
service.register(group)
|
||||
|
||||
address = service.get_multicast_group()
|
||||
address = service.get_group_address()
|
||||
port = service.get_port()
|
||||
self._client = network.GroupClient(address, port)
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
import presence
|
||||
|
||||
class Service(object):
|
||||
def __init__(self, name, stype, port, mgroup=None):
|
||||
def __init__(self, name, stype, port, group_address = None):
|
||||
self._name = name
|
||||
self._stype = stype
|
||||
self._port = int(port)
|
||||
self._mgroup = mgroup
|
||||
self._address = ''
|
||||
self._group_address = group_address
|
||||
|
||||
def get_name(self):
|
||||
return self._name
|
||||
@ -13,25 +14,31 @@ class Service(object):
|
||||
def get_type(self):
|
||||
return self._stype
|
||||
|
||||
def get_address(self):
|
||||
return self._address
|
||||
|
||||
def get_port(self):
|
||||
return self._port
|
||||
|
||||
def set_port(self, port):
|
||||
self._port = port
|
||||
|
||||
def get_multicast_group(self):
|
||||
return self._mgroup
|
||||
|
||||
|
||||
def get_address(self):
|
||||
return self._address
|
||||
|
||||
def get_group_address(self):
|
||||
return self._group_address
|
||||
|
||||
def set_address(self, address):
|
||||
self._address = address
|
||||
|
||||
def set_group_address(self):
|
||||
self._group_address = group_address
|
||||
|
||||
def is_multicast(self):
|
||||
return self._mgroup != None
|
||||
return self._group_address != None
|
||||
|
||||
def register(self, group):
|
||||
pannounce = presence.PresenceAnnounce()
|
||||
if self._mgroup:
|
||||
if self._group_address:
|
||||
pannounce.register_service(self._name, self._port, self._stype,
|
||||
multicast = self._mgroup)
|
||||
group_address = self._group_address)
|
||||
else:
|
||||
pannounce.register_service(self._name, self._port, self._stype)
|
||||
|
@ -24,7 +24,7 @@ class StreamReader:
|
||||
self._callback = callback
|
||||
|
||||
def _setup_multicast(self):
|
||||
address = self._service.get_address()
|
||||
address = self._service.get_group_address()
|
||||
port = self._service.get_port()
|
||||
server = network.GroupServer(address, port, self._recv_multicast)
|
||||
server.start()
|
||||
|
@ -10,6 +10,7 @@ class StreamWriter:
|
||||
self._service = service
|
||||
self._address = self._service.get_address()
|
||||
self._port = self._service.get_port()
|
||||
self._group_address = self._service.get_group_address()
|
||||
|
||||
if self._service.is_multicast():
|
||||
self._setup_multicast()
|
||||
@ -36,7 +37,7 @@ class StreamWriter:
|
||||
return False
|
||||
|
||||
def _setup_multicast(self):
|
||||
self._mclient = network.GroupClient(self._address, self._port)
|
||||
self._mclient = network.GroupClient(self._group_address, self._port)
|
||||
|
||||
def _multicast_write(self, data):
|
||||
nick_name = self._group.get_owner().get_nick_name()
|
||||
|
Loading…
Reference in New Issue
Block a user