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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2019 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under the MIT license <LICENSE-MIT
// http://opensource.org/licenses/MIT> or the Modified BSD license <LICENSE-BSD
// https://opensource.org/licenses/BSD-3-Clause>, at your option. This file may not be copied,
// modified, or distributed except according to those terms. Please review the Licences for the
// specific language governing permissions and limitations relating to use of the SAFE Network
// Software.

use err_derive::Error;
use std::net::SocketAddr;
use std::{io, sync::mpsc};

/// Result used by `QuicP2p`.
pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, Error)]
#[allow(missing_docs)]
pub enum Error {
    #[error(display = "Network bootstrap failed")]
    BootstrapFailure,
    #[error(display = "I/O Error")]
    Io(#[source] io::Error),
    #[error(display = "quinn read")]
    Read(#[source] quinn::ReadError),
    #[error(display = "Bi-directional stream attempted by peer {}", 0)]
    BiDirectionalStreamAttempted(SocketAddr),
    #[error(display = "Establishing connection")]
    Connect(#[source] quinn::ConnectError),
    #[error(display = "Connection lost")]
    Connection(#[source] quinn::ConnectionError),
    #[error(display = "Creating endpoint")]
    Endpoint(#[source] quinn::EndpointError),
    #[error(display = "Cannot parse certificate ")]
    CertificateParseError,
    #[error(display = "Already connected {}", 0)]
    DuplicateConnectionToPeer(SocketAddr),
    #[error(display = "Could not find enpoint server")]
    NoEndpointEchoServerFound,
    #[error(display = "Oneshot receiver")]
    OneShotRx(#[source] tokio::sync::oneshot::error::RecvError),
    #[error(display = "TLS Error ")]
    TLS(#[source] rustls::TLSError),
    #[error(display = "Bincode serialisation")]
    Bincode(#[source] bincode::Error),
    #[error(display = "Base64 decode ")]
    Base64(#[source] base64::DecodeError),
    #[error(display = "Configuration {}", 0)]
    Configuration(String),
    #[error(display = "Operation not allowed")]
    OperationNotAllowed,
    #[error(display = "Connection cancelled")]
    ConnectionCancelled,
    #[error(display = "MPMC channel receive error")]
    MultiChannelRecv(#[source] crossbeam_channel::RecvError),
    #[error(display = "Channel receive error")]
    ChannelRecv(#[source] mpsc::RecvError),
    #[error(display = "Could not add certificate to PKI")]
    WebPki,
    #[error(display = "Invalid wire message.")]
    InvalidWireMsgFlag,
    #[error(display = "Stream write error")]
    WriteError(#[source] quinn::WriteError),
    #[error(display = "Read to end error: {}", 0)]
    ReadToEndError(#[source] quinn::ReadToEndError),
    #[error(display = "Read exact error: {}", 0)]
    ReadExactError(#[source] quinn::ReadExactError),
    #[error(display = "Could not add certificate")]
    AddCertificateError(#[source] quinn::ParseError),
    #[cfg(feature = "upnp")]
    #[error(display = "Could not use IGD for automatic port forwarding")]
    IgdAddPort(#[source] igd::AddAnyPortError),
    #[cfg(feature = "upnp")]
    #[error(display = "Could not renew port mapping using IGD")]
    IgdRenewPort(#[source] igd::AddPortError),
    #[cfg(feature = "upnp")]
    #[error(display = "Could not find the gateway device for IGD")]
    IgdSearch(#[source] igd::SearchError),
    #[cfg(feature = "upnp")]
    #[error(display = "IGD is not supported")]
    IgdNotSupported,
    #[error(display = "Empty response message received from peer")]
    EmptyResponse,
    #[error(display = "Type of the message received was not the expected one")]
    UnexpectedMessageType,
    #[error(display = "Maximum data length exceeded")]
    MaxLengthExceeded,
    #[error(display = "Unexpected: {}", 0)]
    Unexpected(String),
}