Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Nov 1, 2021
1 parent 6345e6c commit 7519d18
Show file tree
Hide file tree
Showing 18 changed files with 193 additions and 391 deletions.
35 changes: 10 additions & 25 deletions src/agent/agentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { Sigchain } from '../sigchain';
import { KeyManager } from '../keys';
import { NotificationsManager } from '../notifications';
import { ErrorGRPC } from '../grpc/errors';
import { AgentServiceService, IAgentServiceServer } from '../proto/js/polykey/v1/agent_service_grpc_pb';
import {
AgentServiceService,
IAgentServiceServer,
} from '../proto/js/polykey/v1/agent_service_grpc_pb';
import * as utilsPB from '../proto/js/polykey/v1/utils/utils_pb';
import * as vaultsPB from '../proto/js/polykey/v1/vaults/vaults_pb';
import * as nodesPB from '../proto/js/polykey/v1/nodes/nodes_pb';
Expand Down Expand Up @@ -50,21 +53,15 @@ function createAgentService({
}): IAgentServiceServer {
const agentService: IAgentServiceServer = {
echo: async (
call: grpc.ServerUnaryCall<
utilsPB.EchoMessage,
utilsPB.EchoMessage
>,
call: grpc.ServerUnaryCall<utilsPB.EchoMessage, utilsPB.EchoMessage>,
callback: grpc.sendUnaryData<utilsPB.EchoMessage>,
): Promise<void> => {
const response = new utilsPB.EchoMessage();
response.setChallenge(call.request.getChallenge());
callback(null, response);
},
vaultsGitInfoGet: async (
call: grpc.ServerWritableStream<
vaultsPB.Vault,
vaultsPB.PackChunk
>,
call: grpc.ServerWritableStream<vaultsPB.Vault, vaultsPB.PackChunk>,
): Promise<void> => {
const genWritable = grpcUtils.generatorWritable(call);
const request = call.request;
Expand Down Expand Up @@ -101,10 +98,7 @@ function createAgentService({
await genWritable.next(null);
},
vaultsGitPackGet: async (
call: grpc.ServerDuplexStream<
vaultsPB.PackChunk,
vaultsPB.PackChunk
>,
call: grpc.ServerDuplexStream<vaultsPB.PackChunk, vaultsPB.PackChunk>,
) => {
const write = promisify(call.write).bind(call);
const clientBodyBuffers: Buffer[] = [];
Expand Down Expand Up @@ -232,10 +226,7 @@ function createAgentService({
* Retrieves the ChainDataEncoded of this node.
*/
nodesChainDataGet: async (
call: grpc.ServerUnaryCall<
utilsPB.EmptyMessage,
nodesPB.ChainData
>,
call: grpc.ServerUnaryCall<utilsPB.EmptyMessage, nodesPB.ChainData>,
callback: grpc.sendUnaryData<nodesPB.ChainData>,
): Promise<void> => {
const response = new nodesPB.ChainData();
Expand Down Expand Up @@ -265,10 +256,7 @@ function createAgentService({
callback(null, response);
},
nodesHolePunchMessageSend: async (
call: grpc.ServerUnaryCall<
nodesPB.Relay,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<nodesPB.Relay, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
const response = new utilsPB.EmptyMessage();
Expand Down Expand Up @@ -344,10 +332,7 @@ function createAgentService({
}
},
nodesCrossSignClaim: async (
call: grpc.ServerDuplexStream<
nodesPB.CrossSign,
nodesPB.CrossSign
>,
call: grpc.ServerDuplexStream<nodesPB.CrossSign, nodesPB.CrossSign>,
) => {
// TODO: Move all "await genClaims.throw" to a final catch(). Wrap this
// entire thing in a try block. And re-throw whatever error is caught
Expand Down
5 changes: 4 additions & 1 deletion src/agent/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export { default as createAgentService, AgentServiceService } from './agentService';
export {
default as createAgentService,
AgentServiceService,
} from './agentService';
export { default as GRPCClientAgent } from './GRPCClientAgent';
export * as errors from './errors';
4 changes: 1 addition & 3 deletions src/claims/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,7 @@ function reconstructClaimIntermediary(
* Reconstructs a ClaimEncoded object from a ClaimMessage (i.e. after GRPC
* transport).
*/
function reconstructClaimEncoded(
claimMsg: nodesPB.AgentClaim,
): ClaimEncoded {
function reconstructClaimEncoded(claimMsg: nodesPB.AgentClaim): ClaimEncoded {
const claim: ClaimEncoded = {
payload: claimMsg.getPayload(),
signatures: claimMsg.getSignaturesList().map((signatureMsg) => {
Expand Down
15 changes: 6 additions & 9 deletions src/client/clientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type { GRPCServer } from '../grpc';

import { promisify } from 'util';
import * as grpc from '@grpc/grpc-js';
import { ClientServiceService, IClientServiceServer } from '../proto/js/polykey/v1/client_service_grpc_pb';
import {
ClientServiceService,
IClientServiceServer,
} from '../proto/js/polykey/v1/client_service_grpc_pb';
import * as utilsPB from '../proto/js/polykey/v1/utils/utils_pb';
import * as vaultsPB from '../proto/js/polykey/v1/vaults/vaults_pb';
import * as nodesPB from '../proto/js/polykey/v1/nodes/nodes_pb';
Expand Down Expand Up @@ -106,10 +109,7 @@ function createClientService({
sessionManager,
}),
nodesList: async (
call: grpc.ServerWritableStream<
utilsPB.EmptyMessage,
nodesPB.Node
>,
call: grpc.ServerWritableStream<utilsPB.EmptyMessage, nodesPB.Node>,
): Promise<void> => {
// Call.request // PROCESS THE REQEUST MESSAGE
const nodeMessage = new nodesPB.Node();
Expand All @@ -119,10 +119,7 @@ function createClientService({
call.end();
},
agentStop: async (
call: grpc.ServerUnaryCall<
utilsPB.EmptyMessage,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<utilsPB.EmptyMessage, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
try {
Expand Down
5 changes: 4 additions & 1 deletion src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export { default as createClientService, ClientServiceService } from './clientService';
export {
default as createClientService,
ClientServiceService,
} from './clientService';
export { default as GRPCClientClient } from './GRPCClientClient';
export * as errors from './errors';
export * as utils from './utils';
Expand Down
5 changes: 1 addition & 4 deletions src/client/rpcEcho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const createEchoRPC = ({
}) => {
return {
echo: async (
call: grpc.ServerUnaryCall<
utilsPB.EchoMessage,
utilsPB.EchoMessage
>,
call: grpc.ServerUnaryCall<utilsPB.EchoMessage, utilsPB.EchoMessage>,
callback: grpc.sendUnaryData<utilsPB.EchoMessage>,
): Promise<void> => {
const response = new utilsPB.EchoMessage();
Expand Down
50 changes: 10 additions & 40 deletions src/client/rpcGestalts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ const createGestaltsRPC = ({
callback(null, response);
},
gestaltsGestaltGetByIdentity: async (
call: grpc.ServerUnaryCall<
identitiesPB.Provider,
gestaltsPB.Graph
>,
call: grpc.ServerUnaryCall<identitiesPB.Provider, gestaltsPB.Graph>,
callback: grpc.sendUnaryData<gestaltsPB.Graph>,
): Promise<void> => {
const response = new gestaltsPB.Graph();
Expand All @@ -77,10 +74,7 @@ const createGestaltsRPC = ({
callback(null, response);
},
gestaltsGestaltList: async (
call: grpc.ServerWritableStream<
utilsPB.EmptyMessage,
gestaltsPB.Gestalt
>,
call: grpc.ServerWritableStream<utilsPB.EmptyMessage, gestaltsPB.Gestalt>,
): Promise<void> => {
const genWritable = grpcUtils.generatorWritable(call);
let gestaltMessage: gestaltsPB.Gestalt;
Expand All @@ -102,10 +96,7 @@ const createGestaltsRPC = ({
}
},
gestaltsDiscoveryByNode: async (
call: grpc.ServerUnaryCall<
nodesPB.Node,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<nodesPB.Node, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
const info = call.request;
Expand All @@ -129,10 +120,7 @@ const createGestaltsRPC = ({
callback(null, emptyMessage);
},
gestaltsDiscoveryByIdentity: async (
call: grpc.ServerUnaryCall<
identitiesPB.Provider,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<identitiesPB.Provider, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
const info = call.request;
Expand All @@ -157,10 +145,7 @@ const createGestaltsRPC = ({
callback(null, emptyMessage);
},
gestaltsActionsGetByNode: async (
call: grpc.ServerUnaryCall<
nodesPB.Node,
permissionsPB.Actions
>,
call: grpc.ServerUnaryCall<nodesPB.Node, permissionsPB.Actions>,
callback: grpc.sendUnaryData<permissionsPB.Actions>,
): Promise<void> => {
const info = call.request;
Expand Down Expand Up @@ -188,10 +173,7 @@ const createGestaltsRPC = ({
callback(null, response);
},
gestaltsActionsGetByIdentity: async (
call: grpc.ServerUnaryCall<
identitiesPB.Provider,
permissionsPB.Actions
>,
call: grpc.ServerUnaryCall<identitiesPB.Provider, permissionsPB.Actions>,
callback: grpc.sendUnaryData<permissionsPB.Actions>,
): Promise<void> => {
const info = call.request;
Expand Down Expand Up @@ -222,10 +204,7 @@ const createGestaltsRPC = ({
callback(null, response);
},
gestaltsActionsSetByNode: async (
call: grpc.ServerUnaryCall<
permissionsPB.ActionSet,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<permissionsPB.ActionSet, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
const info = call.request;
Expand Down Expand Up @@ -259,10 +238,7 @@ const createGestaltsRPC = ({
callback(null, response);
},
gestaltsActionsSetByIdentity: async (
call: grpc.ServerUnaryCall<
permissionsPB.ActionSet,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<permissionsPB.ActionSet, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
const info = call.request;
Expand Down Expand Up @@ -301,10 +277,7 @@ const createGestaltsRPC = ({
callback(null, response);
},
gestaltsActionsUnsetByNode: async (
call: grpc.ServerUnaryCall<
permissionsPB.ActionSet,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<permissionsPB.ActionSet, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
const info = call.request;
Expand Down Expand Up @@ -338,10 +311,7 @@ const createGestaltsRPC = ({
callback(null, response);
},
gestaltsActionsUnsetByIdentity: async (
call: grpc.ServerUnaryCall<
permissionsPB.ActionSet,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<permissionsPB.ActionSet, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
const info = call.request;
Expand Down
25 changes: 5 additions & 20 deletions src/client/rpcIdentities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ const createIdentitiesRPC = ({
callback(null, response);
},
identitiesTokenGet: async (
call: grpc.ServerUnaryCall<
identitiesPB.Provider,
identitiesPB.Token
>,
call: grpc.ServerUnaryCall<identitiesPB.Provider, identitiesPB.Token>,
callback: grpc.sendUnaryData<identitiesPB.Token>,
): Promise<void> => {
const response = new identitiesPB.Token();
Expand All @@ -119,10 +116,7 @@ const createIdentitiesRPC = ({
callback(null, response);
},
identitiesTokenDelete: async (
call: grpc.ServerUnaryCall<
identitiesPB.Provider,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<identitiesPB.Provider, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
const response = new utilsPB.EmptyMessage();
Expand All @@ -142,10 +136,7 @@ const createIdentitiesRPC = ({
callback(null, response);
},
identitiesProvidersList: async (
call: grpc.ServerUnaryCall<
utilsPB.EmptyMessage,
identitiesPB.Provider
>,
call: grpc.ServerUnaryCall<utilsPB.EmptyMessage, identitiesPB.Provider>,
callback: grpc.sendUnaryData<identitiesPB.Provider>,
): Promise<void> => {
const response = new identitiesPB.Provider();
Expand Down Expand Up @@ -212,10 +203,7 @@ const createIdentitiesRPC = ({
* Gets the first identityId of the local keynode.
*/
identitiesInfoGet: async (
call: grpc.ServerUnaryCall<
identitiesPB.Provider,
identitiesPB.Provider
>,
call: grpc.ServerUnaryCall<identitiesPB.Provider, identitiesPB.Provider>,
callback: grpc.sendUnaryData<identitiesPB.Provider>,
): Promise<void> => {
try {
Expand Down Expand Up @@ -243,10 +231,7 @@ const createIdentitiesRPC = ({
* Augments the keynode with a new identity.
*/
identitiesClaim: async (
call: grpc.ServerUnaryCall<
identitiesPB.Provider,
utilsPB.EmptyMessage
>,
call: grpc.ServerUnaryCall<identitiesPB.Provider, utilsPB.EmptyMessage>,
callback: grpc.sendUnaryData<utilsPB.EmptyMessage>,
): Promise<void> => {
// To augment a keynode we need a provider, generate an oauthkey and then
Expand Down
Loading

0 comments on commit 7519d18

Please sign in to comment.