pub struct AppState {Show 16 fields
site_id: String,
site_addr: SocketAddr,
cli_peer_addrs: Vec<SocketAddr>,
connected_neighbours_addrs: Vec<SocketAddr>,
neighbours_socket: HashMap<SocketAddr, SocketAddr>,
sync_needed: bool,
nb_first_attended_neighbours: i64,
pub site_ids_to_adr: HashMap<SocketAddr, String>,
pub parent_addr_for_transaction_wave: HashMap<String, SocketAddr>,
pub attended_neighbours_nb_for_transaction_wave: HashMap<String, i64>,
clocks: Clock,
pub global_mutex_fifo: HashMap<String, MutexStamp>,
pub waiting_sc: bool,
pub in_sc: bool,
pub notify_sc: Arc<Notify>,
pub pending_commands: VecDeque<CriticalCommands>,
}
Expand description
Represents the global state of a Peillute node
Fields§
§site_id: String
Unique identifier for this site
site_addr: SocketAddr
Unique address for this site
cli_peer_addrs: Vec<SocketAddr>
List of peer addresses given in arguments at the launch of the application
connected_neighbours_addrs: Vec<SocketAddr>
List of deg(1) neighbours connected addresses
neighbours_socket: HashMap<SocketAddr, SocketAddr>
Hashmap of sockets for each deg(1) neighbours
sync_needed: bool
Synchronization boolean
nb_first_attended_neighbours: i64
Number of attended neighbours at launch, for the discovery phase
site_ids_to_adr: HashMap<SocketAddr, String>
§parent_addr_for_transaction_wave: HashMap<String, SocketAddr>
Adress of the parent (deg(1) neighbour for this site) for a specific wave from initiator id
attended_neighbours_nb_for_transaction_wave: HashMap<String, i64>
Number of response expected from our direct neighbours (deg(1) neighbours for this site) = nb of connected neighbours - 1 (parent) for a specific wave initiator id
clocks: Clock
Logical clock implementation for distributed synchronization
global_mutex_fifo: HashMap<String, MutexStamp>
§waiting_sc: bool
§in_sc: bool
§notify_sc: Arc<Notify>
§pending_commands: VecDeque<CriticalCommands>
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new(
site_id: String,
peer_addrs: Vec<SocketAddr>,
local_addr: SocketAddr,
) -> Self
pub fn new( site_id: String, peer_addrs: Vec<SocketAddr>, local_addr: SocketAddr, ) -> Self
Creates a new AppState instance with the given configuration
pub fn get_global_mutex_fifo(&self) -> &HashMap<String, MutexStamp>
pub fn set_global_mutex_fifo( &mut self, global_mutex_fifo: HashMap<String, MutexStamp>, )
pub fn add_site_id(&mut self, site_id: String, addr: SocketAddr)
Sourcepub fn init_site_id(&mut self, site_id: String)
pub fn init_site_id(&mut self, site_id: String)
Sets the site ID at initialization
Sourcepub fn init_site_addr(&mut self, site_addr: SocketAddr)
pub fn init_site_addr(&mut self, site_addr: SocketAddr)
Sets the site address at initialization
Sourcepub fn init_cli_peer_addrs(&mut self, cli_peer_addrs: Vec<SocketAddr>)
pub fn init_cli_peer_addrs(&mut self, cli_peer_addrs: Vec<SocketAddr>)
Sets the list of CLI peer addresses at initialization
Sourcepub fn init_clock(&mut self, clock: Clock)
pub fn init_clock(&mut self, clock: Clock)
Set the clock at initialization
Sourcepub fn init_nb_first_attended_neighbours(&mut self, nb: i64)
pub fn init_nb_first_attended_neighbours(&mut self, nb: i64)
Set the number of attended neighbours at initialization
Sourcepub fn get_nb_first_attended_neighbours(&self) -> i64
pub fn get_nb_first_attended_neighbours(&self) -> i64
Get the number of attended neighbours
Sourcepub fn init_parent_addr_for_transaction_wave(&mut self)
pub fn init_parent_addr_for_transaction_wave(&mut self)
Initialize the parent of the current site as self for the wave protocol
Sourcepub fn add_incomming_peer(
&mut self,
new_addr: SocketAddr,
new_socket: SocketAddr,
received_clock: Clock,
)
pub fn add_incomming_peer( &mut self, new_addr: SocketAddr, new_socket: SocketAddr, received_clock: Clock, )
Adds a new peer to the network and updates the logical clock
This function should be safe to call multiple times
If a new site appear on the netword, every peers will launch a wave diffusion to announce the presence of this new site
Sourcepub async fn remove_peer(&mut self, addr_to_remove: SocketAddr)
pub async fn remove_peer(&mut self, addr_to_remove: SocketAddr)
Removes a peer from the network
This function should be safe to call multiple times
If a site disappear from the network, every neighbours will detected the closing of the tcp connection and will launch a wave diffusion to announce the disappearance of this site
If a site is closed properly, it will send a disconnect message to all its neighbours
Sourcepub async fn remove_peer_from_socket_closed(
&mut self,
socket_to_remove: SocketAddr,
)
pub async fn remove_peer_from_socket_closed( &mut self, socket_to_remove: SocketAddr, )
Removes a peer from the network with only an address
This function should be safe to call multiple times
If a site disappear from the network, every neighbours will detected the closing of the tcp connection and will launch a wave diffusion to announce the disappearance of this site
If a site is closed properly, it will send a disconnect message to all its neighbours
Sourcepub fn get_site_addr(&self) -> SocketAddr
pub fn get_site_addr(&self) -> SocketAddr
Returns the local address as a string
pub async fn acquire_mutex(&mut self) -> Result<(), Box<dyn Error>>
pub async fn release_mutex(&mut self) -> Result<(), Box<dyn Error>>
pub fn try_enter_sc(&mut self)
Sourcepub fn get_site_addr_as_string(&self) -> String
pub fn get_site_addr_as_string(&self) -> String
Returns the local address as a string
Sourcepub fn get_site_id(&self) -> String
pub fn get_site_id(&self) -> String
Returns a reference to the local address as &str
Sourcepub fn get_cli_peers_addrs(&self) -> Vec<SocketAddr>
pub fn get_cli_peers_addrs(&self) -> Vec<SocketAddr>
Returns a list of all peer addresses
Sourcepub fn get_cli_peers_addrs_as_string(&self) -> Vec<String>
pub fn get_cli_peers_addrs_as_string(&self) -> Vec<String>
Returns a list of all peer addresses as strings
Sourcepub fn get_connected_nei_addr(&self) -> Vec<SocketAddr>
pub fn get_connected_nei_addr(&self) -> Vec<SocketAddr>
Returns a list of conncted neibhours
Sourcepub fn get_connected_nei_addr_string(&self) -> Vec<String>
pub fn get_connected_nei_addr_string(&self) -> Vec<String>
Returns a list of conncted neibhours as strings
Sourcepub fn add_connected_neighbour(&mut self, addr: SocketAddr)
pub fn add_connected_neighbour(&mut self, addr: SocketAddr)
Add a connected neighbour to the list of connected neighbours
Sourcepub fn set_nb_nei_for_wave(&mut self, initiator_id: String, n: i64)
pub fn set_nb_nei_for_wave(&mut self, initiator_id: String, n: i64)
Set the number of attended neighbors for the wave from initiator_id
Sourcepub fn get_parent_for_wave_map(&self) -> HashMap<String, SocketAddr>
pub fn get_parent_for_wave_map(&self) -> HashMap<String, SocketAddr>
Get the list of attended neighbors for the wave from initiator_id
Sourcepub fn get_nb_nei_for_wave(&self) -> HashMap<String, i64>
pub fn get_nb_nei_for_wave(&self) -> HashMap<String, i64>
Get the list of attended neighbors for the wave from initiator_id
Sourcepub fn get_parent_addr_for_wave(&self, initiator_id: String) -> SocketAddr
pub fn get_parent_addr_for_wave(&self, initiator_id: String) -> SocketAddr
Get the parent (neighbour deg(1)) address for the wave from initiator_id
Sourcepub fn set_parent_addr(&mut self, initiator_id: String, peer_adr: SocketAddr)
pub fn set_parent_addr(&mut self, initiator_id: String, peer_adr: SocketAddr)
Set the parent (neighbour deg(1)) address for the wave from initiator_id
Sourcepub fn get_nb_connected_neighbours(&self) -> i64
pub fn get_nb_connected_neighbours(&self) -> i64
Returns the number of deg(1) neighbors connected
Sourcepub async fn update_clock(&mut self, received_vc: Option<&Clock>)
pub async fn update_clock(&mut self, received_vc: Option<&Clock>)
Update the clock of the site