Skip to content

Commit

Permalink
feat: add reflection service to rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
winprn committed Dec 16, 2024
1 parent 99fdc9e commit 86b378c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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
11 changes: 11 additions & 0 deletions packages/node/src/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as grpc from "@grpc/grpc-js";
import * as protoLoader from "@grpc/proto-loader";
import * as reflection from "@grpc/reflection";

import type { ServerUnaryCall, sendUnaryData } from "@grpc/grpc-js";
import { type DRPNode, log } from "../index.js";
Expand All @@ -11,6 +13,11 @@ import type {
UnsubscribeDRPRequest,
UnsubscribeDRPResponse,
} from "../proto/drp/node/v1/rpc_pb.js";
import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const PROTO_PATH = path.resolve(__dirname, "../proto/topology/node/rpc.proto");

export function init(node: DRPNode) {
function subscribeDRP(
Expand Down Expand Up @@ -70,7 +77,11 @@ export function init(node: DRPNode) {
callback(null, response);
}

const packageDefinition = protoLoader.loadSync(PROTO_PATH);
const reflectionService = new reflection.ReflectionService(packageDefinition);

const server = new grpc.Server();
reflectionService.addToServer(server);
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.

0 comments on commit 86b378c

Please sign in to comment.