Upgrade dns-ptr-resolver

This commit is contained in:
2024-09-22 23:32:10 +02:00
parent 43e9176b49
commit d6757902f6
2 changed files with 33 additions and 12 deletions

View File

@ -40,8 +40,8 @@ hex = "0.4.3"
# mariadb-dev on Alpine # mariadb-dev on Alpine
# "mysqlclient-src" "mysql_backend" # "mysqlclient-src" "mysql_backend"
diesel = { version = "2.2.0", default-features = false, features = ["mysql", "chrono", "uuid", "r2d2"] } diesel = { version = "2.2.0", default-features = false, features = ["mysql", "chrono", "uuid", "r2d2"] }
dns-ptr-resolver = "1.2.0" dns-ptr-resolver = {git = "https://github.com/wdes/dns-ptr-resolver.git"}
hickory-client = { version = "0.24.1", default-features = false } hickory-resolver = { version = "0.24.1", default-features = false, features = ["tokio-runtime", "dns-over-h3", "dns-over-https", "dns-over-quic"]}
chrono = "0.4.38" chrono = "0.4.38"
uuid = { version = "1.10.0", default-features = false, features = ["v7", "serde", "std"] } uuid = { version = "1.10.0", default-features = false, features = ["v7", "serde", "std"] }
cidr = "0.2.2" cidr = "0.2.2"

View File

@ -19,9 +19,10 @@ use uuid::Uuid;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Deserializer, Serialize};
use hickory_client::client::SyncClient; use hickory_resolver::{Name, Resolver};
use hickory_client::rr::Name; use hickory_resolver::config::{NameServerConfigGroup, ResolverOpts, ResolverConfig};
use hickory_client::tcp::TcpClientConnection; use std::time::Duration;
use std::net::IpAddr;
use diesel::serialize::IsNull; use diesel::serialize::IsNull;
use diesel::{serialize, MysqlConnection}; use diesel::{serialize, MysqlConnection};
@ -439,17 +440,28 @@ fn get_connection(database_url: &str) -> DbPool {
// Refer to the `r2d2` documentation for more methods to use // Refer to the `r2d2` documentation for more methods to use
// when building a connection pool // when building a connection pool
Pool::builder() Pool::builder()
.max_size(30) .max_size(5)
.test_on_check_out(true) .test_on_check_out(true)
.build(manager) .build(manager)
.expect("Could not build connection pool") .expect("Could not build connection pool")
} }
fn get_dns_client() -> SyncClient<TcpClientConnection> { fn get_dns_client() -> Resolver {
let server = "1.1.1.1:53".parse().expect("To parse");
let dns_conn = let server_ip = "1.1.1.1";
TcpClientConnection::with_timeout(server, std::time::Duration::new(5, 0)).unwrap();
SyncClient::new(dns_conn) let server = NameServerConfigGroup::from_ips_clear(
&[IpAddr::from_str(server_ip).unwrap()],
53,// Port 53
true,
);
let config = ResolverConfig::from_parts(None, vec![], server);
let mut options = ResolverOpts::default();
options.timeout = Duration::from_secs(5);
options.attempts = 1; // One try
Resolver::new(config, options).unwrap()
} }
fn plain_contents(data: String) -> HttpResponse { fn plain_contents(data: String) -> HttpResponse {
@ -493,13 +505,22 @@ async fn main() -> std::io::Result<()> {
"mysql://localhost".to_string() "mysql://localhost".to_string()
}; };
let pool = get_connection(db_url.as_str());
// note that obtaining a connection from the pool is also potentially blocking
let conn = &mut pool.get().unwrap();
let names = Scanner::list_names(Scanners::Stretchoid, conn);
match names {
Ok(names) => println!("Found {} Stretchoid scanners", names.len()),
Err(err) => eprintln!("Unable to get names: {}", err),
};
let server = HttpServer::new(move || { let server = HttpServer::new(move || {
let static_data_dir: String = match env::var("STATIC_DATA_DIR") { let static_data_dir: String = match env::var("STATIC_DATA_DIR") {
Ok(val) => val, Ok(val) => val,
Err(_) => "../data/".to_string(), Err(_) => "../data/".to_string(),
}; };
let pool = get_connection(db_url.as_str());
App::new() App::new()
.app_data(web::Data::new(pool.clone())) .app_data(web::Data::new(pool.clone()))
.app_data(actix_web::web::Data::new(static_data_dir)) .app_data(actix_web::web::Data::new(static_data_dir))