Files: ed0d0518717fe16a686399588766fb35b3e6e37a / app / page / network / replication-out.js
2005 bytesRaw
1 | const { h, Value, Dict, dictToCollection, onceTrue, computed } = require('mutant') |
2 | |
3 | module.exports = function ReplicationOut ({ connection }) { |
4 | const state = buildState(connection) |
5 | |
6 | const body = h('ReplicationOut', [ |
7 | // mix: hello friend, this area is a total Work In Progress. It's a mess but useful diagnostics. |
8 | // Let's redesign and revisit it aye! |
9 | h('div', ['My sequence: ', state.seq]), |
10 | h('div', [ |
11 | 'Replicated:', |
12 | h('div', computed([state.seq, dictToCollection(state.replication)], (seq, replication) => { |
13 | return replication.map(r => { |
14 | if (!r.value.replicating) { |
15 | return h('div', [ |
16 | h('code', r.key), |
17 | ' no ebt data' |
18 | ]) |
19 | } |
20 | |
21 | const { requested, sent } = r.value.replicating |
22 | // TODO report that r.value.seq is NOT the current local value of the seq (well it's ok, just just gets out of sync) |
23 | // const reqDiff = requested - r.value.seq |
24 | const reqDiff = requested - seq |
25 | const sentDiff = sent - seq |
26 | |
27 | return h('div', [ |
28 | h('code', r.key), |
29 | ` - requested: ${requested} `, |
30 | reqDiff === 0 ? h('i.fa.fa-check-circle-o') : `(${reqDiff})`, |
31 | `, sent: ${sent} `, |
32 | sentDiff === 0 ? h('i.fa.fa-check-circle-o') : `(${sentDiff})` |
33 | ]) |
34 | }) |
35 | })) |
36 | ]) |
37 | ]) |
38 | |
39 | return { |
40 | title: 'Outgoing Traffic', |
41 | body |
42 | } |
43 | } |
44 | |
45 | function buildState (connection) { |
46 | // build seq, replication (my current state, and replicated state) |
47 | const seq = Value() |
48 | const replication = Dict({}) |
49 | onceTrue(connection, server => { |
50 | setInterval(() => { |
51 | // TODO check ebt docs if this is best method |
52 | server.ebt.peerStatus(server.id, (err, data) => { |
53 | if (err) return console.error(err) |
54 | |
55 | seq.set(data.seq) |
56 | for (var peer in data.peers) { |
57 | replication.put(peer, data.peers[peer]) |
58 | } |
59 | }) |
60 | }, 5e3) |
61 | }) |
62 | |
63 | return { |
64 | seq, |
65 | replication |
66 | } |
67 | } |
68 |
Built with git-ssb-web