chore: update defaults in builder (#3299)

Co-authored-by: 0xlosha <koppel444@gmx.de>
Co-authored-by: rya <83345377+rya0x@users.noreply.github.com>
This commit is contained in:
Matthias Seitz
2023-06-21 15:15:22 +02:00
committed by GitHub
parent 00e6adfa57
commit 0c222e5258
3 changed files with 12 additions and 13 deletions

View File

@@ -353,7 +353,7 @@ impl RpcServerArgs {
Tasks: TaskSpawner + Clone + 'static,
{
let socket_address = SocketAddr::new(
self.auth_addr.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
self.auth_addr.unwrap_or(IpAddr::V4(Ipv4Addr::LOCALHOST)),
self.auth_port.unwrap_or(constants::DEFAULT_AUTH_PORT),
);
@@ -424,7 +424,7 @@ impl RpcServerArgs {
if self.http {
let socket_address = SocketAddr::new(
self.http_addr.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
self.http_addr.unwrap_or(IpAddr::V4(Ipv4Addr::LOCALHOST)),
self.http_port.unwrap_or(constants::DEFAULT_HTTP_RPC_PORT),
);
config = config
@@ -436,7 +436,7 @@ impl RpcServerArgs {
if self.ws {
let socket_address = SocketAddr::new(
self.ws_addr.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
self.ws_addr.unwrap_or(IpAddr::V4(Ipv4Addr::LOCALHOST)),
self.ws_port.unwrap_or(constants::DEFAULT_WS_RPC_PORT),
);
config = config.with_ws_address(socket_address).with_ws(self.http_ws_server_builder());
@@ -454,7 +454,7 @@ impl RpcServerArgs {
/// Creates the [AuthServerConfig] from cli args.
fn auth_server_config(&self, jwt_secret: JwtSecret) -> Result<AuthServerConfig, RpcError> {
let address = SocketAddr::new(
self.auth_addr.unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)),
self.auth_addr.unwrap_or(IpAddr::V4(Ipv4Addr::LOCALHOST)),
self.auth_port.unwrap_or(constants::DEFAULT_AUTH_PORT),
);
@@ -556,7 +556,7 @@ mod tests {
assert_eq!(
config.http_address().unwrap(),
SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::UNSPECIFIED,
Ipv4Addr::LOCALHOST,
constants::DEFAULT_HTTP_RPC_PORT
))
);

View File

@@ -203,7 +203,7 @@ impl AuthServerConfigBuilder {
pub fn build(self) -> AuthServerConfig {
AuthServerConfig {
socket_addr: self.socket_addr.unwrap_or_else(|| {
SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), constants::DEFAULT_AUTH_PORT)
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), constants::DEFAULT_AUTH_PORT)
}),
secret: self.secret,
server_config: self.server_config.unwrap_or_else(|| {

View File

@@ -1030,7 +1030,7 @@ impl RpcServerConfig {
/// Configures the [SocketAddr] of the http server
///
/// Default is [Ipv4Addr::UNSPECIFIED] and [DEFAULT_HTTP_RPC_PORT]
/// Default is [Ipv4Addr::LOCALHOST] and [DEFAULT_HTTP_RPC_PORT]
pub fn with_http_address(mut self, addr: SocketAddr) -> Self {
self.http_addr = Some(addr);
self
@@ -1038,7 +1038,7 @@ impl RpcServerConfig {
/// Configures the [SocketAddr] of the ws server
///
/// Default is [Ipv4Addr::UNSPECIFIED] and [DEFAULT_WS_RPC_PORT]
/// Default is [Ipv4Addr::LOCALHOST] and [DEFAULT_WS_RPC_PORT]
pub fn with_ws_address(mut self, addr: SocketAddr) -> Self {
self.ws_addr = Some(addr);
self
@@ -1118,14 +1118,13 @@ impl RpcServerConfig {
/// If both are on the same port, they are combined into one server.
async fn build_ws_http(&mut self) -> Result<WsHttpServer, RpcError> {
let http_socket_addr = self.http_addr.unwrap_or(SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::UNSPECIFIED,
Ipv4Addr::LOCALHOST,
DEFAULT_HTTP_RPC_PORT,
)));
let ws_socket_addr = self.ws_addr.unwrap_or(SocketAddr::V4(SocketAddrV4::new(
Ipv4Addr::UNSPECIFIED,
DEFAULT_WS_RPC_PORT,
)));
let ws_socket_addr = self
.ws_addr
.unwrap_or(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, DEFAULT_WS_RPC_PORT)));
// If both are configured on the same port, we combine them into one server.
if self.http_addr == self.ws_addr &&