-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from firecomm/bind
changes added and getPeer fixed
- Loading branch information
Showing
5 changed files
with
177 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// /server/chattyMathHandlers.js | ||
function BidiMathHandler(bidi) { | ||
let start; | ||
let end; | ||
bidi | ||
.on('metadata', (metadata) => { | ||
start = Number(process.hrtime.bigint()); | ||
bidi.set({thisSetsMetadata: 'responses incoming'}) | ||
console.log(metadata.getMap()); | ||
}) | ||
.on('error', (err) => { | ||
console.exception(err) | ||
}) | ||
.on('data', (benchmark) => { | ||
bidi.send( | ||
{ | ||
requests: benchmark.requests, | ||
responses: benchmark.responses + 1 | ||
} | ||
); | ||
if (benchmark.requests % 10000 === 0) { | ||
end = Number(process.hrtime.bigint()); | ||
console.log( | ||
'client address:', bidi.getPeer(), | ||
'\nnumber of requests:', benchmark.requests, | ||
'\navg millisecond speed per request:', ((end - start) /1000000) / benchmark.requests | ||
); | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
BidiMathHandler, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// package.js | ||
const { build } = require( '../../index.js' ); | ||
const path = require( 'path' ); | ||
const PROTO_PATH = path.join( __dirname, './proto/exampleAPI.proto' ); | ||
|
||
const CONFIG_OBJECT = { | ||
keepCase: true, // keeps everything camelCased | ||
longs: Number, // compiles the potentially enormous `double`s for our BenchmarkMsg requests and responses into a JavaScript Number rather than a String | ||
} | ||
const package = build( PROTO_PATH, CONFIG_OBJECT ); | ||
module.exports = package; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// proto/exampleAPI.proto | ||
syntax = "proto3"; | ||
|
||
package exampleAPI; | ||
|
||
service ChattyMath { | ||
rpc BidiMath (stream Benchmark) returns (stream Benchmark) {}; | ||
} | ||
|
||
message Benchmark { | ||
double requests = 1; | ||
double responses = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,65 @@ | ||
const grpc = require("grpc"); | ||
const firecomm = require("../../index"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const package = require("./packageDefinition"); | ||
|
||
const { | ||
unaryChat, | ||
serverStream, | ||
clientStream, | ||
bidiChat | ||
} = require("./methodHandlers"); | ||
const waitFor = require("./middleware"); | ||
|
||
const server = new firecomm.Server(); | ||
|
||
server.addService( | ||
package.RouteGuide, | ||
{ unaryChat: unaryChat, serverStream, clientStream, bidiChat } | ||
// context => { | ||
// console.log("inside of service level middleware"); | ||
// }, | ||
// (err, call) => { | ||
// console.log("error from error handler:", err); | ||
// console.log("call in error:", call); | ||
// call.send({ message: "BULLDOZE THROUGH ERRORS" }); | ||
// } | ||
); | ||
|
||
// console.log({ server }); | ||
// console.log("server proto", server.__proto__); | ||
// console.log( | ||
// "proto of server handler", | ||
// server.handlers["/routeguide.RouteGuide/UnaryChat"] | ||
// /server/server.js | ||
const { Server } = require( '../../index.js' ); | ||
const package = require( './package.js' ); | ||
const { BidiMathHandler } = require ( './chattyMathHandlers.js' ); | ||
|
||
new Server() | ||
.addService( | ||
package.ChattyMath, | ||
{ BidiMath: BidiMathHandler } | ||
) | ||
.bind('0.0.0.0: 3000') | ||
.start(); | ||
|
||
|
||
// const grpc = require("grpc"); | ||
// const firecomm = require("../../index"); | ||
// const fs = require("fs"); | ||
// const path = require("path"); | ||
|
||
// const package = require("./packageDefinition"); | ||
|
||
// const { | ||
// unaryChat, | ||
// serverStream, | ||
// clientStream, | ||
// bidiChat | ||
// } = require("./methodHandlers"); | ||
// const waitFor = require("./middleware"); | ||
|
||
// const server = new firecomm.Server(); | ||
|
||
// server.addService( | ||
// package.RouteGuide, | ||
// { unaryChat: unaryChat, serverStream, clientStream, bidiChat } | ||
// // context => { | ||
// // console.log("inside of service level middleware"); | ||
// // }, | ||
// // (err, call) => { | ||
// // console.log("error from error handler:", err); | ||
// // console.log("call in error:", call); | ||
// // call.send({ message: "BULLDOZE THROUGH ERRORS" }); | ||
// // } | ||
// ); | ||
|
||
let certPath = path.join(__dirname, "/server.crt"); | ||
let keyPath = path.join(__dirname, "/server.key"); | ||
// // console.log({ server }); | ||
// // console.log("server proto", server.__proto__); | ||
// // console.log( | ||
// // "proto of server handler", | ||
// // server.handlers["/routeguide.RouteGuide/UnaryChat"] | ||
// // ); | ||
|
||
// let certPath = path.join(__dirname, "/server.crt"); | ||
// let keyPath = path.join(__dirname, "/server.key"); | ||
|
||
// const result = | ||
server.bind(["0.0.0.0:3000", "0.0.0.0:2999"], [{ | ||
privateKey: keyPath, | ||
certificate: certPath | ||
}, null]); | ||
// console.log({ result }); | ||
// console.log({ server }); | ||
// console.log(server.__proto__); | ||
// console.log(new grpc.Server().__proto__) | ||
// // const result = | ||
// server.bind(["0.0.0.0:3000", "0.0.0.0:2999"], [{ | ||
// privateKey: keyPath, | ||
// certificate: certPath | ||
// }, null]); | ||
// // console.log({ result }); | ||
// // console.log({ server }); | ||
// // console.log(server.__proto__); | ||
// // console.log(new grpc.Server().__proto__) | ||
|
||
server.start(); | ||
// server.start(); |