Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): add reflection #287

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"dependencies": {
"@chainsafe/libp2p-gossipsub": "^14.1.0",
"@grpc/grpc-js": "^1.12.2",
"@grpc/proto-loader": "^0.7.13",
"@grpc/reflection": "^1.0.4",
"@libp2p/interface": "^2.1.3",
"dotenv": "^16.4.5",
"@ts-drp/blueprints": "0.4.0",
Expand Down
56 changes: 36 additions & 20 deletions packages/node/src/proto/drp/node/v1/rpc_grpc_pb.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,78 @@
import * as node_src_proto_rpc_pb from './rpc_pb.js';

function serialize_drp_node_GetDRPHashGraphRequest(arg) {
let encoded = node_src_proto_rpc_pb.GetDRPHashGraphRequest.encode(arg).finish()
return Buffer.from(encoded);
let encoded =
node_src_proto_rpc_pb.GetDRPHashGraphRequest.encode(arg).finish();
return Buffer.from(encoded);
}

function deserialize_drp_node_GetDRPHashGraphRequest(buffer_arg) {
return node_src_proto_rpc_pb.GetDRPHashGraphRequest.decode(new Uint8Array(buffer_arg));
return node_src_proto_rpc_pb.GetDRPHashGraphRequest.decode(
new Uint8Array(buffer_arg)
);
}

function serialize_drp_node_GetDRPHashGraphResponse(arg) {
let encoded = node_src_proto_rpc_pb.GetDRPHashGraphResponse.encode(arg).finish()
return Buffer.from(encoded);
let encoded =
node_src_proto_rpc_pb.GetDRPHashGraphResponse.encode(arg).finish();
return Buffer.from(encoded);
}

function deserialize_drp_node_GetDRPHashGraphResponse(buffer_arg) {
return node_src_proto_rpc_pb.GetDRPHashGraphResponse.decode(new Uint8Array(buffer_arg));
return node_src_proto_rpc_pb.GetDRPHashGraphResponse.decode(
new Uint8Array(buffer_arg)
);
}

function serialize_drp_node_SubscribeDRPRequest(arg) {
let encoded = node_src_proto_rpc_pb.SubscribeDRPRequest.encode(arg).finish()
return Buffer.from(encoded);
let encoded = node_src_proto_rpc_pb.SubscribeDRPRequest.encode(arg).finish();
return Buffer.from(encoded);
}

function deserialize_drp_node_SubscribeDRPRequest(buffer_arg) {
return node_src_proto_rpc_pb.SubscribeDRPRequest.decode(new Uint8Array(buffer_arg));
return node_src_proto_rpc_pb.SubscribeDRPRequest.decode(
new Uint8Array(buffer_arg)
);
}

function serialize_drp_node_SubscribeDRPResponse(arg) {
let encoded = node_src_proto_rpc_pb.SubscribeDRPResponse.encode(arg).finish()
let encoded = node_src_proto_rpc_pb.SubscribeDRPResponse.encode(arg).finish();
return Buffer.from(encoded);
}

function deserialize_drp_node_SubscribeDRPResponse(buffer_arg) {
return node_src_proto_rpc_pb.SubscribeDRPResponse.decode(new Uint8Array(buffer_arg));
return node_src_proto_rpc_pb.SubscribeDRPResponse.decode(
new Uint8Array(buffer_arg)
);
}

function serialize_drp_node_UnsubscribeDRPRequest(arg) {
let encoded = node_src_proto_rpc_pb.UnsubscribeDRPRequest.encode(arg).finish()
return Buffer.from(encoded);
let encoded =
node_src_proto_rpc_pb.UnsubscribeDRPRequest.encode(arg).finish();
return Buffer.from(encoded);
}

function deserialize_drp_node_UnsubscribeDRPRequest(buffer_arg) {
return node_src_proto_rpc_pb.UnsubscribeDRPRequest.decode(new Uint8Array(buffer_arg));
return node_src_proto_rpc_pb.UnsubscribeDRPRequest.decode(
new Uint8Array(buffer_arg)
);
}

function serialize_drp_node_UnsubscribeDRPResponse(arg) {
let encoded = node_src_proto_rpc_pb.UnsubscribeDRPResponse.encode(arg).finish()
return Buffer.from(encoded);
let encoded =
node_src_proto_rpc_pb.UnsubscribeDRPResponse.encode(arg).finish();
return Buffer.from(encoded);
}

function deserialize_drp_node_UnsubscribeDRPResponse(buffer_arg) {
return node_src_proto_rpc_pb.UnsubscribeDRPResponse.decode(new Uint8Array(buffer_arg));
return node_src_proto_rpc_pb.UnsubscribeDRPResponse.decode(
new Uint8Array(buffer_arg)
);
}

export const DRPRpcService = {
subscribeDRP: {
path: '/drp.node.drpRpc/subscribeDRP',
path: '/drp.node.v1.DrpRpcService/SubscribeDRP',
requestStream: false,
responseStream: false,
requestType: node_src_proto_rpc_pb.SubscribeDRPRequest,
Expand All @@ -67,7 +83,7 @@ export const DRPRpcService = {
responseDeserialize: deserialize_drp_node_SubscribeDRPResponse,
},
unsubscribeDRP: {
path: '/drp.node.drpRpc/unsubscribeDRP',
path: '/drp.node.v1.DrpRpcService/UnsubscribeDRP',
requestStream: false,
responseStream: false,
requestType: node_src_proto_rpc_pb.UnsubscribeDRPRequest,
Expand All @@ -78,7 +94,7 @@ export const DRPRpcService = {
responseDeserialize: deserialize_drp_node_UnsubscribeDRPResponse,
},
getDRPHashGraph: {
path: '/drp.node.drpRpc/getDRPHashGraph',
path: '/drp.node.v1.DrpRpcService/GetDRPHashGraph',
requestStream: false,
responseStream: false,
requestType: node_src_proto_rpc_pb.GetDRPHashGraphRequest,
Expand Down
12 changes: 12 additions & 0 deletions packages/node/src/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";
import * as reflection from "@grpc/reflection";

import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import type { ServerUnaryCall, sendUnaryData } from "@grpc/grpc-js";
import { type DRPNode, log } from "../index.js";
import { DRPRpcService } from "../proto/drp/node/v1/rpc_grpc_pb.js";
Expand Down Expand Up @@ -70,7 +74,15 @@ export function init(node: DRPNode) {
callback(null, response);
}

const protoPath = path.resolve(
dirname(fileURLToPath(import.meta.url)),
"../proto/drp/node/v1/rpc.proto",
);
const packageDefinition = protoLoader.loadSync(protoPath);
const reflectionService = new reflection.ReflectionService(packageDefinition);

const server = new grpc.Server();
reflectionService.addToServer(server);
d-roak marked this conversation as resolved.
Show resolved Hide resolved
server.addService(DRPRpcService, {
subscribeDRP,
unsubscribeDRP,
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading