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; }