Skip to content

Commit 90fefcd

Browse files
committed
frontend _id
1 parent 876cb7a commit 90fefcd

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

frontend/app.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def check_clients_ok():
2525
else:
2626
client['check_ok'] = True
2727

28+
def get_id(host, port):
29+
return 'client_{}_{}'.format(host, port)
30+
2831

2932
@app.route('/')
3033
def index():
@@ -57,7 +60,7 @@ def fake_data():
5760
client = random.choice(client_types)
5861
status = random.choice(statuses)
5962
check_ok = random.choice([True, False])
60-
_id = 'client_{}'.format(port)
63+
_id = 'client_127.0.0.1_{}'.format(port)
6164
data = {
6265
'client_type': client,
6366
'_id': _id,
@@ -82,14 +85,16 @@ def index_fe():
8285
def keep_alive():
8386
global global_state
8487
data = json.loads(request.data)
85-
_id = data['_id']
88+
host = request.remote_addr
89+
port = data['port']
90+
_id = get_id(host, port)
8691
if _id not in global_state['clients']:
8792
global_state['clients'][_id] = {
8893
'joined_at': datetime.now().strftime('%Y-%m-%d %H:%m'),
8994
'client_type': data['client_type'],
90-
'port': data['port'],
95+
'port': port,
9196
'check_ok': True,
92-
'host': data['host'],
97+
'host': host,
9398
'last_ping': datetime.now()
9499
}
95100
global_state['clients'][_id].update({'state': data['state']})
@@ -112,13 +117,13 @@ def get_state():
112117
global global_state
113118
host = request.remote_addr
114119
data = json.loads(request.data)
115-
# TODO: Conform _id from real host
116-
_id = data['_id']
120+
port = data['port']
121+
_id = get_id(host, port)
117122
if _id not in global_state['clients']:
118123
global_state['clients'][_id] = {
119124
'joined_at': datetime.now().strftime('%Y-%m-%d %H:%m'),
120125
'client_type': data['client_type'],
121-
'port': data['port'],
126+
'port': port,
122127
'check_ok': True,
123128
'host': host,
124129
'last_ping': datetime.now()

0 commit comments

Comments
 (0)