import location
import sqlalchemy
-from sqlalchemy import Boolean, Column, DateTime, Double, ForeignKey, Integer, Text
+from sqlalchemy import ARRAY, Boolean, Column, DateTime, Double, ForeignKey, Integer, Text
+from sqlalchemy.dialects.postgresql import INET
from . import base
from . import database
asn = Column(Integer)
+ # Addresses IPv6
+
+ addresses_ipv6 = Column(ARRAY(INET), nullable=False, default=[])
+
+ def supports_ipv6(self):
+ """
+ Returns True if this mirror supports IPv6
+ """
+ if self.addresses_ipv6:
+ return True
+
+ return False
+
+ # Addresses IPv4
+
+ addresses_ipv4 = Column(ARRAY(INET), nullable=False, default=[])
+
+ def supports_ipv4(self):
+ """
+ Returns True if this mirror supports IPv4
+ """
+ if self.addresses_ipv4:
+ return True
+
+ return False
+
async def _update_country_code_and_asn(self):
"""
Updates the country code of this mirror
# Raise anything else
raise e
- for family, address in addresses:
- # Extract the address
- address = address[0]
+ print(addresses)
- # Lookup the address
+ # Store all IP addresses
+ self.addresses_ipv6 = [
+ address[0] for family, address in addresses if family == socket.AF_INET6
+ ]
+ self.addresses_ipv4 = [
+ address[0] for family, address in addresses if family == socket.AF_INET
+ ]
+
+ # Lookup the country code and ASN
+ for address in self.addresses_ipv6 + self.addresses_ipv4:
network = self.backend.mirrors.location.lookup(address)
+
+ # Try the next IP address if we didn't find any data
if not network or not network.country_code:
continue