mirror of
https://github.com/fluencelabs/dashboard
synced 2025-03-16 13:30:48 +00:00
gather all info about peer
This commit is contained in:
parent
fa84ead4a4
commit
a3bce9f135
@ -39,7 +39,6 @@
|
||||
"typescript": "4.1.2",
|
||||
"webpack": "5.7.0",
|
||||
"webpack-cli": "4.2.0",
|
||||
"webpack-dev-server": "3.11.0",
|
||||
"webpack-nano": "^1.1.0",
|
||||
"webpack-plugin-serve": "^1.2.0",
|
||||
"webpack-serve": "3.2.0"
|
||||
|
41
src/AirScripts/GetAll.elm
Normal file
41
src/AirScripts/GetAll.elm
Normal file
@ -0,0 +1,41 @@
|
||||
module AirScripts.GetAll exposing (..)
|
||||
|
||||
import Air exposing (Air)
|
||||
import Air exposing (Air, callBI, fold, next, par, relayEvent, seq, set)
|
||||
import Json.Encode exposing (list, string)
|
||||
|
||||
air : String -> String -> List String -> Air
|
||||
air peerId relayId peers =
|
||||
let
|
||||
clientIdSet =
|
||||
set "clientId" <| string peerId
|
||||
|
||||
relayIdSet =
|
||||
set "relayId" <| string relayId
|
||||
|
||||
peersSet =
|
||||
set "peers" <| list string peers
|
||||
|
||||
airScript =
|
||||
seq
|
||||
(callBI "relayId" ( "op", "identity" ) [] Nothing)
|
||||
(fold "peers" "p" <|
|
||||
par
|
||||
(seq
|
||||
(callBI "p" ( "op", "identify" ) [] (Just "ident"))
|
||||
(seq
|
||||
(callBI "p" ( "dist", "get_blueprints" ) [] (Just "blueprints"))
|
||||
(seq
|
||||
(callBI "p" ( "dist", "get_modules" ) [] (Just "modules"))
|
||||
(seq
|
||||
(callBI "p" ( "srv", "get_interfaces" ) [] (Just "interfaces"))
|
||||
(relayEvent "all_info" [ "p", "ident", "interfaces","blueprints", "modules" ])
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
)
|
||||
(next "p")
|
||||
)
|
||||
in
|
||||
clientIdSet <| relayIdSet <| peersSet <| airScript
|
7
src/Blueprints/Air.elm
Normal file
7
src/Blueprints/Air.elm
Normal file
@ -0,0 +1,7 @@
|
||||
module Blueprints.Air exposing (..)
|
||||
|
||||
import Air exposing (Air)
|
||||
import AirScripts.CallPeers
|
||||
air : String -> String -> List String -> Air
|
||||
air peerId relayId peers =
|
||||
AirScripts.CallPeers.air peerId relayId ("blueprints_discovered", "dist", "get_blueprints") peers
|
7
src/Blueprints/Model.elm
Normal file
7
src/Blueprints/Model.elm
Normal file
@ -0,0 +1,7 @@
|
||||
module Blueprints.Model exposing (..)
|
||||
|
||||
type alias Blueprint =
|
||||
{ dependencies: List String
|
||||
, id: String
|
||||
, name: String
|
||||
}
|
@ -16,8 +16,10 @@ limitations under the License.
|
||||
|
||||
-}
|
||||
|
||||
import Blueprints.Model exposing (Blueprint)
|
||||
import Browser.Navigation as Nav
|
||||
import Dict exposing (Dict)
|
||||
import Nodes.Model exposing (Identify, emptyIdentify)
|
||||
import Services.Model exposing (Service)
|
||||
import Url
|
||||
|
||||
@ -28,14 +30,16 @@ type Route
|
||||
|
||||
|
||||
type alias PeerData =
|
||||
{ services : List Service
|
||||
{ identify : Identify
|
||||
, services : List Service
|
||||
, modules : List String
|
||||
, blueprints : List Blueprint
|
||||
}
|
||||
|
||||
|
||||
emptyPeerData : PeerData
|
||||
emptyPeerData =
|
||||
{ services = [], modules = [] }
|
||||
{ identify = emptyIdentify, services = [], modules = [], blueprints = [] }
|
||||
|
||||
|
||||
type alias Model =
|
||||
|
7
src/Nodes/Model.elm
Normal file
7
src/Nodes/Model.elm
Normal file
@ -0,0 +1,7 @@
|
||||
module Nodes.Model exposing (..)
|
||||
|
||||
type alias Identify =
|
||||
{ external_addresses: List String }
|
||||
|
||||
emptyIdentify : Identify
|
||||
emptyIdentify = { external_addresses = [] }
|
@ -1,8 +1,10 @@
|
||||
port module Port exposing (..)
|
||||
|
||||
import Air exposing (Air(..))
|
||||
import Blueprints.Model exposing (Blueprint)
|
||||
import Dict exposing (Dict)
|
||||
import Json.Encode exposing (Value)
|
||||
import Nodes.Model exposing (Identify)
|
||||
import Services.Model exposing (Service)
|
||||
|
||||
|
||||
@ -11,7 +13,7 @@ type alias SendParticle =
|
||||
|
||||
|
||||
type alias ReceiveEvent =
|
||||
{ name : String, peer : String, peers : Maybe (List String), services : Maybe (List Service), modules : Maybe (List String) }
|
||||
{ name : String, peer : String, peers : Maybe (List String), identify : Maybe Identify, services : Maybe (List Service), modules : Maybe (List String), blueprints : Maybe (List Blueprint)}
|
||||
|
||||
|
||||
port sendParticle : SendParticle -> Cmd msg
|
||||
|
@ -28,6 +28,8 @@ routeView model route =
|
||||
case route of
|
||||
Page page ->
|
||||
case page of
|
||||
"" ->
|
||||
HubPage.view {}
|
||||
"hub" ->
|
||||
HubPage.view {}
|
||||
|
||||
|
@ -16,6 +16,8 @@ limitations under the License.
|
||||
|
||||
-}
|
||||
|
||||
import AirScripts.GetAll
|
||||
import Blueprints.Model exposing (Blueprint)
|
||||
import Browser
|
||||
import Browser.Navigation as Nav
|
||||
import Dict
|
||||
@ -26,9 +28,11 @@ import Model exposing (Model, emptyPeerData)
|
||||
import Modules.Air
|
||||
import Msg exposing (..)
|
||||
import Nodes.Air
|
||||
import Nodes.Model exposing (Identify)
|
||||
import Port exposing (sendAir)
|
||||
import Route
|
||||
import Services.Air
|
||||
import Services.Model exposing (Service)
|
||||
import Url
|
||||
|
||||
|
||||
@ -103,7 +107,7 @@ update msg model =
|
||||
Browser.External href ->
|
||||
( model, Nav.load href )
|
||||
|
||||
AquamarineEvent { name, peer, peers, services, modules } ->
|
||||
AquamarineEvent { name, peer, peers, identify, services, modules, blueprints } ->
|
||||
case name of
|
||||
"peers_discovered" ->
|
||||
let
|
||||
@ -118,21 +122,11 @@ update msg model =
|
||||
in
|
||||
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
||||
|
||||
"services_discovered" ->
|
||||
"all_info" ->
|
||||
let
|
||||
newServices =
|
||||
Maybe.withDefault [] services
|
||||
|
||||
empty =
|
||||
emptyPeerData
|
||||
|
||||
up =
|
||||
\old -> Just (Maybe.withDefault { empty | services = newServices } (Maybe.map (\o -> { o | services = newServices }) old))
|
||||
|
||||
updatedDict =
|
||||
Dict.update peer up model.discoveredPeers
|
||||
updated = Maybe.map4 (updateModel model peer) identify services modules blueprints
|
||||
in
|
||||
( { model | discoveredPeers = updatedDict }, Cmd.none )
|
||||
( withDefault model updated, Cmd.none )
|
||||
|
||||
"modules_discovered" ->
|
||||
let
|
||||
@ -159,17 +153,9 @@ update msg model =
|
||||
|
||||
Click command ->
|
||||
case command of
|
||||
"get_services" ->
|
||||
"get_all" ->
|
||||
( model
|
||||
, sendAir (Services.Air.air model.peerId model.relayId (Dict.keys model.discoveredPeers))
|
||||
)
|
||||
"get_modules" ->
|
||||
( model
|
||||
, sendAir (Modules.Air.air model.peerId model.relayId (Dict.keys model.discoveredPeers))
|
||||
)
|
||||
"get_identify" ->
|
||||
( model
|
||||
, sendAir (Nodes.Air.air model.peerId model.relayId (Dict.keys model.discoveredPeers))
|
||||
, sendAir (AirScripts.GetAll.air model.peerId model.relayId (Dict.keys model.discoveredPeers))
|
||||
)
|
||||
_ ->
|
||||
(model, Cmd.none)
|
||||
@ -177,3 +163,13 @@ update msg model =
|
||||
|
||||
RelayChanged relayId ->
|
||||
( { model | relayId = relayId }, Cmd.none )
|
||||
|
||||
updateModel : Model -> String -> Identify -> List Service -> List String -> List Blueprint -> Model
|
||||
updateModel model peer identify services modules blueprints =
|
||||
let
|
||||
data = Maybe.withDefault emptyPeerData (Dict.get peer model.discoveredPeers)
|
||||
newData = { data | identify = identify, services = services, modules = modules, blueprints = blueprints }
|
||||
updated = Dict.insert peer newData model.discoveredPeers
|
||||
in
|
||||
{ model | discoveredPeers = updated }
|
||||
|
||||
|
@ -16,6 +16,11 @@ limitations under the License.
|
||||
|
||||
-}
|
||||
|
||||
import Maybe exposing (map2)
|
||||
|
||||
combine : List (Maybe a) -> Maybe (List a)
|
||||
combine =
|
||||
List.foldr (map2 (::)) (Just [])
|
||||
|
||||
isEmpty : Maybe a -> Bool
|
||||
isEmpty maybe =
|
||||
|
16
src/View.elm
16
src/View.elm
@ -18,7 +18,6 @@ limitations under the License.
|
||||
|
||||
import Browser exposing (Document, UrlRequest(..))
|
||||
import Html exposing (Html, div, header, text)
|
||||
import Html.Attributes exposing (class, classList)
|
||||
import Html.Events exposing (onClick)
|
||||
import Model exposing (Model, Route(..))
|
||||
import Msg exposing (..)
|
||||
@ -38,21 +37,10 @@ title _ =
|
||||
|
||||
body : Model -> Html Msg
|
||||
body model =
|
||||
let
|
||||
a =
|
||||
1
|
||||
|
||||
url =
|
||||
model.url
|
||||
|
||||
newUrl =
|
||||
{ url | path = "/hub" }
|
||||
in
|
||||
layout <|
|
||||
List.concat
|
||||
[ [ header [ classes "w-100 bt bb b--black-10" ] [ routeView model (Page "hub") ] ]
|
||||
++ [ header [ classes "w-100 bt bb b--black-10" ] [ routeView model (Page "module") ] ]
|
||||
++ [ header [ classes "w-100 bt bb b--black-10", onClick (Click "get_services") ] [ text "GET SERVICES" ] ]
|
||||
[ [ header [ classes "w-100 bt bb b--black-10" ] [ routeView model model.page ] ]
|
||||
++ [ header [ classes "w-100 bt bb b--black-10", onClick (Click "get_all") ] [ text "GET SERVICES" ] ]
|
||||
++ [ header [ classes "w-100 bt bb b--black-10", onClick (Click "get_modules") ] [ text "GET MODULES" ] ]
|
||||
++ [ header [ classes "w-100 bt bb b--black-10", onClick (Click "get_identify") ] [ text "GET IDENTIFY" ] ]
|
||||
]
|
||||
|
26
src/index.ts
26
src/index.ts
@ -32,20 +32,14 @@ function genFlags(peerId: string): any {
|
||||
}
|
||||
}
|
||||
|
||||
function event(name: string, peer: string, peers?: string[], services?: any[], modules?: string[]) {
|
||||
if (!peers) {
|
||||
peers = null
|
||||
}
|
||||
function event(name: string, peer: string, peers?: string[], identify?: string[], services?: any[], blueprints?: string[], modules?: string[]) {
|
||||
if (!peers) { peers = null }
|
||||
if (!services) { services = null }
|
||||
if (!modules) { modules = null }
|
||||
if (!identify) { identify = null }
|
||||
if (!blueprints) { blueprints = null }
|
||||
|
||||
if (!services) {
|
||||
services = null
|
||||
}
|
||||
|
||||
if (!modules) {
|
||||
modules = null
|
||||
}
|
||||
|
||||
return {name, peer, peers, services, modules}
|
||||
return {name, peer, peers, identify, services, modules, blueprints}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
@ -70,10 +64,8 @@ function event(name: string, peer: string, peers?: string[], services?: any[], m
|
||||
try {
|
||||
if (fnName === "peers_discovered") {
|
||||
app.ports.eventReceiver.send(event(fnName, args[0], args[1]))
|
||||
} else if (fnName === "services_discovered") {
|
||||
app.ports.eventReceiver.send(event(fnName, args[0], undefined, args[1]))
|
||||
} else if (fnName === "modules_discovered") {
|
||||
app.ports.eventReceiver.send(event(fnName, args[0], undefined, undefined, args[1]))
|
||||
} else if (fnName === "all_info") {
|
||||
app.ports.eventReceiver.send(event(fnName, args[0], undefined, args[1], args[2], args[3], args[4]))
|
||||
} else {
|
||||
console.error("UNHANDLED")
|
||||
}
|
||||
|
@ -13,13 +13,7 @@ module.exports = {
|
||||
devServer: {
|
||||
contentBase: './bundle',
|
||||
hot: false,
|
||||
inline: false,
|
||||
historyApiFallback: {
|
||||
rewrites: [
|
||||
{from: /^\/$/, to: '/index.html'},
|
||||
{from: /./, to: '/index.html'}
|
||||
]
|
||||
}
|
||||
inline: false
|
||||
},
|
||||
devtool: "eval-source-map",
|
||||
module: {
|
||||
@ -72,7 +66,8 @@ module.exports = {
|
||||
}),
|
||||
new Serve({
|
||||
historyFallback: true,
|
||||
port: 55553
|
||||
port: 55553,
|
||||
host: 'localhost',
|
||||
})
|
||||
]
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user