chia-blockchain/src/server/upnp.py

19 lines
610 B
Python
Raw Normal View History

import logging
import miniupnpc
log = logging.getLogger(__name__)
2020-06-04 02:35:49 +03:00
def upnp_remap_port(port):
log.info(f"Attempting to enable UPnP (open up port {port})")
try:
upnp = miniupnpc.UPnP()
2020-07-06 07:28:25 +03:00
upnp.discoverdelay = 30
upnp.discover()
upnp.selectigd()
upnp.addportmapping(port, "TCP", upnp.lanaddr, port, "chia", "")
2020-12-11 10:27:03 +03:00
log.info(f"Port {port} opened with UPnP. lanaddr {upnp.lanaddr} external: {upnp.externalipaddress()}")
except Exception:
2020-12-11 10:27:03 +03:00
log.info("UPnP failed. This is not required to run chia, but it allows incoming connections from other peers.")