dont give up on localnodes if there is no network
This commit is contained in:
parent
7430d1b483
commit
74d5b21df0
1 changed files with 23 additions and 10 deletions
|
@ -8,6 +8,7 @@ import socket
|
|||
import struct
|
||||
import thread
|
||||
from threading import Thread
|
||||
import time
|
||||
|
||||
from utils import valid, get_public_ipv6, get_local_ipv4, get_interface
|
||||
from settings import preferences, server, USER_ID, sk
|
||||
|
@ -63,6 +64,8 @@ class LocalNodesBase(Thread):
|
|||
pass
|
||||
|
||||
def receive(self):
|
||||
while self._active:
|
||||
try:
|
||||
s = self.get_socket()
|
||||
s.bind(('', self._PORT))
|
||||
while self._active:
|
||||
|
@ -72,6 +75,10 @@ class LocalNodesBase(Thread):
|
|||
data = self.verify(data)
|
||||
if data:
|
||||
self.update_node(data)
|
||||
except:
|
||||
logger.debug('receive failed. restart later', exc_info=1)
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
def verify(self, data):
|
||||
try:
|
||||
|
@ -138,7 +145,10 @@ class LocalNodes4(LocalNodesBase):
|
|||
sockaddr = (self._BROADCAST, self._PORT)
|
||||
s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.setsockopt (socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, self._TTL)
|
||||
try:
|
||||
s.sendto(packet + '\0', sockaddr)
|
||||
except:
|
||||
logger.debug('LocalNodes4.send failed', exc_info=1)
|
||||
s.close()
|
||||
|
||||
def get_socket(self):
|
||||
|
@ -165,7 +175,10 @@ class LocalNodes6(LocalNodesBase):
|
|||
(family, socktype, proto, canonname, sockaddr) = addr
|
||||
s = socket.socket(family, socktype, proto)
|
||||
s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_HOPS, ttl)
|
||||
try:
|
||||
s.sendto(packet + '\0', sockaddr)
|
||||
except:
|
||||
logger.debug('LocalNodes6.send failed', exc_info=1)
|
||||
s.close()
|
||||
|
||||
def get_socket(self):
|
||||
|
|
Loading…
Reference in a new issue