2020-06-03 07:13:01 +03:00
|
|
|
import logging
|
2021-03-10 05:27:27 +03:00
|
|
|
|
2020-06-03 07:13:01 +03:00
|
|
|
import miniupnpc
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2020-06-04 02:35:49 +03:00
|
|
|
|
2020-06-03 07:13:01 +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
|
2020-06-03 07:13:01 +03:00
|
|
|
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()}")
|
2020-06-03 07:13:01 +03:00
|
|
|
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.")
|