-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5e78a1
commit 3756012
Showing
14 changed files
with
383 additions
and
261 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
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
Empty file.
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,51 @@ | ||
/** | ||
* Authorized requests for network channels in the database. | ||
*/ | ||
|
||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
const errors = require("../utils/httperror"); | ||
const request = require("../utils/request"); | ||
const rclient = require("../utils/redis-client"); | ||
|
||
const network = require("../utils/network"); | ||
const channel = require("../utils/channel"); | ||
const node = require("../utils/node"); | ||
|
||
/** | ||
* Create a channel to communicate with multiple nodes. Each network can only have one active channel. | ||
*/ | ||
router.post("/:id/channel", errors.asyncWrap(async function(req, res) { | ||
// parse request | ||
const networkId = req.params.id; | ||
const channelReq = request.validateBody(req, ["nodeIds?"]); | ||
|
||
// validate request | ||
await network.getNetworkFromOwner(req, networkId); | ||
let [err, networkNodeIds] = await rclient.getSetMembers(node.networkNodesKey(networkId)); | ||
|
||
let nodeIds = []; | ||
if ("nodeIds" in channelReq && channelReq.nodeIds.length > 0) { | ||
// filter nodes to the current network | ||
for (let nodeId of channelReq.nodeIds) { | ||
if (networkNodeIds.indexOf(nodeId) != -1) { | ||
nodeIds.push(nodeId); | ||
} | ||
} | ||
} | ||
else { | ||
// if none provided, select all nodes in the network | ||
nodeIds = networkNodeIds; | ||
} | ||
|
||
console.log(nodeIds); | ||
|
||
// create channel | ||
await channel.newChannelObj(networkId, nodeIds); | ||
|
||
// return response | ||
res.status(200); | ||
})); | ||
|
||
module.exports = router; |
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,53 @@ | ||
/** | ||
* Authorized requests for network registrations in the database. | ||
*/ | ||
|
||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
const errors = require("../utils/httperror"); | ||
const request = require("../utils/request"); | ||
|
||
const network = require("../utils/network"); | ||
const passphrases = require("../utils/network_passphrase"); | ||
|
||
/** | ||
* Get the node registration form. | ||
*/ | ||
router.get("/:id/node", errors.asyncWrap(async function(req, res, next) { | ||
[err, redisRes] = await network.getNetworkFromOwner(req, req.params.id); | ||
|
||
res.render("network/register", { | ||
netId: req.params.id | ||
}); | ||
})); | ||
|
||
/** | ||
* Prepare a node passphrase. | ||
*/ | ||
router.post("/:id/node", errors.asyncWrap(async function(req, res, next) { | ||
const nodeReq = request.validateBody(req, ["name", "pass"]); | ||
|
||
passphrases.validateNetworkPassphrase(nodeReq.pass); | ||
|
||
// check requested network | ||
const networkId = req.params.id; | ||
await network.getNetworkFromOwner(req, networkId); | ||
|
||
// set in database | ||
await passphrases.addNetworkPassphrase(networkId, nodeReq.name, nodeReq.pass); | ||
|
||
res.redirect("/nodes?network-id=" + req.params.id); | ||
})); | ||
|
||
/** | ||
* Clear all unused passphrases. | ||
*/ | ||
router.delete("/:id/passphrases", errors.asyncWrap(async function(req, res, next) { | ||
const networkId = req.params.id; | ||
await network.getNetworkFromOwner(req, networkId); | ||
await passphrases.clearPassphrases(networkId); | ||
res.sendStatus(204); | ||
})); | ||
|
||
module.exports = router; |
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
Oops, something went wrong.