mirror of
https://github.com/ChronosX88/Influence-P2P.git
synced 2024-11-22 07:12:19 +00:00
Now put in DHT is successful!
This commit is contained in:
parent
233fa69193
commit
beec4cf4e2
@ -38,13 +38,14 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
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.appcompat:appcompat:1.1.0-alpha02'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
|
||||||
implementation "androidx.room:room-runtime:2.1.0-alpha04"
|
implementation "androidx.room:room-runtime:2.1.0-alpha04"
|
||||||
annotationProcessor "androidx.room:room-compiler:2.1.0-alpha04"
|
annotationProcessor "androidx.room:room-compiler:2.1.0-alpha04"
|
||||||
implementation 'org.slf4j:slf4j-log4j12:1.7.26'
|
implementation 'org.slf4j:slf4j-log4j12:1.7.26'
|
||||||
implementation group: 'com.h2database', name: 'h2-mvstore', version: '1.4.197'
|
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 'com.google.android.material:material:1.1.0-alpha04'
|
||||||
implementation 'androidx.preference:preference:1.1.0-alpha03'
|
implementation 'androidx.preference:preference:1.1.0-alpha03'
|
||||||
implementation 'com.google.code.gson:gson:2.8.5'
|
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -61,9 +61,6 @@ class DataSerializerEx(private val signatureFactory: SignatureFactory) : EntryBi
|
|||||||
// next data - no need to copy to another buffer, just take the data
|
// next data - no need to copy to another buffer, just take the data
|
||||||
// from memory
|
// from memory
|
||||||
writeData(out, data.toByteBuffers())
|
writeData(out, data.toByteBuffers())
|
||||||
// rest
|
|
||||||
// data.encodeDone(acb, signatureFactory)
|
|
||||||
// writeData(out, acb.nioBuffers())
|
|
||||||
} catch (e: SignatureException) {
|
} catch (e: SignatureException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
} catch (e: InvalidKeyException) {
|
} catch (e: InvalidKeyException) {
|
||||||
|
@ -52,7 +52,7 @@ public class KeyPairManager {
|
|||||||
KeyPair keyPair = null;
|
KeyPair keyPair = null;
|
||||||
try {
|
try {
|
||||||
keyPairFile.createNewFile();
|
keyPairFile.createNewFile();
|
||||||
keyPair = KeyPairGenerator.getInstance("DSA").generateKeyPair();
|
keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
|
||||||
FileOutputStream outputStream = new FileOutputStream(keyPairFile);
|
FileOutputStream outputStream = new FileOutputStream(keyPairFile);
|
||||||
outputStream.write(serializer.serialize(keyPair));
|
outputStream.write(serializer.serialize(keyPair));
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
|
@ -40,6 +40,7 @@ public class P2PUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean put(String locationKey, String contentKey, Data data) {
|
public static boolean put(String locationKey, String contentKey, Data data) {
|
||||||
|
data.signed(false);
|
||||||
FuturePut futurePut = peerDHT
|
FuturePut futurePut = peerDHT
|
||||||
.put(Number160.createHash(locationKey))
|
.put(Number160.createHash(locationKey))
|
||||||
.data(contentKey == null ? Number160.ZERO : Number160.createHash(contentKey), data)
|
.data(contentKey == null ? Number160.ZERO : Number160.createHash(contentKey), data)
|
||||||
|
@ -7,7 +7,10 @@ import android.util.Log;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import net.tomp2p.connection.Bindings;
|
||||||
|
import net.tomp2p.connection.ChannelClientConfiguration;
|
||||||
import net.tomp2p.connection.DSASignatureFactory;
|
import net.tomp2p.connection.DSASignatureFactory;
|
||||||
|
import net.tomp2p.connection.RSASignatureFactory;
|
||||||
import net.tomp2p.dht.PeerBuilderDHT;
|
import net.tomp2p.dht.PeerBuilderDHT;
|
||||||
import net.tomp2p.dht.PeerDHT;
|
import net.tomp2p.dht.PeerDHT;
|
||||||
import net.tomp2p.futures.FutureBootstrap;
|
import net.tomp2p.futures.FutureBootstrap;
|
||||||
@ -25,6 +28,7 @@ import net.tomp2p.storage.Data;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
@ -83,11 +87,12 @@ public class MainLogic implements IMainLogicContract {
|
|||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
StorageBerkeleyDB storageBerkeleyDB = new StorageBerkeleyDB(peerID, context.getFilesDir(), new DSASignatureFactory());
|
StorageBerkeleyDB storageBerkeleyDB = new StorageBerkeleyDB(peerID, context.getFilesDir(), new RSASignatureFactory());
|
||||||
this.storage = storageBerkeleyDB;
|
this.storage = storageBerkeleyDB;
|
||||||
peerDHT = new PeerBuilderDHT(
|
peerDHT = new PeerBuilderDHT(
|
||||||
new PeerBuilder(peerID)
|
new PeerBuilder(peerID)
|
||||||
.ports(7243)
|
.ports(7243)
|
||||||
|
.channelClientConfiguration(createChannelClientConfig())
|
||||||
.start()
|
.start()
|
||||||
)
|
)
|
||||||
.storage(storageBerkeleyDB)
|
.storage(storageBerkeleyDB)
|
||||||
@ -230,6 +235,7 @@ public class MainLogic implements IMainLogicContract {
|
|||||||
peerDHT.peer().announceShutdown().start().awaitUninterruptibly();
|
peerDHT.peer().announceShutdown().start().awaitUninterruptibly();
|
||||||
peerDHT.peer().shutdown().awaitUninterruptibly();
|
peerDHT.peer().shutdown().awaitUninterruptibly();
|
||||||
storage.close();
|
storage.close();
|
||||||
|
System.exit(0);
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,19 +251,19 @@ public class MainLogic implements IMainLogicContract {
|
|||||||
|
|
||||||
private void publicProfileToDHT() {
|
private void publicProfileToDHT() {
|
||||||
KeyPair mainKeyPair = keyPairManager.openMainKeyPair();
|
KeyPair mainKeyPair = keyPairManager.openMainKeyPair();
|
||||||
KeyFactory factory = null;
|
/*KeyFactory factory = null;
|
||||||
try {
|
try {
|
||||||
factory = KeyFactory.getInstance("DSA");
|
factory = KeyFactory.getInstance("RSA");
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}*/
|
||||||
PublicUserProfile userProfile = null;
|
PublicUserProfile userProfile = new PublicUserProfile(AppHelper.getPeerID(), peerDHT.peerAddress(), null);
|
||||||
try {
|
/*try {
|
||||||
DSAPublicKeySpec dsaKey = factory.getKeySpec(mainKeyPair.getPublic(), DSAPublicKeySpec.class);
|
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()));
|
userProfile = new PublicUserProfile(AppHelper.getPeerID(), peerDHT.peerAddress(), new DSAKey(dsaKey.getQ(), dsaKey.getP(), dsaKey.getY(), dsaKey.getG()));
|
||||||
} catch (InvalidKeySpecException e) {
|
} catch (InvalidKeySpecException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}*/
|
||||||
Data serializedUserProfile = null;
|
Data serializedUserProfile = null;
|
||||||
try {
|
try {
|
||||||
serializedUserProfile = new Data(gson.toJson(userProfile))
|
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!");
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user