Skip to content
Open
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
121 changes: 116 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ arrayvec = "0.7"
base64 = "0.13"
clap = { version = "4.6", features = ["cargo", "string", "wrap_help", "derive"] }
config = { version = "=0.15.25", default-features = false, features = ["ini"] }
cxx = "=1.0.198"
httparse = "1.7"
ipnet = "2"
jsonwebtoken = "9"
Expand Down Expand Up @@ -109,6 +110,7 @@ test-log = "0.2"
pkg-config = "0.3"
time = { version = "0.3.36", features = ["formatting", "local-offset", "macros"] }
cbindgen = "0.27"
cxx-build = "=1.0.198"

[[bench]]
name = "memorypool"
Expand Down
10 changes: 10 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ fn main() -> Result<(), Box<dyn Error>> {
},
);

cxx_build::bridge("src/handler/settings.rs")
.flag_if_supported("-std=c++17")
.compile("pushpin-cxxbridge");

let (qmake_path, qt_version) = get_qmake()?;

let qt_install_libs = {
Expand Down Expand Up @@ -516,6 +520,12 @@ fn main() -> Result<(), Box<dyn Error>> {

include_paths.push(cpp_build_dir.as_ref());

// Headers generated by cxx_build
let cxx_include_dir = out_dir.join("cxxbridge").join("include");
let cxx_crate_dir = out_dir.join("cxxbridge").join("crate");
include_paths.push(cxx_include_dir.as_ref());
include_paths.push(cxx_crate_dir.as_ref());

if boost_include_dir != Path::new("/usr/include") {
include_paths.push(boost_include_dir.as_ref());
}
Expand Down
61 changes: 55 additions & 6 deletions src/bin/pushpin-handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2025 Fastly, Inc.
* Copyright (C) 2023-2026 Fastly, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,20 +15,69 @@
*/

use clap::Parser;
use pushpin::handler::cliargs::ffi::HandlerCliArgs;
use log::{debug, error};
use pushpin::core::log::ffi::{log_init, log_set_level};
use pushpin::core::settings::{Settings, SettingsError};
use pushpin::handler::cliargs::{destroy_handler_cli_args, CliArgs};
use pushpin::import_cpp;
use pushpin::handler::settings::{ffi, HandlerSettings};
use std::ffi::CString;
use std::path::Path;
use std::process::ExitCode;
use std::ptr;

import_cpp! {
fn handler_init(args: *const HandlerCliArgs) -> libc::c_int;
fn load_settings(args: &CliArgs, config_file: &str) -> Result<HandlerSettings, SettingsError> {
let mut settings = Settings::load(Path::new(config_file))?;

if let Some(ipc_prefix) = args.ipc_prefix.as_deref().filter(|p| !p.is_empty()) {
settings.set_ipc_prefix(ipc_prefix);
}

if let Some(port_offset) = args.port_offset {
settings.set_port_offset(port_offset as i32);
}

HandlerSettings::from_settings(&settings)
}

fn main() -> ExitCode {
let cli_args = CliArgs::parse().verify();

let log_file = cli_args
.log_file
.as_deref()
.filter(|f| !f.is_empty())
.map(|f| CString::new(f).unwrap());

// SAFETY: the pointer is either null or a valid C string
if unsafe { log_init(log_file.as_ref().map_or(ptr::null(), |f| f.as_ptr())) } != 0 {
return ExitCode::from(1);
}

log_set_level(cli_args.log_level as i32);

debug!("starting...");

let config_file = cli_args
.config_file
.clone()
.expect("verify sets the config file");

let settings = match load_settings(&cli_args, &config_file) {
Ok(settings) => settings.to_ffi(),
Err(e) => {
error!("failed to load config file {config_file}: {e}");
return ExitCode::from(1);
}
};

let cli_args_ffi = cli_args.to_ffi();

let exit_code = unsafe { handler_init(&cli_args_ffi) };
let exit_code = unsafe {
ffi::handler_init(
&cli_args_ffi as *const _ as *const ffi::HandlerCliArgs,
&settings,
)
};

// Clean up the allocated memory
unsafe { destroy_handler_cli_args(cli_args_ffi) };
Expand Down
27 changes: 27 additions & 0 deletions src/core/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub enum SettingsError {

#[error("invalid tcp address: {0}")]
InvalidTcpAddress(String),

#[error("must set {0}")]
Missing(&'static str),
}

pub struct Settings {
Expand Down Expand Up @@ -306,6 +309,30 @@ impl Settings {
}
}

pub struct CommonSettings {
pub services: Vec<String>,
pub proxy_workers: u32,
pub client_maxconn: u32,
pub stats_connection_send: bool,
pub stats_connection_ttl: u32,
}

impl CommonSettings {
pub fn from_settings(settings: &Settings) -> Result<Self, SettingsError> {
Ok(Self {
services: settings.list("runner/services")?,
proxy_workers: settings.number("proxy/workers")?.unwrap_or(1),
client_maxconn: settings.number("runner/client_maxconn")?.unwrap_or(50000),
stats_connection_send: settings
.bool("global/stats_connection_send")?
.unwrap_or(true),
stats_connection_ttl: settings
.number("global/stats_connection_ttl")?
.unwrap_or(120),
})
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
3 changes: 2 additions & 1 deletion src/handler/handler.pri
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ HEADERS += \
$$PWD/filter.h \
$$PWD/filterstack.h \
$$PWD/handlerengine.h \
$$PWD/handlerargsdata.h
$$PWD/handlerargsdata.h \
$$PWD/handlerinit.h

SOURCES += \
$$PWD/deferred.cpp \
Expand Down
Loading
Loading