added write config support
This commit is contained in:
@@ -3,6 +3,7 @@ module API
|
|||||||
( P2PRCapi(..)
|
( P2PRCapi(..)
|
||||||
, MapPortRequest(..)
|
, MapPortRequest(..)
|
||||||
, p2prcAPI
|
, p2prcAPI
|
||||||
|
, P2PRCommands(..)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ import System.Process ( ProcessHandle )
|
|||||||
|
|
||||||
import Data.Aeson ( FromJSON )
|
import Data.Aeson ( FromJSON )
|
||||||
|
|
||||||
|
|
||||||
import Error
|
import Error
|
||||||
( IOEitherError
|
( IOEitherError
|
||||||
)
|
)
|
||||||
@@ -49,15 +51,26 @@ data P2PRCapi
|
|||||||
-- ^ List servers in network
|
-- ^ List servers in network
|
||||||
, execMapPort :: MapPortRequest -> IOEitherError MapPortResponse
|
, execMapPort :: MapPortRequest -> IOEitherError MapPortResponse
|
||||||
-- ^ Exposes and associates a local TCP port with a remote DNS address
|
-- ^ Exposes and associates a local TCP port with a remote DNS address
|
||||||
|
, execMaybeMapPortAndAddCustomInformation :: Maybe MapPortRequest -> PassCustomInformation -> IOEitherError String
|
||||||
|
, execAddCustomInformation :: PassCustomInformation -> IOEitherError String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- | This defines the request required to create an association between a TCP socket port and a DNS server in the network. If successful, it makes a resource available in the network.
|
-- | This defines the request required to create an association between a TCP socket port and a DNS server in the network. If successful, it makes a resource available in the network.
|
||||||
data MapPortRequest =
|
data MapPortRequest =
|
||||||
MkMapPortRequest -- ^ P2PRC's port allocation request value
|
MkMapPortRequest -- ^ P2PRC's port allocation request value
|
||||||
Int -- ^ TCP socket number
|
Int -- ^ TCP socket number
|
||||||
String -- ^ Network domain name
|
String -- ^ Network domain name
|
||||||
|
|
||||||
|
-- | This defined the custom information required to be passed through.
|
||||||
|
newtype PassCustomInformation =
|
||||||
|
MkAddCustomInformation
|
||||||
|
String
|
||||||
|
|
||||||
|
data P2PRCommands
|
||||||
|
= MapPort MapPortRequest
|
||||||
|
| CustomInformation PassCustomInformation
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
This function intiates a pure P2PRC runtime state and builds up a 'P2PRCapi' API instance. It allows a developer to create computing orchestration algorithms using the API primitives.
|
This function intiates a pure P2PRC runtime state and builds up a 'P2PRCapi' API instance. It allows a developer to create computing orchestration algorithms using the API primitives.
|
||||||
@@ -94,7 +107,13 @@ main =
|
|||||||
|
|
||||||
{-# WARNING p2prcAPI "This function is currently unstable because the configuration reading is dependent on the following issue: https://github.com/Akilan1999/p2p-rendering-computation/issues/120" #-}
|
{-# WARNING p2prcAPI "This function is currently unstable because the configuration reading is dependent on the following issue: https://github.com/Akilan1999/p2p-rendering-computation/issues/120" #-}
|
||||||
p2prcAPI :: P2PRCapi
|
p2prcAPI :: P2PRCapi
|
||||||
p2prcAPI =
|
p2prcAPI = let
|
||||||
|
|
||||||
|
execTemp :: Maybe MapPortRequest -> PassCustomInformation -> IOEitherError String
|
||||||
|
execTemp mp ci = undefined
|
||||||
|
|
||||||
|
|
||||||
|
in
|
||||||
MkP2PRCapi
|
MkP2PRCapi
|
||||||
{ startServer = spawnProcP2PRC p2prcCmdName [ MkOptAtomic "-s" ]
|
{ startServer = spawnProcP2PRC p2prcCmdName [ MkOptAtomic "-s" ]
|
||||||
|
|
||||||
@@ -115,6 +134,9 @@ p2prcAPI =
|
|||||||
]
|
]
|
||||||
MkEmptyStdInput
|
MkEmptyStdInput
|
||||||
|
|
||||||
|
, execMaybeMapPortAndAddCustomInformation = execTemp
|
||||||
|
, execAddCustomInformation = execTemp Nothing
|
||||||
|
|
||||||
-- , execInitConfig = do
|
-- , execInitConfig = do
|
||||||
|
|
||||||
-- confInitRes <- execProcP2PRC [ MkOptAtomic "--dc" ] MkEmptyStdInput
|
-- confInitRes <- execProcP2PRC [ MkOptAtomic "--dc" ] MkEmptyStdInput
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
module Engine
|
module Engine
|
||||||
( runP2PRC
|
( runP2PRC
|
||||||
|
, fn
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@ import System.Process ( terminateProcess )
|
|||||||
import API
|
import API
|
||||||
( P2PRCapi(..)
|
( P2PRCapi(..)
|
||||||
, MapPortRequest(..)
|
, MapPortRequest(..)
|
||||||
, p2prcAPI
|
, p2prcAPI, P2PRCommands
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -58,14 +59,10 @@ import API
|
|||||||
@
|
@
|
||||||
-}
|
-}
|
||||||
runP2PRC
|
runP2PRC
|
||||||
:: MapPortRequest -- ^ TCP Port Request
|
:: [P2PRCommands] -- ^ TCP Port Request
|
||||||
-> IO ()
|
-> IO ()
|
||||||
runP2PRC
|
runP2PRC [] = putStrLn ""
|
||||||
( MkMapPortRequest
|
runP2PRC nonEmpty@(_:_) =
|
||||||
portNumber
|
|
||||||
domainName
|
|
||||||
)
|
|
||||||
=
|
|
||||||
let
|
let
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -98,6 +95,7 @@ runP2PRC
|
|||||||
-- , execInitConfig = execInitConfig
|
-- , execInitConfig = execInitConfig
|
||||||
, execListServers = execListServers
|
, execListServers = execListServers
|
||||||
, execMapPort = execMapPort
|
, execMapPort = execMapPort
|
||||||
|
, execAddCustomInformation = _
|
||||||
}
|
}
|
||||||
) = p2prcAPI
|
) = p2prcAPI
|
||||||
|
|
||||||
@@ -116,7 +114,8 @@ runP2PRC
|
|||||||
|
|
||||||
|
|
||||||
case eitherStartProcessHandle of
|
case eitherStartProcessHandle of
|
||||||
(Right startProcessHandle) -> do
|
(Right startProcessHandle) ->
|
||||||
|
do
|
||||||
|
|
||||||
let sleepNSecs i = threadDelay (i * 1000000)
|
let sleepNSecs i = threadDelay (i * 1000000)
|
||||||
|
|
||||||
@@ -125,7 +124,8 @@ runP2PRC
|
|||||||
outputStr <- execListServers
|
outputStr <- execListServers
|
||||||
print outputStr
|
print outputStr
|
||||||
|
|
||||||
mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName
|
-- mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName
|
||||||
|
mapPortOut <- execMapPort $ MkMapPortRequest undefined undefined
|
||||||
|
|
||||||
case mapPortOut of
|
case mapPortOut of
|
||||||
(Right v) -> print v
|
(Right v) -> print v
|
||||||
@@ -159,3 +159,7 @@ runP2PRC
|
|||||||
when (toLower c /= 'q') $ exitOnQ exitF
|
when (toLower c /= 'q') $ exitOnQ exitF
|
||||||
exitF
|
exitF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn :: undefined
|
||||||
|
fn = undefined
|
||||||
@@ -52,6 +52,7 @@ module P2PRC
|
|||||||
, P2PRCConfig(..)
|
, P2PRCConfig(..)
|
||||||
, MapPortRequest(..)
|
, MapPortRequest(..)
|
||||||
, MapPortResponse(..)
|
, MapPortResponse(..)
|
||||||
|
, P2PRCommands(..)
|
||||||
|
|
||||||
-- ** Primitive data types
|
-- ** Primitive data types
|
||||||
-- | These types represent the core data that is communicated between requests and the runtime.
|
-- | These types represent the core data that is communicated between requests and the runtime.
|
||||||
@@ -83,6 +84,7 @@ import API
|
|||||||
( MapPortRequest(..)
|
( MapPortRequest(..)
|
||||||
, P2PRCapi(..)
|
, P2PRCapi(..)
|
||||||
, p2prcAPI
|
, p2prcAPI
|
||||||
|
, P2PRCommands(..)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,14 @@ module Main where
|
|||||||
import P2PRC
|
import P2PRC
|
||||||
( runP2PRC
|
( runP2PRC
|
||||||
, MapPortRequest(MkMapPortRequest)
|
, MapPortRequest(MkMapPortRequest)
|
||||||
|
, P2PRCommands(MapPort)
|
||||||
)
|
)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main =
|
main =let
|
||||||
|
in
|
||||||
runP2PRC
|
runP2PRC
|
||||||
( MkMapPortRequest 8080 "jose.akilan.io"
|
[
|
||||||
)
|
( MapPort $ MkMapPortRequest 8080 "jose.akilan.io")
|
||||||
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/Akilan1999/p2p-rendering-computation/abstractions"
|
"github.com/Akilan1999/p2p-rendering-computation/abstractions"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/client"
|
"github.com/Akilan1999/p2p-rendering-computation/client"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
||||||
|
Config "github.com/Akilan1999/p2p-rendering-computation/config"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
"github.com/Akilan1999/p2p-rendering-computation/config/generate"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
"github.com/Akilan1999/p2p-rendering-computation/p2p"
|
||||||
"github.com/Akilan1999/p2p-rendering-computation/plugin"
|
"github.com/Akilan1999/p2p-rendering-computation/plugin"
|
||||||
@@ -232,6 +233,12 @@ var CliAction = func(ctx *cli.Context) error {
|
|||||||
standardOutput(err, nil)
|
standardOutput(err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// display configuration
|
||||||
|
if ViewConfig {
|
||||||
|
config, err := Config.ConfigInit(nil, nil)
|
||||||
|
standardOutput(err, config)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ var (
|
|||||||
AddMetaData string
|
AddMetaData string
|
||||||
AddRootNode bool
|
AddRootNode bool
|
||||||
IP string
|
IP string
|
||||||
|
ViewConfig bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var AppConfigFlags = []cli.Flag{
|
var AppConfigFlags = []cli.Flag{
|
||||||
@@ -288,4 +289,11 @@ var AppConfigFlags = []cli.Flag{
|
|||||||
EnvVars: []string{"IP"},
|
EnvVars: []string{"IP"},
|
||||||
Destination: &IP,
|
Destination: &IP,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "ViewConfig",
|
||||||
|
Aliases: []string{"vc"},
|
||||||
|
Usage: "View config file",
|
||||||
|
EnvVars: []string{"VC"},
|
||||||
|
Destination: &ViewConfig,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ type Config struct {
|
|||||||
UnsafeMode bool
|
UnsafeMode bool
|
||||||
Test bool
|
Test bool
|
||||||
CustomConfig interface{}
|
CustomConfig interface{}
|
||||||
|
ConfigPath string
|
||||||
//NetworkInterface string
|
//NetworkInterface string
|
||||||
//NetworkInterfaceIPV6Index int
|
//NetworkInterfaceIPV6Index int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ func SetDefaults(envName string, forceDefault bool, CustomConfig interface{}, No
|
|||||||
Defaults.BareMetal = false
|
Defaults.BareMetal = false
|
||||||
Defaults.UnsafeMode = false
|
Defaults.UnsafeMode = false
|
||||||
Defaults.Test = false
|
Defaults.Test = false
|
||||||
|
Defaults.ConfigPath = defaultPath + "config.json"
|
||||||
|
|
||||||
// Generate certificate files for SSL
|
// Generate certificate files for SSL
|
||||||
err = GenerateCertificate()
|
err = GenerateCertificate()
|
||||||
|
|||||||
Reference in New Issue
Block a user