Skip to content

Commit

Permalink
Improve worker IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
gbenson committed Nov 25, 2023
1 parent 9c76151 commit 81d392e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .tfstate
Submodule .tfstate updated from 4a7c93 to b600f2
14 changes: 11 additions & 3 deletions listener/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import re
import socket

from abc import ABC, abstractmethod
from base64 import b64encode
Expand Down Expand Up @@ -226,14 +227,14 @@ def worker_id(self):

result = self.source_ip
if ip_address(result) not in self.config.home_network:
return result
return gethostbyaddr(result)

for word in self.miner_status["cpu.brand"].split():
name = self.config.home_hostnames_by_cpu.get(word)
if name is not None:
return name
return f"{name}.nx"

return result
return gethostbyaddr(result)

LIST_SUFFIXES = {
"hashrate.total": ("10s", "1m", "15m"),
Expand Down Expand Up @@ -312,6 +313,13 @@ def is_in_container_hostname(s):
return re.match(r"^[0-9a-f]{12}$", s) is not None


def gethostbyaddr(ip_address):
try:
return socket.gethostbyaddr(ip_address)[0]
except Exception:
return ip_address


def as_dict(obj):
"""JSON serialization helper.
"""
Expand Down

0 comments on commit 81d392e

Please sign in to comment.