Skip to content

Commit ff439a8

Browse files
authored
Fix: don't announce a direct-ip if we already know it (#50)
The idea is to only put new information on the stream. Repeating every announcement that the IP is still the same is not useful, and just wasting everyone's time.
1 parent b3287f7 commit ff439a8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

master_server/database/redis.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,11 @@ async def server_online(self, session_key, server_ip, server_port, info):
117117

118118
# Track this IP based on the server_id.
119119
type = "ipv6" if isinstance(server_ip, ipaddress.IPv6Address) else "ipv4"
120-
res = await self._redis.set(
121-
f"gc-direct-{type}:{server_id}", json.dumps({"ip": str(server_ip), "port": server_port}), ex=TTL_SERVER
122-
)
123-
if res > 0:
120+
res = await self._redis.expire(f"gc-direct-{type}:{server_id}", TTL_SERVER)
121+
if res == 0:
122+
await self._redis.set(
123+
f"gc-direct-{type}:{server_id}", json.dumps({"ip": str(server_ip), "port": server_port}), ex=TTL_SERVER
124+
)
124125
await self.add_to_stream(
125126
"new-direct-ip",
126127
{

0 commit comments

Comments
 (0)