Skip to content
Snippets Groups Projects
Commit 102df6b9 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix #274 Added /network/peers URI

parent c67077bd
No related branches found
No related tags found
No related merge requests found
"use strict"; "use strict";
var _ = require('underscore');
var co = require('co');
var async = require('async'); var async = require('async');
var es = require('event-stream'); var es = require('event-stream');
var dos2unix = require('../lib/dos2unix'); var dos2unix = require('../lib/dos2unix');
...@@ -72,4 +74,30 @@ function NetworkBinding (server, conf) { ...@@ -72,4 +74,30 @@ function NetworkBinding (server, conf) {
.pipe(es.stringify()) .pipe(es.stringify())
.pipe(res); .pipe(res);
}; };
this.peers = function (req, res) {
res.type('application/json');
co(function *() {
try {
let peers = yield server.dal.listAllPeers();
var json = {
peers: peers.map((p) => {
return _.pick(p,
'version',
'currency',
'status',
'first_down',
'last_try',
'pubkey',
'block',
'signature',
'endpoints');
})
};
res.send(200, JSON.stringify(json, null, " "));
} catch (err) {
res.send(400, err);
}
});
};
} }
...@@ -83,6 +83,7 @@ module.exports = function(server, interfaces, httpLogs) { ...@@ -83,6 +83,7 @@ module.exports = function(server, interfaces, httpLogs) {
answerForGet( '/network/peering', net.peer); answerForGet( '/network/peering', net.peer);
answerForGet( '/network/peering/peers', net.peersGet); answerForGet( '/network/peering/peers', net.peersGet);
answerForPost('/network/peering/peers', net.peersPost); answerForPost('/network/peering/peers', net.peersPost);
answerForGet('/network/peers', net.peers);
var wot = require('../../controllers/wot')(server); var wot = require('../../controllers/wot')(server);
answerForPost('/wot/add', wot.add); answerForPost('/wot/add', wot.add);
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
* [tx](#blockchainwithtx) * [tx](#blockchainwithtx)
* [branches](#blockchainbranches) * [branches](#blockchainbranches)
* [network/](#network) * [network/](#network)
* [peers](#networkpeers)
* [peering](#networkpeering) * [peering](#networkpeering)
* [peering/peers (GET)](#networkpeeringpeers-get) * [peering/peers (GET)](#networkpeeringpeers-get)
* [peering/peers (POST)](#networkpeeringpeers-post) * [peering/peers (POST)](#networkpeeringpeers-post)
...@@ -80,6 +81,7 @@ Data is made accessible through an HTTP API mainly inspired from [OpenUDC_exchan ...@@ -80,6 +81,7 @@ Data is made accessible through an HTTP API mainly inspired from [OpenUDC_exchan
| | `-- [NUMBER] | | `-- [NUMBER]
| `-- current | `-- current
|-- network/ |-- network/
| |-- peers
| `-- peering | `-- peering
| `-- peers | `-- peers
|-- tx/ |-- tx/
...@@ -1003,6 +1005,52 @@ Top block of each branch, i.e. the last received block of each branch. An array ...@@ -1003,6 +1005,52 @@ Top block of each branch, i.e. the last received block of each branch. An array
This URL is used for uCoin Gossip protocol (exchanging UCG messages). This URL is used for uCoin Gossip protocol (exchanging UCG messages).
#### `network/peers`
**Goal**
GET the exhaustive list of peers known by the node.
**Parameters**
*None*.
**Returns**
List of peering entries.
```json
{
"peers": [
{
"version": "1",
"currency": "meta_brouzouf",
"status": "UP",
"first_down": null,
"last_try": null,
"pubkey": "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk",
"block": "45180-00000E577DD4B308B98D0ED3E43926CE4D22E9A8",
"signature": "GKTrlUc4um9lQuj9UI8fyA/n/JKieYqBYcl9keIWfAVOnvHamLHaqGzijsdX1kNt64cadcle/zkd7xOgMTdQAQ==",
"endpoints": [
"BASIC_MERKLED_API metab.ucoin.io 88.174.120.187 9201"
]
},
{
"version": "1",
"currency": "meta_brouzouf",
"status": "UP",
"first_down": null,
"last_try": null,
"pubkey": "2aeLmae5d466y8D42wLK5MknwUBCR6MWWeixRzdTQ4Hu",
"block": "45182-0000064EEF412C1CDD1B370CC45A3BC3B9743464",
"signature": "kbdTay1OirDqG/E3jyCaDlL7HVVHb9/BXvNHAg+xO9sSA+NgmBo/4mEqL9b7hH0UnbXHss6TfuvxAHZLmBqsCw==",
"endpoints": [
"BASIC_MERKLED_API twiced.fr 88.174.120.187 9223"
]
},
...
]
}
```
#### `network/peering` #### `network/peering`
**Goal** **Goal**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment