Struct fbp::fbp_iidmessage::FieldConfiguration[][src]

pub struct FieldConfiguration { /* fields omitted */ }
Expand description

Supports the ConfigMessageType::Field ConfigMessage for more complex configurations.

Suppose that a field for a node needs to be generated from base data. For example, suppose that a TCP FBP node that uses TLS needs a PKCS12 so that the certificate and private key can be used to secure the TCP connection. A PKCS12 file also will need a password. Beyond that, one might want to specify if the connection will use mutual authentification or not and what specific cipher list should be used. A struct with this information could be used to create the neccessary security information for a TLS connection, but is NOT the data that is directly used for the necessary fields of a TCP FBP node that uses TLS. This is an example of what the FieldConfiguration struct could be used for.


use serde::{Deserialize, Serialize};

use fbp::fbp_iidmessage::*;
// This struct holds the information for creating  the necessary data
// to use a secure TLS connection with TCP.
// 		file_path: 			This is a file path to a PKCS12 file
//		password: 			This is the password for the PKCS12 file
// 							if there is no password then this will be None
//		require_mutual_authentication:
//							This signifies if the TLS connect needs to be
//							mutually authenticated (Has both a server and
//							a client certificate)
//		cipher_list			The specific cipher list to use.  None means to
//							use the default cipher list.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct SecurityData {
    pub file_path: String,
    pub password: Option<String>,
    pub require_mutual_authentication: bool,
    pub cipher_list: Option<String>,

impl SecurityData {
    pub fn new(file_path: String,
               require_mutual_authentication: bool,
               password: Option<String>,
               cipher_list: Option<String>) -> Self {
        SecurityData {

// Typically configuration JSON data will be stored either in a file or
// sent from another node.  This function shows how the FieldConfiguration
// struct can be used to create complex configuration data.
pub fn make_config_msg() -> IIDMessage {
	let sd =  SecurityData::new("secureData.p12".to_string(),
		true, Some("password".to_string()), None);

	let sd_string = serde_json::to_string(&sd).unwrap();

	let fc = FieldConfiguration::new("tcp_stream_handler".to_string(),

	let fc_string = serde_json::to_string(&fc).unwrap();

	let cm = ConfigMessage::new(ConfigMessageType::Field, Some(fc_string));


// The make_config_msg will return a IIDMessage that can be sent to a FBP
// node to configure that node.  The deal_with_config_message assumes that
// it will be called from the  fn process_config(self: &mut Self, msg: IIDMessage)
// trait message when a FBP node is being configured
pub fn deal_with_config_message(msg: IIDMessage) {

	if msg.msg_type() != MessageType::Config {

	let payload = msg.payload().as_ref().unwrap();
	let config_message: ConfigMessage = serde_json::from_str(&payload)
		.expect("Failed to deserialize the config message");

	let tcp_stream_handler_string = "tcp_stream_handler".to_string();

	if {
		let fc: FieldConfiguration = serde_json::from_str(;
		match fc.get_field_name() {
			tcp_stream_handler_string => {
				let _sd: SecurityData = serde_json::from_str(fc.get_config_string().as_str()).unwrap();
				// Now the SecurityData can be used to configure the TCP FBP Node.
		_ => {
			// Invalid field


Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.