git ssb

16+

Dominic / patchbay



Commit 0a50ea2f8ea043de9dac604adc0602cd504b2f25

minimal network polling, needs mutant patch

mix irving committed on 1/11/2017, 3:14:40 AM
Parent: 83811f3eeab7f9cae46ca83ffe34c19b2974a4ac

Files changed

modules_extra/network.jschanged
modules_extra/network.mcsschanged
modules_extra/network.jsView
@@ -1,14 +1,14 @@
11 const fs = require('fs')
2-const isVisible = require('is-visible').isVisible
2 +// const { isVisible } = require('is-visible')
33 const h = require('../h')
44 const human = require('human-time')
55
6-const mutantMap = require('@mmckegg/mutant/map')
7-const dict = require('@mmckegg/mutant/dict')
86 const Struct = require('@mmckegg/mutant/struct')
97 const Value = require('@mmckegg/mutant/value')
8 +const Dict = require('@mmckegg/mutant/dict')
109 const toCollection = require('@mmckegg/mutant/dict-to-collection')
10 +const mutantMap = require('@mmckegg/mutant/map')
1111 const when = require('@mmckegg/mutant/when')
1212 const computed = require('@mmckegg/mutant/computed')
1313
1414 //var avatar = plugs.first(exports.avatar = [])
@@ -36,55 +36,52 @@
3636 function legacyToMultiServer(addr) {
3737 return 'net:'+addr.host + ':'+addr.port + '~shs:'+addr.key.substring(1).replace('.ed25519','')
3838 }
3939
40-
41-
4240 //on the same wifi network
4341 function isLocal (peer) {
4442 // don't rely on private ip address, because
4543 // cjdns creates fake private ip addresses.
4644 return ip.isPrivate(peer.host) && peer.type === 'local'
4745 }
4846
4947
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-
7248 function getType (peer) {
7349 return (
7450 isLongterm(peer) ? 'modern'
7551 : isLegacy(peer) ? 'legacy'
7652 : isInactive(peer) ? 'inactive'
7753 : isUnattempted(peer) ? 'unattempted'
7854 : 'other' //should never happen
7955 )
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 + }
8078 }
8179
8280 function origin (peer) {
8381 return peer.source === 'local' ? 0 : 1
8482 }
8583
86-
8784 function round(n) {
8885 return Math.round(n*100)/100
8986 }
9087
@@ -121,9 +118,9 @@
121118 )
122119 }
123120
124121 function formatDate (time) {
125- return new Date(time).toString()
122 + return new Date(time).toString()
126123 }
127124
128125 function humanDate (time) {
129126 return human(new Date(time)).replace(/minute/, 'min').replace(/second/, 'sec')
@@ -136,15 +133,15 @@
136133 builtin_tabs: () => ['/network'],
137134 screen_view,
138135 mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8')
139136 }
140-
137 +
141138 function screen_view (path) {
142139 if (path !== '/network') return
143140
144141 var peers = obs_gossip_peers(api)
145142
146- return h('div', { style: {'overflow':'auto'}, className: 'column scroller' }, [
143 + return h('div', { style: {'overflow':'auto'}, className: 'column scroller' }, [
147144 h('Network', [
148145 mutantMap(peers, peer => {
149146 var { key, ping, source, state, stateChange } = peer
150147
@@ -163,8 +160,11 @@
163160 h('code', source)
164161 ]),
165162 h('section.state', [
166163 'state: ',
164 + h('i', {
165 + className: computed(state, (state) => '-'+state)
166 + }),
167167 h('code', when(state, state, 'not connected'))
168168 ]),
169169 h('section.actions', [
170170 h('button', {
@@ -180,9 +180,9 @@
180180 h('section.time-ago', [
181181 h('div',
182182 { title: computed(stateChange, formatDate) },
183183 [ computed(stateChange, humanDate) ]
184- )
184 + )
185185 ]),
186186 h('section.ping', [
187187 h('div.rtt', [
188188 'rtt: ',
@@ -204,16 +204,21 @@
204204 }
205205
206206 function obs_gossip_peers (api) {
207207 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 + // }
215218 })
219 + // TODO - remove this line
220 + setInterval(refresh, 5e3)
216221
217222 refresh()
218223
219224 return toCollection.values(state)
modules_extra/network.mcssView
@@ -9,13 +9,13 @@
99 NetworkConnection {
1010 padding-left: 6rem
1111 padding-bottom: .8rem
1212 position: relative
13-
13 +
1414 display: flex
1515 flex-direction: row
1616 flex-wrap: wrap
17- align-items: center
17 + align-items: center
1818
1919 section.avatar {
2020 position: absolute
2121 left: 0
@@ -53,9 +53,31 @@
5353 flex-basis: 100%
5454 }
5555
5656 section.state {
57 + display: flex
58 + flex-direction: row
59 + align-items: center
60 +
5761 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 + }
5880 }
5981
6082 section.actions {
6183 button {

Built with git-ssb-web