Skip to content

Commit

Permalink
Port UPnPUtil to jupnp
Browse files Browse the repository at this point in the history
This uses the jupnp stack to discover and map ports.
It does not use jupnp's built-in PortMappingListener due to
shortcomings:

1. We need to determine which address to request mappings to dynamically
   instead of specifying the address to map in advance
   since we can only know which address is appropriate after we
   determine which interface has an IGD on.
   We instead use the address that the IGD was discovered from.
   This may not be the most preferred address to use, but it does
   guarantee that it works with routers that reject requests to map ports
   to addresses that the request didn't come from.
2. We need some additional callbacks to be able to wait for some device
   to be discovered and some port to be mapped in order to present
   appropriate error messages.
3. My router doesn't support InternetGatewayDevice:1,
   only InternetGatewayDevice:2, so I needed to add additional checks.
   This is fine because PortMappingAdd is supported on both.

The jupnp data model isn't ideal, since it broadcasts from every IPv4
address and some routers (i.e. mine) will respond to discovery
broadcasts from every address it has, including a few IPv6 ones,
and it assumes that if it gets a response from a different address
then the UPnP device has changed address and so is a new device,
triggering device removed and new device callbacks,
which we have to request a new port mapping for because we can't tell if
it's a new device or not.

As a result, port mapping involves a number of port mapping requests
equal to the number of non-loopback IPv4 addresses you have
multiplied by the number of addresses the IGD responds from.
  • Loading branch information
fishface60 committed Dec 28, 2024
1 parent be26a55 commit 35fa524
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 167 deletions.
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ spotless {
exclude '**/JTextAreaAppender.java'
exclude 'src/main/java/net/rptools/maptool/client/ui/themes/Flat*ContrastIJTheme.java'
exclude 'src/main/java/net/rptools/maptool/client/ui/themes/Utils.java'
exclude 'src/main/java/net/rptools/maptool/util/upnp/PortMappingListener.java'
}
}
}
Expand Down Expand Up @@ -381,7 +382,13 @@ dependencies {
// find running instances in LAN
implementation 'net.tsc.servicediscovery:servicediscovery:1.0.b5'

//maybe replace with jupnp
implementation 'javax.servlet:servlet-api:2.4'
implementation 'org.eclipse.jetty:jetty-client:9.4.56.v20240826'
implementation 'org.eclipse.jetty:jetty-server:9.4.56.v20240826'
implementation 'org.eclipse.jetty:jetty-servlet:9.4.56.v20240826'
implementation 'org.jupnp:org.jupnp:3.0.2'
implementation 'org.jupnp:org.jupnp.support:3.0.2'
// upnplib still used for by SysInfoProvider
implementation 'commons-jxpath:commons-jxpath:1.3'
implementation 'net.sbbi.upnp:upnplib:1.0.9-nodebug'

Expand Down
Loading

0 comments on commit 35fa524

Please sign in to comment.