Skip to content

Commit 10d07c1

Browse files
nadavramonschildbach
authored andcommitted
VersionMessage: replace Guava InetAddresses.forString() with JDK InetAddress.getByAddress()
1 parent 90e83d1 commit 10d07c1

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

core/src/main/java/org/bitcoinj/core/VersionMessage.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package org.bitcoinj.core;
1818

19-
import com.google.common.net.InetAddresses;
2019
import org.bitcoinj.base.internal.Buffers;
2120
import org.bitcoinj.base.internal.TimeUtils;
2221
import org.bitcoinj.base.internal.ByteUtils;
2322

2423
import org.jspecify.annotations.Nullable;
2524
import java.net.InetAddress;
2625
import java.net.InetSocketAddress;
26+
import java.net.UnknownHostException;
2727
import java.nio.BufferOverflowException;
2828
import java.nio.BufferUnderflowException;
2929
import java.nio.ByteBuffer;
@@ -149,14 +149,21 @@ public VersionMessage(NetworkParameters params, int bestHeight) {
149149
this.clientVersion = ProtocolVersion.CURRENT.intValue();
150150
this.localServices = Services.none();
151151
this.time = TimeUtils.currentTime().truncatedTo(ChronoUnit.SECONDS);
152-
InetAddress localhost = InetAddresses.forString("127.0.0.1");
153152
this.receivingServices = Services.none();
154-
this.receivingAddr = new InetSocketAddress(localhost, params.getPort());
153+
this.receivingAddr = new InetSocketAddress(getLocalhostAddr(), params.getPort());
155154
this.subVer = LIBRARY_SUBVER;
156155
this.bestHeight = bestHeight;
157156
this.relayTxesBeforeFilter = true;
158157
}
159158

159+
private InetAddress getLocalhostAddr() {
160+
try {
161+
return InetAddress.getByAddress(new byte[] {127, 0, 0, 1});
162+
} catch (UnknownHostException e) {
163+
throw new RuntimeException(e);
164+
}
165+
}
166+
160167
private VersionMessage(int clientVersion, Services localServices, Instant time, Services receivingServices,
161168
InetSocketAddress receivingAddr, String subVer, long bestHeight,
162169
boolean relayTxesBeforeFilter) {

0 commit comments

Comments
 (0)