Add configuration option that disables federation
This commit is contained in:
parent
608ec096cd
commit
848a0685de
7 changed files with 42 additions and 7 deletions
|
@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
- Added `fep-e232` feature flag (disabled by default).
|
||||
- Added `account_index` parameter to Monero configuration.
|
||||
- Added `/api/v1/instance/peers` API endpoint.
|
||||
- Added `federation.enabled` configuration parameter that can be used to disable federation.
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ retention:
|
|||
|
||||
# Federation parameters
|
||||
#federation:
|
||||
# enabled: true
|
||||
# # Proxy for outgoing requests
|
||||
# #proxy_url: 'socks5h://127.0.0.1:9050'
|
||||
# # Proxy for outgoing requests to .onion targets
|
||||
|
|
|
@ -73,7 +73,7 @@ pub struct Config {
|
|||
pub(super) proxy_url: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub(super) federation: FederationConfig,
|
||||
pub federation: FederationConfig,
|
||||
|
||||
#[serde(default)]
|
||||
pub blocked_instances: Vec<String>,
|
||||
|
@ -100,7 +100,10 @@ impl Config {
|
|||
actor_key: self.instance_rsa_key.clone().unwrap(),
|
||||
proxy_url: self.federation.proxy_url.clone(),
|
||||
onion_proxy_url: self.federation.onion_proxy_url.clone(),
|
||||
is_private: matches!(self.environment, Environment::Development),
|
||||
// Private instance doesn't send activities and sign requests
|
||||
is_private:
|
||||
!self.federation.enabled ||
|
||||
matches!(self.environment, Environment::Development),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,21 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
#[derive(Clone, Default, Deserialize)]
|
||||
fn default_federation_enabled() -> bool { true }
|
||||
|
||||
#[derive(Clone, Deserialize)]
|
||||
pub struct FederationConfig {
|
||||
pub proxy_url: Option<String>,
|
||||
pub onion_proxy_url: Option<String>,
|
||||
#[serde(default = "default_federation_enabled")]
|
||||
pub enabled: bool,
|
||||
pub(super) proxy_url: Option<String>,
|
||||
pub(super) onion_proxy_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for FederationConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: default_federation_enabled(),
|
||||
proxy_url: None,
|
||||
onion_proxy_url: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ fn build_request(
|
|||
) -> RequestBuilder {
|
||||
let mut request_builder = client.request(method, url);
|
||||
if !instance.is_private {
|
||||
// Public instance should set User-Agent header
|
||||
// Public instances should set User-Agent header
|
||||
request_builder = request_builder
|
||||
.header(reqwest::header::USER_AGENT, instance.agent());
|
||||
};
|
||||
|
@ -96,7 +96,7 @@ async fn send_request(
|
|||
request_builder = request_builder.query(query_params);
|
||||
};
|
||||
if !instance.is_private {
|
||||
// Only public instance can send signed request
|
||||
// Only public instances can send signed requests
|
||||
let instance_actor_id = local_instance_actor_id(&instance.url());
|
||||
let instance_actor_key_id = local_actor_key_id(&instance_actor_id);
|
||||
let headers = create_http_signature(
|
||||
|
|
|
@ -106,6 +106,9 @@ async fn inbox(
|
|||
request: HttpRequest,
|
||||
activity: web::Json<serde_json::Value>,
|
||||
) -> Result<HttpResponse, HttpError> {
|
||||
if !config.federation.enabled {
|
||||
return Err(HttpError::PermissionError);
|
||||
};
|
||||
log::debug!("received activity: {}", activity);
|
||||
let activity_type = activity["type"].as_str().unwrap_or("Unknown");
|
||||
log::info!("received in {}: {}", request.uri().path(), activity_type);
|
||||
|
@ -304,8 +307,12 @@ async fn instance_actor_view(
|
|||
|
||||
#[post("/inbox")]
|
||||
async fn instance_actor_inbox(
|
||||
config: web::Data<Config>,
|
||||
activity: web::Json<serde_json::Value>,
|
||||
) -> Result<HttpResponse, HttpError> {
|
||||
if !config.federation.enabled {
|
||||
return Err(HttpError::PermissionError);
|
||||
};
|
||||
log::info!(
|
||||
"received in instance inbox: {}",
|
||||
activity["type"].as_str().unwrap_or("Unknown"),
|
||||
|
|
|
@ -68,11 +68,17 @@ pub struct Usage {
|
|||
pub local_posts: i64,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct FederationMetadata {
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct Metadata {
|
||||
node_name: String,
|
||||
node_description: String,
|
||||
federation: FederationMetadata,
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
|
@ -80,6 +86,9 @@ impl Metadata {
|
|||
Self {
|
||||
node_name: config.instance_title.clone(),
|
||||
node_description: config.instance_short_description.clone(),
|
||||
federation: FederationMetadata {
|
||||
enabled: config.federation.enabled,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue