Skip to content

Commit

Permalink
Divided protobuf messages into their respective domains. Added suppor…
Browse files Browse the repository at this point in the history
…t for `google.protobuf` message types. Fixes (#279)
  • Loading branch information
tegefaulkes authored and CMCDragonkai committed Nov 1, 2021
1 parent 00db14e commit f9fee2c
Show file tree
Hide file tree
Showing 193 changed files with 33,006 additions and 16,649 deletions.
4 changes: 3 additions & 1 deletion scripts/proto-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ while [ -h "$source" ]; do # resolve $source until the file is no longer a symli
done
script_dir="$(cd -P "$(dirname "$source" )" >/dev/null && pwd)"

shopt -qs globstar

exec protoc \
--proto_path="${script_dir}/../src/proto/schemas" \
--plugin=protoc-gen-grpc="$(which grpc_node_plugin)" \
--js_out=import_style=commonjs,binary:src/proto/js \
--ts_out="grpc_js:${script_dir}/../src/proto/js" \
--grpc_out="grpc_js:${script_dir}/../src/proto/js" \
"${script_dir}/../src/proto/schemas/"*.proto
"${script_dir}/../src/proto/schemas/"**/*.proto
16 changes: 8 additions & 8 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import { SessionManager } from './sessions';
import { certNodeId } from './network/utils';
import { IdentitiesManager } from './identities';
import { ForwardProxy, ReverseProxy } from './network';
import { IAgentServer } from './proto/js/Agent_grpc_pb';
import { IClientServer } from './proto/js/Client_grpc_pb';
import { createAgentService, AgentService } from './agent';
import { createClientService, ClientService } from './client';
import { IAgentServiceServer } from './proto/js/polykey/v1/agent_service_grpc_pb';
import { IClientServiceServer } from './proto/js/polykey/v1/client_service_grpc_pb';
import { createAgentService, AgentServiceService } from './agent';
import { createClientService, ClientServiceService } from './client';
import { GithubProvider } from './identities/providers';
import config from './config';
import { ErrorStateVersionMismatch } from './errors';
Expand Down Expand Up @@ -58,12 +58,12 @@ class Polykey {
public readonly clientGrpcServer: GRPCServer;
public readonly clientGrpcHost: string;
public readonly clientGrpcPort: number;
protected clientService: IClientServer;
protected clientService: IClientServiceServer;
// Agent server
public readonly agentGrpcServer: GRPCServer;
public readonly agentGrpcHost: string;
public readonly agentGrpcPort: number;
protected agentService: IAgentServer;
protected agentService: IAgentServiceServer;

// Proxies
public readonly fwdProxy: ForwardProxy;
Expand Down Expand Up @@ -529,7 +529,7 @@ class Polykey {
// GRPC Server
// Client server
await this.clientGrpcServer.start({
services: [[ClientService, this.clientService]],
services: [[ClientServiceService, this.clientService]],
host: this.clientGrpcHost as Host,
port: this.clientGrpcPort as Port,
tlsConfig: {
Expand All @@ -539,7 +539,7 @@ class Polykey {
});
// Agent server
await this.agentGrpcServer.start({
services: [[AgentService, this.agentService]],
services: [[AgentServiceService, this.agentService]],
host: this.agentGrpcHost as Host,
port: this.agentGrpcPort as Port,
});
Expand Down
40 changes: 21 additions & 19 deletions src/agent/GRPCClientAgent.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import type { Host, Port, ProxyConfig } from '../network/types';
import type { NodeId } from '../nodes/types';
import type { TLSConfig } from '../network/types';

import { GRPCClient, utils as grpcUtils } from '../grpc';
import * as agentPB from '../proto/js/Agent_pb';
import { AgentClient } from '../proto/js/Agent_grpc_pb';
import { NodeId } from '../nodes/types';
import { Host, Port, ProxyConfig } from '../network/types';
import Logger from '@matrixai/logger';
import {
CreateDestroyStartStop,
ready,
} from '@matrixai/async-init/dist/CreateDestroyStartStop';
import { errors as grpcErrors } from '../grpc';
import { GRPCClient, utils as grpcUtils, errors as grpcErrors } from '../grpc';
import { AgentServiceClient } 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';
import * as notificationsPB from '../proto/js/polykey/v1/notifications/notifications_pb';

/**
* GRPC Agent Endpoints.
Expand All @@ -20,7 +22,7 @@ import { errors as grpcErrors } from '../grpc';
new grpcErrors.ErrorGRPCClientNotStarted(),
new grpcErrors.ErrorGRPCClientDestroyed(),
)
class GRPCClientAgent extends GRPCClient<AgentClient> {
class GRPCClientAgent extends GRPCClient<AgentServiceClient> {
static async createGRPCClientAgent({
nodeId,
host,
Expand Down Expand Up @@ -55,23 +57,23 @@ class GRPCClientAgent extends GRPCClient<AgentClient> {
timeout?: number;
} = {}): Promise<void> {
await super.start({
clientConstructor: AgentClient,
clientConstructor: AgentServiceClient,
tlsConfig,
timeout,
});
}

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public echo(...args) {
return grpcUtils.promisifyUnaryCall<agentPB.EchoMessage>(
return grpcUtils.promisifyUnaryCall<utilsPB.EchoMessage>(
this.client,
this.client.echo,
)(...args);
}

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public vaultsGitInfoGet(...args) {
return grpcUtils.promisifyReadableStreamCall<agentPB.PackChunk>(
return grpcUtils.promisifyReadableStreamCall<vaultsPB.PackChunk>(
this.client,
this.client.vaultsGitInfoGet,
)(...args);
Expand All @@ -84,55 +86,55 @@ class GRPCClientAgent extends GRPCClient<AgentClient> {

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public vaultsScan(...args) {
return grpcUtils.promisifyReadableStreamCall<agentPB.VaultListMessage>(
return grpcUtils.promisifyReadableStreamCall<vaultsPB.Vault>(
this.client,
this.client.vaultsScan,
)(...args);
}

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public nodesClosestLocalNodesGet(...args) {
return grpcUtils.promisifyUnaryCall<agentPB.NodeTableMessage>(
return grpcUtils.promisifyUnaryCall<nodesPB.NodeTable>(
this.client,
this.client.nodesClosestLocalNodesGet,
)(...args);
}

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public nodesClaimsGet(...args) {
return grpcUtils.promisifyUnaryCall<agentPB.ClaimsMessage>(
return grpcUtils.promisifyUnaryCall<nodesPB.Claims>(
this.client,
this.client.nodesClaimsGet,
)(...args);
}

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public nodesChainDataGet(...args) {
return grpcUtils.promisifyUnaryCall<agentPB.ChainDataMessage>(
return grpcUtils.promisifyUnaryCall<nodesPB.ChainData>(
this.client,
this.client.nodesChainDataGet,
)(...args);
}

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public nodesHolePunchMessageSend(...args) {
return grpcUtils.promisifyUnaryCall<agentPB.EmptyMessage>(
return grpcUtils.promisifyUnaryCall<utilsPB.EmptyMessage>(
this.client,
this.client.nodesHolePunchMessageSend,
)(...args);
}

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public notificationsSend(...args) {
return grpcUtils.promisifyUnaryCall<agentPB.NotificationMessage>(
return grpcUtils.promisifyUnaryCall<notificationsPB.AgentNotification>(
this.client,
this.client.notificationsSend,
)(...args);
}

@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public vaultsPermisssionsCheck(...args) {
return grpcUtils.promisifyUnaryCall<agentPB.PermissionMessage>(
return grpcUtils.promisifyUnaryCall<vaultsPB.NodePermissionAllowed>(
this.client,
this.client.vaultsPermisssionsCheck,
)(...args);
Expand All @@ -141,8 +143,8 @@ class GRPCClientAgent extends GRPCClient<AgentClient> {
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
public nodesCrossSignClaim(...args) {
return grpcUtils.promisifyDuplexStreamCall<
agentPB.CrossSignMessage,
agentPB.CrossSignMessage
nodesPB.CrossSign,
nodesPB.CrossSign
>(
this.client,
this.client.nodesCrossSignClaim,
Expand Down
Loading

0 comments on commit f9fee2c

Please sign in to comment.