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
use mpc_relay_protocol::SessionId;
use std::path::PathBuf;
use thiserror::Error;

/// Errors generated by the relay server.
#[derive(Debug, Error)]
pub enum Error {
    /// Error generated when a file is expected.
    #[error(r#"not a file "{0}""#)]
    NotFile(PathBuf),

    /// Error generated when permission is denied.
    #[error("permission denied")]
    PermissionDenied,

    /// Error generated when the config server key file was not specified.
    #[error("server config requires path to a key file")]
    KeyFileRequired,

    /// Error generated when the config server key file was not found.
    #[error(r#"key file "{0}" not found"#)]
    KeyNotFound(PathBuf),

    /// Error generated attempting to handshake with a peer that
    /// already exists.
    #[error("peer already exists")]
    PeerAlreadyExists,

    /// Error generated when a peer could not be found.
    #[error(r#"peer "{0}" not found "#)]
    PeerNotFound(String),

    /// Error generated when a file does not have a parent directory.
    #[error("no parent directory")]
    NoParentDir,

    /// Error generated when a participant expects to be in the handshake
    /// protocol state.
    #[error("not handshake protocol state")]
    NotHandshakeState,

    /// Error generated when a session could not be found.
    #[error(r#"session "{0}" not found"#)]
    SessionNotFound(SessionId),

    /// Error generated attempting to relay to a peer in the context
    /// of a session but the target peer is not a session participant.
    #[error(r#"session "{0}" does not have participant "{1}""#)]
    NotSessionParticipant(SessionId, String),

    /// Error generated by input/output.
    #[error(transparent)]
    Io(#[from] std::io::Error),

    /// Error generated by the protocol library.
    #[error(transparent)]
    Protocol(#[from] mpc_relay_protocol::Error),

    /// Error generated by the web server library.
    #[error(transparent)]
    Axum(#[from] axum::Error),

    /// Error generated by the noise protocol library.
    #[error(transparent)]
    Snow(#[from] mpc_relay_protocol::snow::error::Error),

    /// Error generated parsing TOML.
    #[error(transparent)]
    Toml(#[from] toml::de::Error),

    /// Error generated when a header value is invalid.
    #[error(transparent)]
    HeaderValue(#[from] axum::http::header::InvalidHeaderValue),

    /// Error generated sending a buffer over a channel.
    #[error(transparent)]
    BufferMpscSend(
        #[from] tokio::sync::mpsc::error::SendError<Vec<u8>>,
    ),
}