kompact_net/events.rs
1use crate::{
2 actors::SystemPath,
3 messaging::DispatchData,
4 net::{SessionId, SocketAddr},
5 prelude::Port,
6};
7use ipnet::IpNet;
8use std::net::IpAddr;
9
10/// A port providing [`NetworkStatus`] updates to listeners.
11pub struct NetworkStatusPort;
12
13impl Port for NetworkStatusPort {
14 type Indication = NetworkStatus;
15 type Request = NetworkStatusRequest;
16}
17
18/// Information regarding changes to remote connectivity for a distributed system.
19#[derive(Clone, Debug)]
20pub enum NetworkStatus {
21 /// Indicates that a connection has been established to the remote system.
22 ConnectionEstablished(SystemPath, SessionId),
23 /// Indicates that a connection has been lost to the remote system.
24 ConnectionLost(SystemPath, SessionId),
25 /// Indicates that a connection has been dropped and queued messages were discarded.
26 ConnectionDropped(SystemPath),
27 /// Indicates that a connection has been gracefully closed.
28 ConnectionClosed(SystemPath, SessionId),
29 /// Indicates that a system has been blocked.
30 BlockedSystem(SystemPath),
31 /// Indicates that an IP address has been blocked.
32 BlockedIp(IpAddr),
33 /// Indicates that an IP network has been blocked.
34 BlockedIpNet(IpNet),
35 /// Indicates that an IP network has been allowed after previously being blocked.
36 AllowedIpNet(IpNet),
37 /// Indicates that a system has been allowed after previously being blocked.
38 AllowedSystem(SystemPath),
39 /// Indicates that an IP address has been allowed after previously being blocked.
40 AllowedIp(IpAddr),
41 /// Indicates that the soft connection limit has been exceeded.
42 SoftConnectionLimitExceeded,
43 /// Indicates that the hard connection limit has been reached.
44 HardConnectionLimitReached,
45 /// Indicates that the transport layer encountered a critical failure.
46 CriticalNetworkFailure,
47}
48
49/// Requests for transport-specific network status operations.
50#[derive(Clone, Debug)]
51pub enum NetworkStatusRequest {
52 /// Request that the connection to the given system is gracefully closed.
53 DisconnectSystem(SystemPath),
54 /// Request that a connection is established to the given system.
55 ConnectSystem(SystemPath),
56 /// Request that a system path be blocked.
57 BlockSystem(SystemPath),
58 /// Request that an IP address be blocked.
59 BlockIp(IpAddr),
60 /// Request that an IP network be blocked.
61 BlockIpNet(IpNet),
62 /// Request that a previously blocked system be allowed again.
63 AllowSystem(SystemPath),
64 /// Request that a previously blocked IP address be allowed again.
65 AllowIp(IpAddr),
66 /// Request that a previously blocked IP network be allowed again.
67 AllowIpNet(IpNet),
68}
69
70/// Internal dispatcher events emitted by the provided transport backend.
71#[derive(Debug)]
72pub(crate) enum NetworkDispatcherEvent {
73 /// A status update from the transport threads.
74 Network(NetworkStatus),
75 /// Data that the transport thread could not deliver and must requeue.
76 RejectedData((SocketAddr, Box<DispatchData>)),
77}