Skip to content

Commit

Permalink
Fix: move "server_id" key in API to server-level (#41)
Browse files Browse the repository at this point in the history
With the recent change to make server_ids independent of IPv4/IPv6,
there is no longer any need to add them twice in the JSON blob.

While at it remove unused fields too.
  • Loading branch information
TrueBrain authored Jul 10, 2021
1 parent 0ab492d commit c52c48f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions master_server/database/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ def _get_server_id(server_ip, server_port):
def _convert_server_to_dict(server):
entry = {
"info": {},
"time_first_seen": server.time_first_seen,
"time_last_seen": server.time_last_seen,
"online": server.online,
}

if server.ipv4:
entry["ipv4"] = {
"ip": str(server.ipv4.ip),
"port": server.ipv4.port,
"server_id": _get_server_id(server.ipv4.ip, server.ipv4.port),
}
entry["server_id"] = _get_server_id(server.ipv4.ip, server.ipv4.port)

if server.ipv6:
entry["ipv6"] = {
"ip": str(server.ipv6.ip),
"port": server.ipv6.port,
"server_id": _get_server_id(server.ipv6.ip, server.ipv6.port),
}
# Make sure the IPv4 variant always wins.
if "server_id" not in entry:
entry["server_id"] = _get_server_id(server.ipv6.ip, server.ipv6.port)

for name, _ in getmembers(InfoMap, lambda o: isinstance(o, Attribute)):
if name == "newgrfs":
Expand Down
4 changes: 1 addition & 3 deletions master_server/database/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def get_server_info_for_web(self, server_id):

entry = {
"info": info,
"online": True,
"server_id": server_id,
}

direct_ipv4_str = await self._redis.get(f"gc-direct-ipv4:{server_id}")
Expand All @@ -142,7 +142,6 @@ async def get_server_info_for_web(self, server_id):
entry["ipv4"] = {
"ip": direct_ipv4["ip"],
"port": direct_ipv4["port"],
"server_id": server_id,
}

direct_ipv6_str = await self._redis.get(f"gc-direct-ipv6:{server_id}")
Expand All @@ -151,7 +150,6 @@ async def get_server_info_for_web(self, server_id):
entry["ipv6"] = {
"ip": direct_ipv6["ip"],
"port": direct_ipv6["port"],
"server_id": server_id,
}

return entry
Expand Down

0 comments on commit c52c48f

Please sign in to comment.