Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to disable discovery #6363

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/android/src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod android {
use jni::sys::jchar;
use repository::database_settings::DatabaseSettings;
use server::{logging_init, start_server};
use service::settings::{LogMode, LoggingSettings, ServerSettings, Settings};
use service::settings::{DiscoveryMode, LogMode, LoggingSettings, ServerSettings, Settings};
use tokio::sync::mpsc;

use self::jni::objects::{JClass, JString};
Expand Down Expand Up @@ -42,6 +42,7 @@ pub mod android {
server: ServerSettings {
port,
danger_allow_http: false,
discovery: DiscoveryMode::Disabled,
debug_no_access_control: false,
cors_origins: vec!["http://localhost".to_string()],
base_dir: Some(files_dir.to_str().unwrap().to_string()),
Expand Down
2 changes: 2 additions & 0 deletions server/configuration/base.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
server:
port: 8000
# one of: Auto | Enabled | Disabled - Auto will enable discovery if the server is running in development mode
# discovery: Auto
# debug_no_access_control: true # enable this if you want to ignore API authorisation (dummy user will be used for all operations)
# danger_allow_http: true # allow http in production mode
cors_origins: [
Expand Down
1 change: 1 addition & 0 deletions server/configuration/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# host: 127.0.0.1
# develop: true
# port: 8000
# # discovery: Enabled # Enabled, Disabled, or Auto
# # debug_no_access_control: true # enable this if you want to ignore API authorisation (dummy user will be used for all operations)
# # danger_allow_http: true # allow http in production mode
# cors_origins: [
Expand Down
22 changes: 19 additions & 3 deletions server/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use service::{
plugin::validation::ValidatedPluginBucket,
processors::Processors,
service_provider::ServiceProvider,
settings::{is_develop, ServerSettings, Settings},
settings::{is_develop, DiscoveryMode, ServerSettings, Settings},
standard_reports::StandardReports,
sync::{
file_sync_driver::FileSyncDriver,
Expand Down Expand Up @@ -270,8 +270,24 @@ pub async fn start_server(
// Don't do discovery in android
#[cfg(not(target_os = "android"))]
{
info!("Starting server DNS-SD discovery",);
discovery::start_discovery(certificates.protocol(), settings.server.port, machine_uid);
let discovery_enabled = match settings.server.discovery {
DiscoveryMode::Disabled => false,
DiscoveryMode::Enabled => true,
DiscoveryMode::Auto => {
if is_develop() {
log::warn!("DNS-SD discovery is automatically disabled in dev mode, add `discovery: Enabled` to local.yaml to turn it on");
false
} else {
true
}
},
};
if discovery_enabled {
info!("Starting server DNS-SD discovery",);
discovery::start_discovery(certificates.protocol(), settings.server.port, machine_uid);
}else {
info!("Server DNS-SD discovery disabled",);
}
}

info!("Starting discovery graphql server",);
Expand Down
10 changes: 10 additions & 0 deletions server/service/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct ServerSettings {
/// Only used in development mode
#[serde(default)]
pub debug_no_access_control: bool,
#[serde(default)]
pub discovery: DiscoveryMode,
/// Sets the allowed origin for cors requests
pub cors_origins: Vec<String>,
/// Directory where the server stores its data, e.g. sqlite DB file or certs
Expand Down Expand Up @@ -65,6 +67,14 @@ pub enum LogMode {
File,
}

#[derive(serde::Deserialize, Clone, Default)]
pub enum DiscoveryMode {
#[default]
Auto,
Enabled,
Disabled,
}

#[derive(serde::Deserialize, Clone, Debug)]
pub enum Level {
Error,
Expand Down
3 changes: 2 additions & 1 deletion server/service/src/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use repository::{
use crate::{
processors::Processors,
service_provider::{ServiceContext, ServiceProvider},
settings::{MailSettings, ServerSettings, Settings},
settings::{DiscoveryMode, MailSettings, ServerSettings, Settings},
sync::{
file_sync_driver::FileSyncDriver,
synchroniser_driver::{SiteIsInitialisedCallback, SynchroniserDriver},
Expand Down Expand Up @@ -42,6 +42,7 @@ pub(crate) async fn setup_all_with_data_and_service_provider(
let settings = Settings {
server: ServerSettings {
port: 0,
discovery: DiscoveryMode::Disabled,
danger_allow_http: false,
debug_no_access_control: false,
cors_origins: vec![],
Expand Down
Loading