Commit 74570276 authored by Michel Schudel's avatar Michel Schudel

fixed peer discovery.

(cherry picked from commit eef99fb8)
parent 5007c90f
......@@ -98,7 +98,7 @@ Het project gevat een `Block` class die een block in de blockchain voorstelt. Vu
- `index` (long). Dit is de zogenaamde BlockHeight en geeft aan hoeveel blocks het block van het genesis block verwijderd is.
- `timestamp` (long)
- lijst van transacties.
- lijst van `Transaction` objecten.
- `previousHash` (string). De hash van het vorige block. dit geeft de blockchain immutability.
- `proof` (long). Het resultaat van een mining actie, hierover later meer.
......
......@@ -7,8 +7,10 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.net.Inet4Address;
import java.net.UnknownHostException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
@Component
public class InstanceInfo {
......@@ -26,14 +28,28 @@ public class InstanceInfo {
@PostConstruct
public void init() {
String host = "";
try {
String host = Inet4Address
.getLocalHost()
.getHostAddress();
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress inetAddress = addresses.nextElement();
String hostAddress = inetAddress.getHostAddress();
if (hostAddress.startsWith("192")) {
host = hostAddress;
break;
}
}
}
// String host = InetAddress
// .getLocalHost()
// .getHostAddress();
this.port = serverProperties.getPort();
this.node = host + ":" + serverProperties.getPort();
LOGGER.info("node name of this node is {}", node);
} catch (UnknownHostException e) {
} catch (SocketException e) {
throw new RuntimeException(e);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment