do not connect to self

This commit is contained in:
narodnik
2021-02-23 15:18:51 +01:00
parent d867564a77
commit 7996ed0e24
2 changed files with 28 additions and 8 deletions

View File

@@ -20,6 +20,8 @@ def debug(line):
pass
def process(info, line):
regex_listen = re.compile(
".* Listening on (\d+[.]\d+[.]\d+[.]\d+:\d+)")
regex_inbound_connect = re.compile(
".* Connected inbound \[(\d+[.]\d+[.]\d+[.]\d+:\d+)\]")
regex_outbound_slots = re.compile(
@@ -43,6 +45,9 @@ def process(info, line):
info["status"] = "p2p-run"
elif "Not configured for accepting incoming connections." in line:
info["inbounds"] = ["Disabled"]
elif (match := regex_listen.match(line)) is not None:
address = match.group(1)
info["listen"] = address
elif (match := regex_inbound_connect.match(line)) is not None:
address = match.group(1)
info["inbounds"].append(address)
@@ -106,6 +111,9 @@ def table_format(ninfo):
table_data.append([filename, "", ""])
table_data.append(["", "status", info["status"]])
if "listen" in info:
table_data.append(["", "listen", info["listen"]])
inbounds = info["inbounds"]
if inbounds:
table_data.append(["", "inbounds", inbounds[0],

View File

@@ -92,15 +92,27 @@ impl OutboundSession {
async fn load_address(&self, slot_number: u32) -> NetResult<SocketAddr> {
let hosts = self.p2p().hosts();
let inbound_addr = self.p2p().settings().inbound;
match hosts.load_single().await {
Some(addr) => Ok(addr),
None => {
error!(
"Hosts address pool is empty. Closing connect slot #{}",
slot_number
);
Err(NetError::ServiceStopped)
loop {
match hosts.load_single().await {
Some(addr) => match inbound_addr {
Some(inbound_addr) => {
if inbound_addr != addr {
return Ok(addr);
}
}
None => {
return Ok(addr);
}
},
None => {
error!(
"Hosts address pool is empty. Closing connect slot #{}",
slot_number
);
return Err(NetError::ServiceStopped);
}
}
}
}