Package utils
Class InterfaceToIp
java.lang.Object
utils.InterfaceToIp
Resolves the process-wide bind address (
babel.address) the node binds
and announces on.
Why this matters for the demo: for multicast auto-discovery (and for peers
to reach each other at all) every node must advertise a reachable
address — not 127.0.0.1 and not 0.0.0.0. So the demo never
silently defaults to loopback. Instead resolveBindAddress(Properties)
picks an address in this order:
- an explicit
babel.address(the user's override always wins — including loopback, e.g.babel.address=127.0.0.1for running several nodes on one disconnected machine); - the IPv4 address of the interface named in
babel.interface(e.g.babel.interface=en0on macOS,eth0on Linux); - experimental auto-detection: the routable IPv4 of the sole
real interface — up, non-loopback, non-point-to-point, non-virtual, with a
non-link-local IPv4, and whose name is not a bridge / VM / container / VPN
adapter (
isLikelyNonPhysical(java.net.NetworkInterface)). If several real interfaces qualify it refuses to guess and lists them; if only bridges/VPNs (or nothing) exist it asks the operator to choose.
babel.interface or babel.address explicitly. The auto-detection
heuristic is name-based and best-effort — an explicit babel.interface /
babel.address always wins and bypasses it.
The parameter keys babel.address / babel.interface /
babel.port are owned by babel-core (Babel.PAR_DEFAULT_ADDRESS /
Babel.PAR_DEFAULT_INTERFACE / Babel.PAR_DEFAULT_PORT); this
class references those constants rather than re-declaring the literals.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringAuto-detect a reachable bind address: the routable IPv4 of the sole real (non-loopback, up, non-virtual, non-p2p, non-bridge/VM/VPN) interface.static StringLogs every network interface and its IPv4 addresses (with up/loopback/virtual/ point-to-point flags) to help diagnose a wrong auto-selection.static StringgetIpOfInterface(String interfaceName) Returns the first non-loopback IPv4 address ofinterfaceName, or null if it has none / does not exist.static StringresolveBindAddress(Properties props) Resolve the process-wide bind address intobabel.address(see the class javadoc for the precedence).
-
Method Details
-
getIpOfInterface
Returns the first non-loopback IPv4 address ofinterfaceName, or null if it has none / does not exist.- Throws:
SocketException
-
autoDetectAddress
Auto-detect a reachable bind address: the routable IPv4 of the sole real (non-loopback, up, non-virtual, non-p2p, non-bridge/VM/VPN) interface. Returns null if none — or more than one — qualifies.- Throws:
SocketException
-
resolveBindAddress
public static String resolveBindAddress(Properties props) throws SocketException, InvalidParameterException Resolve the process-wide bind address intobabel.address(see the class javadoc for the precedence). On returnbabel.addressis guaranteed to be set to a concrete IPv4 address.- Returns:
- a short human-readable description of how the address was chosen
(for startup logging), e.g.
"explicit babel.address","interface en0", or"auto-detected interface en0". - Throws:
InvalidParameterException- if a namedbabel.interfacehas no usable address, or no address could be determined at all — in which case the operator must passbabel.interfaceorbabel.addresson the command line.SocketException
-
describeInterfaces
Logs every network interface and its IPv4 addresses (with up/loopback/virtual/ point-to-point flags) to help diagnose a wrong auto-selection. Written to the log file; never throws.
-