Add basic info page
This commit is contained in:
		
							parent
							
								
									c9bb5632b8
								
							
						
					
					
						commit
						7538041b67
					
				
					 3 changed files with 46 additions and 37 deletions
				
			
		|  | @ -96,6 +96,10 @@ impl Config { | ||||||
|         "v0.1.0-master".to_owned() |         "v0.1.0-master".to_owned() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     pub fn source_code(&self) -> String { | ||||||
|  |         "https://git.asonix.dog/asonix/ap-relay".to_owned() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     pub fn generate_url(&self, kind: UrlKind) -> String { |     pub fn generate_url(&self, kind: UrlKind) -> String { | ||||||
|         let scheme = if self.https { "https" } else { "http" }; |         let scheme = if self.https { "https" } else { "http" }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										26
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								src/main.rs
									
										
									
									
									
								
							|  | @ -18,8 +18,30 @@ mod webfinger; | ||||||
| 
 | 
 | ||||||
| use self::{args::Args, config::Config, db::Db, state::State, webfinger::RelayResolver}; | use self::{args::Args, config::Config, db::Db, state::State, webfinger::RelayResolver}; | ||||||
| 
 | 
 | ||||||
| async fn index() -> impl Responder { | async fn index(state: web::Data<State>, config: web::Data<Config>) -> impl Responder { | ||||||
|     "hewwo, mr obama" |     let mut s = String::new(); | ||||||
|  |     s.push_str(&format!("Welcome to the relay on {}\n", config.hostname())); | ||||||
|  | 
 | ||||||
|  |     let listeners = state.listeners().await; | ||||||
|  |     if listeners.is_empty() { | ||||||
|  |         s.push_str("There are no currently connected servers\n"); | ||||||
|  |     } else { | ||||||
|  |         s.push_str("Here are the currently connected servers:\n"); | ||||||
|  |         s.push_str("\n"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     for listener in listeners { | ||||||
|  |         if let Some(domain) = listener.as_url().domain() { | ||||||
|  |             s.push_str(&format!("{}\n", domain)); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     s.push_str("\n"); | ||||||
|  |     s.push_str(&format!( | ||||||
|  |         "The source code for this project can be found at {}\n", | ||||||
|  |         config.source_code() | ||||||
|  |     )); | ||||||
|  | 
 | ||||||
|  |     s | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[actix_rt::main] | #[actix_rt::main] | ||||||
|  |  | ||||||
							
								
								
									
										53
									
								
								src/state.rs
									
										
									
									
									
								
							
							
						
						
									
										53
									
								
								src/state.rs
									
										
									
									
									
								
							|  | @ -45,36 +45,33 @@ impl State { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn bust_whitelist(&self, whitelist: &str) { |     pub async fn bust_whitelist(&self, whitelist: &str) { | ||||||
|         let hs = self.whitelists.clone(); |         let mut write_guard = self.whitelists.write().await; | ||||||
| 
 |  | ||||||
|         let mut write_guard = hs.write().await; |  | ||||||
|         write_guard.remove(whitelist); |         write_guard.remove(whitelist); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn bust_block(&self, block: &str) { |     pub async fn bust_block(&self, block: &str) { | ||||||
|         let hs = self.blocks.clone(); |         let mut write_guard = self.blocks.write().await; | ||||||
| 
 |  | ||||||
|         let mut write_guard = hs.write().await; |  | ||||||
|         write_guard.remove(block); |         write_guard.remove(block); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn bust_listener(&self, inbox: &XsdAnyUri) { |     pub async fn bust_listener(&self, inbox: &XsdAnyUri) { | ||||||
|         let hs = self.listeners.clone(); |         let mut write_guard = self.listeners.write().await; | ||||||
| 
 |  | ||||||
|         let mut write_guard = hs.write().await; |  | ||||||
|         write_guard.remove(inbox); |         write_guard.remove(inbox); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn listeners_without(&self, inbox: &XsdAnyUri, domain: &str) -> Vec<XsdAnyUri> { |     pub async fn listeners(&self) -> Vec<XsdAnyUri> { | ||||||
|         let hs = self.listeners.clone(); |         let read_guard = self.listeners.read().await; | ||||||
|  |         read_guard.iter().cloned().collect() | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|         let read_guard = hs.read().await; |     pub async fn listeners_without(&self, inbox: &XsdAnyUri, domain: &str) -> Vec<XsdAnyUri> { | ||||||
|  |         let read_guard = self.listeners.read().await; | ||||||
| 
 | 
 | ||||||
|         read_guard |         read_guard | ||||||
|             .iter() |             .iter() | ||||||
|             .filter_map(|listener| { |             .filter_map(|listener| { | ||||||
|                 if let Some(host) = listener.as_url().host() { |                 if let Some(dom) = listener.as_url().domain() { | ||||||
|                     if listener != inbox && host.to_string() != domain { |                     if listener != inbox && dom != domain { | ||||||
|                         return Some(listener.clone()); |                         return Some(listener.clone()); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  | @ -89,10 +86,8 @@ impl State { | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         let hs = self.whitelists.clone(); |  | ||||||
| 
 |  | ||||||
|         if let Some(host) = actor_id.as_url().host() { |         if let Some(host) = actor_id.as_url().host() { | ||||||
|             let read_guard = hs.read().await; |             let read_guard = self.whitelists.read().await; | ||||||
|             return read_guard.contains(&host.to_string()); |             return read_guard.contains(&host.to_string()); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -100,10 +95,8 @@ impl State { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn is_blocked(&self, actor_id: &XsdAnyUri) -> bool { |     pub async fn is_blocked(&self, actor_id: &XsdAnyUri) -> bool { | ||||||
|         let hs = self.blocks.clone(); |  | ||||||
| 
 |  | ||||||
|         if let Some(host) = actor_id.as_url().host() { |         if let Some(host) = actor_id.as_url().host() { | ||||||
|             let read_guard = hs.read().await; |             let read_guard = self.blocks.read().await; | ||||||
|             return read_guard.contains(&host.to_string()); |             return read_guard.contains(&host.to_string()); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -111,9 +104,7 @@ impl State { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn is_listener(&self, actor_id: &XsdAnyUri) -> bool { |     pub async fn is_listener(&self, actor_id: &XsdAnyUri) -> bool { | ||||||
|         let hs = self.listeners.clone(); |         let read_guard = self.listeners.read().await; | ||||||
| 
 |  | ||||||
|         let read_guard = hs.read().await; |  | ||||||
|         read_guard.contains(actor_id) |         read_guard.contains(actor_id) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -125,30 +116,22 @@ impl State { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn cache(&self, object_id: XsdAnyUri, actor_id: XsdAnyUri) { |     pub async fn cache(&self, object_id: XsdAnyUri, actor_id: XsdAnyUri) { | ||||||
|         let cache = self.actor_id_cache.clone(); |         let mut write_guard = self.actor_id_cache.write().await; | ||||||
| 
 |  | ||||||
|         let mut write_guard = cache.write().await; |  | ||||||
|         write_guard.put(object_id, actor_id); |         write_guard.put(object_id, actor_id); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn cache_block(&self, host: String) { |     pub async fn cache_block(&self, host: String) { | ||||||
|         let blocks = self.blocks.clone(); |         let mut write_guard = self.blocks.write().await; | ||||||
| 
 |  | ||||||
|         let mut write_guard = blocks.write().await; |  | ||||||
|         write_guard.insert(host); |         write_guard.insert(host); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn cache_whitelist(&self, host: String) { |     pub async fn cache_whitelist(&self, host: String) { | ||||||
|         let whitelists = self.whitelists.clone(); |         let mut write_guard = self.whitelists.write().await; | ||||||
| 
 |  | ||||||
|         let mut write_guard = whitelists.write().await; |  | ||||||
|         write_guard.insert(host); |         write_guard.insert(host); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn cache_listener(&self, listener: XsdAnyUri) { |     pub async fn cache_listener(&self, listener: XsdAnyUri) { | ||||||
|         let listeners = self.listeners.clone(); |         let mut write_guard = self.listeners.write().await; | ||||||
| 
 |  | ||||||
|         let mut write_guard = listeners.write().await; |  | ||||||
|         write_guard.insert(listener); |         write_guard.insert(listener); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue