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
103
104
105
106
107
108
109
110
111
112
//! Methods of the SDA services.

use super::*;

/// Return message given by the `ping` service call.
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Pong { 
    /// Indication of whether the service believes everything to running correctly.
    pub running: bool 
}

/// Combined SDA services.
pub trait SdaService :
    Send
    + Sync
    + SdaBaseService
    + SdaAgentService
    + SdaAggregationService
    + SdaClerkingService
    + SdaParticipationService
    + SdaRecipientService
{}

/// Basic methods for all SDA services.
pub trait SdaBaseService : Sync + Send {
    /// Send a ping to the service, expecting a pong in return if everything appears to be running.
    fn ping(&self) -> SdaResult<Pong>;
}

/// Methods used mainly for discovering and maintaining agents and their identities.
pub trait SdaAgentService : SdaBaseService {

    /// Create an agent.
    fn create_agent(&self, caller: &Agent, agent: &Agent) -> SdaResult<()>;

    /// Retrieve the agent description.
    fn get_agent(&self, caller: &Agent, agent: &AgentId) -> SdaResult<Option<Agent>>;

    /// Register the given public profile; updates any existing profile.
    fn upsert_profile(&self, caller: &Agent, profile: &Profile) -> SdaResult<()>;

    /// Retrieve the associated public profile.
    fn get_profile(&self, caller: &Agent, owner: &AgentId) -> SdaResult<Option<Profile>>;

    /// Register new encryption key for agent.
    fn create_encryption_key(&self, caller: &Agent, key: &SignedEncryptionKey) -> SdaResult<()>;

    /// Retrieve agent encryption key.
    fn get_encryption_key(&self, caller: &Agent, key: &EncryptionKeyId) -> SdaResult<Option<SignedEncryptionKey>>;
}

/// Methods used mainly for discovering aggregation objects.
pub trait SdaAggregationService : SdaBaseService {

    /// Search for aggregations optionally filtering by title substring and/or
    /// recipient.
    fn list_aggregations(&self, caller: &Agent, filter: Option<&str>, recipient: Option<&AgentId>) -> SdaResult<Vec<AggregationId>>;

    /// Retrieve an aggregation and its description.
    fn get_aggregation(&self, caller: &Agent, aggregation: &AggregationId) -> SdaResult<Option<Aggregation>>;

    /// Retrieve the associated committee.
    fn get_committee(&self, caller: &Agent, owner: &AggregationId) -> SdaResult<Option<Committee>>;
}


/// Methods used for participation in particular.
pub trait SdaParticipationService : SdaBaseService {

    /// Provide user input to an aggregation.
    fn create_participation(&self, caller: &Agent, participation: &Participation) -> SdaResult<()>;

}

/// Methods used for clerking in particular.
pub trait SdaClerkingService : SdaBaseService {

    /// Pull any job waiting to be performed by the speficied clerk.
    fn get_clerking_job(&self, caller: &Agent, clerk: &AgentId) -> SdaResult<Option<ClerkingJob>>;

    /// Push the result of a finished job.
    fn create_clerking_result(&self, caller: &Agent, result: &ClerkingResult) -> SdaResult<()>;

}

/// Methods used by the recipient in particular.
pub trait SdaRecipientService : SdaBaseService {

    /// Create a new aggregation on the service (without any associated result).
    /// If successful, the original id has been replaced by the returned id.
    fn create_aggregation(&self, caller: &Agent, aggregation: &Aggregation) -> SdaResult<()>;

    /// Delete all information (including results) regarding an aggregation.
    fn delete_aggregation(&self, caller: &Agent, aggregation: &AggregationId) -> SdaResult<()>;

    /// Propose suitable members for a committee, taking into account the aggregation constraints.
    // TODO allow additional criteria, as max number, liveliness, etc.
    fn suggest_committee(&self, caller: &Agent, aggregation: &AggregationId) -> SdaResult<Vec<ClerkCandidate>>;

    /// Set the committee for an aggregation.
    fn create_committee(&self, caller: &Agent, committee: &Committee) -> SdaResult<()>;

    /// Poll status of an aggregation.
    fn get_aggregation_status(&self, caller: &Agent, aggregation: &AggregationId) -> SdaResult<Option<AggregationStatus>>;

    /// Create a snapshot for an aggregation.
    fn create_snapshot(&self, caller: &Agent, snapshot: &Snapshot) -> SdaResult<()>;

    /// Retrieve results of an aggregation.
    fn get_snapshot_result(&self, caller: &Agent, aggregation: &AggregationId, snapshot: &SnapshotId) -> SdaResult<Option<SnapshotResult>>;

}