registerPlugin method
Registers the plugin to the toolbox framework.
Throws CommunicationException if registering in the master plugin failed.
Implementation
@override
Future<void> registerPlugin() async {
starting = true;
GeigerApi.logger.info('starting registration: ${starting.toString()}');
final keyPair = await _keyExchangeAlgorithm.newKeyPair();
final pluginInformation = PluginInformation(
id,
executor,
_communicator.port,
declaration,
CommunicationSecret((await keyPair.extractPublicKey()).bytes));
// Needs to be registered before sending the registration request
// incase the master responds too fast
final resultWaiter = _RegisterResultWaiter(this);
final result = await CommunicationHelper.sendAndWait(
this,
Message(
id,
GeigerApi.masterId,
MessageType.registerPlugin,
GeigerUrl(null, GeigerApi.masterId, 'registerPlugin'),
await pluginInformation.toByteArray()));
GeigerApi.logger.info(result.type.toString());
if (result.type == MessageType.comapiError) {
GeigerApi.logger.info('Plugin registration failed');
throw CommunicationException('Plugin registration failed');
}
final secret = await _keyExchangeAlgorithm.sharedSecretKey(
keyPair: keyPair,
remotePublicKey: SimplePublicKey(result.payload,
type: _keyExchangeAlgorithm.keyPairType));
final info = PluginInformation(
GeigerApi.masterId,
GeigerApi.masterExecutor,
GeigerCommunicator.masterPort,
Declaration.doNotShareData,
CommunicationSecret(await secret.extractBytes()));
// TODO: call listener to display fingerprint
final didSucceed = await resultWaiter.wait();
GeigerApi.logger.info(didSucceed);
if (!didSucceed) {
throw CommunicationException('Plugin registration was denied.');
}
plugins[const StorableString(GeigerApi.masterId)] = info;
}