Repository navigation
Expand file tree
/
Copy pathcomms.rs
More file actions
425 lines (339 loc) · 13.3 KB
/
Copy pathcomms.rs
File metadata and controls
425 lines (339 loc) · 13.3 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
use crate::dm_channel::DmChannel;
use crate::filter_set::FilterSet;
use crate::misc::Private;
use crate::nostr_connect_server::{Approval, ParsedCommand};
use crate::people::PersonList;
use crate::relay::Relay;
use nostr_types::{
Event, EventKind, EventReference, Id, Metadata, MilliSatoshi, NAddr, Profile, PublicKey,
RelayUrl, Tag, UncheckedUrl, Unixtime, Url,
};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::path::PathBuf;
/// This is a message sent to the Overlord. Tasks which take any amount of time,
/// especially involving relays, are handled by the Overlord in this way. There is
/// no return value, you'll have to check various GLOBALS state later on if you
/// depend on the result. Such an architecture works best with an immediate-mode
/// renderer.
#[derive(Debug, Clone)]
pub enum ToOverlordMessage {
/// Calls [add_relay](crate::Overlord::add_relay)
AddRelay(RelayUrl),
/// Calls [advertise_relay_list](crate::Overlord::advertise_relay_list)
AdvertiseRelayList,
/// Calls [advertise_relay_list_one](crate::Overlord::advertise_relay_list)
AdvertiseRelayListOne(RelayUrl, Box<Event>, Box<Event>),
/// Calls [auth_approved](crate::Overlord::auth_approved)
/// pass 'true' as the second parameter for a permanent approval
AuthApproved(RelayUrl, bool),
/// Calls [auth_approved](crate::Overlord::auth_declined)
/// pass 'true' as the second parameter for a permanent approval
AuthDeclined(RelayUrl, bool),
/// Accumulate a seen (viewed) write. The Overlord batches it and persists it
/// on a blocking task, so the UI and the command loop never wait for LMDB.
Seen(crate::seen::SeenCommand),
/// Calls [blossom_upload](crate::Overlord::blossom_upload)
/// Uploads the local file to a blossom server
BlossomUpload(PathBuf),
/// Calls [bookmark_add](crate::Overlord::bookmark_add)
/// Adds a bookmark, possibly privately, and publishes new bookmarks list
BookmarkAdd(EventReference, bool),
/// Calls [bookmark_rm](crate::Overlord::bookmark_rm)
/// Removes a bookmark, and publishes new bookmarks list
BookmarkRm(EventReference),
/// Calls [change_passphrase](crate::Overlord::change_passphrase)
ChangePassphrase { old: String, new: String },
/// Calls [clear_person_list](crate::Overlord::clear_person_list)
ClearPersonList(PersonList),
/// Calls [auth_approved](crate::Overlord::connect_approved)
/// pass 'true' as the second parameter for a permanent approval
ConnectApproved(RelayUrl, bool),
/// Calls [auth_approved](crate::Overlord::connect_declined)
/// pass 'true' as the second parameter for a permanent approval
ConnectDeclined(RelayUrl, bool),
/// Calls [delegation_reset](crate::Overlord::delegation_reset)
DelegationReset,
/// Calls [delete_person_list](crate::Overlord::delete_person_list)
DeletePersonList(PersonList),
/// Calls [delete_post](crate::Overlord::delete_post)
DeletePost(Id),
/// Calls [delete_priv](crate::Overlord::delete_priv)
DeletePriv,
/// Calls [delete_pub](crate::Overlord::delete_pub)
DeletePub,
/// Calls [drop_relay](crate::Overlord::drop_relay)
DropRelay(RelayUrl),
/// Calls [fetch_event](crate::Overlord::fetch_event)
FetchEvent(Id, Vec<RelayUrl>),
/// Calls [fetch_naddr](crate::Overlord::fetch_naddr)
FetchNAddr(NAddr),
/// Calls [follow_pubkey](crate::Overlord::follow_pubkey)
FollowPubkey(PublicKey, PersonList, Private),
/// Calls [follow_nip05](crate::Overlord::follow_nip05)
FollowNip05(String, PersonList, Private),
/// Calls [follow_nprofile](crate::Overlord::follow_nprofile)
FollowNprofile(Profile, PersonList, Private),
/// Calls [generate_private_key](crate::Overlord::generate_private_key)
GeneratePrivateKey(String),
/// Calls [hide_or_show_relay](crate::Overlord::hide_or_show_relay)
HideOrShowRelay(RelayUrl, bool),
/// Calls [import_priv](crate::Overlord::import_priv)
ImportPriv {
// nsec, hex, or ncryptsec
privkey: String,
password: String,
},
/// Calls [import_pub](crate::Overlord::import_pub)
ImportPub(String),
/// Calls [load_image_to_copy](crate::Overlord::load_image_to_copy)
LoadImageToCopy(Url),
/// Calls [load_more_current_feed](crate::Overlord::load_more_current_feed)
LoadMoreCurrentFeed,
/// internal (minions use this channel too)
MinionJobComplete(RelayUrl, u64),
/// internal (minions use this channel too)
MinionJobUpdated(RelayUrl, u64, u64),
/// Calls [nip46_server_op_approval_response](crate::Overlord::nip46_server_op_approval_response)
Nip46ServerOpApprovalResponse(PublicKey, ParsedCommand, Approval),
/// Calls [post](crate::Overlord::post)
Post {
content: String,
tags: Vec<Tag>,
in_reply_to: Option<Id>,
annotation: bool,
dm_channel: Option<DmChannel>,
},
/// Calls [post_again](crate::Overlord::post_again)
PostAgain(Event),
/// Calls [post_cancel](crate::Overlord::post_cancel)
PostCancel,
/// Calls [post_nip46_event](crate::Overlord::post_nip46_event)
PostNip46Event(Event, Vec<RelayUrl>),
/// Calls [push_blossom_servers](crate::Overlord::push_blossom_servers)
PushBlossomServers,
/// Calls [push_person_list](crate::Overlord::push_person_list)
PushPersonList(PersonList),
/// Calls [push_metadata](crate::Overlord::push_metadata)
PushMetadata(Metadata),
/// Calls [rank_relay](crate::Overlord::rank_relay)
RankRelay(RelayUrl, u8),
/// Calls [react](crate::Overlord::react)
React(Id, PublicKey, char),
/// internal (the overlord sends messages to itself sometimes!)
ReengageMinion(RelayUrl, Vec<RelayJob>),
/// Calls [refresh_scores_and_pick_relays](crate::Overlord::refresh_scores_and_pick_relays)
RefreshScoresAndPickRelays,
/// Calls [reresh_subscribed_metadata](crate::Overlord::refresh_subscribed_metadata)
RefreshSubscribedMetadata,
/// Calls [repost](crate::Overlord::repost)
Repost(Id),
/// Calls [search](crate::Overlord::search_locally)
SearchLocally(String),
/// Calls [search](crate::Overlord::search_relays)
SearchRelays(String),
/// Calls [set_active_person](crate::Overlord::set_active_person)
SetActivePerson(PublicKey),
/// internal
SetDmChannel(DmChannel),
/// internal
SetGlobalFeed(Unixtime),
/// internal
SetPersonFeed(PublicKey, Unixtime),
/// internal
SetRelayFeed(RelayUrl, Unixtime),
/// internal
SetThreadFeed {
id: Id,
referenced_by: Id,
author: Option<PublicKey>,
},
/// Calls [setup_remote_signer](crate::Overlord::setup_remote_signer)
SetupRemoteSigner(String, String),
/// Calls [share_handler_recommendations](crate::Overlord::share_handler_recommendations)
ShareHandlerRecommendations(EventKind),
/// Calls [start_long_lived_subscriptions](crate::Overlord::start_long_lived_subscriptions)
StartLongLivedSubscriptions,
/// Calls [subscribe_config](crate::Overlord::subscribe_config)
SubscribeConfig(Option<Vec<RelayUrl>>),
/// Calls [subscribe_discover](crate::Overlord::subscribe_discover)
SubscribeDiscover(Vec<PublicKey>, Option<Vec<RelayUrl>>),
/// Calls [subscribe_inbox](crate::Overlord::subscribe_inbox)
SubscribeInbox(Option<Vec<RelayUrl>>),
/// Calls [subscribe_nip46](crate::Overlord::subscribe_nip46)
SubscribeNip46(Vec<RelayUrl>),
/// Calls [test_relay](crate::Overlord::test_relay)
TestRelay(RelayUrl),
/// Calls [track_followers](crate::Overlord::track_followers)
TrackFollowers(PublicKey),
/// Calls [track_follows](crate::Overlord::track_follows)
TrackFollows(PublicKey),
/// Calls [unlock_key](crate::Overlord::unlock_key)
UnlockKey(String),
/// Calls [update_metadata](crate::Overlord::update_metadata)
UpdateMetadata(PublicKey),
/// Calls [update_metadata_in_bulk](crate::Overlord::update_metadata_in_bulk)
UpdateMetadataInBulk(Vec<PublicKey>),
/// Calls [update_person_list](crate::Overlord::update_person_list)
UpdatePersonList {
person_list: PersonList,
merge: bool,
},
/// Calls [update_relay](crate::Overlord::update_relay)
UpdateRelay(Box<Relay>, Box<Relay>),
/// Calls [visible_notes_changed](crate::Overlord::visible_notes_changed)
VisibleNotesChanged(Vec<Id>),
/// Calls [zap_start](crate::Overlord::zap_start)
ZapStart(Id, PublicKey, UncheckedUrl),
/// Calls [zap](crate::Overlord::zap)
Zap(Id, PublicKey, MilliSatoshi, String),
}
/// Internal to gossip-lib.
/// This is a message sent to the minions
#[derive(Debug, Clone)]
pub(crate) struct ToMinionMessage {
/// The minion we are addressing, based on the URL they are listening to
/// as a String. "all" means all minions.
pub target: String,
pub payload: ToMinionPayload,
}
#[derive(Debug, Clone)]
pub(crate) struct ToMinionPayload {
/// A job id, so the minion and overlord can talk about the job.
/// If set to 0, the job is not restarted on failure.
pub job_id: u64,
pub detail: ToMinionPayloadDetail,
}
impl PartialEq for ToMinionPayload {
fn eq(&self, other: &Self) -> bool {
self.detail == other.detail
}
}
#[derive(Debug, Clone, PartialEq)]
pub(crate) enum ToMinionPayloadDetail {
AdvertiseRelayList(Box<Event>, Box<Event>),
AuthApproved,
AuthDeclined,
FetchEvent(Id),
FetchNAddr(NAddr),
PostEvents(Vec<Event>),
Shutdown,
Subscribe(FilterSet),
Unsubscribe(FilterSet),
UnsubscribeReplies,
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum RelayConnectionReason {
Advertising,
Config,
Counting,
Discovery,
FetchAugments,
FetchDirectMessages,
FetchContacts,
FetchEvent,
FetchInbox,
FetchMetadata,
Follow,
Giftwraps,
NostrConnect,
PostBlossomServers,
PostEvent,
PostContacts,
PostLike,
PostMetadata,
PostMuteList,
PostNostrConnect,
ReadThread,
Search,
SubscribePerson,
SubscribeGlobal,
}
impl fmt::Display for RelayConnectionReason {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)?;
Ok(())
}
}
impl RelayConnectionReason {
pub fn description(&self) -> &'static str {
use RelayConnectionReason::*;
match *self {
Discovery => "Searching for other people's Relay Lists",
Config => "Reading our client configuration",
Counting => "Counting",
FetchInbox => "Searching for inbox of us",
FetchAugments => "Fetching events that augment other events (likes, zaps, deletions)",
FetchDirectMessages => "Fetching direct messages",
FetchEvent => "Fetching a particular event",
FetchMetadata => "Fetching metadata for a person",
Follow => "Following the posts of people in our Contact List",
Giftwraps => "Fetch giftwraps addressed to you",
NostrConnect => "Nostr connect",
PostBlossomServers => "Posting blossom servers",
PostEvent => "Posting an event",
Advertising => "Advertising our relay list",
PostLike => "Posting a reaction to an event",
FetchContacts => "Fetching our contact list",
PostContacts => "Posting our contact list",
PostMuteList => "Posting our mute list",
PostMetadata => "Posting our metadata",
PostNostrConnect => "Posting nostrconnect",
ReadThread => "Reading ancestors to build a thread",
Search => "Search",
SubscribePerson => "Subscribe to the events of a person",
SubscribeGlobal => "Subscribe to the global feed on a relay",
}
}
pub fn persistent(&self) -> bool {
use RelayConnectionReason::*;
match *self {
Discovery => false,
Config => false,
Counting => false,
FetchInbox => true,
FetchAugments => false,
FetchDirectMessages => true,
FetchEvent => false,
FetchMetadata => false,
Follow => true,
Giftwraps => true,
NostrConnect => true,
PostBlossomServers => false,
PostEvent => false,
Advertising => false,
PostLike => false,
FetchContacts => false,
PostContacts => false,
PostMuteList => false,
PostMetadata => false,
PostNostrConnect => false,
ReadThread => true,
Search => false,
SubscribePerson => false,
SubscribeGlobal => false,
}
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct RelayJob {
// Short reason for human viewing
pub reason: RelayConnectionReason,
// Payload sent when it was started
pub(crate) payload: ToMinionPayload,
// NOTE, there is other per-relay data stored elsewhere in
// overlord.minions_task_url
// GLOBALS.relay_picker
}
/// Lazy hash using only reason
impl Hash for RelayJob {
fn hash<H: Hasher>(&self, state: &mut H) {
self.reason.hash(state);
}
}
impl RelayJob {
// This is like equality, but ignores the random job id
pub fn matches(&self, other: &RelayJob) -> bool {
self.reason == other.reason && self.payload.detail == other.payload.detail
}
}