-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-dht-first.js
More file actions
40 lines (35 loc) · 937 Bytes
/
test-dht-first.js
File metadata and controls
40 lines (35 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const dht = require("./dht")
const grpc = require('@grpc/grpc-js');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
// yargs를 사용하여 명령줄 인자 파싱
const argv = yargs(hideBin(process.argv))
.option('address', {
alias: 'a',
describe: 'Server address',
default: 'localhost:50051',
type: 'string'
})
.option('peer', {
alias: 'p',
describe: 'Peer address',
default: 'localhost:50052',
type: 'string'
})
.argv;
// Set up gRPC server
const server = new grpc.Server();
dht.addService(server)
dht.addPeer(argv.peer);
server.bindAsync(argv.address, grpc.ServerCredentials.createInsecure(), () => {
server.start();
});
dht.put("a", "aa")
// get은 비동기적으로 작동하므로 콜백을 사용합니다.
dht.get("a", (err, value) => {
if (err) {
console.error(err);
return;
}
console.log("Retrieved value:", value);
});