|
16 | 16 |
|
17 | 17 | package org.bitcoinj.core; |
18 | 18 |
|
19 | | -import com.google.common.net.InetAddresses; |
20 | 19 | import org.bitcoinj.base.internal.Buffers; |
21 | 20 | import org.bitcoinj.base.internal.TimeUtils; |
22 | 21 | import org.bitcoinj.base.internal.ByteUtils; |
23 | 22 |
|
24 | 23 | import org.jspecify.annotations.Nullable; |
25 | 24 | import java.net.InetAddress; |
26 | 25 | import java.net.InetSocketAddress; |
| 26 | +import java.net.UnknownHostException; |
27 | 27 | import java.nio.BufferOverflowException; |
28 | 28 | import java.nio.BufferUnderflowException; |
29 | 29 | import java.nio.ByteBuffer; |
@@ -149,14 +149,21 @@ public VersionMessage(NetworkParameters params, int bestHeight) { |
149 | 149 | this.clientVersion = ProtocolVersion.CURRENT.intValue(); |
150 | 150 | this.localServices = Services.none(); |
151 | 151 | this.time = TimeUtils.currentTime().truncatedTo(ChronoUnit.SECONDS); |
152 | | - InetAddress localhost = InetAddresses.forString("127.0.0.1"); |
153 | 152 | this.receivingServices = Services.none(); |
154 | | - this.receivingAddr = new InetSocketAddress(localhost, params.getPort()); |
| 153 | + this.receivingAddr = new InetSocketAddress(getLocalhostAddr(), params.getPort()); |
155 | 154 | this.subVer = LIBRARY_SUBVER; |
156 | 155 | this.bestHeight = bestHeight; |
157 | 156 | this.relayTxesBeforeFilter = true; |
158 | 157 | } |
159 | 158 |
|
| 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 | + |
160 | 167 | private VersionMessage(int clientVersion, Services localServices, Instant time, Services receivingServices, |
161 | 168 | InetSocketAddress receivingAddr, String subVer, long bestHeight, |
162 | 169 | boolean relayTxesBeforeFilter) { |
|
0 commit comments