Trait foca::Identity

source ·
pub trait Identity: Clone + Eq + Debug {
    type Addr: PartialEq;

    // Required methods
    fn renew(&self) -> Option<Self>;
    fn addr(&self) -> Self::Addr;
    fn win_addr_conflict(&self, _adversary: &Self) -> bool;
}
Expand description

Identity is a cluster-global identifier. It qualifies a cluster member and there must not be multiple members sharing the same identity.

When talking about network protocols we’re often talking about an IP-address paired with a port number (std::net::SocketAddr, for example), but Foca doesn’t actually care about what’s inside an identity so long as its unique.

This allows implementations to make their identities as lean or large as they need. For example: if every Foca instance will bind to the same port, there’s no need to make the port number part of the identity.

That said, most of the time it’s useful to have more information in a identity than just a way to figure out a “network” address. And that’s because of how SWIM works: when an identity is declared down or deliberately leaves the cluster, it cannot rejoin for a relatively long while, so a little extra metadata allows us to come back as fast as possible.

See examples/identity_golf.rs for ideas

Required Associated Types§

source

type Addr: PartialEq

The type of the unique (cluster-wide) address of this identity

A plain identity that cannot auto-rejoin (see Identity::renew) could have Addr the same as Self (std::net::SocketAddr is an example of one)

It’s a good idea to have this type as lean as possible

Required Methods§

source

fn renew(&self) -> Option<Self>

Opt-in on auto-rejoining by providing a new identity.

When Foca detects it’s been declared Down by another member of the cluster, it will call Self::renew() on its current identity and if it yields a new one will immediately switch to it and notify the cluster so that downtime is minimized.

NOTE The new identity must win the conflict

source

fn addr(&self) -> Self::Addr

Return this identity’s unique address

Typically a socket address, a hostname or similar

On previous versions of this crate, there was a has_same_prefix() method. This serves the same purpose. Having a concrete type instead of just a yes/no allows Foca to fully manage the cluster members and keep its memory bound by the number of nodes instead of the number of identities

source

fn win_addr_conflict(&self, _adversary: &Self) -> bool

Decides which to keep when Foca encounters multiple identities sharing the same address

Returning true means that self will be kept

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Identity for SocketAddr

§

type Addr = SocketAddr

source§

fn renew(&self) -> Option<Self>

source§

fn addr(&self) -> SocketAddr

source§

fn win_addr_conflict(&self, _adversary: &Self) -> bool

source§

impl Identity for SocketAddrV4

§

type Addr = SocketAddrV4

source§

fn renew(&self) -> Option<Self>

source§

fn addr(&self) -> SocketAddrV4

source§

fn win_addr_conflict(&self, _adversary: &Self) -> bool

source§

impl Identity for SocketAddrV6

§

type Addr = SocketAddrV6

source§

fn renew(&self) -> Option<Self>

source§

fn addr(&self) -> SocketAddrV6

source§

fn win_addr_conflict(&self, _adversary: &Self) -> bool

Implementors§