agent_tk/delegation/
transport.rs

1//! definition of a transport module for the delegation
2
3use crate::{agent, delegation, module, Result};
4
5//  ___                   _   __  __
6// |_ _|_ __  _ __  _   _| |_|  \/  | ___  ___ ___  __ _  __ _  ___
7//  | || '_ \| '_ \| | | | __| |\/| |/ _ \/ __/ __|/ _` |/ _` |/ _ \
8//  | || | | | |_) | |_| | |_| |  | |  __/\__ \__ \ (_| | (_| |  __/
9// |___|_| |_| .__/ \__,_|\__|_|  |_|\___||___/___/\__,_|\__, |\___|
10//           |_|                                         |___/
11
12/// Input message for the transport
13#[derive(Clone)]
14pub enum InputMessage
15{
16  /// Send a cfp
17  SendCFP
18  {
19    /// CFP
20    cfp: delegation::CFP,
21  },
22  /// Send a proposal with the cost for executing a task
23  SendProposal
24  {
25    /// content of the proposal
26    proposal: delegation::Proposal,
27  },
28  /// Send a message indicating the acceptance of a proposal
29  SendProposalAcceptance
30  {
31    /// Content of the acceptance
32    acceptance: super::transport_messages::Acceptance,
33  },
34  /// Send a message indicating the acceptance of an execution
35  SendExecutionAcceptance
36  {
37    /// Content of the acceptance
38    acceptance: super::transport_messages::Acceptance,
39  },
40  /// Send the withdrawal of the acceptance
41  SendCancelAcceptance
42  {
43    /// Content of the cancellation
44    cancel_acceptance: super::transport_messages::CancelAcceptance,
45  },
46}
47
48//   ___        _               _   __  __
49//  / _ \ _   _| |_ _ __  _   _| |_|  \/  | ___  ___ ___  __ _  __ _  ___
50// | | | | | | | __| '_ \| | | | __| |\/| |/ _ \/ __/ __|/ _` |/ _` |/ _ \
51// | |_| | |_| | |_| |_) | |_| | |_| |  | |  __/\__ \__ \ (_| | (_| |  __/
52//  \___/ \__,_|\__| .__/ \__,_|\__|_|  |_|\___||___/___/\__,_|\__, |\___|
53//                 |_|                                         |___/
54
55/// Output message from the transport, correspond to received messages.
56#[derive(Clone)]
57pub enum OutputMessage
58{
59  /// Contains a CFP received by the transport
60  ReceivedCFP
61  {
62    /// CFP
63    cfp: delegation::CFP,
64  },
65  /// Contains a proposal received by the transport
66  ReceivedProposal
67  {
68    /// proposal
69    proposal: delegation::Proposal,
70  },
71  /// Contains a received an accepted proposal
72  ReceivedProposalAccepted
73  {
74    /// acceptance
75    acceptance: super::transport_messages::Acceptance,
76  },
77  /// Contains a received an accepted execution
78  ReceivedExecutionAccepted
79  {
80    /// acceptance
81    acceptance: super::transport_messages::Acceptance,
82  },
83  /// Contains a cancel acceptance
84  ReceivedCancelAcceptance
85  {
86    /// cancel the acceptance
87    cancel_acceptance: super::transport_messages::CancelAcceptance,
88  },
89  /// Contains a received status
90  ReceivedStatus
91  {
92    /// the status
93    status: super::transport_messages::Status,
94  },
95}
96
97//  __  __           _       _      ___       _             __
98// |  \/  | ___   __| |_   _| | ___|_ _|_ __ | |_ ___ _ __ / _| __ _  ___ ___
99// | |\/| |/ _ \ / _` | | | | |/ _ \| || '_ \| __/ _ \ '__| |_ / _` |/ __/ _ \
100// | |  | | (_) | (_| | |_| | |  __/| || | | | ||  __/ |  |  _| (_| | (_|  __/
101// |_|  |_|\___/ \__,_|\__,_|_|\___|___|_| |_|\__\___|_|  |_|  \__,_|\___\___|
102
103/// Module interface for transport
104pub type ModuleInterface = module::ModuleInterface<InputMessage, OutputMessage>;
105
106//  __  __           _       _
107// |  \/  | ___   __| |_   _| | ___
108// | |\/| |/ _ \ / _` | | | | |/ _ \
109// | |  | | (_) | (_| | |_| | |  __/
110// |_|  |_|\___/ \__,_|\__,_|_|\___|
111
112/// Trait to define the interface to transport module
113pub trait Module:
114  crate::module::Module<InputMessage = InputMessage, OutputMessage = OutputMessage> + Sized
115{
116  /// Options for the creation of the transport module
117  type Options;
118  /// Start a new transport module
119  fn start<'a>(
120    agent_data: agent::AgentData,
121    module_interfaces: (
122      module::ModuleInterface<InputMessage, OutputMessage>,
123      Self::ModulePrivateInterface,
124    ),
125    delegation_module_interface: delegation::ModuleInterface,
126    options: Self::Options,
127  ) -> Result<futures::future::BoxFuture<'a, ()>>;
128}