Skip to content

Commit

Permalink
fix: client service handlers no longer need to use `Promise<PolykeyAg…
Browse files Browse the repository at this point in the history
…ent>` due to changing to Start/Stop
  • Loading branch information
CMCDragonkai committed Oct 11, 2023
1 parent 10ed279 commit e0306a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
21 changes: 11 additions & 10 deletions src/client/handlers/agentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@ import * as keysUtils from '../../keys/utils';

class AgentStatus extends UnaryHandler<
{
pkAgentProm: Promise<PolykeyAgent>;
polykeyAgent: PolykeyAgent;
},
ClientRPCRequestParams,
ClientRPCResponseResult<StatusResultMessage>
> {
public handle = async (): Promise<
ClientRPCResponseResult<StatusResultMessage>
> => {
const { pkAgentProm } = this.container;
const pkAgent = await pkAgentProm;
const { polykeyAgent } = this.container;
return {
pid: process.pid,
nodeIdEncoded: nodesUtils.encodeNodeId(pkAgent.keyRing.getNodeId()),
clientHost: pkAgent.clientServiceHost,
clientPort: pkAgent.clientServicePort,
agentHost: pkAgent.agentServiceHost,
agentPort: pkAgent.agentServicePort,
publicKeyJwk: keysUtils.publicKeyToJWK(pkAgent.keyRing.keyPair.publicKey),
certChainPEM: await pkAgent.certManager.getCertPEMsChainPEM(),
nodeIdEncoded: nodesUtils.encodeNodeId(polykeyAgent.keyRing.getNodeId()),
clientHost: polykeyAgent.clientServiceHost,
clientPort: polykeyAgent.clientServicePort,
agentHost: polykeyAgent.agentServiceHost,
agentPort: polykeyAgent.agentServicePort,
publicKeyJwk: keysUtils.publicKeyToJWK(
polykeyAgent.keyRing.keyPair.publicKey,
),
certChainPEM: await polykeyAgent.certManager.getCertPEMsChainPEM(),
};
};
}
Expand Down
9 changes: 4 additions & 5 deletions src/client/handlers/agentStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ import { UnaryHandler } from '@matrixai/rpc';

class AgentStop extends UnaryHandler<
{
pkAgentProm: Promise<PolykeyAgent>;
polykeyAgent: PolykeyAgent;
},
ClientRPCRequestParams,
ClientRPCResponseResult
> {
public handle = async (): Promise<ClientRPCResponseResult> => {
const { pkAgentProm } = this.container;
const pkAgent = await pkAgentProm;
const { polykeyAgent } = this.container;
// If not running or in stopping status, then respond successfully
if (!pkAgent[running] || pkAgent[status] === 'stopping') {
if (!polykeyAgent[running] || polykeyAgent[status] === 'stopping') {
return {};
}
// Stop PK agent in the background, allow the RPC time to respond
setTimeout(async () => {
await pkAgent.stop();
await polykeyAgent.stop();
}, 500);
return {};
};
Expand Down
2 changes: 1 addition & 1 deletion src/client/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import vaultsVersion from './vaultsVersion';
* Server manifest factory.
*/
const serverManifest = (container: {
pkAgentProm: Promise<PolykeyAgent>;
polykeyAgent: PolykeyAgent;
keyRing: KeyRing;
certManager: CertManager;
db: DB;
Expand Down

0 comments on commit e0306a4

Please sign in to comment.