From 4b617c249aa6928dd07878bf0d00700051a6dce4 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Fri, 1 Mar 2019 18:49:31 +0400 Subject: [PATCH] Fixed hex representation of KademliaID --- app/build.gradle | 2 +- .../chronosx88/influence/kademlia/node/KademliaId.java | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 185a9bd..44a0d7b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,7 +20,6 @@ android { dependencies { def room_version = "2.1.0-alpha04" - implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' @@ -30,4 +29,5 @@ dependencies { implementation 'com.google.code.gson:gson:2.8.5' implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version" + implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359' } diff --git a/app/src/main/java/io/github/chronosx88/influence/kademlia/node/KademliaId.java b/app/src/main/java/io/github/chronosx88/influence/kademlia/node/KademliaId.java index c5e0b54..7751e88 100644 --- a/app/src/main/java/io/github/chronosx88/influence/kademlia/node/KademliaId.java +++ b/app/src/main/java/io/github/chronosx88/influence/kademlia/node/KademliaId.java @@ -14,6 +14,7 @@ import java.util.Arrays; import java.util.BitSet; import java.util.Random; import io.github.chronosx88.influence.kademlia.message.Streamable; +import javax.xml.bind.DatatypeConverter; public class KademliaId implements Streamable, Serializable { @@ -28,7 +29,7 @@ public class KademliaId implements Streamable, Serializable */ public KademliaId(String data) { - keyBytes = data.getBytes(); + keyBytes = DatatypeConverter.parseHexBinary(data); if (keyBytes.length != ID_LENGTH / 8) { throw new IllegalArgumentException("Specified Data need to be " + (ID_LENGTH / 8) + " characters long."); @@ -249,9 +250,7 @@ public class KademliaId implements Streamable, Serializable public String hexRepresentation() { - /* Returns the hex format of this NodeId */ - BigInteger bi = new BigInteger(1, this.keyBytes); - return String.format("%0" + (this.keyBytes.length << 1) + "X", bi); + return DatatypeConverter.printHexBinary(this.keyBytes); } @Override