radicle_protocol/fetcher/state/
command.rs1use std::time;
2
3use radicle_core::{NodeId, RepoId};
4
5use crate::fetcher::RefsToFetch;
6
7#[derive(Clone, Debug, PartialEq, Eq)]
11pub enum Command {
12 Fetch(Fetch),
13 Fetched(Fetched),
14 Cancel(Cancel),
15}
16
17impl From<Fetch> for Command {
18 fn from(v: Fetch) -> Self {
19 Self::Fetch(v)
20 }
21}
22
23impl From<Fetched> for Command {
24 fn from(v: Fetched) -> Self {
25 Self::Fetched(v)
26 }
27}
28
29impl From<Cancel> for Command {
30 fn from(v: Cancel) -> Self {
31 Self::Cancel(v)
32 }
33}
34
35impl Command {
36 pub fn fetch(from: NodeId, rid: RepoId, refs: RefsToFetch, timeout: time::Duration) -> Self {
37 Self::from(Fetch {
38 from,
39 rid,
40 refs,
41 timeout,
42 })
43 }
44
45 pub fn fetched(from: NodeId, rid: RepoId) -> Self {
46 Self::from(Fetched { from, rid })
47 }
48
49 pub fn cancel(from: NodeId) -> Self {
50 Self::from(Cancel { from })
51 }
52}
53
54#[derive(Clone, Debug, PartialEq, Eq)]
56pub struct Fetch {
57 pub from: NodeId,
59 pub rid: RepoId,
61 pub refs: RefsToFetch,
63 pub timeout: time::Duration,
65}
66
67#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
69pub struct Fetched {
70 pub from: NodeId,
72 pub rid: RepoId,
74}
75
76#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
78pub struct Cancel {
79 pub from: NodeId,
81}