diff --git a/app/build.gradle b/app/build.gradle index 2c19038..e95e8ed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/libs/tomp2p-all-5.0-Beta8.jar b/app/libs/tomp2p-all-5.0-Beta8.jar deleted file mode 100644 index f9b158d..0000000 Binary files a/app/libs/tomp2p-all-5.0-Beta8.jar and /dev/null differ diff --git a/app/libs/tomp2p/gcm-server-1.0.2.jar b/app/libs/tomp2p/gcm-server-1.0.2.jar deleted file mode 100644 index 0554b24..0000000 Binary files a/app/libs/tomp2p/gcm-server-1.0.2.jar and /dev/null differ diff --git a/app/libs/tomp2p/json-simple-1.1.jar b/app/libs/tomp2p/json-simple-1.1.jar deleted file mode 100644 index f395f41..0000000 Binary files a/app/libs/tomp2p/json-simple-1.1.jar and /dev/null differ diff --git a/app/libs/tomp2p/netty-buffer-4.0.28.Final.jar b/app/libs/tomp2p/netty-buffer-4.0.28.Final.jar deleted file mode 100644 index 89265f4..0000000 Binary files a/app/libs/tomp2p/netty-buffer-4.0.28.Final.jar and /dev/null differ diff --git a/app/libs/tomp2p/netty-common-4.0.28.Final.jar b/app/libs/tomp2p/netty-common-4.0.28.Final.jar deleted file mode 100644 index a86716e..0000000 Binary files a/app/libs/tomp2p/netty-common-4.0.28.Final.jar and /dev/null differ diff --git a/app/libs/tomp2p/netty-transport-4.0.28.Final.jar b/app/libs/tomp2p/netty-transport-4.0.28.Final.jar deleted file mode 100644 index 50a9e5f..0000000 Binary files a/app/libs/tomp2p/netty-transport-4.0.28.Final.jar and /dev/null differ diff --git a/app/libs/tomp2p/slf4j-api-1.7.5.jar b/app/libs/tomp2p/slf4j-api-1.7.5.jar deleted file mode 100644 index 8f004d3..0000000 Binary files a/app/libs/tomp2p/slf4j-api-1.7.5.jar and /dev/null differ diff --git a/app/libs/tomp2p/tomp2p-all-5.0-Beta8.jar b/app/libs/tomp2p/tomp2p-all-5.0-Beta8.jar deleted file mode 100644 index f9b158d..0000000 Binary files a/app/libs/tomp2p/tomp2p-all-5.0-Beta8.jar and /dev/null differ diff --git a/app/libs/tomp2p/tomp2p-android-5.0-Beta8.jar b/app/libs/tomp2p/tomp2p-android-5.0-Beta8.jar deleted file mode 100644 index 3851393..0000000 Binary files a/app/libs/tomp2p/tomp2p-android-5.0-Beta8.jar and /dev/null differ diff --git a/app/libs/tomp2p/tomp2p-core-5.0-Beta8.jar b/app/libs/tomp2p/tomp2p-core-5.0-Beta8.jar deleted file mode 100644 index 83e3296..0000000 Binary files a/app/libs/tomp2p/tomp2p-core-5.0-Beta8.jar and /dev/null differ diff --git a/app/libs/tomp2p/tomp2p-dht-5.0-Beta8.jar b/app/libs/tomp2p/tomp2p-dht-5.0-Beta8.jar deleted file mode 100644 index 2649756..0000000 Binary files a/app/libs/tomp2p/tomp2p-dht-5.0-Beta8.jar and /dev/null differ diff --git a/app/libs/tomp2p/tomp2p-nat-5.0-Beta8.jar b/app/libs/tomp2p/tomp2p-nat-5.0-Beta8.jar deleted file mode 100644 index e424314..0000000 Binary files a/app/libs/tomp2p/tomp2p-nat-5.0-Beta8.jar and /dev/null differ diff --git a/app/libs/tomp2p/tomp2p-replication-5.0-Beta8.jar b/app/libs/tomp2p/tomp2p-replication-5.0-Beta8.jar deleted file mode 100644 index 0998fe2..0000000 Binary files a/app/libs/tomp2p/tomp2p-replication-5.0-Beta8.jar and /dev/null differ diff --git a/app/libs/tomp2p/tomp2p-tracker-5.0-Beta8.jar b/app/libs/tomp2p/tomp2p-tracker-5.0-Beta8.jar deleted file mode 100644 index 50a792b..0000000 Binary files a/app/libs/tomp2p/tomp2p-tracker-5.0-Beta8.jar and /dev/null differ diff --git a/app/libs/tomp2p/weupnp-0.1.2.jar b/app/libs/tomp2p/weupnp-0.1.2.jar deleted file mode 100644 index 43daf9f..0000000 Binary files a/app/libs/tomp2p/weupnp-0.1.2.jar and /dev/null differ diff --git a/app/src/main/java/io/github/chronosx88/influence/helpers/DataSerializerEx.kt b/app/src/main/java/io/github/chronosx88/influence/helpers/DataSerializerEx.kt index fcacbef..cb3f727 100644 --- a/app/src/main/java/io/github/chronosx88/influence/helpers/DataSerializerEx.kt +++ b/app/src/main/java/io/github/chronosx88/influence/helpers/DataSerializerEx.kt @@ -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) { diff --git a/app/src/main/java/io/github/chronosx88/influence/helpers/KeyPairManager.java b/app/src/main/java/io/github/chronosx88/influence/helpers/KeyPairManager.java index 9d4d8e1..258d4f9 100644 --- a/app/src/main/java/io/github/chronosx88/influence/helpers/KeyPairManager.java +++ b/app/src/main/java/io/github/chronosx88/influence/helpers/KeyPairManager.java @@ -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(); diff --git a/app/src/main/java/io/github/chronosx88/influence/helpers/P2PUtils.java b/app/src/main/java/io/github/chronosx88/influence/helpers/P2PUtils.java index fc04923..9d4ef52 100644 --- a/app/src/main/java/io/github/chronosx88/influence/helpers/P2PUtils.java +++ b/app/src/main/java/io/github/chronosx88/influence/helpers/P2PUtils.java @@ -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) diff --git a/app/src/main/java/io/github/chronosx88/influence/logic/MainLogic.java b/app/src/main/java/io/github/chronosx88/influence/logic/MainLogic.java index a9938da..27dd92b 100644 --- a/app/src/main/java/io/github/chronosx88/influence/logic/MainLogic.java +++ b/app/src/main/java/io/github/chronosx88/influence/logic/MainLogic.java @@ -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; + } }