mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-08 14:24:09 -05:00
do not connect to self
This commit is contained in:
@@ -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],
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user