p2prc-0.1.0.0: P2PRC haskell library
CopyrightCopyright (C) 2024-2024 Jose Fernandes
LicenseGNU GPL, version 2 or above
MaintainerJose Fernandes <[email protected]>
Stabilitybeta
Portabilityportable
Safe HaskellSafe-Inferred
LanguageGHC2021

P2PRC

Description

This library provides an interface to the P2Prc runtime.

This Module intends to export the main functions and data type definitions necessary to get started with the P2PRC api.

A minimal application will require the import of runP2PRC function that accepts a MapPortRequest value that exposes a specific port number and associates it with a domain name in the internet.

This is a small template to get quickly get started with this interface. We assume the user has already an application listening on the tcp socket "8080".

module Main where

import P2PRC
  ( runP2PRC
  , MapPortRequest(MkMapPortRequest)
  )

main :: IO ()
main =
  runP2PRC
    ( MkMapPortRequest 8080 "jose.akilan.io"
    )
Synopsis

Functions

These are the available functions available to interact with the P2Prc environment, at a lower level of abstraction. It is intended this way to give freedom to the developer to implement their own orchestration strategies.

runP2PRC #

Arguments

:: MapPortRequest

TCP Port Request

-> IO () 

This function starts and bootstraps the P2PRC runtime that associates the a specific host's machine port to a DNS address to expose a certain application to the P2PRC network. You will only need to also import the MkMapPortRequest data constructor to represent the this port request.

Example

Expand

This example demonstrates how it can be ran on the IO context:

 example :: IO ()
 example = do
   runP2PRC
     ( MkMapPortRequest 8080 "jose.akilan.io"
     )
 

getP2prcAPI :: IOEitherError P2PRCapi #

Warning: This function is currently unstable since it assumes that the Haskell program is executed from the P2PRC "haskell" subfolder and the "p2prc" executable in the the root folder.

This function cleans the previous running state (ensuring a pure P2PRC runtime state) and builds up a conditional P2PRCapi instance.

Example

Expand

The following example show how this function can be used to expose the runtime functionalities:

 example :: IOEitherError P2PRCapi
 example = do

   eitherP2prcAPI <- getP2prcAPI

   case eitherP2prcAPI of
     ( Right
       ( MkP2PRCapi
         { startServer     = startServer
         , execInitConfig  = execInitConfig
         , execListServers = execListServers
         , execMapPort     = execMapPort
         }
       )) -> do

       -- Your code logic

     errValue -> errValue
 

Data Types

This section describes and explains the library's type system, more specifically, the interfaces and primitive types.

Interface data types

This section gives an overview on the runtime and host machine interfaces.

data P2PRCapi #

Lower level P2PRC Haskell api that exposes basic functionality necessary to joint the network.

Constructors

MkP2PRCapi 

Fields

newtype P2prcConfig #

Warning: This type is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015

This represents the server configuration that defines its attributes and behaviours in the network, as well as, the location of the runtime persistence artifacts.

Constructors

MkP2prConfig 

Fields

Instances

Instances details
FromJSON P2prcConfig # 
Instance details

Defined in JSON

Show P2prcConfig # 
Instance details

Defined in JSON

data MapPortRequest #

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.

Constructors

MkMapPortRequest

P2PRC's port allocation request value

Fields

  • Int

    TCP socket number

  • String

    Network domain name

newtype MapPortResponse #

Warning: This newtype is unstable at the moment due to the P2PRC's library error handling bug. For more information visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114#issuecomment-2474737015

This represents P2PRC's response to the TCP port and DNS address allocation. This value will confirm the successful allocation and return information about it.

Constructors

MkMapPortResponse

Allocation information value

Fields

  • String

    Column separated Host's IP address and Port String

Instances

Instances details
FromJSON MapPortResponse # 
Instance details

Defined in JSON

Show MapPortResponse # 
Instance details

Defined in JSON

Primitive data types

These types represent the core data that is communicated between requests and the runtime.

newtype IPAddressTable #

Warning: This newtype is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114

This is a wrapper value that parses a json key value from the list of ip addresses in the network.

Constructors

MkIPAddressTable

Wrapping constructor

Fields

Instances

Instances details
FromJSON IPAddressTable # 
Instance details

Defined in JSON

Show IPAddressTable # 
Instance details

Defined in JSON

data ServerInfo #

Warning: This type is highly unstable due to undergoing work on improving P2PRC's server api. For more information, visit: https://github.com/Akilan1999/p2p-rendering-computation/issues/114

This is a record that keeps track of the current state of every node in the network. It is crucial information required for orchestration strategies.

Constructors

MkServerInfo 

Fields

Instances

Instances details
FromJSON ServerInfo # 
Instance details

Defined in JSON

Show ServerInfo # 
Instance details

Defined in JSON

data IPAddress #

This is a simple representation of the IP address of nodes in the network.

Constructors

MkIPv4 String

IP version 4 address

MkIPv6 String

IP version 6 address

Instances

Instances details
Show IPAddress # 
Instance details

Defined in JSON

data Error #

Haskell-side Error value. This type is designed to parse and track System and P2PRC's error signals in a safe and effective manner.

It does have an MkUnknownError value which is meant to be warn about new kinds of error not yet accounted in this client. Github issues and pull requests are very welcome to improve error handling by parsing more types of errors.

Constructors

MkCLISystemError

This is a CLI System Error

Fields

MkErrorSpawningProcess

Spawing process error

Fields

  • String

    Spawning executable name

MkUnknownError

This is an unparsed P2PRC's error

Fields

Instances

Instances details
Show Error # 
Instance details

Defined in Error

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

Type Synonyms

This section is reserved to some useful type synonyms that add significant ergonomics.

type IOEitherError a = IO (Either Error a) #

Type synonym for an IO action with either returns an Error or a parsed value