def set_address(self, address):
address = address.strip()
# Do some basic validation of the address
# Relays must all have IPv4 addresses, so just checking for IPv4 is ok
if len(address) < 7 or len(address) > 15:
logging.warning("Bad address length %d: %s", len(address), address)
return False
if not all(c in (string.digits + '.') for c in address):
logging.warning("Bad address characters: %s", address)
return False
# We could check each component is between 0 and 255, but that's overkill
# Are we replacing an existing address?
if self.address is not None:
if self.address != address:
logging.warning("Replacing address %s with %s", self.address, address)
else:
logging.debug("Duplicate address received %s", address)
self.address = address
return True
评论列表
文章目录