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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
//! # Apub: utilities for building activitypub servers
//!
//! ## Delivery
//!
//! The [`Deliver`] trait defines how to deliver objects to remote servers. There are three
//! implementations of `Deliver` provided by this crate: one backed by Reqwest, one backed by Awc,
//! and one backed by Background Jobs, with the HTTP portion backed by another Deliver
//! implementation.
//!
//! For more information, see the [`clients`] module
//!
//! ## Fetching
//!
//! The [`Repo`] trait defines how to fetch an Object from somewhere. This is generic enough to be
//! used for fetching from a Database as well as fetching from a remote server. There are no
//! database implementations provided by default, implementing `Repo` is simple enough with the help
//! of [`async_trait`](https://docs.rs/async-trait/0.1.51/async_trait/). There are two HTTP
//! implementations of `Repo` provided by apub, one backed by Reqwest and one backed by Apub.
//!
//! For more information, see the [`clients`] module
//!
//! ## Accepting
//!
//! The [`Ingest`] trait is the main point for accepting activities into your system. `Ingest` is
//! generic over the type it ingests. This allows for a single type to accept multiple kinds of
//! activities with different implementations. It may be worthwile to implement
//! `Ingest<DeleteActivity>` differently from `Ingest<UndoActivity>`. Further, implementations can
//! implement `Ingest<A> where A: SomeTrait`. Creating generic `Ingest` implementations can enable
//! better code re-use between kinds of activities.
//!
//! See the [`ingest`] module for more types and traits to help with accepting activities
//!
//! ## Request Utilities
//!
//! When you're building an application that frequently makes HTTP Requests, you may want to
//! preemptively stop a request from continuing. For this behavior, apub provides the [`Session`]
//! trait. When a request is made via Awc or Reqwest's Repo or Deliver implementations, a check to
//! the current `Session` is made to see if the given request should procede, and when the request
//! finishes, the current session is notified of whether the request completed succesfully or
//! failed. Two Session types are provided by default: [`BreakerSession`] and
//! [`RequestCountSession`]. `BreakerSession` is designed to be shared between all requests the
//! application makes, and will stop requests to domains with too many consecutive failures for a
//! configured duration. `RequestCountSession` will keep track of how many requests a client makes
//! in total, and prevents future requests if a configured limit is exceeded. A new
//! `RequestCountSession` should be instantiated for each `Ingest`
//!
//!
//! ## Request Validation
//!
//! Much like transportation, apub provides two implementations for cryptography, one backed by
//! OpenSSL and one backed by the Rustcrypto libraries. When using the provided HTTP Repo
//! implementations, HTTP SIgnatures and HTTP Digests will automatically be applied to all requests.
//!
//! For dealing with Public and Private keys, two additional traits are provided: [`PublicKeyRepo`]
//! and [`PrivateKeyRepo`]. These traits define an API for storing and retrieving keys that server
//! ingegrations can rely on for signing and validating requests.
//!
//! For more information, see the [`cryptography`] and [`activitypub::keys`] modules.
//!
//! ## ActivityPub Impelementation
//!
//! Apub provides basic traits for dealing with a few kinds of activitypub Objects. These traits are
//! far from a perfect representation of the activitypub spec, and are instead meant to ease dealing
//! with common types.
//!
//! In addition, apub provides simple concrete implementations for an Object, and Actor, an
//! Activity, and a Public Key. These implementations may be too basic to be of much help, but are
//! included to aide in prototyping. The `SimplePublicKey` type is used in the [`PublicKeyRepo`]
//! api.
//!
//! For more information, see the [`activitypub`] module.
//!
//! ## Feature Flags
//!
//! | Feature | Description | default |
//! | -------------------- | ---------------------------------------------------- | ------- |
//! | full | Enable every feature | false |
//! | with-actix-web | Enable apub's actix-web integration | false |
//! | with-awc | Enable apub's awc Repo and Deliver | false |
//! | with-background-jobs | Enable apub's background_jobs delivery integration | false |
//! | with-openssl | Enable HTTP Signatures with OpenSSL | false |
//! | with-reqwest | Enable apub's reqwest Repo and Deliver | false |
//! | with-rustcrypto | Enable HTTP Signatures with rustcrypto | false |
//! | utils | Enable helper types and traits not strictly required | true |
//!
//! ## Examples
//! See the [examples directory](https://git.asonix.dog/asonix/apub/src/branch/main/examples) for
//! concrete implementations.
//!
//! [`BreakerSession`]: session::BreakerSession
//! [`RequestCountSession`]: session::RequestCountSession
//! [`PublicKeyRepo`]: activitypub::keys::PublicKeyRepo
//! [`PrivateKeyRepo`]: activitypub::keys::PrivateKeyRepo
pub use ;