Package com.frostwire.jlibtorrent
Enum Class PortmapProtocol
- All Implemented Interfaces:
Serializable,Comparable<PortmapProtocol>,Constable
Protocol for port mapping with UPnP and NAT-PMP.
PortmapProtocol identifies which port mapping protocol to use when
automatically opening ports on the router. UPnP (Universal Plug and Play) and
NAT-PMP (Network Address Translation Protocol Mapping) allow applications to
request the router to forward incoming connections to the application's port.
Understanding Port Mapping:
Port mapping enables incoming peer connections through NAT/firewall:
- TCP: BitTorrent peer connections (data transfer)
- UDP: DHT and uTP protocol (peer discovery, alternative transport)
- NONE: No port mapping attempted (static port or manual config)
Port Mapping Protocols:
NONE: - No port mapping is attempted - Use if router doesn't support mapping or you manage ports manually - May reduce incoming connections if behind NAT TCP: - Map TCP port for BitTorrent peer connections - Allows incoming peers to connect for block transfers - Primary protocol for download/upload UDP: - Map UDP port for DHT and uTP - Enables direct peer discovery via DHT - Alternative transport protocol (faster for some scenarios)
Configuring Port Mapping:
// Example: Enable UPnP for both TCP and UDP
SettingsPack settings = new SettingsPack();
settings.setString("upnp_ignore_nonrouters", "true");
settings.setInteger("upnp_lsd_timeout", 250);
// Port mapping happens automatically if enabled in settings
// Use PortmapProtocol via portmap_error_alert to diagnose issues
Port Mapping Error Handling:
sm.addListener(new AlertListener() {
public int[] types() {
return new int[] {AlertType.PORTMAP_ERROR.swig()};
}
public void alert(Alert<?> alert) {
PortmapErrorAlert a = (PortmapErrorAlert) alert;
PortmapProtocol protocol = a.mapProtocol();
System.err.println("Port mapping failed for: \" + protocol);
// TCP mapping failed: no incoming peer connections possible
// UDP mapping failed: DHT and uTP may not work
}
});
Performance Notes:
- Port mapping discovery takes 1-5 seconds on startup
- Improves connectivity significantly on NAT'd networks
- Not available if router doesn't support UPnP/NAT-PMP
- Manual port forwarding always works as alternative
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionstatic PortmapProtocolfromSwig(int swigValue) intswig()static PortmapProtocolReturns the enum constant of this class with the specified name.static PortmapProtocol[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NONE
-
TCP
-
UDP
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
swig
public int swig() -
fromSwig
-