Skip to content

Commit 75a3627

Browse files
committed
Divided protobuf messages into their respective domains. Added support for google.protobuf message types. Fixes (#279)
1 parent 00db14e commit 75a3627

143 files changed

Lines changed: 19271 additions & 17441 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/agent/GRPCClientAgent.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { TLSConfig } from '../network/types';
22

33
import { GRPCClient, utils as grpcUtils } from '../grpc';
4-
import * as agentPB from '../proto/js/Agent_pb';
4+
import { messages } from '.';
55
import { AgentClient } from '../proto/js/Agent_grpc_pb';
66
import { NodeId } from '../nodes/types';
77
import { Host, Port, ProxyConfig } from '../network/types';
@@ -63,15 +63,15 @@ class GRPCClientAgent extends GRPCClient<AgentClient> {
6363

6464
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
6565
public echo(...args) {
66-
return grpcUtils.promisifyUnaryCall<agentPB.EchoMessage>(
66+
return grpcUtils.promisifyUnaryCall<messages.common.EchoMessage>(
6767
this.client,
6868
this.client.echo,
6969
)(...args);
7070
}
7171

7272
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
7373
public vaultsGitInfoGet(...args) {
74-
return grpcUtils.promisifyReadableStreamCall<agentPB.PackChunk>(
74+
return grpcUtils.promisifyReadableStreamCall<messages.vaults.PackChunk>(
7575
this.client,
7676
this.client.vaultsGitInfoGet,
7777
)(...args);
@@ -84,55 +84,55 @@ class GRPCClientAgent extends GRPCClient<AgentClient> {
8484

8585
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
8686
public vaultsScan(...args) {
87-
return grpcUtils.promisifyReadableStreamCall<agentPB.VaultListMessage>(
87+
return grpcUtils.promisifyReadableStreamCall<messages.vaults.Vault>(
8888
this.client,
8989
this.client.vaultsScan,
9090
)(...args);
9191
}
9292

9393
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
9494
public nodesClosestLocalNodesGet(...args) {
95-
return grpcUtils.promisifyUnaryCall<agentPB.NodeTableMessage>(
95+
return grpcUtils.promisifyUnaryCall<messages.nodes.NodeTable>(
9696
this.client,
9797
this.client.nodesClosestLocalNodesGet,
9898
)(...args);
9999
}
100100

101101
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
102102
public nodesClaimsGet(...args) {
103-
return grpcUtils.promisifyUnaryCall<agentPB.ClaimsMessage>(
103+
return grpcUtils.promisifyUnaryCall<messages.nodes.Claims>(
104104
this.client,
105105
this.client.nodesClaimsGet,
106106
)(...args);
107107
}
108108

109109
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
110110
public nodesChainDataGet(...args) {
111-
return grpcUtils.promisifyUnaryCall<agentPB.ChainDataMessage>(
111+
return grpcUtils.promisifyUnaryCall<messages.nodes.ChainData>(
112112
this.client,
113113
this.client.nodesChainDataGet,
114114
)(...args);
115115
}
116116

117117
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
118118
public nodesHolePunchMessageSend(...args) {
119-
return grpcUtils.promisifyUnaryCall<agentPB.EmptyMessage>(
119+
return grpcUtils.promisifyUnaryCall<messages.common.EmptyMessage>(
120120
this.client,
121121
this.client.nodesHolePunchMessageSend,
122122
)(...args);
123123
}
124124

125125
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
126126
public notificationsSend(...args) {
127-
return grpcUtils.promisifyUnaryCall<agentPB.NotificationMessage>(
127+
return grpcUtils.promisifyUnaryCall<messages.notifications.AgentNotification>(
128128
this.client,
129129
this.client.notificationsSend,
130130
)(...args);
131131
}
132132

133133
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
134134
public vaultsPermisssionsCheck(...args) {
135-
return grpcUtils.promisifyUnaryCall<agentPB.PermissionMessage>(
135+
return grpcUtils.promisifyUnaryCall<messages.vaults.NodePermissionAllowed>(
136136
this.client,
137137
this.client.vaultsPermisssionsCheck,
138138
)(...args);
@@ -141,8 +141,8 @@ class GRPCClientAgent extends GRPCClient<AgentClient> {
141141
@ready(new grpcErrors.ErrorGRPCClientNotStarted())
142142
public nodesCrossSignClaim(...args) {
143143
return grpcUtils.promisifyDuplexStreamCall<
144-
agentPB.CrossSignMessage,
145-
agentPB.CrossSignMessage
144+
messages.nodes.CrossSign,
145+
messages.nodes.CrossSign
146146
>(
147147
this.client,
148148
this.client.nodesCrossSignClaim,

src/agent/agentPB.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * as common from '../proto/js/Common_pb';
2+
export * as vaults from '../proto/js/Vaults_pb';
3+
export * as nodes from '../proto/js/Nodes_pb';
4+
export * as notifications from '../proto/js/Notifications_pb';

src/agent/agentService.ts

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { NotificationsManager } from '../notifications';
1616
import { ErrorGRPC } from '../grpc/errors';
1717
import { AgentService, IAgentServer } from '../proto/js/Agent_grpc_pb';
1818

19-
import * as agentPB from '../proto/js/Agent_pb';
19+
import { messages } from '.';
2020
import * as grpcUtils from '../grpc/utils';
2121
import {
2222
utils as notificationsUtils,
@@ -48,19 +48,25 @@ function createAgentService({
4848
}): IAgentServer {
4949
const agentService: IAgentServer = {
5050
echo: async (
51-
call: grpc.ServerUnaryCall<agentPB.EchoMessage, agentPB.EchoMessage>,
52-
callback: grpc.sendUnaryData<agentPB.EchoMessage>,
51+
call: grpc.ServerUnaryCall<
52+
messages.common.EchoMessage,
53+
messages.common.EchoMessage
54+
>,
55+
callback: grpc.sendUnaryData<messages.common.EchoMessage>,
5356
): Promise<void> => {
54-
const response = new agentPB.EchoMessage();
57+
const response = new messages.common.EchoMessage();
5558
response.setChallenge(call.request.getChallenge());
5659
callback(null, response);
5760
},
5861
vaultsGitInfoGet: async (
59-
call: grpc.ServerWritableStream<agentPB.InfoRequest, agentPB.PackChunk>,
62+
call: grpc.ServerWritableStream<
63+
messages.vaults.Vault,
64+
messages.vaults.PackChunk
65+
>,
6066
): Promise<void> => {
6167
const genWritable = grpcUtils.generatorWritable(call);
6268
const request = call.request;
63-
const vaultNameOrId = request.getVaultId();
69+
const vaultNameOrId = request.getNameOrId();
6470
let vaultId, vaultName;
6571
try {
6672
vaultId = makeVaultId(idUtils.fromString(vaultNameOrId));
@@ -80,7 +86,7 @@ function createAgentService({
8086
meta.set('vaultName', vaultName);
8187
meta.set('vaultId', makeVaultIdPretty(vaultId));
8288
genWritable.stream.sendMetadata(meta);
83-
const response = new agentPB.PackChunk();
89+
const response = new messages.vaults.PackChunk();
8490
const responseGen = vaultManager.handleInfoRequest(vaultId);
8591
for await (const byte of responseGen) {
8692
if (byte !== null) {
@@ -93,7 +99,10 @@ function createAgentService({
9399
await genWritable.next(null);
94100
},
95101
vaultsGitPackGet: async (
96-
call: grpc.ServerDuplexStream<agentPB.PackChunk, agentPB.PackChunk>,
102+
call: grpc.ServerDuplexStream<
103+
messages.vaults.PackChunk,
104+
messages.vaults.PackChunk
105+
>,
97106
) => {
98107
const write = promisify(call.write).bind(call);
99108
const clientBodyBuffers: Buffer[] = [];
@@ -123,7 +132,7 @@ function createAgentService({
123132
}
124133
}
125134
// TODO: Check the permissions here
126-
const response = new agentPB.PackChunk();
135+
const response = new messages.vaults.PackChunk();
127136
const [sideBand, progressStream] = await vaultManager.handlePackRequest(
128137
vaultId,
129138
Buffer.from(body),
@@ -151,12 +160,12 @@ function createAgentService({
151160
},
152161
vaultsScan: async (
153162
call: grpc.ServerWritableStream<
154-
agentPB.NodeIdMessage,
155-
agentPB.VaultListMessage
163+
messages.nodes.Node,
164+
messages.vaults.Vault
156165
>,
157166
): Promise<void> => {
158167
const genWritable = grpcUtils.generatorWritable(call);
159-
const response = new agentPB.VaultListMessage();
168+
const response = new messages.vaults.Vault();
160169
const id = makeNodeId(call.request.getNodeId());
161170
try {
162171
throw Error('Not implemented');
@@ -165,7 +174,7 @@ function createAgentService({
165174
let listResponse;
166175
for await (const vault of listResponse) {
167176
if (vault !== null) {
168-
response.setVault(vault);
177+
response.setNameOrId(vault);
169178
await genWritable.next(response);
170179
} else {
171180
await genWritable.next(null);
@@ -183,22 +192,19 @@ function createAgentService({
183192
* @param callback
184193
*/
185194
nodesClosestLocalNodesGet: async (
186-
call: grpc.ServerUnaryCall<
187-
agentPB.NodeIdMessage,
188-
agentPB.NodeTableMessage
189-
>,
190-
callback: grpc.sendUnaryData<agentPB.NodeTableMessage>,
195+
call: grpc.ServerUnaryCall<messages.nodes.Node, messages.nodes.NodeTable>,
196+
callback: grpc.sendUnaryData<messages.nodes.NodeTable>,
191197
): Promise<void> => {
192-
const response = new agentPB.NodeTableMessage();
198+
const response = new messages.nodes.NodeTable();
193199
try {
194200
const targetNodeId = makeNodeId(call.request.getNodeId());
195201
// Get all local nodes that are closest to the target node from the request
196202
const closestNodes = await nodeManager.getClosestLocalNodes(
197203
targetNodeId,
198204
);
199205
for (const node of closestNodes) {
200-
const addressMessage = new agentPB.NodeAddressMessage();
201-
addressMessage.setIp(node.address.ip);
206+
const addressMessage = new messages.nodes.Address();
207+
addressMessage.setHost(node.address.ip);
202208
addressMessage.setPort(node.address.port);
203209
// Add the node to the response's map (mapping of node ID -> node address)
204210
response.getNodeTableMap().set(node.id, addressMessage);
@@ -215,12 +221,12 @@ function createAgentService({
215221
*/
216222
nodesClaimsGet: async (
217223
call: grpc.ServerUnaryCall<
218-
agentPB.ClaimTypeMessage,
219-
agentPB.ClaimsMessage
224+
messages.nodes.ClaimType,
225+
messages.nodes.Claims
220226
>,
221-
callback: grpc.sendUnaryData<agentPB.ClaimsMessage>,
227+
callback: grpc.sendUnaryData<messages.nodes.Claims>,
222228
): Promise<void> => {
223-
const response = new agentPB.ClaimsMessage();
229+
const response = new messages.nodes.Claims();
224230
// Response.setClaimsList(
225231
// await sigchain.getClaims(call.request.getClaimtype() as ClaimType)
226232
// );
@@ -231,24 +237,24 @@ function createAgentService({
231237
*/
232238
nodesChainDataGet: async (
233239
call: grpc.ServerUnaryCall<
234-
agentPB.EmptyMessage,
235-
agentPB.ChainDataMessage
240+
messages.common.EmptyMessage,
241+
messages.nodes.ChainData
236242
>,
237-
callback: grpc.sendUnaryData<agentPB.ChainDataMessage>,
243+
callback: grpc.sendUnaryData<messages.nodes.ChainData>,
238244
): Promise<void> => {
239-
const response = new agentPB.ChainDataMessage();
245+
const response = new messages.nodes.ChainData();
240246
try {
241247
const chainData = await nodeManager.getChainData();
242248
// Iterate through each claim in the chain, and serialize for transport
243249
for (const c in chainData) {
244250
const claimId = c as ClaimIdString;
245251
const claim = chainData[claimId];
246-
const claimMessage = new agentPB.ClaimMessage();
252+
const claimMessage = new messages.nodes.AgentClaim();
247253
// Will always have a payload (never undefined) so cast as string
248254
claimMessage.setPayload(claim.payload as string);
249255
// Add the signatures
250256
for (const signatureData of claim.signatures) {
251-
const signature = new agentPB.SignatureMessage();
257+
const signature = new messages.nodes.Signature();
252258
// Will always have a protected header (never undefined) so cast as string
253259
signature.setProtected(signatureData.protected as string);
254260
signature.setSignature(signatureData.signature);
@@ -263,10 +269,13 @@ function createAgentService({
263269
callback(null, response);
264270
},
265271
nodesHolePunchMessageSend: async (
266-
call: grpc.ServerUnaryCall<agentPB.RelayMessage, agentPB.EmptyMessage>,
267-
callback: grpc.sendUnaryData<agentPB.EmptyMessage>,
272+
call: grpc.ServerUnaryCall<
273+
messages.nodes.Relay,
274+
messages.common.EmptyMessage
275+
>,
276+
callback: grpc.sendUnaryData<messages.common.EmptyMessage>,
268277
): Promise<void> => {
269-
const response = new agentPB.EmptyMessage();
278+
const response = new messages.common.EmptyMessage();
270279
try {
271280
// Firstly, check if this node is the desired node
272281
// If so, then we want to make this node start sending hole punching packets
@@ -292,12 +301,12 @@ function createAgentService({
292301
},
293302
notificationsSend: async (
294303
call: grpc.ServerUnaryCall<
295-
agentPB.NotificationMessage,
296-
agentPB.EmptyMessage
304+
messages.notifications.AgentNotification,
305+
messages.common.EmptyMessage
297306
>,
298-
callback: grpc.sendUnaryData<agentPB.EmptyMessage>,
307+
callback: grpc.sendUnaryData<messages.common.EmptyMessage>,
299308
): Promise<void> => {
300-
const response = new agentPB.EmptyMessage();
309+
const response = new messages.common.EmptyMessage();
301310
try {
302311
const jwt = call.request.getContent();
303312
const notification = await notificationsUtils.verifyAndDecodeNotif(jwt);
@@ -313,12 +322,12 @@ function createAgentService({
313322
},
314323
vaultsPermisssionsCheck: async (
315324
call: grpc.ServerUnaryCall<
316-
agentPB.VaultPermMessage,
317-
agentPB.PermissionMessage
325+
messages.vaults.NodePermission,
326+
messages.vaults.NodePermissionAllowed
318327
>,
319-
callback: grpc.sendUnaryData<agentPB.PermissionMessage>,
328+
callback: grpc.sendUnaryData<messages.vaults.NodePermissionAllowed>,
320329
): Promise<void> => {
321-
const response = new agentPB.PermissionMessage();
330+
const response = new messages.vaults.NodePermissionAllowed();
322331
try {
323332
const nodeId = makeNodeId(call.request.getNodeId());
324333
const vaultId = makeVaultId(call.request.getVaultId());
@@ -340,8 +349,8 @@ function createAgentService({
340349
},
341350
nodesCrossSignClaim: async (
342351
call: grpc.ServerDuplexStream<
343-
agentPB.CrossSignMessage,
344-
agentPB.CrossSignMessage
352+
messages.nodes.CrossSign,
353+
messages.nodes.CrossSign
345354
>,
346355
) => {
347356
// TODO: Move all "await genClaims.throw" to a final catch(). Wrap this

src/agent/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { default as createAgentService, AgentService } from './agentService';
22
export { default as GRPCClientAgent } from './GRPCClientAgent';
33
export * as errors from './errors';
4-
export * as agentPB from '../proto/js/Agent_pb';
4+
export * as messages from './agentPB';

src/bin/agent/lockall.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as grpcErrors from '../../grpc/errors';
55
import PolykeyClient from '../../PolykeyClient';
66
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
77

8-
import { clientPB } from '../../client';
8+
import { messages } from '../../client';
99

1010
const lockall = binUtils.createCommand('lockall', {
1111
description:
@@ -29,7 +29,7 @@ lockall.action(async (options) => {
2929
clientConfig['nodePath'] = nodePath;
3030

3131
const client = await PolykeyClient.createPolykeyClient(clientConfig);
32-
const m = new clientPB.EmptyMessage();
32+
const m = new messages.common.EmptyMessage();
3333

3434
try {
3535
await client.start({});

src/bin/agent/stop.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
2-
import { clientPB } from '../../client';
2+
import { messages } from '../../client';
33
import PolykeyClient from '../../PolykeyClient';
44
import * as utils from '../../utils';
55
import * as binUtils from '../utils';
@@ -27,7 +27,7 @@ stop.action(async (options) => {
2727
: utils.getDefaultNodePath();
2828

2929
const client = await PolykeyClient.createPolykeyClient(clientConfig);
30-
const emptyMessage = new clientPB.EmptyMessage();
30+
const emptyMessage = new messages.common.EmptyMessage();
3131

3232
try {
3333
await client.start({});

src/bin/agent/unlock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as grpcErrors from '../../grpc/errors';
77
import PolykeyClient from '../../PolykeyClient';
88
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
99

10-
import { clientPB } from '../../client';
10+
import { messages } from '../../client';
1111

1212
const unlock = binUtils.createCommand('unlock', {
1313
description:
@@ -19,7 +19,7 @@ const unlock = binUtils.createCommand('unlock', {
1919
});
2020
unlock.arguments('[password]');
2121
unlock.action(async (password, options) => {
22-
const sessionPasswordMessage = new clientPB.PasswordMessage();
22+
const sessionPasswordMessage = new messages.sessions.Password();
2323

2424
const clientConfig = {};
2525
clientConfig['logger'] = new Logger('CLI Logger', LogLevel.WARN, [

0 commit comments

Comments
 (0)