diff --git a/sugar/p2p/Buddy.py b/sugar/p2p/Buddy.py index 45aeac36..aa7774b3 100644 --- a/sugar/p2p/Buddy.py +++ b/sugar/p2p/Buddy.py @@ -105,3 +105,13 @@ class Owner(Buddy): def register(self): self._presence_service.register(self._group) + + def notify_service_registered(self, service): + """New services registered in our group are automatically owned + by us.""" + self._services[service.get_type()] = service + + def add_service(self, service): + """Do nothing here, since all services we need to know about + are registered with us by our group.""" + pass diff --git a/sugar/p2p/Group.py b/sugar/p2p/Group.py index 48e6a290..38dcecb7 100644 --- a/sugar/p2p/Group.py +++ b/sugar/p2p/Group.py @@ -90,6 +90,10 @@ class LocalGroup(Group): if self._buddies.has_key(name): return self._buddies[name] return None + + def notify_service_registered(self, service): + """A new service is automatically owned by the owner of this group.""" + self._owner.notify_service_registered(service) def _add_buddy(self, buddy): bid = buddy.get_nick_name() @@ -130,15 +134,17 @@ class LocalGroup(Group): if key == 'group_address': service.set_group_address(value) - # print "ServiceResolved: name=%s, stype=%s, port=%s, address=%s" % (name, stype, port, address) + print "ServiceResolved: name=%s, stype=%s, port=%s, address=%s" % (name, stype, port, address) if stype in get_recognized_buddy_service_types(): # Service recognized as Buddy services either create a new # buddy if one doesn't exist yet, or get added to the existing # buddy buddy = self.get_buddy(name) if buddy: + print "Found buddy %s" % name buddy.add_service(service) else: + print "New buddy %s" % name self._add_buddy(Buddy(service)) self.add_service(service) elif stype.startswith(_OLPC_SERVICE_TYPE_PREFIX): diff --git a/sugar/p2p/Service.py b/sugar/p2p/Service.py index 2fa102d2..8bc73f71 100644 --- a/sugar/p2p/Service.py +++ b/sugar/p2p/Service.py @@ -35,10 +35,12 @@ class Service(object): def is_multicast(self): return self._group_address != None - def register(self, group): + def register(self, group): pannounce = presence.PresenceAnnounce() if self._group_address: pannounce.register_service(self._name, self._port, self._stype, group_address = self._group_address) else: pannounce.register_service(self._name, self._port, self._stype) + # Notify the group that we're registering a new service + group.notify_service_registered(self)