Skip to content

Commit 041cb79

Browse files
authored
Revert #52 (egress functionality) (#63)
1 parent b810757 commit 041cb79

File tree

6 files changed

+4
-159
lines changed

6 files changed

+4
-159
lines changed

README.md

-12
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,6 @@ UUID uuid = gen.generate();
7373
UUID anotherUuid = gen.generate();
7474
```
7575

76-
If your machine has a standard IP networking setup, the `Generators.egressTimeBasedGenerator` (added in JUG 4.1)
77-
factory method will try to determine which network interface corresponds to the default route for
78-
all outgoing network traffic, and use that for creating a time based generator.
79-
This is likely a good choice for common usage scenarios if you want a version 1 UUID generator, but unfortunately
80-
is known not to work reliably on some platforms (MacOS seems to have some issues).
81-
82-
```java
83-
TimeBasedGenerator gen = Generators.egressTimeBasedGenerator();
84-
UUID uuid = gen.generate();
85-
UUID anotherUuid = gen.generate();
86-
```
87-
8876
Generators are fully thread-safe, so a single instance may be shared among multiple threads.
8977

9078
Javadocs for further information can be found from [Project Wiki](../../wiki).

release-notes/CREDITS

-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,3 @@ Hal Hildebrand (Hellblazer@github)
120120
[4.1.0]
121121
* Contributed #46: Add support for Proposed type v7 (epoch-based time uuid)
122122
[4.1.0]
123-
124-
Paul Galbraith (pgalbraith@github)
125-
* Contributed #52: Add `Generators.egressTimeBasedGenerator()` method that constructs
126-
`TimedBasedGenerator` with a sensible choice of interface

release-notes/VERSION

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ Releases
1010
(contributed by Hal H)
1111
#46: Add support for Proposed type v7 (epoch-based time uuid)
1212
(contributed by Hal H)
13-
#52: Add `Generators.egressTimeBasedGenerator()` method that constructs `TimedBasedGenerator`
14-
with a sensible choice of interface
15-
(contributed by Paul G)
16-
#55: Add `Main-Class` manifest to make jar invoke `Jug` class
13+
#55: Add `Main-Class` manifest to make jar invoke `Jug` class
1714
- Fix a minor issue with argument validation for `Jug` tool class
1815
- Update junit dependency (via oss-parent:41)
1916
- Update slf4j-api to 1.7.36

src/main/java/com/fasterxml/uuid/EthernetAddress.java

+3-80
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ public static EthernetAddress fromInterface()
275275
while (en.hasMoreElements()) {
276276
NetworkInterface nint = en.nextElement();
277277
if (!nint.isLoopback()) {
278-
EthernetAddress addr = fromInterface(nint);
279-
if (addr != null) {
280-
return addr;
278+
byte[] data = nint.getHardwareAddress();
279+
if ((data != null) && (data.length == 6)) {
280+
return new EthernetAddress(data);
281281
}
282282
}
283283
}
@@ -287,83 +287,6 @@ public static EthernetAddress fromInterface()
287287
return null;
288288
}
289289

290-
/**
291-
* A factory method to return the ethernet address of a specified network interface.
292-
*
293-
* @since 4.1
294-
*/
295-
public static EthernetAddress fromInterface(NetworkInterface nint)
296-
{
297-
if (nint != null) {
298-
try {
299-
byte[] data = nint.getHardwareAddress();
300-
if (data != null && data.length == 6) {
301-
return new EthernetAddress(data);
302-
}
303-
} catch (SocketException e) {
304-
// could not get address
305-
}
306-
}
307-
return null;
308-
}
309-
310-
/**
311-
* A factory method that will try to determine the ethernet address of
312-
* the network interface that connects to the default network gateway.
313-
* To do this it will try to open a connection to one of the root DNS
314-
* servers, or barring that, to address 1.1.1.1, or finally if that also
315-
* fails then to IPv6 address "1::1". If a connection can be opened then
316-
* the interface through which that connection is routed is determined
317-
* to be the default egress interface, and the corresponding address of
318-
* that interface will be returned. If all attempts are unsuccessful,
319-
* null will be returned.
320-
*
321-
* @since 4.1
322-
*/
323-
public static EthernetAddress fromEgressInterface()
324-
{
325-
String roots = "abcdefghijklm";
326-
int index = new Random().nextInt(roots.length());
327-
String name = roots.charAt(index) + ".root-servers.net";
328-
// Specify standard/default port DNS uses; more robust on some platforms
329-
// (MacOS/JDK 17), see:
330-
// https://github.com/cowtowncoder/java-uuid-generator/pull/59
331-
InetSocketAddress externalAddress = new InetSocketAddress(name, 53);
332-
if (externalAddress.isUnresolved()) {
333-
externalAddress = new InetSocketAddress("1.1.1.1", 0);
334-
}
335-
EthernetAddress ifAddr = fromEgressInterface(externalAddress);
336-
if (ifAddr == null) {
337-
return fromEgressInterface(new InetSocketAddress("1::1", 0));
338-
} else {
339-
return ifAddr;
340-
}
341-
}
342-
343-
/**
344-
* A factory method to return the address of the interface used to route
345-
* traffic to the specified IP address.
346-
*
347-
* @since 4.1
348-
*/
349-
public static EthernetAddress fromEgressInterface(InetSocketAddress externalSocketAddress)
350-
{
351-
DatagramSocket socket = null;
352-
try {
353-
socket = new DatagramSocket();
354-
socket.connect(externalSocketAddress);
355-
InetAddress localAddress = socket.getLocalAddress();
356-
NetworkInterface egressIf = NetworkInterface.getByInetAddress(localAddress);
357-
return fromInterface(egressIf);
358-
} catch (SocketException e) {
359-
return null;
360-
} finally {
361-
if (socket != null) {
362-
socket.close();
363-
}
364-
}
365-
}
366-
367290
/**
368291
* Factory method that can be used to construct a random multicast
369292
* address; to be used in cases where there is no "real" ethernet

src/main/java/com/fasterxml/uuid/Generators.java

-30
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public class Generators
4242
*/
4343
protected static UUIDTimer _sharedTimer;
4444

45-
/**
46-
* The hardware address of the egress network interface.
47-
*/
48-
protected static EthernetAddress _egressIfAddr = null;
49-
5045
// // Random-based generation
5146

5247
/**
@@ -144,23 +139,6 @@ public static TimeBasedEpochGenerator timeBasedEpochGenerator(Random random)
144139

145140
// // Time+location-based generation
146141

147-
/**
148-
* Factory method for constructing UUID generator that generates UUID using variant 1
149-
* (time+location based). This method will use the ethernet address of the interface
150-
* that routes to the default gateway. For most simple and common networking configurations
151-
* this will be the most appropriate address to use. The default interface is determined
152-
* by the calling {@link EthernetAddress#fromEgressInterface()}. Note that this will only
153-
* identify the egress interface once: if you have a complex network setup where your
154-
* outbound routes/interfaces may change dynamically, and you want your UUIDs to
155-
* accurately reflect which interface is being actively used, this method is not for you.
156-
*
157-
* @since 4.1
158-
*/
159-
public static TimeBasedGenerator egressTimeBasedGenerator()
160-
{
161-
return timeBasedGenerator(egressInterfaceAddress());
162-
}
163-
164142
/**
165143
* Factory method for constructing UUID generator that generates UUID using
166144
* variant 1 (time+location based).
@@ -283,12 +261,4 @@ private static synchronized UUIDTimer sharedTimer()
283261
}
284262
return _sharedTimer;
285263
}
286-
287-
private static synchronized EthernetAddress egressInterfaceAddress()
288-
{
289-
if (_egressIfAddr == null) {
290-
_egressIfAddr = EthernetAddress.fromEgressInterface();
291-
}
292-
return _egressIfAddr;
293-
}
294264
}

src/test/java/com/fasterxml/uuid/EthernetAddressTest.java

-29
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
*
3333
* @author Eric Bie
3434
* @author Tatu Saloranta (changes for version 3.0)
35-
* @author Paul Galbraith (egress-related tests)
3635
*/
3736
public class EthernetAddressTest extends TestCase
3837
{
@@ -1310,34 +1309,6 @@ public void testFromInterface() throws Exception
13101309
assertNotNull(addr.toString());
13111310
}
13121311

1313-
// 20-Jun-2022, tatu: Not sure why @Ignore didn't work but
1314-
// need to comment out until [#52] is fully resolved
1315-
/*
1316-
public void testFromEgressInterfaceRoot() throws Exception
1317-
{
1318-
InetSocketAddress extAddr = new InetSocketAddress("a.root-servers.net", 0);
1319-
EthernetAddress ifAddr = EthernetAddress.fromEgressInterface(extAddr);
1320-
assertNotNull(ifAddr);
1321-
assertNotNull(ifAddr.toString());
1322-
}
1323-
1324-
public void testFromEgressInterface() throws Exception
1325-
{
1326-
EthernetAddress ifAddr = EthernetAddress.fromEgressInterface();
1327-
assertNotNull(ifAddr);
1328-
assertNotNull(ifAddr.toString());
1329-
}
1330-
*/
1331-
1332-
public void testDefaultTimeBasedGenerator()
1333-
{
1334-
TimeBasedGenerator generator = Generators.egressTimeBasedGenerator();
1335-
assertNotNull(generator);
1336-
EthernetAddress ifAddr = generator.getEthernetAddress();
1337-
assertNotNull(ifAddr);
1338-
assertNotNull(ifAddr.toString());
1339-
}
1340-
13411312
public void testBogus() throws Exception
13421313
{
13431314
// First, two using pseudo-random; verify they are different

0 commit comments

Comments
 (0)