1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2022 MASSA LABS <info@massa.net>

use displaydoc::Display;
use massa_models::error::ModelsError;
use massa_pos_exports::PosError;
use massa_versioning::versioning_factory::FactoryError;
use std::net::IpAddr;
use thiserror::Error;

/// protocol error
#[non_exhaustive]
#[derive(Display, Error, Debug)]
pub enum ProtocolError {
    /// Wrong signature
    WrongSignature,
    /// Protocol error: {0}
    GeneralProtocolError(String),
    /// Invalid block: {0}
    InvalidBlock(String),
    /// An error occurred during channel communication: {0}
    ChannelError(String),
    /// Error during network connection: `{0:?}`
    PeerConnectionError(NetworkConnectionErrorType),
    /// The ip: `{0}` address is not valid
    InvalidIpError(IpAddr),
    /// IO error: {0}
    IOError(#[from] std::io::Error),
    /// Serde error: {0}
    SerdeError(#[from] serde_json::Error),
    /// The network controller should not drop a node command sender before shutting down the node.
    UnexpectedNodeCommandChannelClosure,
    /// The writer of a node should not drop its event sender before sending a `clean_exit` message.
    UnexpectedWriterClosure,
    /// Time error: {0}
    TimeError(#[from] massa_time::TimeError),
    /// Missing peers
    MissingPeersError,
    /// Models error: {0}
    ModelsError(#[from] ModelsError),
    /// Send error: {0}
    SendError(String),
    /// Peer disconnected : {0}
    PeerDisconnected(String),
    /// Container inconsistency error: {0}
    ContainerInconsistencyError(String),
    /// Invalid operation error: {0}
    InvalidOperationError(String),
    /// Listener error: {0}
    ListenerError(String),
    /// Incompatible network version: local current is {local} received is {received}
    IncompatibleNetworkVersion {
        /// local current version
        local: u32,
        /// received current network version from incoming header
        received: u32,
    },
    /// Invalid announced network version
    OutdatedAnnouncedNetworkVersion {
        /// local current version
        local: u32,
        /// received announced network version
        announced_received: u32,
    },
    /// Versioned factory error: {0}
    FactoryError(#[from] FactoryError),
    /// PoS error: {0}
    PosError(#[from] PosError),
}

#[derive(Debug)]
pub enum NetworkConnectionErrorType {
    CloseConnectionWithNoConnectionToClose(IpAddr),
    PeerInfoNotFoundError(IpAddr),
    ToManyConnectionAttempt(IpAddr),
    ToManyConnectionFailure(IpAddr),
}