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 lib3h_protocol::{data_types::EntryData, Address};
use url::Url;
pub type FromPeerAddress = String;
#[derive(Debug, PartialEq, Clone)]
pub enum DhtCommand {
/// Owner received a gossip bundle from a remote peer, and asks us to handle it.
HandleGossip(RemoteGossipBundleData),
/// Owner wants a specific entry.
FetchEntry(FetchDhtEntryData),
/// Owner wants us to hold a peer discovery data item.
HoldPeer(PeerData),
/// Owner notifies us that it is holding one or several Aspects for an Entry.
/// Note: Need an EntryData to know the aspect addresses, but aspects' content can be empty.
HoldEntryAspectAddress(EntryData),
/// Owner wants us to bookkeep an entry and broadcast it to neighbors
BroadcastEntry(EntryData),
/// Owner notifies us that is is not holding an entry anymore.
DropEntryAddress(Address),
/// Owner's response to ProvideEntry request
EntryDataResponse(FetchDhtEntryResponseData),
}
#[derive(Debug, PartialEq, Clone)]
pub enum DhtEvent {
/// Ask owner to send this binary gossip bundle
/// to the specified list of peerAddress' in a reliable manner.
GossipTo(GossipToData),
/// Ask owner to send this binary gossip bundle
/// to as many peers listed in peerList as possible.
/// It is okay if not all peers on the list receive the message.
GossipUnreliablyTo(GossipToData),
/// Notify owner that gossip is requesting we hold a peer discovery data item.
HoldPeerRequested(PeerData),
/// Notify owner that we believe a peer has dropped
PeerTimedOut(String),
/// Notify owner that gossip is requesting we hold an entry.
/// String argument is: from_peer_address
HoldEntryRequested(FromPeerAddress, EntryData),
/// DHT wants an entry in order to send it to someone on the network
EntryDataRequested(FetchDhtEntryData),
/// Response to a `FetchEntry` command.
FetchEntryResponse(FetchDhtEntryResponseData),
/// Notify owner that we are no longer tracking this entry internally.
/// Owner should purge this address from storage, but they can, of course, choose not to.
EntryPruned(Address),
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct RemoteGossipBundleData {
pub from_peer_address: String,
pub bundle: Vec<u8>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct GossipToData {
pub peer_address_list: Vec<String>,
pub bundle: Vec<u8>,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct PeerData {
pub peer_address: String,
#[serde(with = "url_serde")]
pub peer_uri: Url,
pub timestamp: u64,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct FetchDhtEntryData {
pub msg_id: String,
pub entry_address: Address,
}
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
pub struct FetchDhtEntryResponseData {
pub msg_id: String,
pub entry: EntryData,
}