Make use of WKD configurable when doing sq network search.

- See #336.
This commit is contained in:
Justus Winter 2024-12-02 16:27:45 +01:00
parent 1fe498db4e
commit a81a1a7689
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
2 changed files with 54 additions and 1 deletions

View File

@ -958,7 +958,9 @@ pub fn dispatch_search(mut sq: Sq, c: cli::network::search::Command)
}
}
if let Some(address) = query.as_address() {
if let Some(address) = query.as_address()
.filter(|_| sq.config.network_search_wkd())
{
let a = address.to_string();
let http_client = http_client.clone();
pb.inc_length(1);
@ -971,7 +973,9 @@ pub fn dispatch_search(mut sq: Sq, c: cli::network::search::Command)
method: Method::WKD,
}
});
}
if let Some(address) = query.as_address() {
let a = address.to_string();
pb.inc_length(1);
requests.spawn(async move {

View File

@ -52,8 +52,13 @@ pub struct Config {
policy_path: Option<PathBuf>,
policy_inline: Option<Vec<u8>>,
cipher_suite: Option<sequoia_openpgp::cert::CipherSuite>,
/// The set of keyservers to use.
key_servers: Option<Vec<Url>>,
/// Whether network search should use WKD.
network_search_wkd: bool,
/// The location of the backend server executables.
servers_path: Option<PathBuf>,
}
@ -69,6 +74,7 @@ impl Default for Config {
policy_inline: None,
cipher_suite: None,
key_servers: None,
network_search_wkd: true,
servers_path: None,
}
}
@ -211,6 +217,11 @@ impl Config {
}
}
/// Returns whether network search should use WKD.
pub fn network_search_wkd(&self) -> bool {
self.network_search_wkd
}
/// Returns the path to the backend servers.
pub fn servers_path(&self) -> Option<&Path> {
self.servers_path.as_ref().map(|p| p.as_path())
@ -243,6 +254,9 @@ impl ConfigFile {
[network]
#keyservers = <DEFAULT-KEY-SERVERS>
[network.search]
#use-wkd = true
[servers]
#path = <DEFAULT-SERVERS-PATH>
@ -826,6 +840,7 @@ fn apply_key_generate_cipher_suite(config: &mut Option<&mut Config>,
/// Schema for the `network` section.
const NETWORK_SCHEMA: Schema = &[
("keyservers", apply_network_keyservers),
("search", apply_network_search),
];
/// Validates the `network` section.
@ -879,6 +894,40 @@ fn apply_network_keyservers(config: &mut Option<&mut Config>,
Ok(())
}
/// Schema for the `network.search` section.
const NETWORK_SEARCH_SCHEMA: Schema = &[
("use-wkd", apply_network_search_use_wkd),
];
/// Validates the `network.search` section.
fn apply_network_search(config: &mut Option<&mut Config>,
cli: &mut Option<&mut Augmentations>,
path: &str, item: &Item)
-> Result<()>
{
let section = item.as_table_like()
.ok_or_else(|| Error::bad_item_type(path, item, "table"))?;
apply_schema(config, cli, Some(path), section.iter(),
NETWORK_SEARCH_SCHEMA)?;
Ok(())
}
/// Validates the `network.search.use-wkd` value.
fn apply_network_search_use_wkd(config: &mut Option<&mut Config>,
_cli: &mut Option<&mut Augmentations>,
path: &str, item: &Item)
-> Result<()>
{
let s = item.as_bool()
.ok_or_else(|| Error::bad_item_type(path, item, "bool"))?;
if let Some(config) = config {
config.network_search_wkd = s;
}
Ok(())
}
/// Schema for the `policy` section.
const POLICY_SCHEMA: Schema = &[
("aead_algorithms", apply_nop),