From 169bd148b488ea8ee8b5162072316904b8c7648a Mon Sep 17 00:00:00 2001 From: Robin Date: Thu, 13 Dec 2018 16:45:53 +0100 Subject: [PATCH] TreeSet needs a total ordering, bugfix: same node multiple times in contact list --- src/kademlia/routing/Contact.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/kademlia/routing/Contact.java b/src/kademlia/routing/Contact.java index 896d1df..e23a352 100644 --- a/src/kademlia/routing/Contact.java +++ b/src/kademlia/routing/Contact.java @@ -1,5 +1,6 @@ package kademlia.routing; +import kademlia.node.KademliaId; import kademlia.node.Node; /** @@ -106,6 +107,17 @@ public int compareTo(Contact o) return 0; } + if (this.lastSeen() == o.lastSeen()) { + + for (int i = 0; i < KademliaId.ID_LENGTH / 8; i++) { + int compare = Byte.compare(this.getNode().getNodeId().getBytes()[i], o.getNode().getNodeId().getBytes()[i]); + if (compare != 0) { + return compare; + } + } + + } + return (this.lastSeen() > o.lastSeen()) ? 1 : -1; }