use mdns for local peer discovery
This commit is contained in:
parent
bea7c57515
commit
417195cfd1
7 changed files with 132 additions and 259 deletions
|
|
@ -123,9 +123,9 @@ def getUsers(data):
|
|||
users.append(u.json())
|
||||
ids.add(u.id)
|
||||
if state.nodes:
|
||||
for id in state.nodes._local._nodes:
|
||||
for id in state.nodes.local:
|
||||
if id not in ids:
|
||||
n = state.nodes._local._nodes[id].copy()
|
||||
n = state.nodes.local[id].copy()
|
||||
n['online'] = True
|
||||
n['name'] = n['username']
|
||||
users.append(n)
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ class User(db.Model):
|
|||
if not user:
|
||||
user = cls(id=id, peered=False, online=False)
|
||||
user.info = {}
|
||||
if state.nodes and state.nodes._local and id in state.nodes._local._nodes:
|
||||
user.info['local'] = state.nodes._local._nodes[id]
|
||||
if state.nodes and state.nodes.local and id in state.nodes.local:
|
||||
user.info['local'] = state.nodes.local[id]
|
||||
user.info['username'] = user.info['local']['username']
|
||||
user.update_name()
|
||||
user.save()
|
||||
|
|
@ -598,3 +598,21 @@ def update_user_peering(user_id, peered, username=None):
|
|||
if u:
|
||||
u.update_peering(peered, username)
|
||||
|
||||
def remove_local_info(id):
|
||||
with db.session():
|
||||
u = User.get(id)
|
||||
if u and 'local' in u.info:
|
||||
del u.info['local']
|
||||
u.save()
|
||||
u.trigger_status()
|
||||
|
||||
def add_local_info(data):
|
||||
with db.session():
|
||||
u = User.get(data['id'])
|
||||
if u:
|
||||
if u.info['username'] != data['username']:
|
||||
u.info['username'] = data['username']
|
||||
u.update_name()
|
||||
u.info['local'] = data
|
||||
u.save()
|
||||
state.nodes.queue('add', u.id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue