From b5e57da191db7a24cff77b5f1bec1948999f1f5a Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 23 Mar 2020 03:39:57 -0500 Subject: [PATCH] lan can now properly connect --- src/lan/__init__.py | 2 +- src/lan/client/__init__.py | 6 +++--- src/lan/discover.py | 13 +++++-------- src/lan/getip.py | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/lan/__init__.py b/src/lan/__init__.py index 3ba55908..230312df 100644 --- a/src/lan/__init__.py +++ b/src/lan/__init__.py @@ -34,7 +34,7 @@ class LANManager: def start(self): - Thread(target=learn_services, args=[self.peers], daemon=True).start() + Thread(target=learn_services, args=[self.too_many.get(Client)], daemon=True).start() Thread(target=advertise_service, daemon=True).start() Thread(target=self.too_many.get(Client, (self.peers,)).start, daemon=True).start() diff --git a/src/lan/client/__init__.py b/src/lan/client/__init__.py index 1a2ee01c..61f627ef 100644 --- a/src/lan/client/__init__.py +++ b/src/lan/client/__init__.py @@ -22,11 +22,11 @@ from utils.bettersleep import better_sleep class Client: - def __init__(self, peer_list: List): - self.peers = peer_list + def __init__(self): + self.peers = [] return def start(self): while True: - print(1, self.peers) + print(1, self.peers, type(self.peers)) better_sleep(1) diff --git a/src/lan/discover.py b/src/lan/discover.py index 71f74a1d..3f6ed819 100644 --- a/src/lan/discover.py +++ b/src/lan/discover.py @@ -32,7 +32,7 @@ ANNOUNCE_LOOP_SLEEP = 30 -def learn_services(lan_service_list: List): +def learn_services(lan_client): """Take a list to infintely add lan service info to.""" sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) @@ -54,18 +54,15 @@ def learn_services(lan_service_list: List): service_ips = service_ips.replace('onionr-', '').split('-') port = 0 for service in service_ips: - print(service) try: ip_address(service) if not ip_address(service).is_private: raise ValueError + if service in lan_ips: raise ValueError + if service in lan_client.peers: raise ValueError except ValueError: service_ips.remove(service) - continue - # remove our own ips - service_ips = set(lan_ips) ^ set(service_ips) - # remove known ips and add to external list - lan_service_list = list(set(service_ips) ^ set(lan_service_list)) - print('discover', list(lan_service_list)) + p = list(lan_client.peers) + lan_client.peers = list(set(service_ips + p)) def advertise_service(specific_ips=None): diff --git a/src/lan/getip.py b/src/lan/getip.py index f07dd4b7..23f41c64 100644 --- a/src/lan/getip.py +++ b/src/lan/getip.py @@ -29,7 +29,7 @@ for interface in net_if_addrs().keys(): # Don't see benefit in ipv6, so just check for v4 addresses if address[0] == AF_INET: # Mark the address for use in LAN if it is a private address - if IPv4Address(address[1]).is_private: + if IPv4Address(address[1]).is_private and not IPv4Address(address[1]).is_loopback: lan_ips.append(address[1]) # These are more likely to be actual local subnets rather than VPNs