[][src]Trait rust_ipv8::community::Community

pub trait Community {
    fn new(endpoint: &NetworkSender) -> Result<Self, Box<dyn Error>>
    where
        Self: Sized
;
fn get_mid(&self) -> Vec<u8>;
fn on_receive(
        &self,
        header: Header,
        deserializer: PacketDeserializer,
        address: Address
    ) -> Result<(), Box<dyn Error>>; }

Community struct

This is the main struct defining a community

Example Community

This is an example of how to create a community

Note: Try to avoid the use of .unwrap() in actual production code, this is just an example

Required methods

fn new(endpoint: &NetworkSender) -> Result<Self, Box<dyn Error>> where
    Self: Sized

Every community should have a constructor. It will receive an endpoint from the NetworkSender which constructs the community. An endpoint is used to send messages over the network to other communities.

fn get_mid(&self) -> Vec<u8>

Returns a unique (currently 20 byte) sequence identifying a community.

This is used to be the SHA1 hash of its public key. You are free to choose whatever.

As OpenSSL keys are deprecated, this library provides no way of calculating the sha1 of an OpenSSL key. Master peer keys still can be OpenSSL keys. This SHA1 has to be hardcoded for communities that are compatible with old communities. New communities recommended to use ED25519 in the future which sha1 hashes can be calculated.

The sha1 of a key does not serve any purpose besides uniquely identifying communities and as such can be any unique 20 byte sequence.

fn on_receive(
    &self,
    header: Header,
    deserializer: PacketDeserializer,
    address: Address
) -> Result<(), Box<dyn Error>>

This method called for every incoming message, directed at this community, which is not captured.

Messages are captured whenever they have a reserved message_type (235 ~ 255). These are used for legacy support and some default responses which every community should give.

Loading content...

Implementors

Loading content...