forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: [torrust#878] extract net section in core config section
- Loading branch information
1 parent
4a39d65
commit 36c7ed1
Showing
8 changed files
with
99 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::net::{IpAddr, Ipv4Addr}; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[allow(clippy::struct_excessive_bools)] | ||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] | ||
pub struct Network { | ||
/// The external IP address of the tracker. If the client is using a | ||
/// loopback IP address, this IP address will be used instead. If the peer | ||
/// is using a loopback IP address, the tracker assumes that the peer is | ||
/// in the same network as the tracker and will use the tracker's IP | ||
/// address instead. | ||
#[serde(default = "Network::default_external_ip")] | ||
pub external_ip: Option<IpAddr>, | ||
|
||
/// Weather the tracker is behind a reverse proxy or not. | ||
/// If the tracker is behind a reverse proxy, the `X-Forwarded-For` header | ||
/// sent from the proxy will be used to get the client's IP address. | ||
#[serde(default = "Network::default_on_reverse_proxy")] | ||
pub on_reverse_proxy: bool, | ||
} | ||
|
||
impl Default for Network { | ||
fn default() -> Self { | ||
Self { | ||
external_ip: Self::default_external_ip(), | ||
on_reverse_proxy: Self::default_on_reverse_proxy(), | ||
} | ||
} | ||
} | ||
|
||
impl Network { | ||
#[allow(clippy::unnecessary_wraps)] | ||
fn default_external_ip() -> Option<IpAddr> { | ||
Some(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))) | ||
} | ||
|
||
fn default_on_reverse_proxy() -> bool { | ||
false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters