Now put in DHT is successful!

This commit is contained in:
ChronosX88 2019-04-10 17:50:51 +04:00
parent 233fa69193
commit beec4cf4e2
20 changed files with 31 additions and 12 deletions

View File

@ -38,13 +38,14 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation fileTree(include: ['*.jar'], dir: 'libs/tomp2p')
//implementation fileTree(include: ['*.jar'], dir: 'libs/tomp2p')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation "androidx.room:room-runtime:2.1.0-alpha04"
annotationProcessor "androidx.room:room-compiler:2.1.0-alpha04"
implementation 'org.slf4j:slf4j-log4j12:1.7.26'
implementation group: 'com.h2database', name: 'h2-mvstore', version: '1.4.197'
implementation 'net.tomp2p:tomp2p-all:5.0-Beta8'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation 'androidx.preference:preference:1.1.0-alpha03'
implementation 'com.google.code.gson:gson:2.8.5'

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -61,9 +61,6 @@ class DataSerializerEx(private val signatureFactory: SignatureFactory) : EntryBi
// next data - no need to copy to another buffer, just take the data
// from memory
writeData(out, data.toByteBuffers())
// rest
// data.encodeDone(acb, signatureFactory)
// writeData(out, acb.nioBuffers())
} catch (e: SignatureException) {
e.printStackTrace()
} catch (e: InvalidKeyException) {

View File

@ -52,7 +52,7 @@ public class KeyPairManager {
KeyPair keyPair = null;
try {
keyPairFile.createNewFile();
keyPair = KeyPairGenerator.getInstance("DSA").generateKeyPair();
keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
FileOutputStream outputStream = new FileOutputStream(keyPairFile);
outputStream.write(serializer.serialize(keyPair));
outputStream.close();

View File

@ -40,6 +40,7 @@ public class P2PUtils {
}
public static boolean put(String locationKey, String contentKey, Data data) {
data.signed(false);
FuturePut futurePut = peerDHT
.put(Number160.createHash(locationKey))
.data(contentKey == null ? Number160.ZERO : Number160.createHash(contentKey), data)

View File

@ -7,7 +7,10 @@ import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import net.tomp2p.connection.Bindings;
import net.tomp2p.connection.ChannelClientConfiguration;
import net.tomp2p.connection.DSASignatureFactory;
import net.tomp2p.connection.RSASignatureFactory;
import net.tomp2p.dht.PeerBuilderDHT;
import net.tomp2p.dht.PeerDHT;
import net.tomp2p.futures.FutureBootstrap;
@ -25,6 +28,7 @@ import net.tomp2p.storage.Data;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.security.KeyFactory;
import java.security.KeyPair;
@ -83,11 +87,12 @@ public class MainLogic implements IMainLogicContract {
new Thread(() -> {
try {
StorageBerkeleyDB storageBerkeleyDB = new StorageBerkeleyDB(peerID, context.getFilesDir(), new DSASignatureFactory());
StorageBerkeleyDB storageBerkeleyDB = new StorageBerkeleyDB(peerID, context.getFilesDir(), new RSASignatureFactory());
this.storage = storageBerkeleyDB;
peerDHT = new PeerBuilderDHT(
new PeerBuilder(peerID)
.ports(7243)
.channelClientConfiguration(createChannelClientConfig())
.start()
)
.storage(storageBerkeleyDB)
@ -230,6 +235,7 @@ public class MainLogic implements IMainLogicContract {
peerDHT.peer().announceShutdown().start().awaitUninterruptibly();
peerDHT.peer().shutdown().awaitUninterruptibly();
storage.close();
System.exit(0);
}).start();
}
@ -245,19 +251,19 @@ public class MainLogic implements IMainLogicContract {
private void publicProfileToDHT() {
KeyPair mainKeyPair = keyPairManager.openMainKeyPair();
KeyFactory factory = null;
/*KeyFactory factory = null;
try {
factory = KeyFactory.getInstance("DSA");
factory = KeyFactory.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
PublicUserProfile userProfile = null;
try {
}*/
PublicUserProfile userProfile = new PublicUserProfile(AppHelper.getPeerID(), peerDHT.peerAddress(), null);
/*try {
DSAPublicKeySpec dsaKey = factory.getKeySpec(mainKeyPair.getPublic(), DSAPublicKeySpec.class);
userProfile = new PublicUserProfile(AppHelper.getPeerID(), peerDHT.peerAddress(), new DSAKey(dsaKey.getQ(), dsaKey.getP(), dsaKey.getY(), dsaKey.getG()));
} catch (InvalidKeySpecException e) {
e.printStackTrace();
}
}*/
Data serializedUserProfile = null;
try {
serializedUserProfile = new Data(gson.toJson(userProfile))
@ -268,4 +274,18 @@ public class MainLogic implements IMainLogicContract {
}
Log.i(LOG_TAG, P2PUtils.put(AppHelper.getPeerID() + "_profile", null, serializedUserProfile) ? "# Profile successfully published!" : "# Profile publishing failed!");
}
private ChannelClientConfiguration createChannelClientConfig() {
ChannelClientConfiguration channelClientConfiguration = new ChannelClientConfiguration();
channelClientConfiguration.bindings(new Bindings());
channelClientConfiguration.maxPermitsPermanentTCP(250);
channelClientConfiguration.maxPermitsTCP(250);
channelClientConfiguration.maxPermitsUDP(250);
channelClientConfiguration.pipelineFilter(new PeerBuilder.DefaultPipelineFilter());
channelClientConfiguration.signatureFactory(new RSASignatureFactory());
channelClientConfiguration.senderTCP((new InetSocketAddress(0)).getAddress());
channelClientConfiguration.senderUDP((new InetSocketAddress(0)).getAddress());
channelClientConfiguration.byteBufPool(false);
return channelClientConfiguration;
}
}