Python-cellframe en

From wiki.cellframe.net
Jump to navigation Jump to search

python-cellframe

This is a library which includes the following libraries:

  • libdap-python
  • libdap-crypto-python
  • libdap-server-core-python

Also one of the main tasks of this module is initialization/deinitialization of plug-in libraries.

Build and Installation

Setting up a packet using PIP

This type of installation is not supported at the moment.

Installation from source code

To install python-cellframe. You need python3.7, python3.7-dev scikit-build, git, cmake, make, gcc, g++.

You can download the source code from the repository by command

$ git clone https://gitlab.demlabs.net/cellframe/python-cellframe.git

Then you need to go to the python-cellframe directory

$ cd python-cellframe

After that you need to update for the modules

$ git submodule update --init

$ cd cellframe-sdk

$ git submodule update --init

$ cd ..

You can then proceed with the installation as administrator (usually using the sudo command).

$ python3.7 setup.py install

Initialisation

Initialization of python-cellframe is done by calling the init function. As a parameter of this function is passed string, which contains JSON. JSON must contain JSON:

  • Array with the name of modules listing the modules to be initialized, this array can be empty if only the libdap-python module needs to be initialized.
  • object named DAP, which contains value key pairs:
    • config_dir - directory in which configuration files are stored
    • log_level - responsible for setting the log level
    • application_name - responsible for setting the application name
    • file_name_log - responsible for setting log file name

Also, JSON must contain module name and configuration information required for module initialization.

Attention! The libdap-python module must be initialized, so JSON needs a DAP object, and it's not necessary to add it to the list of modules".

An example of a JSON string that initializes the libdap-crypto-python library

{
    "modules." ["crypto"]
    "DAP." {
       "config_dir." \""""+os.getcwd()+"""\",
       "log_level." "L_DEBUG."
       "application_name." \""""+app_name+"""\",
       "file_name_log." \""""+app_name+""".text\"
    }
}

Configuring the node

For full node initialisation, it is necessary to describe the configuration by which the function of python-cellframe initialisation creates configuration files necessary for work under modules.

The description of the configuration is in the object called Configuration. This object contains the description of networks the node can connect to and the description of the main configuration file of the application.

Description of networks to be located in the object - networks. This object contains the object(s) in the name of which the name of the network is given, further it will be named as the object of the description of the network configuration. The object that contains the network configuration description describes the contents of the network configuration file and additional files necessary for network operation.

Paths to the directories, in which the configuration files will be generated

Additional files, network configurations are located in directory

 <programmer-defined directory>/network/<name of network>/

. Main network configuration files are located in directory

 <programmer-defined directory>/network/<name of network>.cfg

. The main configuration file of the application is located in the path

 <programmer-defined directory>/<application name>.cfg

.

libdap-python and python-cellframe

These libraries are the basis of DAP (Deus Applications Prototypes). The libdap-python library is a wrapper above the libdap library.

Functions

  • init - Provides python-cellframe and this function performs all initialization work, accepts one JSON parameter string.
  • deinit - Provides python-cellframe and this function does all the work on deinitialization, does not accept parameters.
  • setLogLevel - Provides libdap-python with this function sets the logging level, takes one parameter to input a numeric parameter
  • logIt - Displays and writes a message to a log file, accepts two log level and text parameters
  • logItDebug - Same as the previous log level only is set to DEBUG (0).
  • logItInfo - Same as the previous only log level set to INFO (1).
  • logItNotice - Same as the previous only log level set to NOTICE (2).
  • logItMessage - Same as the previous only log level set by MSG (3).
  • logItDap - Same as the previous only log level is set to DAP (4).
  • logItWarning - Same as the previous only log level is set to WARNING (5).
  • logItAtt - Same as the previous only log level is set to ATT (6).
  • logItError - Same as the previous only log level is set to ERROR (7).
  • logItCritical - Same as the previous only log level set to CRITICAL (8).
  • configGetItem - Receives data from the configuration file, accepts two input parameters: selector, key.
  • configGetItemDefault - Receives data from the configuration file, accepts two input parameters: selector, key.

libdap-python-crypto

This library is a wrapper above libdap-crypto. It provides access to libdap-crypto functions through an object like Crypto. It also provides objects like CryptoKeyType and CryptoDataType.

Initialization

To initialize the library you need to JSON line, which is passed as a parameter of the module's initialization function. This JSON string in the modules array must contain the record "crypto".

Object Types

CryptoKey

CryptoKey object - stores the encryption/decryption key, is essentially a wrapper for the dap_enc_key structure of the libdap-crypto library. Accordingly, this object is necessary and used for encryption/decryption algorithms.

CryptoKeyType

An object of CryptoKeyType type is an analogue of the usual enum. And it provides functions to get their values by enumerating dap_enc_key_type. Therefore, all functions it provides are static, return a numerical value and do not accept arguments.

Functions
Title Returned value !
DAP_ENC_KEY_TYPE_IAES 0
DAP_ENC_KEY_TYPE_OAES 1
DAP_ENC_KEY_TYPE_RLWE_NEWHOPE 2
DAP_ENC_KEY_TYPE_SIDH_CLN16 3
DAP_ENC_KEY_TYPE_DEFEO 4
DAP_ENC_KEY_TYPE_MSRLN 5
DAP_ENC_KEY_TYPE_MSRLN16 6
DAP_ENC_KEY_TYPE_RLWE_BCNS15 7
DAP_ENC_KEY_TYPE_LWE_FRODO 8
DAP_ENC_KEY_TYPE_SIDH_IQC_REF 9
DAP_ENC_KEY_TYPE_CODE_MCBITS 10
DAP_ENC_KEY_TYPE_NTRU 11
DAP_ENC_KEY_TYPE_MLWE_KYBER 12
DAP_ENC_KEY_TYPE_SIG_PICNIC 13
DAP_ENC_KEY_TYPE_SIG_BLISS 14
DAP_ENC_KEY_TYPE_SIG_TESLA 15
DAP_ENC_KEY_TYPE_SIG_DILITHIUM 16
DAP_ENC_KEY_TYPE_NULL 0
CryptoDataType

An object of CryptoDataType type is an analogue of the usual enum. And it provides functions to get their values enumerated dap_enc_data_type. Therefore, all functions it provides are static, return a numerical value and do not accept arguments.

Functions
Title Returned value !
DAP_ENC_DATA_TYPE_RAW 0
DAP_ENC_DATA_TYPE_B64 1
DAP_ENC_DATA_TYPE_B64_URLSAFE 2

Functions

Attention the functions marked grey color are not implemented .

libdap-python-crypto - provides the following functions

  • To work with Base58 algorithms implementation
    • encodeBase58 - This function accepts bytes-type object as an argument, encodes them to Base58 algorithms and returns a string.
    • decodeBase58 - This function takes a string as an argument, decodes it using the Base58 algorithm and returns an object of bytes type.
  • For working with the implementation of Base64 algorithms
    • encodeBase64 - This function takes as its arguments two parameters of bytes object type and number from one to two, which defines the type of encoded data, the number can also be obtained using the Crypto.DataType object and its functions. The function returns the encoded data as a string.
    • decodeBase64 - This function takes as its arguments two parameters object string and number from one to two, which defines the type of encoded data, the number can also be obtained using the object Crypto.DataType and its functions. The function returns an object of bytes type, which contains decoded data.
  • For working with encryption keys. Note: You may have to specify the type of these keys to work with encryption keys. Therefore it is recommended to read the object of Crypto.KeyType type.
    • newKey - This function takes as the first parameter the number that denotes the type of the generated key and returns an object of CryptoKey type.
    • generateNewKey - This function accepts six arguments for input, number - type of the generated key, object of bytes type - kex buffer, size of this object, object of bytes type - seed, size of this object, size of the key - specify 0 by default. The function generates a key of the specified type, places it to the CryptoKey object and returns it.
    • getEncSizeKey - this function accepts two parameters of the CryptoKey object and the size of encrypted data. The function returns the size of encrypted data using the algorithm, to which this key belongs.
    • getDecSizeKey - This function accepts two parameters of CryptoKey object and the size of encrypted data. The function returns the size of decrypted data using the algorithm to which this key belongs.
  • In order to work with the implementation of the IAES256 algorithms.
    • newKeyIAES - This function takes a CryptoKey object and is responsible for adding the IAES key to it.
    • deleteKeyIAES - This function takes an object of CryptoKey type to input and is responsible for removing the IAES key from it
    • generateKeyIAES - This function accepts five arguments, an object of CryptoKey type, an object of bytes type, the size of this object, an object of bytes type, the size of this object. And it generates a key

libdap-server-core-python

libdap-server-core-python is libdap-server-core library mapping. The library also provides some DapServer, Events and EventsSocket objects.

Initialization

To initialize the library you need to JSON line, which is passed as a parameter of the module's initialization function. This JSON string in the modules array must contain the record "ServerCore", as well as JSON string must contain the object "ServerCore" which has two numeric fields:

  • thread_cnt - This field contains the number of threads, allowed value from 0.
  • conn - This field contains the number of connections, allowed value from 0.

Types of objects

DapServer

An object of DapServer type stores a variable of dap_server_t type and transfers it to other functions that interact with it.

Events

An object of the Events type stores a variable of the dap_events_t type, and provides the following functions

  • start - This function does not accept any parameters. The function's task is to initialize and prepare Events. This function is a wrapper over the dap_events_start function.
  • wait - This function does not accept any parameters. The function task is to start waiting for the event. This function is a wrapper over the dap_events_wait function.
  • killSocket - This function accepts one parameter, an object of EventsSocket type. The task of this function is to destroy the socket. This function is a wrapper for dap_events_kill_socket function.
  • removeAndDeleteSocket - This function accepts two parameters: object of the EventsSocket type, a variable of the logical type that, if true, will be saved. This function is a wrapper for dap_events_socket_remove_and_delete function.

===== EventsSocket =====. An object of EventsSocket type stores a variable of dap_events_socket_t type and provides the following functions

  • createAfter - This function does not accept any parameters, is a wrapper for the function dap_events_socket_create_after
  • find - This function accepts two parameters: number - socket number and Events object, the function assigns to the current object found. This function is a wrapper for dap_events_socket_find function.
  • setReadable - This function accepts one logical parameter as its arguments. And sets the socket capture for reading to the state, which is set by the first parameter
  • setWritable - This service accepts one logical parameter as an argument. And sets the socket capture for writing to the state, which is set by the first parameter
  • write - This function accepts two parameters, the bytes object and the number of elements in the bytes object. This function writes data to the socket. This function returns the number of written bytes.
  • writeF - This function accepts two parameters, a data format string and a motorcade, the data in which correspond to the transmitted format. This function parses the received tuple into va_list and makes a quick write to the socket, relying on a string variable describing the data format and va_list. This function returns the number of bytes written.
  • read - This function takes one parameter, the number of read bytes, to the input. This function performs reading. This function returns a motorcade consisting of the number of read bytes and bytes object.
  • delete - This function takes one logical parameter to input, which is responsible for removing the client from the list, if the value is set to truth. This function deletes the socket.
  • shringBufIn - This function takes a numerical value - size as an input. This function decreases the buffer size (by shifting it to the left).

Functions

libdap-server-core-python provides a ServerCore object to access the main functions:

  • loop - This function accepts one parameter: object of DapServer type. This function starts the ServerCore loop.
  • listen - This function accepts three parameters: string - server address, number - port, number - server type. This function creates an instance of DapServer and starts listening to the TCP port with the selected address.

libdap-chain-python

libdap-chain-python is a library for python-cellframe that wraps libdap-chain and allows you to interact with it using the Python and python-cellframe programming languages.

libdap-chain-net-python

libdap-chain-net-python is the library, the purpose and task of interacting with libdap-chain-net with Python programs through Python-cellframe and directly libdap-chain-net-python.

libdap-chain-global-db-python

libdap-chain-global-db-python is the library, the purpose and task of interacting with libdap-chain-global-db, i.e. working with the database using Python programs, using Python-cellframe and directly libdap-chain-global-db-python.