nodeDescriptorFrom function
Recovers OmnyServer's descriptor from an omnyhub descriptor.
Throws ProtocolException if the node did not advertise one — it is not an OmnyServer node, and nothing downstream can treat it as one.
Implementation
NodeDescriptor nodeDescriptorFrom(omnyhub.NodeDescriptor descriptor) {
final raw = descriptor.attributes[descriptorAttribute];
if (raw is! Map) {
throw ProtocolException(
'node ${descriptor.id.value} did not advertise an OmnyServer descriptor',
);
}
final parsed = NodeDescriptor.fromJson(raw.cast<String, dynamic>());
// omnyhub owns liveness, so its view of online/offline wins over whatever the
// node advertised about itself.
return parsed.copyWith(
online: descriptor.status == omnyhub.NodeStatus.online,
);
}