diff --git a/sugar/p2p/Buddy.py b/sugar/p2p/Buddy.py index ad6b8aab..9a4d985a 100644 --- a/sugar/p2p/Buddy.py +++ b/sugar/p2p/Buddy.py @@ -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) diff --git a/sugar/p2p/Group.py b/sugar/p2p/Group.py index 4ac2518f..58e8be08 100644 --- a/sugar/p2p/Group.py +++ b/sugar/p2p/Group.py @@ -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"): diff --git a/sugar/p2p/Notifier.py b/sugar/p2p/Notifier.py index 50d96b4b..33222f12 100644 --- a/sugar/p2p/Notifier.py +++ b/sugar/p2p/Notifier.py @@ -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) diff --git a/sugar/p2p/Service.py b/sugar/p2p/Service.py index 7c864dff..8f5a1fc1 100644 --- a/sugar/p2p/Service.py +++ b/sugar/p2p/Service.py @@ -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) diff --git a/sugar/p2p/StreamReader.py b/sugar/p2p/StreamReader.py index d3dbf83e..3aca0a8f 100644 --- a/sugar/p2p/StreamReader.py +++ b/sugar/p2p/StreamReader.py @@ -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() diff --git a/sugar/p2p/StreamWriter.py b/sugar/p2p/StreamWriter.py index 6007a934..4fc912a7 100644 --- a/sugar/p2p/StreamWriter.py +++ b/sugar/p2p/StreamWriter.py @@ -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()