Commit 635e5c42 authored by 神楽坂玲奈's avatar 神楽坂玲奈

test

parent 442e4dab
...@@ -12,9 +12,10 @@ let updating: any = null; ...@@ -12,9 +12,10 @@ let updating: any = null;
let timeout_timer: any = null; let timeout_timer: any = null;
export function send_route(from: Router, to: Router, via: Router) { export function send_route(from: Router, to: Router, via: Router) {
if (!from.rinfo) return;
const message: DownloadMessage = { seq: from.seq, to: to.id, via: via.id }; const message: DownloadMessage = { seq: from.seq, to: to.id, via: via.id };
console.log(from.id, message); console.log(from.id, message);
return socket.send(JSON.stringify(message), from.rinfo!.port, from.rinfo!.address); return socket.send(JSON.stringify(message), from.rinfo.port, from.rinfo.address);
} }
const socket = dgram const socket = dgram
...@@ -79,7 +80,11 @@ socket.bind(config.port); ...@@ -79,7 +80,11 @@ socket.bind(config.port);
http http
.createServer(function(req, res) { .createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'application/json' }); res.writeHead(200, { 'Content-Type': 'application/json' });
const result = Router.all.map(from => ({id: from.id, peers: from.peers, via: Object.fromEntries([...from.via.entries()].map(([to, via]) => [to.id, via.id]))})); const result = Router.all.map(from => ({
id: from.id,
peers: from.peers,
via: Object.fromEntries([...from.via.entries()].map(([to, via]) => [to.id, via.id]))
}));
// const result: Record<number, Record<number, number>> = Object.fromEntries(Router.all.map(from => [from.id, ])); // const result: Record<number, Record<number, number>> = Object.fromEntries(Router.all.map(from => [from.id, ]));
return res.end(JSON.stringify(result)); return res.end(JSON.stringify(result));
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment