diff --git a/Bindings/Haskell/lib/API.hs b/Bindings/Haskell/lib/API.hs index bf67f96..cbb1cc5 100644 --- a/Bindings/Haskell/lib/API.hs +++ b/Bindings/Haskell/lib/API.hs @@ -3,6 +3,7 @@ module API ( P2PRCapi(..) , MapPortRequest(..) , p2prcAPI + , P2PRCommands(..) ) where @@ -13,6 +14,7 @@ import System.Process ( ProcessHandle ) import Data.Aeson ( FromJSON ) + import Error ( IOEitherError ) @@ -49,15 +51,26 @@ data P2PRCapi -- ^ List servers in network , execMapPort :: MapPortRequest -> IOEitherError MapPortResponse -- ^ 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. data MapPortRequest = MkMapPortRequest -- ^ P2PRC's port allocation request value Int -- ^ TCP socket number 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. @@ -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" #-} p2prcAPI :: P2PRCapi -p2prcAPI = +p2prcAPI = let + + execTemp :: Maybe MapPortRequest -> PassCustomInformation -> IOEitherError String + execTemp mp ci = undefined + + + in MkP2PRCapi { startServer = spawnProcP2PRC p2prcCmdName [ MkOptAtomic "-s" ] @@ -115,6 +134,9 @@ p2prcAPI = ] MkEmptyStdInput + , execMaybeMapPortAndAddCustomInformation = execTemp + , execAddCustomInformation = execTemp Nothing + -- , execInitConfig = do -- confInitRes <- execProcP2PRC [ MkOptAtomic "--dc" ] MkEmptyStdInput diff --git a/Bindings/Haskell/lib/Engine.hs b/Bindings/Haskell/lib/Engine.hs index de13bf9..493f7d8 100644 --- a/Bindings/Haskell/lib/Engine.hs +++ b/Bindings/Haskell/lib/Engine.hs @@ -2,6 +2,7 @@ module Engine ( runP2PRC + , fn ) where @@ -18,7 +19,7 @@ import System.Process ( terminateProcess ) import API ( P2PRCapi(..) , MapPortRequest(..) - , p2prcAPI + , p2prcAPI, P2PRCommands ) @@ -58,14 +59,10 @@ import API @ -} runP2PRC - :: MapPortRequest -- ^ TCP Port Request + :: [P2PRCommands] -- ^ TCP Port Request -> IO () -runP2PRC - ( MkMapPortRequest - portNumber - domainName - ) - = +runP2PRC [] = putStrLn "" +runP2PRC nonEmpty@(_:_) = let -- @@ -98,6 +95,7 @@ runP2PRC -- , execInitConfig = execInitConfig , execListServers = execListServers , execMapPort = execMapPort + , execAddCustomInformation = _ } ) = p2prcAPI @@ -116,7 +114,8 @@ runP2PRC case eitherStartProcessHandle of - (Right startProcessHandle) -> do + (Right startProcessHandle) -> + do let sleepNSecs i = threadDelay (i * 1000000) @@ -125,7 +124,8 @@ runP2PRC outputStr <- execListServers print outputStr - mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName + -- mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName + mapPortOut <- execMapPort $ MkMapPortRequest undefined undefined case mapPortOut of (Right v) -> print v @@ -159,3 +159,7 @@ runP2PRC when (toLower c /= 'q') $ exitOnQ exitF exitF + + +fn :: undefined +fn = undefined \ No newline at end of file diff --git a/Bindings/Haskell/lib/P2PRC.hs b/Bindings/Haskell/lib/P2PRC.hs index c948ced..2c679d0 100644 --- a/Bindings/Haskell/lib/P2PRC.hs +++ b/Bindings/Haskell/lib/P2PRC.hs @@ -52,6 +52,7 @@ module P2PRC , P2PRCConfig(..) , MapPortRequest(..) , MapPortResponse(..) + , P2PRCommands(..) -- ** Primitive data types -- | These types represent the core data that is communicated between requests and the runtime. @@ -83,6 +84,7 @@ import API ( MapPortRequest(..) , P2PRCapi(..) , p2prcAPI + , P2PRCommands(..) ) diff --git a/Bindings/Haskell/src/Main.hs b/Bindings/Haskell/src/Main.hs index 97d8636..aa1efa6 100644 --- a/Bindings/Haskell/src/Main.hs +++ b/Bindings/Haskell/src/Main.hs @@ -3,10 +3,14 @@ module Main where import P2PRC ( runP2PRC , MapPortRequest(MkMapPortRequest) + , P2PRCommands(MapPort) ) main :: IO () -main = +main =let + in runP2PRC - ( MkMapPortRequest 8080 "jose.akilan.io" - ) + [ + ( MapPort $ MkMapPortRequest 8080 "jose.akilan.io") + ] + diff --git a/cmd/action.go b/cmd/action.go index 11b059a..9660482 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -5,6 +5,7 @@ import ( "github.com/Akilan1999/p2p-rendering-computation/abstractions" "github.com/Akilan1999/p2p-rendering-computation/client" "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/p2p" "github.com/Akilan1999/p2p-rendering-computation/plugin" @@ -232,6 +233,12 @@ var CliAction = func(ctx *cli.Context) error { standardOutput(err, nil) } + // display configuration + if ViewConfig { + config, err := Config.ConfigInit(nil, nil) + standardOutput(err, config) + } + return nil } diff --git a/cmd/flags.go b/cmd/flags.go index 34423b4..1d5597a 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -43,6 +43,7 @@ var ( AddMetaData string AddRootNode bool IP string + ViewConfig bool ) var AppConfigFlags = []cli.Flag{ @@ -288,4 +289,11 @@ var AppConfigFlags = []cli.Flag{ EnvVars: []string{"IP"}, Destination: &IP, }, + &cli.BoolFlag{ + Name: "ViewConfig", + Aliases: []string{"vc"}, + Usage: "View config file", + EnvVars: []string{"VC"}, + Destination: &ViewConfig, + }, } diff --git a/config/config.go b/config/config.go index 76a41cf..e32aa7f 100644 --- a/config/config.go +++ b/config/config.go @@ -40,6 +40,7 @@ type Config struct { UnsafeMode bool Test bool CustomConfig interface{} + ConfigPath string //NetworkInterface string //NetworkInterfaceIPV6Index int } diff --git a/config/generate/generate.go b/config/generate/generate.go index b6254f8..0e55ba7 100644 --- a/config/generate/generate.go +++ b/config/generate/generate.go @@ -96,6 +96,7 @@ func SetDefaults(envName string, forceDefault bool, CustomConfig interface{}, No Defaults.BareMetal = false Defaults.UnsafeMode = false Defaults.Test = false + Defaults.ConfigPath = defaultPath + "config.json" // Generate certificate files for SSL err = GenerateCertificate()