Skip to content

Commit

Permalink
New nodes naming system. Restructuring, cleaning, refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
graninas committed Nov 30, 2018
1 parent eb60ec7 commit 776b09b
Show file tree
Hide file tree
Showing 50 changed files with 456 additions and 422 deletions.
27 changes: 14 additions & 13 deletions app/Enecuum/App/GenConfigs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@

module App.GenConfigs where

import qualified Enecuum.Assets.Scenarios as A
import qualified Enecuum.Assets.TstScenarios as Tst
import qualified Enecuum.Config as Cfg
import qualified Enecuum.Domain as D
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Lazy as B
import qualified Enecuum.Assets.Scenarios as Prd
import qualified Enecuum.Assets.TstScenarios as Tst
import qualified Enecuum.Config as Cfg
import qualified Enecuum.Domain as D
import Enecuum.Prelude
import qualified Data.ByteString.Lazy as B
import Data.Aeson.Encode.Pretty (encodePretty)

genConfigs = forM_ configs (uncurry B.writeFile)

configs =
[ ("configs/default/poa.json", encodePretty $ D.defConfig A.Good A.defaultPoANodeConfig)
, ("configs/default/PoANode_Bad.json", encodePretty $ D.defConfig A.Bad A.defaultPoANodeConfig)
, ("configs/default/pow.json", encodePretty $ D.defConfig A.PoW A.defaultPoWNodeConfig)
, ("configs/default/GN_0.json", encodePretty $ D.defConfig A.GN A.defaultGraphNodeConfig)
, ("configs/default/GraphNodeReceiver.json", encodePretty $ D.defConfig Tst.TstGN Tst.graphNodeReceiverConfig)
, ("configs/default/GraphNodeTransmitter.json", encodePretty $ D.defConfig Tst.TstGN Tst.graphNodeTransmitterConfig)
, ("configs/default/MultiNode.json", encodePretty $ D.defConfig A.MultiNodeS A.defaultMultiNodeConfig)
[ ("configs/default/routing_gen_poa.json", encodePretty $ D.defConfig Prd.Good Prd.routingGenPoANodeConfig)
, ("configs/default/routing_gen_poa_bad.json", encodePretty $ D.defConfig Prd.Bad Prd.routingGenPoANodeConfig)
, ("configs/default/routing_gen_pow.json", encodePretty $ D.defConfig Prd.PoW Prd.routingGenPoWNodeConfig)
, ("configs/default/routing_graph_node_0.json", encodePretty $ D.defConfig Prd.GN Prd.routingGraphNodeConfig)
, ("configs/default/routing_multinode.json", encodePretty $ D.defConfig Prd.MultiNodeS Prd.routingMultiNodeConfig)

, ("configs/default/tst_graph_node_receiver.json", encodePretty $ D.defConfig Tst.GN Tst.tstGraphNodeReceiverConfig)
, ("configs/default/tst_graph_node_transmitter.json", encodePretty $ D.defConfig Tst.GN Tst.tstGraphNodeTransmitterConfig)
]
83 changes: 44 additions & 39 deletions app/Enecuum/App/Initialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
module App.Initialize where

import qualified Data.Map as M
import qualified Enecuum.Assets.Nodes.Address as A
import Enecuum.Assets.Nodes.ConfigParsing (parseConfig)
import qualified Enecuum.Assets.Scenarios as A
import qualified Enecuum.Assets.Scenarios as Prd
import Enecuum.Assets.System.Directory (clientStory)
import qualified Enecuum.Assets.TstScenarios as Tst
import qualified Enecuum.Config as Cfg
Expand Down Expand Up @@ -84,51 +85,55 @@ initialize configSrc = do

-- Don't forget to update the list in ConfigParsing!
let runners =
[ runNode' $ Cfg.dispatchScenario @A.GraphNode configSrc
, runNode' $ Cfg.dispatchScenario @A.PoANode configSrc
, runNode' $ Cfg.dispatchScenario @A.PoWNode configSrc
, runNode' $ Cfg.dispatchScenario @A.ClientNode configSrc
, runNode' $ Cfg.dispatchScenario @A.BN configSrc
[ runNode' $ Cfg.dispatchScenario @Prd.GraphNode configSrc
, runNode' $ Cfg.dispatchScenario @Prd.GenPoANode configSrc
, runNode' $ Cfg.dispatchScenario @Prd.GenPoWNode configSrc
, runNode' $ Cfg.dispatchScenario @Prd.BootNode configSrc

, runNode' $ Cfg.dispatchScenario @A.TestClient configSrc
, runNode' $ Cfg.dispatchScenario @A.TestServer configSrc
, runNode' $ Cfg.dispatchScenario @Prd.ClientNode configSrc

, runNode' $ Cfg.dispatchScenario @Tst.NN configSrc
, runNode' $ Cfg.dispatchScenario @Tst.TestClient configSrc
, runNode' $ Cfg.dispatchScenario @Tst.TestServer configSrc

, runNode' $ Cfg.dispatchScenario @Tst.TstNetworkNode configSrc
, runNode' $ Cfg.dispatchScenario @Tst.TstGraphNode configSrc
, runNode' $ Cfg.dispatchScenario @Tst.TstGenPoWNode configSrc
, runNode' $ Cfg.dispatchScenario @Tst.TstGenPoANode configSrc
, runNode' $ Cfg.dispatchScenario @Tst.TstRealPoWNode configSrc
]
sequence_ runners


runMultiNode :: LByteString -> IO ()
runMultiNode configSrc = case Cfg.dispatchScenario @A.MultiNode configSrc of
Just (cfg, _) -> do
startPoWNodes (A._powPorts $ Cfg.nodeConfig cfg) (A._powConfig $ Cfg.nodeConfig cfg)
startPoANodes (A._poaPorts $ Cfg.nodeConfig cfg) (A._poaConfig $ Cfg.nodeConfig cfg)
startNNNodes (A._gnPorts $ Cfg.nodeConfig cfg) (A._gnConfig $ Cfg.nodeConfig cfg)
forever $ threadDelay 50000000

Nothing -> putTextLn "Parse error of multi node config."

startPoWNodes range cfg = do
putTextLn $ "Start pow in range from " <> show (D.bottomBound range) <> " to " <> show (D.topBound range)
forM_ (D.rangeToList range) $ \nPort -> do
threadDelay 3000
let nodeCfg = cfg {A._powNodePorts = A.makeNodePorts1000 nPort}
void $ forkIO $ void $ runNode D.nullLoger (A.powNode' nodeCfg)

startPoANodes range cfg = do
putTextLn $ "Start poa in range from " <> show (D.bottomBound range) <> " to " <> show (D.topBound range)
forM_ (D.rangeToList range) $ \nPort -> do
threadDelay 3000
let nodeCfg = cfg {A._poaNodePorts = A.makeNodePorts1000 nPort}
void $ forkIO $ void $ runNode D.nullLoger (A.poaNode A.Good nodeCfg)

startNNNodes range cfg = do
putTextLn $ "Start gn in range from " <> show (D.bottomBound range) <> " to " <> show (D.topBound range)
forM_ (D.rangeToList range) $ \nPort -> do
threadDelay 3000
let nodeCfg = cfg {A._nodePorts = A.makeNodePorts1000 nPort}
void $ forkIO $ void $ runNode D.nullLoger (A.graphNode nodeCfg)
runMultiNode = error "Not working"

--
-- runMultiNode :: LByteString -> IO ()
-- runMultiNode configSrc = case Cfg.dispatchScenario @A.MultiNode configSrc of
-- Just (cfg, _) -> do
-- startPoWNodes (A._powPorts $ Cfg.nodeConfig cfg) (A._powConfig $ Cfg.nodeConfig cfg)
-- startPoANodes (A._poaPorts $ Cfg.nodeConfig cfg) (A._poaConfig $ Cfg.nodeConfig cfg)
-- startNNNodes (A._gnPorts $ Cfg.nodeConfig cfg) (A._gnConfig $ Cfg.nodeConfig cfg)
-- forever $ threadDelay 50000000
--
-- Nothing -> putTextLn "Parse error of multi node config."
--
-- startPoWNodes range cfg = do
-- putTextLn $ "Start pow in range from " <> show (D.bottomBound range) <> " to " <> show (D.topBound range)
-- forM_ (D.rangeToList range) $ \nPort -> do
-- threadDelay 3000
-- let nodeCfg = cfg {A._powNodePorts = A.makeNodePorts1000 nPort}
-- void $ forkIO $ void $ runNode D.nullLoger (A.powNode' nodeCfg)
--
-- startPoANodes range cfg = do
-- putTextLn $ "Start poa in range from " <> show (D.bottomBound range) <> " to " <> show (D.topBound range)
-- forM_ (D.rangeToList range) $ \nPort -> do
-- threadDelay 3000
-- let nodeCfg = cfg {A._poaNodePorts = A.makeNodePorts1000 nPort}
-- void $ forkIO $ void $ runNode D.nullLoger (A.poaNode A.Good nodeCfg)
--
-- startNNNodes range cfg = do
-- putTextLn $ "Start gn in range from " <> show (D.bottomBound range) <> " to " <> show (D.topBound range)
-- forM_ (D.rangeToList range) $ \nPort -> do
-- threadDelay 3000
-- let nodeCfg = cfg {A._nodePorts = A.makeNodePorts1000 nPort}
-- void $ forkIO $ void $ runNode D.nullLoger (A.graphNode nodeCfg)
4 changes: 2 additions & 2 deletions app/Enecuum/Main.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Main where

import App.Initialize (initialize, runMultiNode)
import App.GenConfigs (genConfigs)
import App.Initialize (initialize, runMultiNode)
import Enecuum.Config (withConfig)
import Enecuum.Prelude

Expand All @@ -14,5 +14,5 @@ main = do
case args of
["singlenode", configFile] -> withConfig configFile initialize
["multinode", configFile] -> withConfig configFile runMultiNode
["genConfigs"] -> genConfigs
["generate-configs"] -> genConfigs
_ -> withConfig defaultConfig initialize
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"nodeConfig": {
"tag": "PoANodeConfig",
"tag": "GenPoANodeConfig",
"poaBnAddress": {
"tag": "NodeAddress",
"nodePorts": {
Expand All @@ -19,7 +19,7 @@
"nodeTcpPort": 5200
}
},
"node": "PoANode",
"node": "GenPoANode",
"loggerConfig": {
"logFilePath": "",
"format": "$prio $loggername: $msg",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"nodeConfig": {
"tag": "PoANodeConfig",
"tag": "GenPoANodeConfig",
"poaBnAddress": {
"tag": "NodeAddress",
"nodePorts": {
Expand All @@ -19,7 +19,7 @@
"nodeTcpPort": 5200
}
},
"node": "PoANode",
"node": "GenPoANode",
"loggerConfig": {
"logFilePath": "",
"format": "$prio $loggername: $msg",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"nodeConfig": {
"defaultBlocksDelay": 1000000,
"tag": "PoWNodeConfig",
"tag": "GenPoWNodeConfig",
"kblocksOrder": "InOrder",
"powNodebnAddress": {
"tag": "NodeAddress",
Expand All @@ -21,7 +21,7 @@
"nodeTcpPort": 5020
}
},
"node": "PoWNode",
"node": "GenPoWNode",
"loggerConfig": {
"logFilePath": "",
"format": "$prio $loggername: $msg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"graphWindowConfig": {
"tag": "GraphWindowConfig",
"shrinkingEnabled": false,
"windowSize": 100,
"windowSize": 10,
"shrinkingDelay": 1000000
},
"tag": "GraphServiceConfig",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"nodeConfig": {
"poaConfig": {
"tag": "PoANodeConfig",
"routingGenPoAConfig": {
"tag": "GenPoANodeConfig",
"poaBnAddress": {
"tag": "NodeAddress",
"nodePorts": {
Expand All @@ -20,9 +20,9 @@
"nodeTcpPort": 5200
}
},
"powConfig": {
"routingGenPoWConfig": {
"defaultBlocksDelay": 1000000,
"tag": "PoWNodeConfig",
"tag": "GenPoWNodeConfig",
"kblocksOrder": "InOrder",
"powNodebnAddress": {
"tag": "NodeAddress",
Expand All @@ -42,13 +42,16 @@
"nodeTcpPort": 5020
}
},
"tag": "MultiNodeConfig",
"gnPorts": {
"routingGraphNodePorts": {
"maxValue": 5070,
"tag": "Range",
"minValue": 5050
},
"gnConfig": {
"tag": "MultiNodeConfig",
"routingGenPoAPorts": {
"tag": "EmptyRange"
},
"routingGraphNodeConfig": {
"tag": "GraphNodeConfig",
"graphServiceConfig": {
"dbConfig": {
Expand All @@ -65,7 +68,7 @@
"graphWindowConfig": {
"tag": "GraphWindowConfig",
"shrinkingEnabled": false,
"windowSize": 100,
"windowSize": 10,
"shrinkingDelay": 1000000
},
"tag": "GraphServiceConfig",
Expand All @@ -89,10 +92,7 @@
"nodeTcpPort": 5050
}
},
"poaPorts": {
"tag": "EmptyRange"
},
"powPorts": {
"routingGenPoWPorts": {
"tag": "EmptyRange"
}
},
Expand All @@ -105,4 +105,4 @@
"level": "Debug"
},
"nodeScenario": "MultiNodeS"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"graphWindowConfig": {
"tag": "GraphWindowConfig",
"shrinkingEnabled": false,
"windowSize": 100,
"windowSize": 10,
"shrinkingDelay": 1000000
},
"tag": "GraphServiceConfig",
Expand All @@ -40,5 +40,5 @@
"logToConsole": true,
"level": "Debug"
},
"nodeScenario": "TstGN"
"nodeScenario": "GN"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"graphWindowConfig": {
"tag": "GraphWindowConfig",
"shrinkingEnabled": false,
"windowSize": 100,
"windowSize": 10,
"shrinkingDelay": 1000000
},
"tag": "GraphServiceConfig",
Expand All @@ -37,5 +37,5 @@
"logToConsole": true,
"level": "Debug"
},
"nodeScenario": "TstGN"
"nodeScenario": "GN"
}
10 changes: 5 additions & 5 deletions configs/BN.json → configs/routing_boot_node.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"node":"BN",
"nodeScenario":"BNS",
{
"node":"BootNode",
"nodeScenario":"BootNodeS",
"nodeConfig":
{
"tag":"BNConfig",
"dummyOptionBN":0
"tag":"BootNodeConfig",
"dummyOptionBootNode":0
},
"loggerConfig":
{
Expand Down
4 changes: 2 additions & 2 deletions configs/poa.json → configs/routing_gen_poa.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"nodeConfig": {
"tag": "PoANodeConfig",
"tag": "GenPoANodeConfig",
"poaBnAddress": {
"tag": "NodeAddress",
"nodePorts": {
Expand All @@ -19,7 +19,7 @@
"nodeTcpPort": 5200
}
},
"node": "PoANode",
"node": "GenPoANode",
"loggerConfig": {
"logFilePath": "",
"format": "$prio $loggername: $msg",
Expand Down
4 changes: 2 additions & 2 deletions configs/pow.json → configs/routing_gen_pow.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"nodeConfig": {
"defaultBlocksDelay": 1000000,
"tag": "PoWNodeConfig",
"tag": "GenPoWNodeConfig",
"kblocksOrder": "InOrder",
"powNodebnAddress": {
"tag": "NodeAddress",
Expand All @@ -21,7 +21,7 @@
"nodeTcpPort": 5020
}
},
"node": "PoWNode",
"node": "GenPoWNode",
"loggerConfig": {
"logFilePath": "/tmp/log/PoW.log",
"format": "$prio $loggername: $msg",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions configs/PoANode_Bad.json → configs/routing_poa_bad.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"nodeConfig": {
"tag": "PoANodeConfig",
"tag": "GenPoANodeConfig",
"poaBnAddress": {
"tag": "NodeAddress",
"nodePorts": {
Expand All @@ -19,7 +19,7 @@
"nodeTcpPort": 5200
}
},
"node": "PoANode",
"node": "GenPoANode",
"loggerConfig": {
"logFilePath": "",
"format": "$prio $loggername: $msg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
"level":"Debug"
}
}

Loading

0 comments on commit 776b09b

Please sign in to comment.