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
91
92
93
94
95
96
97
98
99
100
101
102
// This is free and unencumbered software released into the public domain.
use crate::BoxError;
use asimov_id::Id;
use asimov_protocol::Topic;
use clientele::{StandardOptions, crates::clap::Subcommand};
#[derive(Debug, Subcommand)]
pub enum ProtocolCommand {
/// Accept and monitor inbound peer traffic
#[clap(aliases = ["monitor", "pong"])]
Accept {},
/// Ping a peer node directly
Ping {
/// The handle to ping
handle: Id,
/// A peer ticket for bootstrapping
#[arg(long)]
ticket: Option<String>,
},
/// Connect to a peer node directly
#[clap(alias = "hello")]
Connect {
/// The handle to connect to
handle: Id,
/// A peer ticket for bootstrapping
#[arg(long)]
ticket: Option<String>,
},
/// Publish a message to a gossip topic
#[clap(aliases = ["pub", "send"])]
Publish {
/// The topic to publish to
topic: Topic,
/// The message to publish
message: String,
/// A peer ticket for bootstrapping
#[arg(long)]
ticket: Option<String>,
},
/// Resolve a handle into a set of peer IDs
#[clap(aliases = ["lookup"])]
Resolve {
/// The handle to resolve
handle: Id,
},
/// Subscribe to messages on a gossip topic
#[clap(aliases = ["sub", "recv"])]
Subscribe {
/// The topic to publish to
topic: Topic,
/// A peer ticket for bootstrapping
#[arg(long)]
ticket: Option<String>,
},
}
impl ProtocolCommand {
pub async fn run(&self, flags: &StandardOptions) -> Result<(), BoxError> {
use ProtocolCommand::*;
match self {
Accept {} => accept(flags).await,
Ping { handle, ticket } => ping(handle, ticket, flags).await,
Connect { handle, ticket } => connect(handle, ticket, flags).await,
Publish {
topic,
message,
ticket,
} => publish(topic, message, ticket, flags).await,
Resolve { handle } => resolve(handle, flags).await,
Subscribe { topic, ticket } => subscribe(topic, ticket, flags).await,
}
}
}
mod accept;
pub use accept::*;
mod connect;
pub use connect::*;
mod ping;
pub use ping::*;
mod publish;
pub use publish::*;
mod resolve;
pub use resolve::*;
mod subscribe;
pub use subscribe::*;