# Path: bts_tools/network_utils.py
# @copy_cached_value
# @cachetools.func.lfu_cache(8192)
# def get_geoip_info(ip_addr):
#     try:
#         cred = core.config.get('credentials', {})['geoip2']  # check that we have a geoip2 section in config.yaml
#         client = geoip2.webservice.Client(cred['user'], cred['password'])
#     except KeyError as e:
#         raise ValueError('No geoip2 user and password defined in config.yaml') from e
# 
# 
#     log.debug('getting geoip2 info for for {}'.format(ip_addr))
#     response = client.city(ip_addr)
# 
#     pt = {'country': response.country.name,
#           'country_iso': response.country.iso_code,
#           'lat': response.location.latitude,
#           'lon': response.location.longitude
#           }
# 
#     log.debug('  {} -- {} ({}, {})'.format(ip_addr, pt['country'], pt['lat'], pt['lon']))
#     return pt
# 
# @cachetools.func.ttl_cache(maxsize=8192, ttl=3600)
# def resolve_dns(host):
#     if ':' in host:
#         ip, port = host.split(':')
#         return '%s:%s' % (resolve_dns(ip), port)
#     try:
#         return socket.gethostbyname(host)
#     except socket.gaierror:
#         log.warning('Cannot resolve host "{}"'.format(host))
#         return host


from bts_tools.network_utils import get_geoip_info, resolve_dns
from collections import defaultdict, deque
import socket
import time
import threading
import logging
        for i, v in enumerate(l):
            l[i] = ((l[i][0], l[i][1])
                    if l[i][0] < offset
                    else (l[i][0] - offset, l[i][1] + ncols))

    return items, attrs


def get_seeds_as_peers(chain):
    return [{'addr': d[0], 'provided_by': d[2]} for d in SEED_NODES[chain]]


def get_seeds_view_data(chain, cached=False):
    seed_nodes = SEED_NODES[chain]

    if cached:
        seed_status = check_all_seeds_cached(chain)
    else:
        seed_status = check_all_seeds(chain)

    success = lambda s: '<div class="btn btn-xs btn-success">{}</div>'.format(s)
    warning = lambda s: '<div class="btn btn-xs btn-warning">{}</div>'.format(s)
    error = lambda s: '<div class="btn btn-xs btn-danger">{}</div>'.format(s)

    def get_flag(country):
        return '<i class="famfamfam-flag-%s" style="margin:0 8px 0 0;"></i>' % country

    def add_flag(country, ip):
        if not country:
            try:

# Path: bts_tools/network_utils.py
# @copy_cached_value
# @cachetools.func.lfu_cache(8192)
# def get_geoip_info(ip_addr):
#     try:
#         cred = core.config.get('credentials', {})['geoip2']  # check that we have a geoip2 section in config.yaml
#         client = geoip2.webservice.Client(cred['user'], cred['password'])
#     except KeyError as e:
#         raise ValueError('No geoip2 user and password defined in config.yaml') from e
# 
# 
#     log.debug('getting geoip2 info for for {}'.format(ip_addr))
#     response = client.city(ip_addr)
# 
#     pt = {'country': response.country.name,
#           'country_iso': response.country.iso_code,
#           'lat': response.location.latitude,
#           'lon': response.location.longitude
#           }
# 
#     log.debug('  {} -- {} ({}, {})'.format(ip_addr, pt['country'], pt['lat'], pt['lon']))
#     return pt
# 
# @cachetools.func.ttl_cache(maxsize=8192, ttl=3600)
# def resolve_dns(host):
#     if ':' in host:
#         ip, port = host.split(':')
#         return '%s:%s' % (resolve_dns(ip), port)
#     try:
#         return socket.gethostbyname(host)
#     except socket.gaierror:
#         log.warning('Cannot resolve host "{}"'.format(host))
#         return host


# Path: bts_tools/seednodes.py
from bts_tools.network_utils import get_geoip_info, resolve_dns
from collections import defaultdict, deque
import socket
import time
import threading
import logging

        for i, v in enumerate(l):
            l[i] = ((l[i][0], l[i][1])
                    if l[i][0] < offset
                    else (l[i][0] - offset, l[i][1] + ncols))

    return items, attrs


def get_seeds_as_peers(chain):
    return [{'addr': d[0], 'provided_by': d[2]} for d in SEED_NODES[chain]]


def get_seeds_view_data(chain, cached=False):
    seed_nodes = SEED_NODES[chain]

    if cached:
        seed_status = check_all_seeds_cached(chain)
    else:
        seed_status = check_all_seeds(chain)

    success = lambda s: '<div class="btn btn-xs btn-success">{}</div>'.format(s)
    warning = lambda s: '<div class="btn btn-xs btn-warning">{}</div>'.format(s)
    error = lambda s: '<div class="btn btn-xs btn-danger">{}</div>'.format(s)

    def get_flag(country):
        return '<i class="famfamfam-flag-%s" style="margin:0 8px 0 0;"></i>' % country

    def add_flag(country, ip):
        if not country:
            try:

                geo = get_geoip_info(resolve_dns(ip).split(':')[0])