mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 08:57:26 +02:00
Rename "web" to "http."
This commit is contained in:
parent
5a0de399d7
commit
ce5edba44d
5 changed files with 25 additions and 21 deletions
|
@ -20,7 +20,7 @@ use hyper::{Uri, Method, StatusCode};
|
|||
use colored::*;
|
||||
|
||||
use crate::store::Store;
|
||||
use crate::webclient::*;
|
||||
use crate::httpclient::*;
|
||||
use crate::service::ServiceStatus;
|
||||
use crate::{GlobalFlags, HTTP_API_OBJECT_SIZE_LIMIT};
|
||||
|
||||
|
@ -48,6 +48,6 @@ pub(crate) async fn run(store: Arc<Store>, global_flags: GlobalFlags, client: Ht
|
|||
|
||||
Ok(0)
|
||||
},
|
||||
_ => Err(Box::new(UnexpectedStatusCodeError(res.status())))
|
||||
_ => Err(Box::new(UnexpectedStatusCodeError(res.status(), "")))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,13 +40,17 @@ impl std::fmt::Display for IncorrectAuthTokenError {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct UnexpectedStatusCodeError(pub StatusCode);
|
||||
pub(crate) struct UnexpectedStatusCodeError(pub StatusCode, pub &'static str);
|
||||
|
||||
impl Error for UnexpectedStatusCodeError {}
|
||||
|
||||
impl std::fmt::Display for UnexpectedStatusCodeError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "unexpected status code: {} {}", self.0.as_str(), self.0.canonical_reason().unwrap_or("???"))
|
||||
if self.1.is_empty() {
|
||||
write!(f, "unexpected status code: {} {}", self.0.as_str(), self.0.canonical_reason().unwrap_or("???"))
|
||||
} else {
|
||||
write!(f, "unexpected status code: {} {} ({})", self.0.as_str(), self.0.canonical_reason().unwrap_or("???"), self.1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +113,7 @@ pub(crate) async fn request(client: &HttpClient, method: Method, uri: Uri, data:
|
|||
if res.status() == StatusCode::UNAUTHORIZED {
|
||||
let auth = res.headers().get(hyper::header::WWW_AUTHENTICATE);
|
||||
if auth.is_none() {
|
||||
return Ok(res); // return the 401 reply
|
||||
return Err(Box::new(UnexpectedStatusCodeError(StatusCode::UNAUTHORIZED, "host returned 401 but no WWW-Authenticate header found")))
|
||||
}
|
||||
let auth = auth.unwrap().to_str();
|
||||
if auth.is_err() {
|
|
@ -26,22 +26,22 @@ use crate::service::Service;
|
|||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
/// Handles API dispatch and other HTTP handler stuff.
|
||||
async fn web_handler(service: Service, req: Request<Body>) -> Result<Response<Body>, Infallible> {
|
||||
async fn http_handler(service: Service, req: Request<Body>) -> Result<Response<Body>, Infallible> {
|
||||
Ok(Response::new("Hello, World".into()))
|
||||
}
|
||||
|
||||
/// Listener for http connections to the API or for TCP P2P.
|
||||
/// Dropping a listener initiates shutdown of the background hyper Server instance,
|
||||
/// but it might not shut down instantly as this occurs asynchronously.
|
||||
pub(crate) struct WebListener {
|
||||
pub(crate) struct HttpListener {
|
||||
pub address: SocketAddr,
|
||||
shutdown_tx: RefCell<Option<tokio::sync::oneshot::Sender<()>>>,
|
||||
server: JoinHandle<hyper::Result<()>>,
|
||||
}
|
||||
|
||||
impl WebListener {
|
||||
impl HttpListener {
|
||||
/// Create a new "background" TCP WebListener using the current tokio reactor async runtime.
|
||||
pub async fn new(_device_name: &str, address: SocketAddr, service: &Service) -> Result<WebListener, Box<dyn std::error::Error>> {
|
||||
pub async fn new(_device_name: &str, address: SocketAddr, service: &Service) -> Result<HttpListener, Box<dyn std::error::Error>> {
|
||||
let listener = if addr.is_ipv4() {
|
||||
let listener = socket2::Socket::new(socket2::Domain::ipv4(), socket2::Type::stream(), Some(socket2::Protocol::tcp()));
|
||||
if listener.is_err() {
|
||||
|
@ -100,13 +100,13 @@ impl WebListener {
|
|||
Ok::<_, Infallible>(service_fn(move |req: Request<Body>| {
|
||||
let service = service.clone();
|
||||
async move {
|
||||
web_handler(service, req).await
|
||||
http_handler(service, req).await
|
||||
}
|
||||
}))
|
||||
}
|
||||
})).with_graceful_shutdown(async { let _ = shutdown_rx.await; }));
|
||||
|
||||
Ok(WebListener {
|
||||
Ok(HttpListener {
|
||||
address,
|
||||
shutdown_tx: RefCell::new(Some(shutdown_tx)),
|
||||
server,
|
||||
|
@ -114,7 +114,7 @@ impl WebListener {
|
|||
}
|
||||
}
|
||||
|
||||
impl Drop for WebListener {
|
||||
impl Drop for HttpListener {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.shutdown_tx.take().map(|tx| {
|
||||
let _ = tx.send(());
|
|
@ -21,8 +21,8 @@ mod network;
|
|||
mod vnic;
|
||||
mod service;
|
||||
mod utils;
|
||||
mod webclient;
|
||||
mod weblistener;
|
||||
mod httplistener;
|
||||
mod httpclient;
|
||||
|
||||
#[allow(non_snake_case, non_upper_case_globals, non_camel_case_types, dead_code, improper_ctypes)]
|
||||
mod osdep; // bindgen generated
|
||||
|
@ -324,7 +324,7 @@ fn main() {
|
|||
println!("{}.{}.{}", ver.0, ver.1, ver.2);
|
||||
0
|
||||
}
|
||||
("status", _) => crate::webclient::run_command(make_store(&cli_args), get_global_flags(&cli_args), crate::commands::status::run),
|
||||
("status", _) => crate::httpclient::run_command(make_store(&cli_args), get_global_flags(&cli_args), crate::commands::status::run),
|
||||
("set", Some(sub_cli_args)) => { 0 }
|
||||
("peer", Some(sub_cli_args)) => { 0 }
|
||||
("network", Some(sub_cli_args)) => { 0 }
|
||||
|
|
|
@ -30,7 +30,7 @@ use crate::log::Log;
|
|||
use crate::network::Network;
|
||||
use crate::store::Store;
|
||||
use crate::utils::{ms_since_epoch, ms_monotonic};
|
||||
use crate::weblistener::WebListener;
|
||||
use crate::httplistener::HttpListener;
|
||||
|
||||
/// How often to check for major configuration changes. This shouldn't happen
|
||||
/// too often since it uses a bit of CPU.
|
||||
|
@ -244,8 +244,8 @@ async fn run_async(store: Arc<Store>, log: Arc<Log>, local_config: Arc<LocalConf
|
|||
let mut process_exit_value: i32 = 0;
|
||||
|
||||
let mut udp_sockets: BTreeMap<InetAddress, FastUDPSocket> = BTreeMap::new();
|
||||
let mut web_listeners: BTreeMap<InetAddress, WebListener> = BTreeMap::new();
|
||||
let mut local_web_listeners: (Option<WebListener>, Option<WebListener>) = (None, None); // IPv4, IPv6
|
||||
let mut web_listeners: BTreeMap<InetAddress, HttpListener> = BTreeMap::new();
|
||||
let mut local_web_listeners: (Option<HttpListener>, Option<HttpListener>) = (None, None); // IPv4, IPv6
|
||||
|
||||
let (interrupt_tx, mut interrupt_rx) = futures::channel::mpsc::channel::<()>(1);
|
||||
let mut service = Service {
|
||||
|
@ -430,7 +430,7 @@ async fn run_async(store: Arc<Store>, log: Arc<Log>, local_config: Arc<LocalConf
|
|||
if addr.0.port() == local_config.settings.primary_port && !web_listeners.contains_key(addr.0) {
|
||||
let sa = addr.0.to_socketaddr();
|
||||
if sa.is_some() {
|
||||
let wl = WebListener::new(addr.1.as_str(), sa.unwrap(), &service).await.map_or_else(|e| {
|
||||
let wl = HttpListener::new(addr.1.as_str(), sa.unwrap(), &service).await.map_or_else(|e| {
|
||||
l!(log, "error creating HTTP listener at {}: {}", addr.0.to_string(), e.to_string());
|
||||
}, |l| {
|
||||
l!(log, "created HTTP listener at {}", addr.0.to_string());
|
||||
|
@ -442,14 +442,14 @@ async fn run_async(store: Arc<Store>, log: Arc<Log>, local_config: Arc<LocalConf
|
|||
}
|
||||
|
||||
if local_web_listeners.0.is_none() {
|
||||
let _ = WebListener::new(loopback_dev_name.as_str(), SocketAddr::new(IpAddr::from(Ipv4Addr::LOCALHOST), local_config.settings.primary_port), &service).await.map(|wl| {
|
||||
let _ = HttpListener::new(loopback_dev_name.as_str(), SocketAddr::new(IpAddr::from(Ipv4Addr::LOCALHOST), local_config.settings.primary_port), &service).await.map(|wl| {
|
||||
local_web_listeners.0 = Some(wl);
|
||||
let _ = store.write_uri(format!("http://127.0.0.1:{}/", local_config.settings.primary_port).as_str());
|
||||
bindings_changed = true;
|
||||
});
|
||||
}
|
||||
if local_web_listeners.1.is_none() {
|
||||
let _ = WebListener::new(loopback_dev_name.as_str(), SocketAddr::new(IpAddr::from(Ipv6Addr::LOCALHOST), local_config.settings.primary_port), &service).await.map(|wl| {
|
||||
let _ = HttpListener::new(loopback_dev_name.as_str(), SocketAddr::new(IpAddr::from(Ipv6Addr::LOCALHOST), local_config.settings.primary_port), &service).await.map(|wl| {
|
||||
local_web_listeners.1 = Some(wl);
|
||||
if local_web_listeners.0.is_none() {
|
||||
let _ = store.write_uri(format!("http://[::1]:{}/", local_config.settings.primary_port).as_str());
|
||||
|
|
Loading…
Add table
Reference in a new issue