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
use std::fmt;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BucketError {
    BucketFull,
    IncorrectBucket,
    RepeatedLNode,
    LNodeNotFound,
    NodeNotFound,
    IndexError,
}

impl std::error::Error for BucketError {}

impl fmt::Display for BucketError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            BucketError::BucketFull => write!(f, "This bucket is full."),
            BucketError::IncorrectBucket => write!(f, "The node does not fit."),
            BucketError::RepeatedLNode => write!(f, "There already is a local node."),
            BucketError::LNodeNotFound => write!(f, "Could not find the local node."),
            BucketError::NodeNotFound => write!(f, "Could not find the node."),
            BucketError::IndexError => write!(f, "Index is out of bounds."),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServerError {
    SearchRouter,
    AddPort,
}

impl std::error::Error for ServerError {}

impl fmt::Display for ServerError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            ServerError::SearchRouter => write!(f, "Could not find UPnP functions on router."),
            ServerError::AddPort => write!(f, "Could not add a new port redirection."),
        }
    }
}



#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileError {
    OpenFile,
    SaveData,
    LoadData,
}

impl std::error::Error for FileError {}

impl fmt::Display for FileError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            FileError::OpenFile => write!(f, "Failed to open file for saving or loading."),
            FileError::SaveData => write!(f, "Failed to write json peer data to file."),
            FileError::LoadData => write!(f, "Failed to read json peer data from file."),
        }
    }
}