Skip to content

Commit 2f876c6

Browse files
committed
Fix #125 for Linux.
Still allows the local node to connect to itself over the local network.
1 parent 7de9e23 commit 2f876c6

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/Network/Clients.nim

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,20 @@ proc add*(
288288
networkFunctions: NetworkLibFunctionBox
289289
) {.forceCheck: [], async.} =
290290
#Get the IP.
291-
var addressParts: seq[string] = @[]
291+
var
292+
address: string
293+
addressParts: seq[string]
292294
try:
293-
addressParts = socket.getPeerAddr()[0].split(".")
295+
address = socket.getPeerAddr()[0]
296+
297+
if (socket.getLocalAddr()[0] == address) and (address != "127.0.0.1"):
298+
try:
299+
socket.close()
300+
except Exception as e:
301+
doAssert(false, "Failed to close a socket: " & e.msg)
302+
return
303+
304+
addressParts = address.split(".")
294305
except OSError as e:
295306
doAssert(false, "Failed to get a peer's address: " & e.msg)
296307

0 commit comments

Comments
 (0)