Struct confitul::LocalHost

source ·
pub struct LocalHost { /* private fields */ }
Expand description

LocalHost is a host for which this instance of the program is responsible.

It holds the private key for the host, which should never be transmitted over the wire to any other peer.

It is serializable because you may want to re-use a host after a program restart, to inform other peers that yes, you are still the same host, after all.

Implementations§

Create a new local host.

Parameters typically come from a UI or config, user specifying what is the name of the host and how it can be reached.

Examples
use confitul::LocalHost;

let lh = LocalHost::new(None).unwrap();
print!("{}", lh);
Examples found in repository?
src/cluster.rs (line 20)
18
19
20
21
22
23
24
25
26
27
28
    pub fn new(options: Option<ClusterOptions>) -> Result<Cluster, ParseError> {
        let real_options = options.unwrap_or(ClusterOptions::default());
        let local_host = LocalHost::new(Some(real_options.local_host))?;
        let mut cluster = Cluster {
            local_host,
            remote_hosts: HashMap::new(),
            nodes: HashMap::new(),
        };
        cluster.resize(real_options.size);
        Ok(cluster)
    }

Sign a message.

Anything sent over the wire should be signed. Only local hosts can sign, by design, as the only host you can trust for this is yourself.

Examples
use confitul::LocalHost;
use confitul::Host;

let local_host = LocalHost::new(None).unwrap();
let msg = "a message".as_bytes();
let sig = local_host.sign_msg(msg);
assert!(matches!(local_host.verify_msg(msg, &sig), Ok(())));
assert!(matches!(local_host.verify_msg(msg, msg), Err(_)));

Update local host name.

A special call is needed for this as the signature depends on the name, so this function ensure that the signature is updated after the name is modified.

Examples
use confitul::LocalHost;
use confitul::Host;

let mut local_host = LocalHost::new(None).unwrap();
local_host.update_name("another test");

Update local host description.

A special call is needed for this as the signature depends on the description, so this function ensure that the signature is updated after the description is modified.

Examples
use confitul::LocalHost;
use confitul::Host;

let mut local_host = LocalHost::new(None).unwrap();
local_host.update_description("another test");

Update local host URLs.

A special call is needed for this as the signature depends on the URLs, so this function ensure that the signature is updated after the URLs are modified.

Examples
use confitul::LocalHost;
use confitul::Host;
use url::Url;

let mut local_host = LocalHost::new(None).unwrap();
local_host.update_urls(&vec![String::from("https://a-location"), String::from("https://another-location")]).unwrap();
Examples found in repository?
src/local_host.rs (line 55)
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    pub fn new(options: Option<LocalHostOptions>) -> Result<LocalHost, ParseError> {
        let mut csprng = OsRng {};
        let keypair: Keypair = Keypair::generate(&mut csprng);
        let real_options = options.unwrap_or(LocalHostOptions::default());
        let mut local_host = LocalHost {
            info: HostInfo {
                id: HostId::new(&keypair),
                name: real_options.name,
                description: real_options.description,
                urls: Vec::new(),
                sig: None,
            },
            keypair: keypair,
        };
        local_host.update_urls(&real_options.urls)?; // update_urls will update the sig
        Ok(local_host)
    }

Trait Implementations§

Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more
Informations about the host. Read more
Verify a message signature. Read more
ID of the host. Read more
Name of the host. Read more
Description of the host. Read more
URLs of the host. Read more
Signature of the host. Read more
Verify this host signature. 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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
Converts the given value to a String. 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.