Skip to content
Snippets Groups Projects
Select Git revision
  • 7f26b8577e60ed8952dbcea760aee4f955ea7dcc
  • experimental
  • master
  • v2021.1.2-ffs
  • v2021.1.1-ffs
  • nrb/gluon-master-cpe510
  • v2021.1-ffs
  • v2020.2.3-ffs
  • nrbffs/fastd-remove-delay
  • v2020.2.2-ffs
  • v2020.2.1-ffs
  • v2020.2-ffs
  • v2020.2.x
  • v2020.1.3-ffs
  • v2020.1.1-ffs
  • v2020.1-ffs
  • v2019.1.2-ffs
  • v2019.1.1-ffs
  • nrb/test-radv-filter
  • v2019.1-ffs
  • nrbffs/netgear-ex6120
  • v2021.1.2-ffs0.2
  • v2021.1.2-ffs0.1
  • v2021.1.1-ffs0.4
  • v2021.1.1-ffs0.3
  • v2021.1.1-ffs0.2
  • v2021.1.1-ffs0.1
  • v2021.1-ffs0.1
  • v2020.2.3-ffs0.3
  • v2020.2.3-ffs0.2
  • v2020.2.3-ffs0.1
  • v2020.2.2-ffs0.1
  • v2020.2.1-ffs0.1
  • v2020.2-ffs0.1
  • v2020.2
  • v2020.2.x-ffs0.1
  • v2020.1.3-ffs0.1
  • v2020.1.1-ffs0.1
  • v2020.1-ffs0.1
  • v2019.1.2-ffs0.1
  • v2019.1.1-ffs0.1
41 results

config-mode.rst

Blame
  • Forked from firmware / FFS Gluon
    Source project has a limited visibility.
    main.js 2.64 KiB
    "use strict"
    require([ "bacon"
            , "lib/helper"
            , "lib/streams"
            , "lib/gui"
            ], function(Bacon, Helper, Streams, GUI) {
    
      var mgmtBus = new Bacon.Bus()
    
      mgmtBus.pushEvent = function (key, a) {
        var v = [key].concat(a)
        return this.push(v)
      }
    
      mgmtBus.onEvent = function (events) {
        return this.onValue(function (e) {
          var d = e.slice() // shallow copy so calling shift doesn't change it
          var ev = d.shift()
          if (ev in events)
            events[ev].apply(this, d)
        })
      }
    
      var nodesBusIn = new Bacon.Bus()
    
      var nodesBus = nodesBusIn.scan({ "nodes": {}
                                     , "macs": {}
                                     }, scanNodeInfo)
    
      new GUI(mgmtBus, nodesBus)
    
      mgmtBus.onEvent({ "goto": gotoNode
                      , "nodeinfo": function (d) { nodesBusIn.push(d) }
                      })
    
      function tryIp(ip) {
        return Helper.request(ip, "nodeinfo").map(function () { return ip })
      }
    
      var gotoEpoch = 0
    
      function onEpoch(epoch, f) {
        return function (d) {
          if (epoch === gotoEpoch)
            return f(d)
        }
      }
    
      function gotoNode(nodeInfo) {
        gotoEpoch++
    
        var addresses = nodeInfo.network.addresses.filter(function (d) { return !/^fe80:/.test(d) })
        var race = Bacon.fromArray(addresses).flatMap(tryIp).withStateMachine([], function (acc, ev) {
          if (ev.isError())
            return [acc.concat(ev.error), []]
          else if (ev.isEnd() && acc.length > 0)
            return [undefined, [new Bacon.Error(acc), ev]]
          else if (ev.hasValue())
            return [[], [ev, new Bacon.End()]]
        })
    
        race.onValue(onEpoch(gotoEpoch, function (d) {
              mgmtBus.pushEvent("arrived", [nodeInfo, d])
            }))
    
        race.onError(onEpoch(gotoEpoch, function () {
              mgmtBus.pushEvent("gotoFailed", nodeInfo)
            }))
      }
    
      function scanNodeInfo(a, nodeInfo) {
        a.nodes[nodeInfo.node_id] = nodeInfo
    
        var mesh = Helper.dictGet(nodeInfo, ["network", "mesh"])
    
        if (mesh)
          for (var m in mesh)
            for (var ifname in mesh[m].interfaces)
              mesh[m].interfaces[ifname].forEach( function (d) {
                a.macs[d] = nodeInfo
              })
    
        return a
      }
    
      if (localStorage.nodes)
        JSON.parse(localStorage.nodes).forEach(nodesBusIn.push)
    
      nodesBus.map(".nodes").onValue(function (nodes) {
        var out = []
    
        for (var k in nodes)
          out.push(nodes[k])
    
        localStorage.nodes = JSON.stringify(out)
      })
    
      var bootstrap = Helper.getJSON(bootstrapUrl)
    
      bootstrap.onError(function () {
        console.log("FIXME bootstrapping failed")
      })
    
      bootstrap.onValue(function (d) {
        mgmtBus.pushEvent("nodeinfo", d)
        mgmtBus.pushEvent("goto", d)
      })
    })