More PS fixes
This commit is contained in:
		
							parent
							
								
									bca4e1ca9b
								
							
						
					
					
						commit
						1d0b4e12b8
					
				| @ -369,6 +369,11 @@ class PresenceService(object): | |||||||
| 			self._services[key] = service | 			self._services[key] = service | ||||||
| 		else: | 		else: | ||||||
| 			service = self._services[key] | 			service = self._services[key] | ||||||
|  | 			if not service.get_address(): | ||||||
|  | 				set_addr = service.get_one_property('address') | ||||||
|  | 				if not set_addr: | ||||||
|  | 					set_addr = address | ||||||
|  | 				service.set_address(set_addr) | ||||||
| 		adv.set_service(service) | 		adv.set_service(service) | ||||||
| 
 | 
 | ||||||
| 		# Merge the service into our buddy and activity lists, if needed | 		# Merge the service into our buddy and activity lists, if needed | ||||||
| @ -382,6 +387,9 @@ class PresenceService(object): | |||||||
| 		gobject.idle_add(self._resolve_service_reply_cb, interface, protocol, | 		gobject.idle_add(self._resolve_service_reply_cb, interface, protocol, | ||||||
| 				name, stype, domain, host, aprotocol, address, port, txt, flags) | 				name, stype, domain, host, aprotocol, address, port, txt, flags) | ||||||
| 
 | 
 | ||||||
|  | 	def _resolve_service_error_handler(self, err): | ||||||
|  | 		logging.error("error resolving service: %s" % err) | ||||||
|  | 
 | ||||||
| 	def _resolve_service(self, adv): | 	def _resolve_service(self, adv): | ||||||
| 		"""Resolve and lookup a ZeroConf service to obtain its address and TXT records.""" | 		"""Resolve and lookup a ZeroConf service to obtain its address and TXT records.""" | ||||||
| 		# Ask avahi to resolve this particular service | 		# Ask avahi to resolve this particular service | ||||||
| @ -523,47 +531,35 @@ class PresenceService(object): | |||||||
| 
 | 
 | ||||||
| 	def register_service(self, name, stype, properties={}, address=None, port=None, domain=u"local"): | 	def register_service(self, name, stype, properties={}, address=None, port=None, domain=u"local"): | ||||||
| 		"""Register a new service, advertising it to other Buddies on the network.""" | 		"""Register a new service, advertising it to other Buddies on the network.""" | ||||||
| 		objid = self._get_next_object_id() |  | ||||||
| 		service = Service.Service(self._bus_name, objid, name=name, |  | ||||||
| 				stype=stype, domain=domain, address=address, port=port, |  | ||||||
| 				properties=properties) |  | ||||||
| 		key = (name, stype) |  | ||||||
| 		self._services[key] = service |  | ||||||
| 
 |  | ||||||
| 		if self.get_owner() and name != self.get_owner().get_nick_name(): | 		if self.get_owner() and name != self.get_owner().get_nick_name(): | ||||||
| 			raise RuntimeError("Tried to register a service that didn't have Owner nick as the service name!") | 			raise RuntimeError("Tried to register a service that didn't have Owner nick as the service name!") | ||||||
| 		actid = service.get_activity_id() | 		if not domain or not len(domain): | ||||||
| 		rs_name = name | 			domain = u"local" | ||||||
| 		if actid: |  | ||||||
| 			rs_name = Service.compose_service_name(rs_name, actid) |  | ||||||
| 		rs_stype = service.get_type() |  | ||||||
| 		rs_port = service.get_port() |  | ||||||
| 		rs_props = service.get_properties() |  | ||||||
| 		rs_domain = service.get_domain() |  | ||||||
| 		rs_address = service.get_address() |  | ||||||
| 		if not rs_domain or not len(rs_domain): |  | ||||||
| 			rs_domain = "" |  | ||||||
| 		logging.debug("registered service name '%s' type '%s' on port %d with args %s" % (rs_name, rs_stype, rs_port, rs_props)) |  | ||||||
| 
 | 
 | ||||||
| 		try: | 		try: | ||||||
| 			obj = self._session_bus.get_object(avahi.DBUS_NAME, self._mdns_service.EntryGroupNew()) | 			obj = self._system_bus.get_object(avahi.DBUS_NAME, self._mdns_service.EntryGroupNew()) | ||||||
| 			group = dbus.Interface(obj, avahi.DBUS_INTERFACE_ENTRY_GROUP) | 			group = dbus.Interface(obj, avahi.DBUS_INTERFACE_ENTRY_GROUP) | ||||||
| 
 | 
 | ||||||
| 			# Add properties; ensure they are converted to ByteArray types | 			# Add properties; ensure they are converted to ByteArray types | ||||||
| 			# because python sometimes can't figure that out | 			# because python sometimes can't figure that out | ||||||
| 			info = [""] | 			info = [] | ||||||
| 			for k, v in rs_props.items(): | 			for k, v in properties.items(): | ||||||
| 				tmp_item = "%s=%s" % (k, v) | 				info.append(dbus.types.ByteArray("%s=%s" % (k, v))) | ||||||
| 				info.append(dbus.types.ByteArray(tmp_item)) |  | ||||||
| 
 | 
 | ||||||
| 			if rs_address and len(rs_address): | 			objid = self._get_next_object_id() | ||||||
| 				info.append("address=%s" % (rs_address)) | 			service = Service.Service(self._bus_name, objid, name=name, | ||||||
| 			logging.debug("PS: about to call AddService for Avahi with rs_name='%s' (%s), rs_stype='%s' (%s)," \ | 					stype=stype, domain=domain, address=address, port=port, | ||||||
| 					" rs_domain='%s' (%s), rs_port=%d (%s), info='%s' (%s)" % (rs_name, type(rs_name), rs_stype, | 					properties=properties) | ||||||
| 					type(rs_stype), rs_domain, type(rs_domain), rs_port, type(rs_port), info, type(info))) | 			self._services[(name, stype)] = service | ||||||
| 			group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, 0, rs_name, rs_stype, | 			port = service.get_port() | ||||||
| 					rs_domain, "", # let Avahi figure the 'host' out | 
 | ||||||
| 					dbus.UInt16(rs_port), info,) | 			if address and len(address): | ||||||
|  | 				info.append("address=%s" % (address)) | ||||||
|  | 			logging.debug("PS: Will register service with name='%s', stype='%s'," \ | ||||||
|  | 					" domain='%s', port=%d, info='%s'" % (name, stype, domain, port, info)) | ||||||
|  | 			group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, 0, name, stype, | ||||||
|  | 					domain, "", # let Avahi figure the 'host' out | ||||||
|  | 					dbus.UInt16(port), info,) | ||||||
| 			group.Commit() | 			group.Commit() | ||||||
| 		except dbus.dbus_bindings.DBusException, exc: | 		except dbus.dbus_bindings.DBusException, exc: | ||||||
| 			# FIXME: ignore local name collisions, since that means | 			# FIXME: ignore local name collisions, since that means | ||||||
| @ -571,8 +567,7 @@ class PresenceService(object): | |||||||
| 			# should un-register it an re-register with the correct info | 			# should un-register it an re-register with the correct info | ||||||
| 			if str(exc) == "Local name collision": | 			if str(exc) == "Local name collision": | ||||||
| 				pass | 				pass | ||||||
| 		activity_stype = service.get_type() | 		self.register_service_type(stype) | ||||||
| 		self.register_service_type(activity_stype) |  | ||||||
| 		return service | 		return service | ||||||
| 
 | 
 | ||||||
| 	def register_service_type(self, stype): | 	def register_service_type(self, stype): | ||||||
|  | |||||||
| @ -247,6 +247,8 @@ class Service(object): | |||||||
| 			if type(address) != type(u""): | 			if type(address) != type(u""): | ||||||
| 				raise ValueError("address must be unicode") | 				raise ValueError("address must be unicode") | ||||||
| 		self._address = address | 		self._address = address | ||||||
|  | 		if not self._publisher_address: | ||||||
|  | 			self._publisher_address = address | ||||||
| 
 | 
 | ||||||
| 	def get_domain(self): | 	def get_domain(self): | ||||||
| 		"""Return the ZeroConf/mDNS domain the service was found in.""" | 		"""Return the ZeroConf/mDNS domain the service was found in.""" | ||||||
|  | |||||||
| @ -53,7 +53,7 @@ class PresenceServiceProcess(Process): | |||||||
| 		return "PresenceService" | 		return "PresenceService" | ||||||
| 
 | 
 | ||||||
| 	def start(self): | 	def start(self): | ||||||
| 		Process.start(self, True) | 		Process.start(self) | ||||||
| 		time.sleep(3) | 		time.sleep(3) | ||||||
| 
 | 
 | ||||||
| class Session: | class Session: | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Dan Williams
						Dan Williams