another rename

This commit is contained in:
Mike Dilger 2023-02-08 18:35:23 +13:00
parent 5d4b9378a1
commit 67dd46202c
11 changed files with 54 additions and 54 deletions

View File

@ -338,7 +338,7 @@ impl DbPersonRelay {
Direction::Write => {
// substitute our read relays
let additional: Vec<(RelayUrl, u64)> = GLOBALS
.relay_picker
.relay_tracker
.all_relays
.iter()
.filter_map(|r| {
@ -355,7 +355,7 @@ impl DbPersonRelay {
Direction::Read => {
// substitute our write relays
let additional: Vec<(RelayUrl, u64)> = GLOBALS
.relay_picker
.relay_tracker
.all_relays
.iter()
.filter_map(|r| {

View File

@ -5,7 +5,7 @@ use crate::feed::Feed;
use crate::fetcher::Fetcher;
use crate::people::People;
use crate::relationship::Relationship;
use crate::relay_picker::RelayPicker;
use crate::relays::RelayTracker;
use crate::settings::Settings;
use crate::signer::Signer;
use nostr_types::{Event, Id, Profile, PublicKeyHex, RelayUrl};
@ -46,8 +46,8 @@ pub struct Globals {
/// All nostr people records currently loaded into memory, keyed by pubkey
pub people: People,
/// The relay picker, used to pick the next relay
pub relay_picker: RelayPicker,
/// The relay tracker, used to pick the next relay
pub relay_tracker: RelayTracker,
/// Whether or not we are shutting down. For the UI (minions will be signaled and
/// waited for by the overlord)
@ -97,7 +97,7 @@ lazy_static! {
incoming_events: RwLock::new(Vec::new()),
relationships: RwLock::new(HashMap::new()),
people: People::new(),
relay_picker: Default::default(),
relay_tracker: Default::default(),
shutting_down: AtomicBool::new(false),
settings: RwLock::new(Settings::default()),
signer: Signer::default(),
@ -201,7 +201,7 @@ impl Globals {
relays: Vec::new(),
};
for ri in GLOBALS.relay_picker.all_relays.iter().filter(|ri| ri.value().write) {
for ri in GLOBALS.relay_tracker.all_relays.iter().filter(|ri| ri.value().write) {
profile.relays.push(ri.key().to_unchecked_url())
}
@ -212,7 +212,7 @@ impl Globals {
where
F: FnMut(&DbRelay) -> bool,
{
self.relay_picker
self.relay_tracker
.all_relays
.iter()
.filter_map(|r| {
@ -229,7 +229,7 @@ impl Globals {
where
F: FnMut(&DbRelay) -> bool,
{
self.relay_picker
self.relay_tracker
.all_relays
.iter()
.filter_map(|r| {
@ -243,6 +243,6 @@ impl Globals {
}
pub fn relay_is_connected(&self, url: &RelayUrl) -> bool {
self.relay_picker.connected_relays.contains(url)
self.relay_tracker.connected_relays.contains(url)
}
}

View File

@ -17,7 +17,7 @@ mod overlord;
mod people;
mod process;
mod relationship;
mod relay_picker;
mod relays;
mod settings;
mod signer;
mod tags;

View File

@ -125,7 +125,7 @@ async fn update_relays(
let db_relay = DbRelay::new(relay_url.clone());
DbRelay::insert(db_relay.clone()).await?;
if let Entry::Vacant(entry) = GLOBALS.relay_picker.all_relays.entry(relay_url.clone()) {
if let Entry::Vacant(entry) = GLOBALS.relay_tracker.all_relays.entry(relay_url.clone()) {
entry.insert(db_relay);
}

View File

@ -53,7 +53,7 @@ impl Minion {
)
.await?;
// set in globals
if let Some(mut dbrelay) = GLOBALS.relay_picker.all_relays.get_mut(&self.dbrelay.url) {
if let Some(mut dbrelay) = GLOBALS.relay_tracker.all_relays.get_mut(&self.dbrelay.url) {
dbrelay.last_general_eose_at =
Some(event.created_at.0 as u64);
}

View File

@ -75,7 +75,7 @@ impl Minion {
tracing::error!("{}: ERROR bumping relay failure count: {}", &self.url, e);
}
// Update in globals too
if let Some(mut dbrelay) = GLOBALS.relay_picker.all_relays.get_mut(&self.dbrelay.url) {
if let Some(mut dbrelay) = GLOBALS.relay_tracker.all_relays.get_mut(&self.dbrelay.url) {
dbrelay.failure_count += 1;
}
}
@ -186,7 +186,7 @@ impl Minion {
tracing::error!("{}: ERROR bumping relay success count: {}", &self.url, e);
}
// set in globals
if let Some(mut dbrelay) = GLOBALS.relay_picker.all_relays.get_mut(&self.dbrelay.url) {
if let Some(mut dbrelay) = GLOBALS.relay_tracker.all_relays.get_mut(&self.dbrelay.url) {
dbrelay.last_connected_at = self.dbrelay.last_connected_at;
}
}

View File

@ -95,7 +95,7 @@ impl Overlord {
{
let mut all_relays: Vec<DbRelay> = DbRelay::fetch(None).await?;
for dbrelay in all_relays.drain(..) {
GLOBALS.relay_picker.all_relays.insert(
GLOBALS.relay_tracker.all_relays.insert(
dbrelay.url.clone(),
dbrelay
);
@ -211,10 +211,10 @@ impl Overlord {
// Pick Relays and start Minions
if !GLOBALS.settings.read().await.offline {
// Initialize the RelayPicker
GLOBALS.relay_picker.init().await?;
GLOBALS.relay_tracker.init().await?;
// Pick relays
self.pick_relays2().await;
self.pick_relays().await;
}
// For NIP-65, separately subscribe to our mentions on our read relays
@ -288,20 +288,20 @@ impl Overlord {
}
} else {
// That one didn't work. Return to the relay picker.
relay_picker.return_assignment(relay_assignment);
relay_tracker.return_assignment(relay_assignment);
}
}
*/
async fn pick_relays2(&mut self) {
async fn pick_relays(&mut self) {
loop {
match GLOBALS.relay_picker.pick().await {
match GLOBALS.relay_tracker.pick().await {
Err(failure) => {
tracing::info!("Done picking relays: {}", failure);
break;
}
Ok(relay_url) => {
if let Some(elem) = GLOBALS.relay_picker.relay_assignments.get(&relay_url) {
if let Some(elem) = GLOBALS.relay_tracker.relay_assignments.get(&relay_url) {
tracing::debug!("PICKED {} covering {} pubkeys", &relay_url, elem.value().pubkeys.len());
} else {
tracing::warn!("Relay Picker just picked {} but it is already no longer part of it's relay assignments!", &relay_url);
@ -320,7 +320,7 @@ impl Overlord {
let abort_handle = self.minions.spawn(async move { minion.handle().await });
let id = abort_handle.id();
self.minions_task_url.insert(id, url.clone());
GLOBALS.relay_picker.connected_relays.insert(url);
GLOBALS.relay_tracker.connected_relays.insert(url);
Ok(())
}
@ -383,7 +383,7 @@ impl Overlord {
// Minion probably already logged failure in relay table
// Set to not connected
GLOBALS.relay_picker.connected_relays.remove(&url);
GLOBALS.relay_tracker.connected_relays.remove(&url);
// Remove from our hashmap
self.minions_task_url.remove(&id);
@ -405,7 +405,7 @@ impl Overlord {
tracing::info!("Relay Task {} completed", &url);
// Set to not connected
GLOBALS.relay_picker.connected_relays.remove(&url);
GLOBALS.relay_tracker.connected_relays.remove(&url);
// Remove from our hashmap
self.minions_task_url.remove(&id);
@ -422,11 +422,11 @@ impl Overlord {
}
async fn recover_from_minion_exit(&mut self, url: RelayUrl) {
GLOBALS.relay_picker.relay_disconnected(&url);
if let Err(e) = GLOBALS.relay_picker.refresh_person_relay_scores(false).await {
GLOBALS.relay_tracker.relay_disconnected(&url);
if let Err(e) = GLOBALS.relay_tracker.refresh_person_relay_scores(false).await {
tracing::error!("Error: {}", e);
}
self.pick_relays2().await;
self.pick_relays().await;
}
async fn handle_message(&mut self, message: ToOverlordMessage) -> Result<bool, Error> {
@ -434,7 +434,7 @@ impl Overlord {
ToOverlordMessage::AddRelay(relay_str) => {
let dbrelay = DbRelay::new(relay_str.clone());
DbRelay::insert(dbrelay.clone()).await?;
GLOBALS.relay_picker.all_relays.insert(
GLOBALS.relay_tracker.all_relays.insert(
relay_str,
dbrelay
);
@ -551,7 +551,7 @@ impl Overlord {
self.push_metadata(metadata).await?;
}
ToOverlordMessage::RankRelay(relay_url, rank) => {
if let Some(mut dbrelay) = GLOBALS.relay_picker.all_relays.get_mut(&relay_url) {
if let Some(mut dbrelay) = GLOBALS.relay_tracker.all_relays.get_mut(&relay_url) {
dbrelay.rank = rank as u64;
}
DbRelay::set_rank(relay_url, rank).await?;
@ -567,14 +567,14 @@ impl Overlord {
GLOBALS.people.set_active_person(pubkey).await?;
}
ToOverlordMessage::SetRelayReadWrite(relay_url, read, write) => {
if let Some(mut dbrelay) = GLOBALS.relay_picker.all_relays.get_mut(&relay_url) {
if let Some(mut dbrelay) = GLOBALS.relay_tracker.all_relays.get_mut(&relay_url) {
dbrelay.read = read;
dbrelay.write = write;
}
DbRelay::update_read_and_write(relay_url, read, write).await?;
}
ToOverlordMessage::SetRelayAdvertise(relay_url, advertise) => {
if let Some(mut dbrelay) = GLOBALS.relay_picker.all_relays.get_mut(&relay_url) {
if let Some(mut dbrelay) = GLOBALS.relay_tracker.all_relays.get_mut(&relay_url) {
dbrelay.advertise = advertise;
}
DbRelay::update_advertise(relay_url, advertise).await?;
@ -1183,7 +1183,7 @@ impl Overlord {
let db_relay = DbRelay::new(relay_url.clone());
DbRelay::insert(db_relay.clone()).await?;
if let Entry::Vacant(entry) = GLOBALS.relay_picker.all_relays.entry(relay_url.clone()) {
if let Entry::Vacant(entry) = GLOBALS.relay_tracker.all_relays.entry(relay_url.clone()) {
entry.insert(db_relay);
}

View File

@ -23,10 +23,10 @@ impl RelayAssignment {
}
}
/// Ways that the RelayPicker can fail
/// Ways that pick() can fail
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(clippy::enum_variant_names)]
pub enum RelayPickerFailure {
pub enum RelayPickFailure {
/// No people left to assign. A good result.
NoPeopleLeft,
@ -37,22 +37,22 @@ pub enum RelayPickerFailure {
MaxConnectedRelays,
}
impl fmt::Display for RelayPickerFailure {
impl fmt::Display for RelayPickFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
RelayPickerFailure::NoPeopleLeft => write!(f, "All people accounted for."),
RelayPickerFailure::NoProgress => write!(f, "Unable to make further progress."),
RelayPickerFailure::MaxConnectedRelays => write!(f, "We have hit the maximum number of connected relays"),
RelayPickFailure::NoPeopleLeft => write!(f, "All people accounted for."),
RelayPickFailure::NoProgress => write!(f, "Unable to make further progress."),
RelayPickFailure::MaxConnectedRelays => write!(f, "We have hit the maximum number of connected relays"),
}
}
}
/// The RelayPicker is a structure that helps assign people we follow to relays we watch.
/// The RelayTracker is a structure that helps assign people we follow to relays we watch.
/// It remembers which publickeys are assigned to which relays, which pubkeys need more
/// relays and how many, which relays need a time out, and person-relay scores for making
/// good assignments dynamically.
#[derive(Debug, Default)]
pub struct RelayPicker {
pub struct RelayTracker {
/// All of the relays we might use
pub all_relays: DashMap<RelayUrl, DbRelay>,
@ -77,8 +77,8 @@ pub struct RelayPicker {
pub person_relay_scores: DashMap<PublicKeyHex, Vec<(RelayUrl, u64)>>,
}
impl RelayPicker {
/// This starts a new RelayPicker that has:
impl RelayTracker {
/// This starts a new RelayTracker that has:
/// * All relays
/// * All followed public keys, with count starting at num_relays_per_person
/// * person relay scores for all person-relay pairings
@ -159,7 +159,7 @@ impl RelayPicker {
/// Create the next assignment, and return the RelayUrl that has it.
/// The caller is responsible for making that assignment actually happen.
pub async fn pick(&self) -> Result<RelayUrl, RelayPickerFailure> {
pub async fn pick(&self) -> Result<RelayUrl, RelayPickFailure> {
// Maybe we hit max
let max_relays = GLOBALS.settings.read().await.max_relays as usize;
if self
@ -167,7 +167,7 @@ impl RelayPicker {
.len()
>= max_relays
{
return Err(RelayPickerFailure::MaxConnectedRelays);
return Err(RelayPickFailure::MaxConnectedRelays);
}
// Maybe include excluded relays
@ -175,7 +175,7 @@ impl RelayPicker {
self.excluded_relays.retain(|_, v| *v > now);
if self.pubkey_counts.is_empty() {
return Err(RelayPickerFailure::NoPeopleLeft);
return Err(RelayPickFailure::NoPeopleLeft);
}
// Keep score for each relay
@ -240,7 +240,7 @@ impl RelayPicker {
let winning_score: u64 = *winner.value();
if winning_score == 0 {
return Err(RelayPickerFailure::NoProgress);
return Err(RelayPickFailure::NoProgress);
}
// Get all the pubkeys this relay covers
@ -265,7 +265,7 @@ impl RelayPicker {
}
if covered_public_keys.is_empty() {
return Err(RelayPickerFailure::NoProgress);
return Err(RelayPickFailure::NoProgress);
}
// Only keep pubkey_counts that are still > 0

View File

@ -23,7 +23,7 @@ pub(super) fn posting_area(
}
ui.label(" to post.");
});
} else if !GLOBALS.relay_picker.all_relays.iter().any(|r| r.value().write) {
} else if !GLOBALS.relay_tracker.all_relays.iter().any(|r| r.value().write) {
ui.horizontal_wrapped(|ui| {
ui.label("You need to ");
if ui.link("choose write relays").clicked() {

View File

@ -42,7 +42,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
// TBD time how long this takes. We don't want expensive code in the UI
// FIXME keep more relay info and display it
let mut relays: Vec<DbRelay> = GLOBALS
.relay_picker
.relay_tracker
.all_relays
.iter()
.map(|ri| ri.value().clone())

View File

@ -36,7 +36,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
ui.add_space(18.0);
let connected_relays: Vec<RelayUrl> = GLOBALS
.relay_picker
.relay_tracker
.connected_relays
.iter()
.map(|r| r.key().clone())
@ -65,7 +65,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
ui.label(&relay_url.0);
});
row.col(|ui| {
if let Some(ref assignment) = GLOBALS.relay_picker.relay_assignments.get(relay_url) {
if let Some(ref assignment) = GLOBALS.relay_tracker.relay_assignments.get(relay_url) {
ui.label(format!("{}", assignment.pubkeys.len()));
}
});
@ -81,11 +81,11 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
ui.heading("Coverage");
if !GLOBALS
.relay_picker
.relay_tracker
.pubkey_counts
.is_empty()
{
for elem in GLOBALS.relay_picker.pubkey_counts.iter() {
for elem in GLOBALS.relay_tracker.pubkey_counts.iter() {
let pk = elem.key();
let count = elem.value();
let maybe_person = GLOBALS.people.get(pk);