relayDevice method
Future<EventModel<EventBodyModel> ?>
relayDevice(
- String deviceKey,
- EventModel<
EventBodyModel> event
Implementation
Future<EventModel?> relayDevice(String deviceKey, EventModel event) async {
final device = await db.devices.id(deviceKey).get();
if (device == null) {
throw StateError('Missing device: $deviceKey');
}
if (!device.online || device.isRevoked) {
_logger.log('Device $deviceKey is not reachable');
return null;
}
final peer = await db.peers.id(device.peerKey).get();
if (peer?.isRevoked == true) {
_logger.log('Peer ${device.peerKey} is revoked');
return null;
}
final ip = device.ip;
if (ip == null) {
_logger.log('Device $deviceKey has no IP');
return null;
}
return relayIP(ip, event);
}