mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-06-09 11:09:28 +08:00
注释掉了mapdb相关的代码,以适配安卓
This commit is contained in:
@@ -243,11 +243,11 @@
|
||||
|
||||
<!-- mapDB kv存储 -->
|
||||
<!-- https://mvnrepository.com/artifact/org.mapdb/mapdb -->
|
||||
<dependency>
|
||||
<groupId>org.mapdb</groupId>
|
||||
<artifactId>mapdb</artifactId>
|
||||
<version>3.0.8</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.mapdb</groupId>-->
|
||||
<!-- <artifactId>mapdb</artifactId>-->
|
||||
<!-- <version>3.0.8</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- Sqlite Driver compatible with sqlcipher-->
|
||||
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
|
||||
|
||||
@@ -67,8 +67,8 @@
|
||||
<!-- <exclude>org.mortbay.jetty:jetty-util</exclude>-->
|
||||
<!-- wefree added: 去掉这些依赖,以解决与安卓编译时候的库冲突 -->
|
||||
<exclude>org.jetbrains.kotlin</exclude>
|
||||
<!-- <exclude>org.jetbrains.kotlin:kotlin-stdlib</exclude>-->
|
||||
<!-- <exclude>org.jetbrains.kotlin:kotlin-stdlib-common</exclude>-->
|
||||
<exclude>org.jetbrains.kotlin:kotlin-stdlib</exclude>
|
||||
<exclude>org.jetbrains.kotlin:kotlin-stdlib-common</exclude>
|
||||
<exclude>org.jetbrains:annotations</exclude>
|
||||
<!-- <exclude>org.jetbrains.kotlin:kotlin-stdlib-jdk8</exclude>-->
|
||||
<!-- <exclude>org.jetbrains.kotlin:kotlin-stdlib-reflect</exclude>-->
|
||||
|
||||
@@ -120,6 +120,7 @@ public class UdpTransport extends Transport implements ITransport{
|
||||
@Override
|
||||
public boolean setReadTimeout(long duration) throws LogicFaceException {
|
||||
try {
|
||||
System.out.println("udp setReadTimeout duration: "+duration);
|
||||
if (duration <= 0) {
|
||||
// this.channel.socket().setSoTimeout(0);
|
||||
return true;
|
||||
|
||||
@@ -1,97 +1,97 @@
|
||||
package minsecurity.identity.persist;
|
||||
|
||||
import minsecurity.Common;
|
||||
import minsecurity.certificate.cert.CertException;
|
||||
import minsecurity.certificate.cert.CertUtils;
|
||||
import minsecurity.certificate.cert.Certificate;
|
||||
import minsecurity.crypto.sm2.SM2PrivateKey;
|
||||
import minsecurity.crypto.sm2.SM2PublicKey;
|
||||
import minsecurity.identity.Identity;
|
||||
import minsecurity.identity.KeyParam;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.mapdb.DataInput2;
|
||||
import org.mapdb.DataOutput2;
|
||||
import org.mapdb.Serializer;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
|
||||
/*
|
||||
* @Author: hongyu guo
|
||||
* @Description: mapDB需要自定义序列化、反序列化方法
|
||||
* @Version: 1.0.0
|
||||
* @Date: 20:50 2021/03/09
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
|
||||
// DONE: 加密版本的序列化可以不用实现 已经改用加密Sqlite
|
||||
public class IdentitySerializer implements Serializer<Identity> {
|
||||
|
||||
@Override
|
||||
public void serialize(@NotNull DataOutput2 dataOutput2, @NotNull Identity identity) throws IOException {
|
||||
String name = identity.getName();
|
||||
String pub = ByteUtils.toHexString(identity.getPubkey().getBytes());
|
||||
String priv = ByteUtils.toHexString(identity.getPrikey().getBytes());
|
||||
int pubAlgo = identity.getKeyParam().PublicKeyAlgorithm;
|
||||
int signAlgo = identity.getKeyParam().SignatureAlgorithm;
|
||||
String passwd = identity.getPasswd();
|
||||
String cert = "";
|
||||
try {
|
||||
cert = CertUtils.toPem(identity.getCert(),null, Common.SM4CBC);
|
||||
} catch (CertException | NoSuchPaddingException | InvalidAlgorithmParameterException |
|
||||
NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException |
|
||||
NoSuchProviderException | InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean isDefault = identity.isDefault();
|
||||
String prikeyRawByte = identity.getPrikeyRawByte()== null ?
|
||||
"" :ByteUtils.toHexString(identity.getPrikeyRawByte());
|
||||
|
||||
|
||||
dataOutput2.writeUTF(name);
|
||||
dataOutput2.writeUTF(pub);
|
||||
dataOutput2.writeUTF(priv);
|
||||
dataOutput2.writeInt(pubAlgo);
|
||||
dataOutput2.writeInt(signAlgo);
|
||||
dataOutput2.writeUTF(passwd);
|
||||
dataOutput2.writeUTF(cert);
|
||||
dataOutput2.writeBoolean(isDefault);
|
||||
dataOutput2.writeUTF(prikeyRawByte);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identity deserialize(@NotNull DataInput2 dataInput2, int i) throws IOException {
|
||||
String name = dataInput2.readUTF();
|
||||
byte[] pub = ByteUtils.fromHexString(dataInput2.readUTF());
|
||||
byte[] priv = ByteUtils.fromHexString(dataInput2.readUTF());
|
||||
int pubAlgo = dataInput2.readInt();
|
||||
int signAlgo = dataInput2.readInt();
|
||||
String passwd = dataInput2.readUTF();
|
||||
String certString = dataInput2.readUTF();
|
||||
Certificate certificate = null;
|
||||
try {
|
||||
certificate = CertUtils.fromPem(certString, null, Common.SM4CBC);
|
||||
} catch (CertException | BadPaddingException | NoSuchPaddingException |
|
||||
InvalidAlgorithmParameterException | NoSuchAlgorithmException |
|
||||
IllegalBlockSizeException | NoSuchProviderException | InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean isDefault = dataInput2.readBoolean();
|
||||
byte[] prikeyRawByte = dataInput2.readUTF().equals("") ?
|
||||
null : ByteUtils.fromHexString(dataInput2.readUTF());
|
||||
KeyParam keyParam = new KeyParam(pubAlgo, signAlgo);
|
||||
SM2PrivateKey sm2PrivateKey = new SM2PrivateKey();
|
||||
sm2PrivateKey.setBytes(priv);
|
||||
SM2PublicKey sm2PublicKey = new SM2PublicKey();
|
||||
sm2PublicKey.setBytes(pub);
|
||||
return new Identity(name,keyParam, sm2PrivateKey,prikeyRawByte, sm2PublicKey, passwd, certificate, isDefault);
|
||||
}
|
||||
|
||||
}
|
||||
//package minsecurity.identity.persist;
|
||||
//// 不能用于安卓,安卓编译会报错,暂时注释掉
|
||||
//import minsecurity.Common;
|
||||
//import minsecurity.certificate.cert.CertException;
|
||||
//import minsecurity.certificate.cert.CertUtils;
|
||||
//import minsecurity.certificate.cert.Certificate;
|
||||
//import minsecurity.crypto.sm2.SM2PrivateKey;
|
||||
//import minsecurity.crypto.sm2.SM2PublicKey;
|
||||
//import minsecurity.identity.Identity;
|
||||
//import minsecurity.identity.KeyParam;
|
||||
//import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
//import org.jetbrains.annotations.NotNull;
|
||||
//import org.mapdb.DataInput2;
|
||||
//import org.mapdb.DataOutput2;
|
||||
//import org.mapdb.Serializer;
|
||||
//
|
||||
//import javax.crypto.BadPaddingException;
|
||||
//import javax.crypto.IllegalBlockSizeException;
|
||||
//import javax.crypto.NoSuchPaddingException;
|
||||
//import java.io.IOException;
|
||||
//import java.security.InvalidAlgorithmParameterException;
|
||||
//import java.security.InvalidKeyException;
|
||||
//import java.security.NoSuchAlgorithmException;
|
||||
//import java.security.NoSuchProviderException;
|
||||
//
|
||||
///*
|
||||
// * @Author: hongyu guo
|
||||
// * @Description: mapDB需要自定义序列化、反序列化方法
|
||||
// * @Version: 1.0.0
|
||||
// * @Date: 20:50 2021/03/09
|
||||
// * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
// */
|
||||
//
|
||||
//// DONE: 加密版本的序列化可以不用实现 已经改用加密Sqlite
|
||||
//public class IdentitySerializer implements Serializer<Identity> {
|
||||
//
|
||||
// @Override
|
||||
// public void serialize(@NotNull DataOutput2 dataOutput2, @NotNull Identity identity) throws IOException {
|
||||
// String name = identity.getName();
|
||||
// String pub = ByteUtils.toHexString(identity.getPubkey().getBytes());
|
||||
// String priv = ByteUtils.toHexString(identity.getPrikey().getBytes());
|
||||
// int pubAlgo = identity.getKeyParam().PublicKeyAlgorithm;
|
||||
// int signAlgo = identity.getKeyParam().SignatureAlgorithm;
|
||||
// String passwd = identity.getPasswd();
|
||||
// String cert = "";
|
||||
// try {
|
||||
// cert = CertUtils.toPem(identity.getCert(),null, Common.SM4CBC);
|
||||
// } catch (CertException | NoSuchPaddingException | InvalidAlgorithmParameterException |
|
||||
// NoSuchAlgorithmException | IllegalBlockSizeException | BadPaddingException |
|
||||
// NoSuchProviderException | InvalidKeyException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// boolean isDefault = identity.isDefault();
|
||||
// String prikeyRawByte = identity.getPrikeyRawByte()== null ?
|
||||
// "" :ByteUtils.toHexString(identity.getPrikeyRawByte());
|
||||
//
|
||||
//
|
||||
// dataOutput2.writeUTF(name);
|
||||
// dataOutput2.writeUTF(pub);
|
||||
// dataOutput2.writeUTF(priv);
|
||||
// dataOutput2.writeInt(pubAlgo);
|
||||
// dataOutput2.writeInt(signAlgo);
|
||||
// dataOutput2.writeUTF(passwd);
|
||||
// dataOutput2.writeUTF(cert);
|
||||
// dataOutput2.writeBoolean(isDefault);
|
||||
// dataOutput2.writeUTF(prikeyRawByte);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Identity deserialize(@NotNull DataInput2 dataInput2, int i) throws IOException {
|
||||
// String name = dataInput2.readUTF();
|
||||
// byte[] pub = ByteUtils.fromHexString(dataInput2.readUTF());
|
||||
// byte[] priv = ByteUtils.fromHexString(dataInput2.readUTF());
|
||||
// int pubAlgo = dataInput2.readInt();
|
||||
// int signAlgo = dataInput2.readInt();
|
||||
// String passwd = dataInput2.readUTF();
|
||||
// String certString = dataInput2.readUTF();
|
||||
// Certificate certificate = null;
|
||||
// try {
|
||||
// certificate = CertUtils.fromPem(certString, null, Common.SM4CBC);
|
||||
// } catch (CertException | BadPaddingException | NoSuchPaddingException |
|
||||
// InvalidAlgorithmParameterException | NoSuchAlgorithmException |
|
||||
// IllegalBlockSizeException | NoSuchProviderException | InvalidKeyException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// boolean isDefault = dataInput2.readBoolean();
|
||||
// byte[] prikeyRawByte = dataInput2.readUTF().equals("") ?
|
||||
// null : ByteUtils.fromHexString(dataInput2.readUTF());
|
||||
// KeyParam keyParam = new KeyParam(pubAlgo, signAlgo);
|
||||
// SM2PrivateKey sm2PrivateKey = new SM2PrivateKey();
|
||||
// sm2PrivateKey.setBytes(priv);
|
||||
// SM2PublicKey sm2PublicKey = new SM2PublicKey();
|
||||
// sm2PublicKey.setBytes(pub);
|
||||
// return new Identity(name,keyParam, sm2PrivateKey,prikeyRawByte, sm2PublicKey, passwd, certificate, isDefault);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@@ -1,154 +1,153 @@
|
||||
package minsecurity.identity.persist;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import minsecurity.identity.Identity;
|
||||
import org.mapdb.DB;
|
||||
import org.mapdb.DBMaker;
|
||||
import org.mapdb.Serializer;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/*
|
||||
* @Author: hongyu guo
|
||||
* @Description: 封装MapDB中需要的方法
|
||||
* @Version: 1.0.0
|
||||
* @Date: 10:34 2021/03/10
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class MapDB {
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(MapDB.class);
|
||||
// TODO: 如有需要, 后续添加其他map
|
||||
// TODO: 数据库加密?
|
||||
public static final String defaultPath = "./target/test.db";
|
||||
public static final String defaultIdentity = "identity";
|
||||
public static final String defaultName = "/default";
|
||||
|
||||
|
||||
private DB db;
|
||||
private ConcurrentMap<String, Identity> identityMap;
|
||||
private Serializer<Identity> customSerializer;
|
||||
private static MapDB mapDB = null;
|
||||
|
||||
private MapDB(){
|
||||
db = DBMaker.fileDB(defaultPath).closeOnJvmShutdown().transactionEnable().make();
|
||||
customSerializer = new IdentitySerializer();
|
||||
identityMap = db.hashMap(defaultIdentity)
|
||||
.keySerializer(Serializer.STRING)
|
||||
.valueSerializer(customSerializer)
|
||||
.createOrOpen();
|
||||
}
|
||||
private MapDB(String filePath){
|
||||
db = DBMaker.fileDB(filePath).closeOnJvmShutdown().transactionEnable().make();
|
||||
customSerializer = new IdentitySerializer();
|
||||
identityMap = db.hashMap(defaultIdentity)
|
||||
.keySerializer(Serializer.STRING)
|
||||
.valueSerializer(customSerializer)
|
||||
.createOrOpen();
|
||||
}
|
||||
|
||||
public static MapDB getInstance(){
|
||||
if(mapDB == null){
|
||||
mapDB = new MapDB();
|
||||
}
|
||||
return mapDB;
|
||||
}
|
||||
public static MapDB getInstance(String filePath){
|
||||
if(mapDB == null){
|
||||
mapDB = new MapDB(filePath);
|
||||
}
|
||||
return mapDB;
|
||||
}
|
||||
|
||||
public Identity addIdentity(String name, Identity identity, boolean commit){
|
||||
Identity id = identityMap.put(name,identity);
|
||||
if(identityMap.size() == 1){
|
||||
// 首次添加default Identity
|
||||
setDefaultIdentity(name, commit);
|
||||
}
|
||||
|
||||
|
||||
if(commit){
|
||||
db.commit();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public void closeDB(){
|
||||
db.close();
|
||||
mapDB = null;
|
||||
}
|
||||
|
||||
public void commit(){
|
||||
db.commit();
|
||||
}
|
||||
|
||||
|
||||
public Identity getIdentityByName(String name){
|
||||
return identityMap.get(name);
|
||||
}
|
||||
|
||||
public ArrayList<Identity> getAllIdentity(){
|
||||
ArrayList<Identity> list = new ArrayList<>();
|
||||
for(String key : identityMap.keySet()){
|
||||
list.add(identityMap.get(key));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public boolean setDefaultIdentity(String name, boolean commit){
|
||||
Identity identity = identityMap.get(name);
|
||||
if(identity == null)
|
||||
return false;
|
||||
// 将所有identity的设置为非默认
|
||||
for(String key : identityMap.keySet()){
|
||||
Identity id = identityMap.get(key);
|
||||
if(id.isDefault()) {
|
||||
id.setDefault(false);
|
||||
identityMap.put(key, id);
|
||||
}
|
||||
}
|
||||
identity.setDefault(true);
|
||||
identityMap.put(name, identity);
|
||||
// set /default
|
||||
identityMap.put(defaultName, identity);
|
||||
if(commit){
|
||||
db.commit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Identity getDefaultIdentity(){
|
||||
return identityMap.get(defaultName);
|
||||
}
|
||||
|
||||
public Identity deleteIdentity(String name, boolean commit){
|
||||
// 不能删除默认Identity
|
||||
if(name.equals(defaultName)){
|
||||
logger.error("不能删除default identity");
|
||||
return null;
|
||||
}
|
||||
Identity identity = identityMap.remove(name);
|
||||
if(commit){
|
||||
db.commit();
|
||||
}
|
||||
return identity;
|
||||
}
|
||||
|
||||
public DB getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
public void setDb(DB db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public ConcurrentMap<String, Identity> getIdentityMap() {
|
||||
return identityMap;
|
||||
}
|
||||
|
||||
public void setIdentityMap(ConcurrentMap<String, Identity> identityMap) {
|
||||
this.identityMap = identityMap;
|
||||
}
|
||||
}
|
||||
//package minsecurity.identity.persist;
|
||||
// // 不能用于安卓,安卓编译会报错,暂时注释掉
|
||||
//import minsecurity.identity.Identity;
|
||||
//import org.mapdb.DB;
|
||||
//import org.mapdb.DBMaker;
|
||||
//import org.mapdb.Serializer;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.concurrent.ConcurrentMap;
|
||||
//
|
||||
///*
|
||||
// * @Author: hongyu guo
|
||||
// * @Description: 封装MapDB中需要的方法
|
||||
// * @Version: 1.0.0
|
||||
// * @Date: 10:34 2021/03/10
|
||||
// * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
// */
|
||||
//public class MapDB {
|
||||
// private static final org.slf4j.Logger logger = LoggerFactory.getLogger(MapDB.class);
|
||||
// // TODO: 如有需要, 后续添加其他map
|
||||
// // TODO: 数据库加密?
|
||||
// public static final String defaultPath = "./target/test.db";
|
||||
// public static final String defaultIdentity = "identity";
|
||||
// public static final String defaultName = "/default";
|
||||
//
|
||||
//
|
||||
// private DB db;
|
||||
// private ConcurrentMap<String, Identity> identityMap;
|
||||
// private Serializer<Identity> customSerializer;
|
||||
// private static MapDB mapDB = null;
|
||||
//
|
||||
// private MapDB(){
|
||||
// db = DBMaker.fileDB(defaultPath).closeOnJvmShutdown().transactionEnable().make();
|
||||
// customSerializer = new IdentitySerializer();
|
||||
// identityMap = db.hashMap(defaultIdentity)
|
||||
// .keySerializer(Serializer.STRING)
|
||||
// .valueSerializer(customSerializer)
|
||||
// .createOrOpen();
|
||||
// }
|
||||
// private MapDB(String filePath){
|
||||
// db = DBMaker.fileDB(filePath).closeOnJvmShutdown().transactionEnable().make();
|
||||
// customSerializer = new IdentitySerializer();
|
||||
// identityMap = db.hashMap(defaultIdentity)
|
||||
// .keySerializer(Serializer.STRING)
|
||||
// .valueSerializer(customSerializer)
|
||||
// .createOrOpen();
|
||||
// }
|
||||
//
|
||||
// public static MapDB getInstance(){
|
||||
// if(mapDB == null){
|
||||
// mapDB = new MapDB();
|
||||
// }
|
||||
// return mapDB;
|
||||
// }
|
||||
// public static MapDB getInstance(String filePath){
|
||||
// if(mapDB == null){
|
||||
// mapDB = new MapDB(filePath);
|
||||
// }
|
||||
// return mapDB;
|
||||
// }
|
||||
//
|
||||
// public Identity addIdentity(String name, Identity identity, boolean commit){
|
||||
// Identity id = identityMap.put(name,identity);
|
||||
// if(identityMap.size() == 1){
|
||||
// // 首次添加default Identity
|
||||
// setDefaultIdentity(name, commit);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if(commit){
|
||||
// db.commit();
|
||||
// }
|
||||
// return id;
|
||||
// }
|
||||
//
|
||||
// public void closeDB(){
|
||||
// db.close();
|
||||
// mapDB = null;
|
||||
// }
|
||||
//
|
||||
// public void commit(){
|
||||
// db.commit();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public Identity getIdentityByName(String name){
|
||||
// return identityMap.get(name);
|
||||
// }
|
||||
//
|
||||
// public ArrayList<Identity> getAllIdentity(){
|
||||
// ArrayList<Identity> list = new ArrayList<>();
|
||||
// for(String key : identityMap.keySet()){
|
||||
// list.add(identityMap.get(key));
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
//
|
||||
// public boolean setDefaultIdentity(String name, boolean commit){
|
||||
// Identity identity = identityMap.get(name);
|
||||
// if(identity == null)
|
||||
// return false;
|
||||
// // 将所有identity的设置为非默认
|
||||
// for(String key : identityMap.keySet()){
|
||||
// Identity id = identityMap.get(key);
|
||||
// if(id.isDefault()) {
|
||||
// id.setDefault(false);
|
||||
// identityMap.put(key, id);
|
||||
// }
|
||||
// }
|
||||
// identity.setDefault(true);
|
||||
// identityMap.put(name, identity);
|
||||
// // set /default
|
||||
// identityMap.put(defaultName, identity);
|
||||
// if(commit){
|
||||
// db.commit();
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// public Identity getDefaultIdentity(){
|
||||
// return identityMap.get(defaultName);
|
||||
// }
|
||||
//
|
||||
// public Identity deleteIdentity(String name, boolean commit){
|
||||
// // 不能删除默认Identity
|
||||
// if(name.equals(defaultName)){
|
||||
// logger.error("不能删除default identity");
|
||||
// return null;
|
||||
// }
|
||||
// Identity identity = identityMap.remove(name);
|
||||
// if(commit){
|
||||
// db.commit();
|
||||
// }
|
||||
// return identity;
|
||||
// }
|
||||
//
|
||||
// public DB getDb() {
|
||||
// return db;
|
||||
// }
|
||||
//
|
||||
// public void setDb(DB db) {
|
||||
// this.db = db;
|
||||
// }
|
||||
//
|
||||
// public ConcurrentMap<String, Identity> getIdentityMap() {
|
||||
// return identityMap;
|
||||
// }
|
||||
//
|
||||
// public void setIdentityMap(ConcurrentMap<String, Identity> identityMap) {
|
||||
// this.identityMap = identityMap;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -6,7 +6,7 @@ import minsecurity.crypto.sm2.SM2KeyPair;
|
||||
import minsecurity.identity.Identity;
|
||||
import minsecurity.identity.IdentityException;
|
||||
import minsecurity.identity.KeyParam;
|
||||
import minsecurity.identity.persist.MapDB;
|
||||
//import minsecurity.identity.persist.MapDB;
|
||||
import minsecurity.identity.persist.Persist;
|
||||
import minsecurity.identity.persist.sqlite.Sqlite;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package component;
|
||||
|
||||
import encoding.*;
|
||||
import mgmt.MgmtException;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
import org.junit.Test;
|
||||
import packet.PacketException;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -129,6 +129,7 @@ public class LogicFaceTest {
|
||||
}
|
||||
}
|
||||
|
||||
// todo: 在这里测试为何超时依然能接收到UDP包
|
||||
@Test
|
||||
public void testReceiveDataByUdp() throws ComponentException, LogicFaceException, EncoderException, BlockException, MgmtException, PacketException {
|
||||
Data data=new Data();
|
||||
@@ -244,7 +245,7 @@ public class LogicFaceTest {
|
||||
* 测试结果:
|
||||
* [-15, 0, -6, 25, -52, 4, 4, 5, 6, 7, -15, 0, -5, 15, -15, 0, -4, 1, 1, -15, 0, -3, 1, 1, -15, 0, -2, 1, 0]
|
||||
*/
|
||||
// @Test
|
||||
@Test
|
||||
public void startUDPServer() throws IOException {
|
||||
while(true){
|
||||
//1.创建服务端+端口
|
||||
@@ -263,6 +264,14 @@ public class LogicFaceTest {
|
||||
|
||||
SocketAddress remoteHost=packet.getSocketAddress();
|
||||
System.out.println("remote host: "+packet.getSocketAddress());
|
||||
// 睡眠5s
|
||||
try {
|
||||
System.out.println("start 5s sleeping ... ");
|
||||
Thread.sleep(5000);
|
||||
System.out.println("After 5s, wake up now!");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 做数据应答
|
||||
server.connect(remoteHost);
|
||||
server.send(packet);
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
import org.eclipse.collections.api.partition.ordered.PartitionReversibleIterable;
|
||||
//import org.eclipse.collections.api.partition.ordered.PartitionReversibleIterable;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
|
||||
@@ -8,18 +8,18 @@ import minsecurity.crypto.sm2.SM2Base;
|
||||
import minsecurity.crypto.sm2.SM2KeyPair;
|
||||
import minsecurity.crypto.sm2.SM2PrivateKey;
|
||||
import minsecurity.crypto.sm2.SM2PublicKey;
|
||||
import minsecurity.identity.persist.IdentitySerializer;
|
||||
import minsecurity.identity.persist.MapDB;
|
||||
//import minsecurity.identity.persist.IdentitySerializer;
|
||||
//import minsecurity.identity.persist.MapDB;
|
||||
import minsecurity.identity.persist.Persist;
|
||||
import minsecurity.identity.persist.sqlite.Sqlite;
|
||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.junit.Test;
|
||||
import org.mapdb.BTreeMap;
|
||||
import org.mapdb.DB;
|
||||
import org.mapdb.DBMaker;
|
||||
import org.mapdb.Serializer;
|
||||
//import org.mapdb.BTreeMap;
|
||||
//import org.mapdb.DB;
|
||||
//import org.mapdb.DBMaker;
|
||||
//import org.mapdb.Serializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import minsecurity.crypto.sm2.SM2KeyPair;
|
||||
import minsecurity.identity.Identity;
|
||||
import minsecurity.identity.KeyParam;
|
||||
import minsecurity.identity.TestIdentity;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
//import org.checkerframework.checker.units.qual.C;
|
||||
//import org.checkerframework.checker.units.qual.K;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import packet.CPacket;
|
||||
|
||||
@@ -10,7 +10,7 @@ import minsecurity.certificate.cert.Certificate;
|
||||
import minsecurity.crypto.sm2.SM2KeyPair;
|
||||
import minsecurity.identity.Identity;
|
||||
import minsecurity.identity.KeyParam;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
//import org.checkerframework.checker.units.qual.K;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
|
||||
Reference in New Issue
Block a user