UPNP has an addAnyPortMapping method where the gateway selects a free high-number port, avoiding collisions with an existing port.
It seems PMP has an equivalent:
If the client would prefer to have a high-numbered "anonymous"
external port assigned, then it should set the Requested External
Port to zero, which indicates to the gateway that it should allocate
a high-numbered port of its choosing.
Given a blank API it'd be worth considering client.map(port, [opts]) to auto-assign the public port, but this already has defined semantics (sets both private and public ports). If backwards-compatibility is required, perhaps setting publicPort = 'auto' would work? Happy to send a PR if you're interested.
UPNP has an
addAnyPortMappingmethod where the gateway selects a free high-number port, avoiding collisions with an existing port.It seems PMP has an equivalent:
Given a blank API it'd be worth considering
client.map(port, [opts])to auto-assign the public port, but this already has defined semantics (sets both private and public ports). If backwards-compatibility is required, perhaps settingpublicPort = 'auto'would work? Happy to send a PR if you're interested.