Commit 0a50ea2f8ea043de9dac604adc0602cd504b2f25
minimal network polling, needs mutant patch
mix irving committed on 1/11/2017, 3:14:40 AMParent: 83811f3eeab7f9cae46ca83ffe34c19b2974a4ac
Files changed
modules_extra/network.js | changed |
modules_extra/network.mcss | changed |
modules_extra/network.js | ||
---|---|---|
@@ -1,14 +1,14 @@ | ||
1 | 1 … | const fs = require('fs') |
2 | -const isVisible = require('is-visible').isVisible | |
2 … | +// const { isVisible } = require('is-visible') | |
3 | 3 … | const h = require('../h') |
4 | 4 … | const human = require('human-time') |
5 | 5 … | |
6 | -const mutantMap = require('@mmckegg/mutant/map') | |
7 | -const dict = require('@mmckegg/mutant/dict') | |
8 | 6 … | const Struct = require('@mmckegg/mutant/struct') |
9 | 7 … | const Value = require('@mmckegg/mutant/value') |
8 … | +const Dict = require('@mmckegg/mutant/dict') | |
10 | 9 … | const toCollection = require('@mmckegg/mutant/dict-to-collection') |
10 … | +const mutantMap = require('@mmckegg/mutant/map') | |
11 | 11 … | const when = require('@mmckegg/mutant/when') |
12 | 12 … | const computed = require('@mmckegg/mutant/computed') |
13 | 13 … | |
14 | 14 … | //var avatar = plugs.first(exports.avatar = []) |
@@ -36,55 +36,52 @@ | ||
36 | 36 … | function legacyToMultiServer(addr) { |
37 | 37 … | return 'net:'+addr.host + ':'+addr.port + '~shs:'+addr.key.substring(1).replace('.ed25519','') |
38 | 38 … | } |
39 | 39 … | |
40 | - | |
41 | - | |
42 | 40 … | //on the same wifi network |
43 | 41 … | function isLocal (peer) { |
44 | 42 … | // don't rely on private ip address, because |
45 | 43 … | // cjdns creates fake private ip addresses. |
46 | 44 … | return ip.isPrivate(peer.host) && peer.type === 'local' |
47 | 45 … | } |
48 | 46 … | |
49 | 47 … | |
50 | -//pub is running scuttlebot >=8 | |
51 | -//have connected successfully. | |
52 | -function isLongterm (peer) { | |
53 | - return peer.ping && peer.ping.rtt && peer.ping.rtt.mean > 0 | |
54 | -} | |
55 | - | |
56 | -//pub is running scuttlebot < 8 | |
57 | -//have connected sucessfully | |
58 | -function isLegacy (peer) { | |
59 | - return /connect/.test(peer.state) || (peer.duration && peer.duration.mean) > 0 && !isLongterm(peer) | |
60 | -} | |
61 | - | |
62 | -//tried to connect, but failed. | |
63 | -function isInactive (peer) { | |
64 | - return peer.stateChange && (peer.duration && peer.duration.mean == 0) | |
65 | -} | |
66 | - | |
67 | -//havn't tried to connect peer yet. | |
68 | -function isUnattempted (peer) { | |
69 | - return !peer.stateChange | |
70 | -} | |
71 | - | |
72 | 48 … | function getType (peer) { |
73 | 49 … | return ( |
74 | 50 … | isLongterm(peer) ? 'modern' |
75 | 51 … | : isLegacy(peer) ? 'legacy' |
76 | 52 … | : isInactive(peer) ? 'inactive' |
77 | 53 … | : isUnattempted(peer) ? 'unattempted' |
78 | 54 … | : 'other' //should never happen |
79 | 55 … | ) |
56 … | + | |
57 … | + //pub is running scuttlebot >=8 | |
58 … | + //have connected successfully. | |
59 … | + function isLongterm (peer) { | |
60 … | + return peer.ping && peer.ping.rtt && peer.ping.rtt.mean > 0 | |
61 … | + } | |
62 … | + | |
63 … | + //pub is running scuttlebot < 8 | |
64 … | + //have connected sucessfully | |
65 … | + function isLegacy (peer) { | |
66 … | + return /connect/.test(peer.state) || (peer.duration && peer.duration.mean) > 0 && !isLongterm(peer) | |
67 … | + } | |
68 … | + | |
69 … | + //tried to connect, but failed. | |
70 … | + function isInactive (peer) { | |
71 … | + return peer.stateChange && (peer.duration && peer.duration.mean == 0) | |
72 … | + } | |
73 … | + | |
74 … | + //havn't tried to connect peer yet. | |
75 … | + function isUnattempted (peer) { | |
76 … | + return !peer.stateChange | |
77 … | + } | |
80 | 78 … | } |
81 | 79 … | |
82 | 80 … | function origin (peer) { |
83 | 81 … | return peer.source === 'local' ? 0 : 1 |
84 | 82 … | } |
85 | 83 … | |
86 | - | |
87 | 84 … | function round(n) { |
88 | 85 … | return Math.round(n*100)/100 |
89 | 86 … | } |
90 | 87 … | |
@@ -121,9 +118,9 @@ | ||
121 | 118 … | ) |
122 | 119 … | } |
123 | 120 … | |
124 | 121 … | function formatDate (time) { |
125 | - return new Date(time).toString() | |
122 … | + return new Date(time).toString() | |
126 | 123 … | } |
127 | 124 … | |
128 | 125 … | function humanDate (time) { |
129 | 126 … | return human(new Date(time)).replace(/minute/, 'min').replace(/second/, 'sec') |
@@ -136,15 +133,15 @@ | ||
136 | 133 … | builtin_tabs: () => ['/network'], |
137 | 134 … | screen_view, |
138 | 135 … | mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') |
139 | 136 … | } |
140 | - | |
137 … | + | |
141 | 138 … | function screen_view (path) { |
142 | 139 … | if (path !== '/network') return |
143 | 140 … | |
144 | 141 … | var peers = obs_gossip_peers(api) |
145 | 142 … | |
146 | - return h('div', { style: {'overflow':'auto'}, className: 'column scroller' }, [ | |
143 … | + return h('div', { style: {'overflow':'auto'}, className: 'column scroller' }, [ | |
147 | 144 … | h('Network', [ |
148 | 145 … | mutantMap(peers, peer => { |
149 | 146 … | var { key, ping, source, state, stateChange } = peer |
150 | 147 … | |
@@ -163,8 +160,11 @@ | ||
163 | 160 … | h('code', source) |
164 | 161 … | ]), |
165 | 162 … | h('section.state', [ |
166 | 163 … | 'state: ', |
164 … | + h('i', { | |
165 … | + className: computed(state, (state) => '-'+state) | |
166 … | + }), | |
167 | 167 … | h('code', when(state, state, 'not connected')) |
168 | 168 … | ]), |
169 | 169 … | h('section.actions', [ |
170 | 170 … | h('button', { |
@@ -180,9 +180,9 @@ | ||
180 | 180 … | h('section.time-ago', [ |
181 | 181 … | h('div', |
182 | 182 … | { title: computed(stateChange, formatDate) }, |
183 | 183 … | [ computed(stateChange, humanDate) ] |
184 | - ) | |
184 … | + ) | |
185 | 185 … | ]), |
186 | 186 … | h('section.ping', [ |
187 | 187 … | h('div.rtt', [ |
188 | 188 … | 'rtt: ', |
@@ -204,16 +204,21 @@ | ||
204 | 204 … | } |
205 | 205 … | |
206 | 206 … | function obs_gossip_peers (api) { |
207 | 207 … | var timer = null |
208 | - var state = dict({}, { | |
209 | - onListen: () => { | |
210 | - timer = setInterval(refresh, 5e3) | |
211 | - }, | |
212 | - onUnlisten: () => { | |
213 | - clearInterval(timer) | |
214 | - } | |
208 … | + var state = Dict({}, { | |
209 … | + // | |
210 … | + // TODO - get this api implemented in mutantDict | |
211 … | + // | |
212 … | + // onListen: () => { | |
213 … | + // timer = setInterval(refresh, 5e3) | |
214 … | + // }, | |
215 … | + // onUnlisten: () => { | |
216 … | + // clearInterval(timer) | |
217 … | + // } | |
215 | 218 … | }) |
219 … | + // TODO - remove this line | |
220 … | + setInterval(refresh, 5e3) | |
216 | 221 … | |
217 | 222 … | refresh() |
218 | 223 … | |
219 | 224 … | return toCollection.values(state) |
modules_extra/network.mcss | ||
---|---|---|
@@ -9,13 +9,13 @@ | ||
9 | 9 … | NetworkConnection { |
10 | 10 … | padding-left: 6rem |
11 | 11 … | padding-bottom: .8rem |
12 | 12 … | position: relative |
13 | - | |
13 … | + | |
14 | 14 … | display: flex |
15 | 15 … | flex-direction: row |
16 | 16 … | flex-wrap: wrap |
17 | - align-items: center | |
17 … | + align-items: center | |
18 | 18 … | |
19 | 19 … | section.avatar { |
20 | 20 … | position: absolute |
21 | 21 … | left: 0 |
@@ -53,9 +53,31 @@ | ||
53 | 53 … | flex-basis: 100% |
54 | 54 … | } |
55 | 55 … | |
56 | 56 … | section.state { |
57 … | + display: flex | |
58 … | + flex-direction: row | |
59 … | + align-items: center | |
60 … | + | |
57 | 61 … | margin-right: 2rem |
62 … | + | |
63 … | + i { | |
64 … | + width: 1rem | |
65 … | + height: 1rem | |
66 … | + border-radius: .5rem | |
67 … | + | |
68 … | + margin: 0 .2rem 0 .5rem | |
69 … | + | |
70 … | + background: #ccc | |
71 … | + | |
72 … | + -connecting, -disconnecting { | |
73 … | + background: #95cc95 | |
74 … | + } | |
75 … | + | |
76 … | + -connected { | |
77 … | + background: #06e206 | |
78 … | + } | |
79 … | + } | |
58 | 80 … | } |
59 | 81 … | |
60 | 82 … | section.actions { |
61 | 83 … | button { |
Built with git-ssb-web