Mercurial > libervia-backend
comparison libervia/backend/core/main.py @ 4306:94e0968987cd
plugin XEP-0033: code modernisation, improve delivery, data validation:
- Code has been rewritten using Pydantic models and `async` coroutines for data validation
and cleaner element parsing/generation.
- Delivery has been completely rewritten. It now works even if server doesn't support
multicast, and send to local multicast service first. Delivering to local multicast
service first is due to bad support of XEP-0033 in server (notably Prosody which has an
incomplete implementation), and the current impossibility to detect if a sub-domain
service handles fully multicast or only for local domains. This is a workaround to have
a good balance between backward compatilibity and use of bandwith, and to make it work
with the incoming email gateway implementation (the gateway will only deliver to
entities of its own domain).
- disco feature checking now uses `async` corountines. `host` implementation still use
Deferred return values for compatibility with legacy code.
rel 450
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Sep 2024 16:12:01 +0200 |
parents | 3a550e9a2b55 |
children | e94799a0908f |
comparison
equal
deleted
inserted
replaced
4305:4cd4922de876 | 4306:94e0968987cd |
---|---|
1165 ## Discovery ## | 1165 ## Discovery ## |
1166 # discovery methods are shortcuts to self.memory.disco | 1166 # discovery methods are shortcuts to self.memory.disco |
1167 # the main difference with client.disco is that self.memory.disco manage cache | 1167 # the main difference with client.disco is that self.memory.disco manage cache |
1168 | 1168 |
1169 def hasFeature(self, *args, **kwargs): | 1169 def hasFeature(self, *args, **kwargs): |
1170 return self.memory.disco.hasFeature(*args, **kwargs) | 1170 return defer.ensureDeferred(self.memory.disco.has_feature(*args, **kwargs)) |
1171 | 1171 |
1172 def check_feature(self, *args, **kwargs): | 1172 def check_feature(self, *args, **kwargs): |
1173 return self.memory.disco.check_feature(*args, **kwargs) | 1173 return defer.ensureDeferred(self.memory.disco.check_feature(*args, **kwargs)) |
1174 | 1174 |
1175 def check_features(self, *args, **kwargs): | 1175 def check_features(self, *args, **kwargs): |
1176 return self.memory.disco.check_features(*args, **kwargs) | 1176 return defer.ensureDeferred(self.memory.disco.check_features(*args, **kwargs)) |
1177 | 1177 |
1178 def has_identity(self, *args, **kwargs): | 1178 def has_identity(self, *args, **kwargs): |
1179 return self.memory.disco.has_identity(*args, **kwargs) | 1179 return self.memory.disco.has_identity(*args, **kwargs) |
1180 | 1180 |
1181 def get_disco_infos(self, *args, **kwargs): | 1181 def get_disco_infos(self, *args, **kwargs): |
1188 return self.memory.disco.find_service_entity(*args, **kwargs) | 1188 return self.memory.disco.find_service_entity(*args, **kwargs) |
1189 | 1189 |
1190 def find_service_entities(self, *args, **kwargs): | 1190 def find_service_entities(self, *args, **kwargs): |
1191 return self.memory.disco.find_service_entities(*args, **kwargs) | 1191 return self.memory.disco.find_service_entities(*args, **kwargs) |
1192 | 1192 |
1193 def find_features_set(self, *args, **kwargs): | 1193 async def find_features_set(self, *args, **kwargs): |
1194 return self.memory.disco.find_features_set(*args, **kwargs) | 1194 return await self.memory.disco.find_features_set(*args, **kwargs) |
1195 | 1195 |
1196 def _find_by_features( | 1196 def _find_by_features( |
1197 self, | 1197 self, |
1198 namespaces, | 1198 namespaces, |
1199 identities, | 1199 identities, |
1264 ) | 1264 ) |
1265 found_service = {} | 1265 found_service = {} |
1266 found_own = {} | 1266 found_own = {} |
1267 found_roster = {} | 1267 found_roster = {} |
1268 if service: | 1268 if service: |
1269 services_jids = await self.find_features_set(client, namespaces) | 1269 services_jids = await self.memory.disco.find_features_set(client, namespaces) |
1270 services_jids = list(services_jids) # we need a list to map results below | 1270 services_jids = list(services_jids) # we need a list to map results below |
1271 services_infos = await defer.DeferredList( | 1271 services_infos = await defer.DeferredList( |
1272 [ | 1272 [ |
1273 self.get_disco_infos(client, service_jid) | 1273 self.get_disco_infos(client, service_jid) |
1274 for service_jid in services_jids | 1274 for service_jid in services_jids |