Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide default values information in generated config file, better handle logging default parameters #3053

Closed
wants to merge 9 commits into from
76 changes: 53 additions & 23 deletions config/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,41 +258,71 @@ fn comments() -> HashMap<String, String> {
);

retval.insert(
"[server.p2p_config.capabilities]".to_string(),
"#If the seeding type is List, the list of peers to connect to can
#be specified as follows:
#seeds = [\"192.168.0.1:3414\",\"192.168.0.2:3414\"]

#hardcoded peer lists for allow/deny
#will *only* connect to peers in allow list
#peers_allow = [\"192.168.0.1:3414\", \"192.168.0.2:3414\"]
#will *never* connect to peers in deny list
#peers_deny = [\"192.168.0.3:3414\", \"192.168.0.4:3414\"]
#a list of preferred peers to connect to
#peers_preferred = [\"192.168.0.1:3414\",\"192.168.0.2:3414\"]

"ban_window".to_string(),
"
#how long a banned peer should stay banned
#ban_window = 10800
"
.to_string(),
);

retval.insert(
"peer_max_inbound_count".to_string(),
"
#maximum number of inbound peer connections
#peer_max_inbound_count = 128
"
.to_string(),
);

retval.insert(
"peer_max_outbound_count".to_string(),
"
#maximum number of outbound peer connections
#peer_max_outbound_count = 8
"
.to_string(),
);

retval.insert(
"peer_min_preferred_outbound_count".to_string(),
"
#preferred minimum number of outbound peers (we'll actively keep trying to add peers
#until we get to at least this number)
#peer_min_preferred_outbound_count = 8
"
.to_string(),
);

retval.insert(
"peer_listener_buffer_count".to_string(),
"
#amount of incoming connections temporarily allowed to exceed peer_max_inbound_count
#peer_listener_buffer_count = 8

# 15 = Bit flags for FULL_NODE
#This structure needs to be changed internally, to make it more configurable
"
.to_string(),
);

retval.insert(
"dandelion_peer".to_string(),
"
# A preferred dandelion_peer, mainly used for testing dandelion
# dandelion_peer = \"10.0.0.1:13144\"
"
.to_string(),
);

retval.insert(
"capabilities".to_string(),
"
#If the seeding type is List, the list of peers to connect to can
#be specified as follows:
#seeds = [\"192.168.0.1:3414\",\"192.168.0.2:3414\"]

#hardcoded peer lists for allow/deny
#will *only* connect to peers in allow list
#peers_allow = [\"192.168.0.1:3414\", \"192.168.0.2:3414\"]
#will *never* connect to peers in deny list
#peers_deny = [\"192.168.0.3:3414\", \"192.168.0.4:3414\"]
#a list of preferred peers to connect to
#peers_preferred = [\"192.168.0.1:3414\",\"192.168.0.2:3414\"]

# 15 = Bit flags for FULL_NODE
#This structure needs to be changed internally, to make it more configurable
"
.to_string(),
);
Expand Down Expand Up @@ -477,7 +507,7 @@ fn comments() -> HashMap<String, String> {
}

fn get_key(line: &str) -> String {
if line.contains("[") && line.contains("]") {
if line.contains("[") && line.contains("]") && !line.contains("=") {
return line.to_owned();
} else if line.contains("=") {
return line.split("=").collect::<Vec<&str>>()[0].trim().to_owned();
Expand Down
22 changes: 22 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ pub fn initial_setup_server(chain_type: &global::ChainTypes) -> Result<GlobalCon
}
}

fn comment_values(orig: String) -> String {
let lines: Vec<&str> = orig.split("\n").collect();
let mut out_lines = vec![];
for l in lines {
// Comment lines with values (not starting by #) that don't define paths
if l.contains("=") && !l.starts_with("#") && !l.contains("root") && !l.contains("path") {
let mut commented = l.to_owned();
commented.insert_str(0, "#");
out_lines.push(commented.to_owned());
} else {
out_lines.push(l.to_owned());
}
out_lines.push("\n".to_owned());
}
let mut ret_val = String::from("");
for l in out_lines {
ret_val.push_str(&l);
}
ret_val.to_owned()
}

/// Returns the defaults, as strewn throughout the code
impl Default for ConfigMembers {
fn default() -> ConfigMembers {
Expand Down Expand Up @@ -297,6 +318,7 @@ impl GlobalConfig {
pub fn write_to_file(&mut self, name: &str) -> Result<(), ConfigError> {
let conf_out = self.ser_config()?;
let conf_out = insert_comments(conf_out);
let conf_out = comment_values(conf_out);
let mut file = File::create(name)?;
file.write_all(conf_out.as_bytes())?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion p2p/src/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl Peers {

/// We have enough outbound connected peers
pub fn enough_outbound_peers(&self) -> bool {
self.peer_outbound_count() >= self.config.peer_min_preferred_outbound_count()
self.peer_outbound_count() >= self.config.peer_min_preferred_outbound_count
}

/// Removes those peers that seem to have expired
Expand Down
2 changes: 1 addition & 1 deletion p2p/src/serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl Server {
/// duplicate connections, malicious or not.
fn check_undesirable(&self, stream: &TcpStream) -> bool {
if self.peers.peer_inbound_count()
>= self.config.peer_max_inbound_count() + self.config.peer_listener_buffer_count()
>= self.config.peer_max_inbound_count + self.config.peer_listener_buffer_count
{
debug!("Accepting new connection will exceed peer limit, refusing connection.");
return true;
Expand Down
Loading