added write config support

This commit is contained in:
2025-06-28 12:03:56 +01:00
parent be1f3308ca
commit 36930be8e4
8 changed files with 63 additions and 14 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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(..)
)

View File

@@ -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")
]

View File

@@ -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
}

View File

@@ -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,
},
}

View File

@@ -40,6 +40,7 @@ type Config struct {
UnsafeMode bool
Test bool
CustomConfig interface{}
ConfigPath string
//NetworkInterface string
//NetworkInterfaceIPV6Index int
}

View File

@@ -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()