lan can now properly connect

This commit is contained in:
Kevin Froman 2020-03-23 03:39:57 -05:00
parent 2c8f1fdf99
commit b5e57da191
4 changed files with 10 additions and 13 deletions

View File

@ -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()

View File

@ -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)

View File

@ -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):

View File

@ -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