Published artifact to Maven Central and changed representation of NodeID to Base64

This commit is contained in:
ChronosX88 2019-03-02 21:23:43 +04:00
parent d48645b644
commit e94135f256
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
4 changed files with 89 additions and 10 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/build/ /build/
/.gradle/ /.gradle/
/.idea/ /.idea/
/gradle.properties

View File

@ -1,10 +1,89 @@
plugins { plugins {
id 'java-library' id 'java-library'
id 'maven'
id 'signing'
} }
group 'io.github.chronosx88' group 'io.github.chronosx88'
version '1.0' version '1.0'
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives javadocJar, sourcesJar
}
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addBooleanOption('Xdoclint:none', true)
}
}
}
signing {
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: username, password: password)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: username, password: password)
}
pom.project {
name 'KademliaDHT'
packaging 'jar'
description 'KademliaDHT implementation in Java'
url 'https://github.com/ChronosX88/KademliaDHT'
scm {
connection 'scm:git:git://github.com/ChronosX88/KademliaDHT.git'
developerConnection 'scm:git:git@github.com:ChronosX88/KademliaDHT.git'
url 'https://github.com/ChronosX88/KademliaDHT'
}
licenses {
license {
name 'The MIT License (MIT)'
url 'https://opensource.org/licenses/MIT'
distribution repository
}
}
developers {
developer {
id 'JoshuaKissoon'
name 'Joshua Kissoon'
email 'JoshuaKissoon@gmail.com'
}
developer {
id 'ChronosX88'
name 'ChronosX88'
email 'chronosx88@gmail.com'
}
}
}
}
}
}
sourceCompatibility = 1.8 sourceCompatibility = 1.8
repositories { repositories {
@ -13,5 +92,4 @@ repositories {
dependencies { dependencies {
implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.google.code.gson:gson:2.8.5'
implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'
} }

View File

@ -223,7 +223,7 @@ public class DHT implements KademliaDHT
* *
* The name of the file containing the content is the hash of this content * The name of the file containing the content is the hash of this content
*/ */
String folderName = key.hexRepresentation().substring(0, 2); String folderName = key.stringRepresentation().substring(0, 2);
File contentStorageFolder = new File(this.config.getNodeDataFolder(ownerId) + File.separator + folderName); File contentStorageFolder = new File(this.config.getNodeDataFolder(ownerId) + File.separator + folderName);
/* Create the content folder if it doesn't exist */ /* Create the content folder if it doesn't exist */

View File

@ -5,17 +5,17 @@
*/ */
package io.github.chronosx88.kademliadht.node; package io.github.chronosx88.kademliadht.node;
import io.github.chronosx88.kademliadht.message.Streamable;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64;
import java.util.BitSet; import java.util.BitSet;
import java.util.Random; import java.util.Random;
import io.github.chronosx88.kademliadht.message.Streamable;
import javax.xml.bind.DatatypeConverter;
public class KademliaId implements Streamable, Serializable public class KademliaId implements Streamable, Serializable
{ {
@ -30,7 +30,7 @@ public class KademliaId implements Streamable, Serializable
*/ */
public KademliaId(String data) public KademliaId(String data)
{ {
keyBytes = DatatypeConverter.parseHexBinary(data); keyBytes = Base64.getDecoder().decode(data);
if (keyBytes.length != ID_LENGTH / 8) if (keyBytes.length != ID_LENGTH / 8)
{ {
throw new IllegalArgumentException("Specified Data need to be " + (ID_LENGTH / 8) + " characters long."); throw new IllegalArgumentException("Specified Data need to be " + (ID_LENGTH / 8) + " characters long.");
@ -249,16 +249,16 @@ public class KademliaId implements Streamable, Serializable
this.keyBytes = input; this.keyBytes = input;
} }
public String hexRepresentation() public String stringRepresentation()
{ {
/* Returns the hex format of this NodeId */ /* Returns the base64 format of this NodeId */
return DatatypeConverter.printHexBinary(this.keyBytes); return Base64.getEncoder().encodeToString(this.keyBytes);
} }
@Override @Override
public String toString() public String toString()
{ {
return this.hexRepresentation(); return this.stringRepresentation();
} }
} }