在v0.1版本基础上,增加了通信加密功能

This commit is contained in:
free will
2020-08-04 21:24:11 +08:00
commit 93d343dcf5
215 changed files with 21681 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
.gradle/
build/
out/
ndn/pid/*
ndn/tpm/*
ndn/log.txt
.idea/
+45
View File
@@ -0,0 +1,45 @@
plugins {
id 'java'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
apply plugin: 'java'
apply plugin: 'org.openjfx.javafxplugin'
group 'pkusz'
version '0.1'
sourceCompatibility = 11
targetCompatibility = 11
//指定编译编码
tasks.withType(JavaCompile){
options.encoding="UTF-8"
}
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
// mavenCentral()
}
dependencies {
// compile files('lib/controlsfx-8.0.6_20.jar')
testCompile group: 'junit', name: 'junit', version: '4.12'
compile fileTree(dir: 'lib',includes: ['*jar'])
compile 'com.blankj:utilcode:1.10.0'
}
javafx {
version = "11.0.2"
modules = [ 'javafx.controls','javafx.fxml' ]
}
jar{
manifestContentCharset 'utf-8'
metadataCharset 'utf-8'
manifest{
attributes "Main-Class": "cn.minoa.Main"
}
from{
configurations.compile.collect{it.isDirectory()?it:zipTree(it)}
}
}
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
View File
@@ -0,0 +1,2 @@
#commit changes: delete a prefix
#Fri Apr 17 20:54:49 CST 2020
+5
View File
@@ -0,0 +1,5 @@
#commit changes
#Sat Jun 13 21:01:12 CST 2020
filePoint-17A14B227AA88D90777E474A4FB069FB=1700C7E9006964993B9205E1475D2971
fileServerPath-17A14B227AA88D90777E474A4FB069FB=6FBECA975021EF837FA57E30E2385322
fileName-17A14B227AA88D90777E474A4FB069FB=AAEE06DF89E40D8A3BC74AF731335E7C
+1
View File
@@ -0,0 +1 @@
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDdQhZHnXQmXCTrLbzsN9ZamwLFp+lWvZAt6o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uZeVpbj6W76Cc90426OFEH8eHHWg8QlG1QX8Z+2AfO/SzRjL1UBvYNzMg3Yr1+5W/km8Zc/vj5zDBOh85dd9zvxh2lcRQeX0T9akdlygWyFc/MPwuka0Q24ie5EXC1z6KCJTa92cF8cj1Mnp7MLjosW5EqfN66wMpM5VMB7/0asufFP1u/B1rd0B7MJaDwIDAQAB
+12
View File
@@ -0,0 +1,12 @@
#\u4FEE\u6539\u914D\u7F6E\u6587\u4EF6
#Sat Jun 13 22:34:20 CST 2020
KeyName=/MYGOD
loginUserName=FDF5A6F1F2B78ADE3DC7700AEFEF5C0F
ndnBlockChainIPAddress=116.77.74.140
ServerIPAddress=116.77.74.139
ThreadNumberForFileTransfer=5
ndnBlockChainPortAddress=9001
DataPackagePrefix=/ndn/edu/pkusz/OA
LoginStatus=false
loginPassWord=A1B9652D9ED940B8FC63453C50CB3337
ServerPortAddress=6363
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

+4
View File
@@ -0,0 +1,4 @@
rootProject.name = 'CUTV_FileSystem'
rootProject.name = 'CUTV_FileSystem'
rootProject.name = 'CUTV_FileSystem'
+11
View File
@@ -0,0 +1,11 @@
package cn.minoa;
// 放置主函数入口。
// 解决了“缺少运行JavaFX组件”的报错.
import javafx.application.Application;
public class Main {
public static void main(String[] args) {
Application.launch(MainApp.class);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,206 @@
package cn.minoa.dataRequestInterface;
/**
* @author mac
* @description
* 拥塞窗口
* @date 2020-03-24 10:25
*/
public class CongestionWindow {
//拥塞窗口大小
private Double cwnd;
//表示当前正在发送的数据,发送一条数据需要加一,收到成功恢复需要减一
private Double inFlight;
//拥塞窗口阈值
private Double thresh;
//下一次窗口减小的界限
private Integer nSupress = 0;
//收到数据包的数量,收到一个数据包进行加一操作
private Long nIndata = 0l;
//发送兴趣包的数量,发出一个兴趣包进行加一操作
private Long nOutInterest = 0l;
//更新nsupress时的一个比率
private static Double rate = 0.5d;
public CongestionWindow(){
this.cwnd = 4d;
this.thresh = 300d;
this.inFlight = 0d;
}
public CongestionWindow(Double cwnd, Double thresh, Double inFlight){
this.inFlight = inFlight;
this.cwnd = cwnd;
this.thresh = thresh;
}
/**
* 当前窗口是否为空
* @return
*/
public boolean empty(){
boolean res = false;
synchronized (this){
if (inFlight == 0){
res = true;
}
}
return res;
}
/**
* 当前窗口是否已满
* @return
*/
public boolean full(){
boolean res = false;
synchronized (this){
if(cwnd == inFlight){
res = true;
}
}
return res;
}
/**
* 获取当前还能发送多少数据
* 如果不能发送数据,返回值为0
* @return
*/
public int getAvailableCwnd(){
int res = 0;
synchronized (this){
if(inFlight >= cwnd){
res = 0;
}else{
res = (int)(cwnd - inFlight);
}
}
return res;
}
/**
* 在onData函数中
* 收到一个数据包,执行加一操作,需要加锁
*/
public void nIndataIncrease(){
synchronized (this){
nIndata++;
}
}
/**
* 发出一个兴趣包,执行加一操作,不需要加锁
*/
public void nOutInterestIncrease(){
nOutInterest++;
}
/**
* inFlight加一
*/
public void inFlightIncrease(){
synchronized (this){
this.inFlight++;
}
}
public void inFlightIncrease(int inFlight){
synchronized (this){
this.inFlight += inFlight;
}
}
/**
* inFliehgt减一
*/
public void inFlightDecrease(){
synchronized (this){
this.inFlight--;
}
}
public void inFlightDecrease(int inFlight){
synchronized (this){
this.inFlight -= inFlight;
}
}
/**
* 增加拥塞窗口的值
*
*/
public void cwndIncrease(){
synchronized (this){
if(this.cwnd < this.thresh){
//慢开始算法
this.cwnd += 1;
/*if(this.cwnd > this.thresh){
this.thresh = this.cwnd;
}*/
}else{
//拥塞避免算法
this.cwnd += (1.0/this.cwnd);
}
}
System.out.println("-----------------------------------------cwnd:" + cwnd + ", thresh:" + thresh);
}
/**
* 减少拥塞窗口的值
* 每当检测到拥塞时,就需要执行此函数
*/
public void cwndDecrease(){
synchronized (this){
if(nIndata >= nSupress){
// this.thresh = Math.floor(this.cwnd/2);
this.thresh = this.cwnd/2;
this.cwnd = this.thresh;
nSupress = (int)(nOutInterest + rate*(nOutInterest - nIndata));
}
}
System.out.println("-----------------------------------------cwnd:" + cwnd + ", thresh:" + thresh);
}
/**
* 设置拥塞窗口大小
* @param cwnd
*/
public void setCwnd(Double cwnd){
synchronized (this){
this.cwnd = cwnd;
}
}
/**
* 获得当前拥塞窗口大小
* @return
*/
public Integer getCwnd(){
int res = 0;
synchronized (this){
res = this.cwnd.intValue();
}
return res;
}
@Override
public String toString() {
return "CongestionWindow {" +
"cwnd=" + cwnd +
", inFlight=" + inFlight +
", thresh=" + thresh +
'}';
}
}
@@ -0,0 +1,54 @@
package cn.minoa.dataRequestInterface;
//缓存服务器的回执数据
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class DataCacheQueue {
//存储数据回执
// public static volatile Map<Long, ResponseData> responseDataMap;
public static volatile ConcurrentHashMap<Long, ResponseData> responseDataMap = new ConcurrentHashMap<Long, ResponseData>();
public DataCacheQueue() {
// TODO Auto-generated constructor stub
// responseDataMap=new TreeMap<Long, ResponseData>();
responseDataMap=new ConcurrentHashMap<Long, ResponseData>();
}
//放入一个数据
public static void setResponseData(Long seq,ResponseData rd) {
responseDataMap.put(seq, rd);
}
//根据seq获取ResponseData
public static ResponseData getResponseDataBySeq(Long seq) {
//等待数据回执
while(!responseDataMap.containsKey(seq)) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
ResponseData rd=responseDataMap.get(seq);
responseDataMap.remove(seq);
return rd;
}
//判断是否为空
public static boolean isEmpty() {
return responseDataMap.isEmpty();
}
public static void showMapData(){
System.out.println("this is responseDataMap info:");
for(Map.Entry<Long, ResponseData> entry : responseDataMap.entrySet()){
System.out.println("entry-key:" + entry.getKey() + ", entry-value:");
entry.getValue().printSelf();
}
System.out.println("--------------- end ----------------");
}
}
@@ -0,0 +1,133 @@
package cn.minoa.dataRequestInterface;
import org.json.JSONObject;
import cn.minoa.MainApp;
public class DataTestMain {
//文件操作命令
static private String getFileActionJson(String uuid,String cmd) {
JSONObject jsonObject =new JSONObject();
String commandString="/fileAction";
String usernameString="wefree";
String uuidString=uuid;
String cmdString=cmd;
String filename="/";
try {
jsonObject.put("command", commandString);
jsonObject.put("username", usernameString);
jsonObject.put("uuid", uuidString);
jsonObject.put("fileCmd", cmdString);
jsonObject.put("filename", filename);
} catch (Exception e) {
// TODO: handle exception
System.out.println("exception: " + e.getMessage());
}
return jsonObject.toString();
}
//发送消息
static private String getSendRTMsgJson(String uuid,String msgTail) {
JSONObject jsonObject =new JSONObject();
String commandString="/sendRTMsg";
String fromString="oa_wefree";
String toString="wefree";
String uuidString=uuid;
String msgString="hello,wefree. iam oa_wefree. --"+msgTail;
try {
jsonObject.put("command", commandString);
jsonObject.put("from", fromString);
jsonObject.put("to", toString);
jsonObject.put("uuid", uuidString);
jsonObject.put("msg", msgString);
} catch (Exception e) {
// TODO: handle exception
System.out.println("exception: " + e.getMessage());
}
return jsonObject.toString();
}
//请求通知消息
static private String getGetInformJson(Integer pageNo,String uuidString) {
JSONObject jsonObject =new JSONObject();
String commandString="/getInform";
String usernameString="wefree";
Integer pageNoInteger=pageNo;
Integer pageSizeInteger=10;
try {
jsonObject.put("command", commandString);
jsonObject.put("username", usernameString);
jsonObject.put("uuid", uuidString);
jsonObject.put("pageNo", pageNoInteger);
jsonObject.put("pageSize", pageSizeInteger);
} catch (Exception e) {
// TODO: handle exception
System.out.println("exception: " + e.getMessage());
}
return jsonObject.toString();
}
public static void main(String args[]){
MainApp mainApp=new MainApp();
MinoaDataAPI minoaDataAPI=new MinoaDataAPI(mainApp);
//test register
// minoaDataAPI.executeOrder("/register", orderInfo);
//test login
OrderInfo loginOrderInfo=new OrderInfo();
loginOrderInfo.setSeq((long) 0);
loginOrderInfo.setLoginJson();
minoaDataAPI.executeOrder("/login", loginOrderInfo);
ResponseData responseData=minoaDataAPI.dataCacheQueue.getResponseDataBySeq((long) 0);
responseData.printSelf();
String uuidString=responseData.getUuidByPraseLoginData();
//test getUsers
// minoaDataAPI.executeOrder("/getUsers", orderInfo);
//test sendRTMsg
// minoaDataAPI.executeOrder("/sendRTMsg", orderInfo);
//test getRTMsg
// minoaDataAPI.executeOrder("/getRTMsg", orderInfo);
//test getRTMsgLog
// minoaDataAPI.executeOrder("/getRTMsgLog", orderInfo);
//制造点假数据出来[wefree=>oa_wefree]
// OrderInfo orderInfo=new OrderInfo();
// String sendJsonString;
// for(int i=1;i<5;i++) {
// orderInfo.setSeq((long) i);
// sendJsonString=getSendRTMsgJson(uuidString,String.valueOf(i));
// orderInfo.setJsonString(sendJsonString);
// minoaDataAPI.executeOrder("/sendRTMsg", orderInfo);
// responseData=minoaDataAPI.dataCacheQueue.getResponseDataBySeq((long) i);
// responseData.printSelf();
// }
//测试请求通知信息
// OrderInfo orderInfo=new OrderInfo();
// orderInfo.setSeq((long)1);
// orderInfo.setJsonString(getGetInformJson(0,uuidString));
// minoaDataAPI.executeOrder("/getInform", orderInfo);
// responseData=minoaDataAPI.dataCacheQueue.getResponseDataBySeq((long) 1);
// responseData.printSelf();
//测试云文件上传下载
OrderInfo orderInfo=new OrderInfo();
orderInfo.setSeq((long)1);
orderInfo.setJsonString(getFileActionJson(uuidString, "ls"));
minoaDataAPI.executeOrder("/fileAction", orderInfo);
responseData=minoaDataAPI.dataCacheQueue.getResponseDataBySeq((long) 1);
responseData.printSelf();
orderInfo.setSeq((long)2);
orderInfo.setJsonString(getFileActionJson(uuidString, "rm"));
minoaDataAPI.executeOrder("/fileAction", orderInfo);
responseData=minoaDataAPI.dataCacheQueue.getResponseDataBySeq((long) 2);
responseData.printSelf();
orderInfo.setSeq((long)3);
orderInfo.setJsonString(getFileActionJson(uuidString, "mkdir"));
minoaDataAPI.executeOrder("/fileAction", orderInfo);
responseData=minoaDataAPI.dataCacheQueue.getResponseDataBySeq((long) 3);
responseData.printSelf();
}
}
@@ -0,0 +1,420 @@
package cn.minoa.dataRequestInterface;
// 多线程上传下载:数据收发接口【3/3】
import cn.minoa.MainApp;
import cn.minoa.util.StringByteLengthUtil;
import net.named_data.jndn.Data;
import net.named_data.jndn.Interest;
import net.named_data.jndn.Name;
import net.named_data.jndn.OnData;
import net.named_data.jndn.security.KeyChain;
import net.named_data.jndn.security.SecurityException;
import net.named_data.jndn.security.pib.PibImpl;
import net.named_data.jndn.util.Blob;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
/**
* @author mac
* @description
* @date 2020-03-16 11:16
*/
public class DownAndUpLoadData {
/**
* 构造下载文件的json信息
* @param filename
* @param sliceNo
* @return
*/
public static String getDownloadFileJson(String filename, Integer sliceNo) {
JSONObject jsonObject = new JSONObject();
String commandString;
if(filename.contains("/")){
commandString = "/downloadFile";
}else{
commandString="/downloadShareFile";
}
String usernameString = MainApp.loginer.getUserName();
String uuidString = MainApp.loginer.getUuid();
String filenameString = filename;
Integer sliceNoInteger = sliceNo;
try {
jsonObject.put("command", commandString);
jsonObject.put("username", usernameString);
jsonObject.put("uuid", uuidString);
jsonObject.put("filename", filenameString);
jsonObject.put("sliceNo", sliceNoInteger);
} catch (Exception e) {
// TODO: handle exception
System.out.println("exception: " + e.getMessage());
}
System.out.println("getDownloadFileJson: "+jsonObject.toString());
return jsonObject.toString();
}
/**
* 构造上传文件的json字符串
* @param filename
* @param offset
* @return
*/
public static String getUploadFile(String filename, Long offset) {
JSONObject jsonObject = new JSONObject();
String commandString = "/uploadFile";
String usernameString = MainApp.loginer.getUserName();
String uuidString = MainApp.loginer.getUuid();
String filenameString = filename;
Long offsetInteger = offset;
try {
jsonObject.put("command", commandString);
jsonObject.put("username", usernameString);
jsonObject.put("uuid", uuidString);
jsonObject.put("filename", filenameString);
jsonObject.put("offset", offsetInteger);
} catch (Exception e) {
// TODO: handle exception
System.out.println("exception: " + e.getMessage());
}
return jsonObject.toString();
}
// public static String getUploadFile(String filename, Integer offset) {
// JSONObject jsonObject = new JSONObject();
// String commandString = "/uploadFile";
// String usernameString = MainApp.loginer.getUserName();
// String uuidString = MainApp.loginer.getUuid();
// String filenameString = filename;
// Integer offsetInteger = offset;
// try {
// jsonObject.put("command", commandString);
// jsonObject.put("username", usernameString);
// jsonObject.put("uuid", uuidString);
// jsonObject.put("filename", filenameString);
// jsonObject.put("offset", offsetInteger);
// } catch (Exception e) {
// // TODO: handle exception
// System.out.println("exception: " + e.getMessage());
// }
// return jsonObject.toString();
// }
// // 请求文件分片数据=>返回0表示分片数据被成功下载
//
// /**
// * 请求文件分片数据
// * @param filename
// * 文件名
// * @param sliceNo
// * 分片号
// * @param localDir
// * 文件下载到本地时的文件夹
// * @param localName
// * 文件下载到本地时的文件名
// * @return
// */
// public static Integer downLoadFileBySliceYuhy(String filename, Integer sliceNo, String localDir, String localName) {
//// System.out.println("&&&&&&&&&&downloaddata::downLoadFileBySliceYuhy method");
// OrderInfo orderInfo = new OrderInfo();
// Integer flagInteger = 0;
// // 发送数据请求
// Long seqLong = MainApp.getNewDataReqId();
// orderInfo.setSeq(seqLong);
//
//// System.out.println("orderInfo_id:" + seqLong);
//
// orderInfo.setJsonString(getDownloadFileJson(filename, sliceNo));
//
//// System.out.println("*****************" + seqLong + ",&&&&&&&&&&&&&&&," + orderInfo.getJsonString());
// if(filename.contains("/")){
// DownAndUpLoadData.executeOrderYhy("/downloadFile", orderInfo, localDir, localName);
// }else{
// DownAndUpLoadData.executeOrderYhy("/downloadShareFile", orderInfo, localDir, localName);
// }
//
// //输出dataCacheQueue中的map的信息
//// DataCacheQueue.showMapData();
//
// //获取头像信息
// ResponseData responseData = DataCacheQueue.getResponseDataBySeq(seqLong);
//
//// System.out.println("size" + DataCacheQueue.responseDataMap.size());
// flagInteger = Integer.parseInt(responseData.getResponseJsonDataString());
//
//// System.out.println("downloadFileSlice-JSON: " + responseData.getResponseJsonDataString());
// return flagInteger;
// }
// /**
// * 向服务器发送下载文件请求,并下载文件
// * @param orderPrefix
// * 下载文件的命令
// * @param orderInfo
// * @param localDir
// * @param localName
// * @return
// */
// public static boolean executeOrderYhy(String orderPrefix, OrderInfo orderInfo, String localDir, String localName) {
//// System.out.println("********************" + "downloadData");
// // 获取json格式的数据请求字符串
// String requestStr = MinoaDataAPI.getRequestStr(orderPrefix, orderInfo);
//// System.out.println("requestStr:" + requestStr);
// // 命令前缀格式不对的情况下返回false
// if (requestStr.equals("*wrong command string*")) {
// System.out.println(requestStr);
// return false;
// }
//
// // 发送数据兴趣包
// Name name = new Name(MinoaDataAPI.globalPrefixString + orderPrefix + "/" + orderInfo.getSeq() +"/" +localName.substring(localName.length()-1));
//// System.out.println("uri:" + MinoaDataAPI.globalPrefixString + orderPrefix + "/" + orderInfo.getSeq() + "/" +localName.substring(localName.length()-1));
// Interest interest = new Interest(name);
// interest.setMustBeFresh(true);
// try {
// // 文件下载
// interest.setApplicationParameters(new Blob(requestStr));
// // 密钥“黑盒”
//// MinoaDataAPI.keyChain.sign(interest);
// KeyManager.INSTANCE.getKeyChain().sign(interest);
// expressTheDownloadInterest(orderPrefix, interest, orderInfo,localDir,localName);
// return true;
// } catch (Exception e) {
// System.out.println("exception: " + e.getMessage());
// e.printStackTrace();
// return false;
// }
// }
//下载文件的数据分片到指定路径,并将文件重命名为指定文件名
// private static void expressTheDownloadInterest(String orderPrefix, Interest interest, OrderInfo orderInfo, String localDir, String localName) {
// // 设置回执前缀
// ResponseData responseData = new ResponseData();
// responseData.setPrefix(orderPrefix);
// try {
// // 使用匿名内部类,发送数据请求兴趣包
// MinoaDataAPI.face.expressInterest(interest, new OnData() {
// @Override
// public void onData(Interest interest, Data data) {
// // 解析文件名、分片编号
// String filePathString = localDir;
// Integer sliceSizeInteger = MainApp.sliceSize;
// String filenameString = localName;
// Integer sliceNoInteger = null;
// try {
// JSONObject jsonObject = new JSONObject(orderInfo.getJsonString());
// sliceNoInteger = jsonObject.getInt("sliceNo");
// } catch (JSONException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// // 写入本地文件
// Integer successInfoInteger = 1;
// try {
// System.out.println("开始写入文件数据分片... :" + filePathString + filenameString);
// int contentSize = data.getContent().size();
// System.out.println("该数据分片长度为:" + contentSize);
// byte[] content = new byte[contentSize];
// for (int i = 0; i < contentSize; i++) {
// content[i] = data.getContent().buf().get(i);
// }
//
//// RandomAccessFile randomAccessFile = new RandomAccessFile(filePathString + filenameString, "rw");
//// // 设置数据分片写入到文件的起点位置
//// randomAccessFile.seek(sliceNoInteger * sliceSizeInteger);
//// // 写入数据分片
//// randomAccessFile.write(content, 0, contentSize);
//// randomAccessFile.close();
//
// FileOutputStream fos = new FileOutputStream(filePathString + filenameString,true);
// fos.write(content,0,contentSize);
// fos.flush();//强制刷新出去
// fos.close();
// System.out.println("写入文件数据分片完毕:" + filePathString + filenameString);
// successInfoInteger = 0;
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// // 返回成功写入或失败写入消息
// responseData.setResponseData(successInfoInteger.toString());
// DataCacheQueue.setResponseData(orderInfo.getSeq(), responseData);
//// System.out.println("getCommandPrefix:" + responseData.getCommandPrefix());
//// System.out.println("getResponseJsonDataString:" + responseData.getResponseJsonDataString());
//// System.out.println("map-key:" + orderInfo.getSeq());
// }
// });
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// /**
// * 上传文件
// * @param orderPrefix
// * @param fileAbsolutePath
// * @param offset
// * @param serverpath
// * @return
// */
// public static boolean uploadOrder(String orderPrefix, String fileAbsolutePath, Integer offset, String serverpath) {
//
// OrderInfo orderInfo = new OrderInfo();
// Long seqLong = MainApp.getNewDataReqId();
// orderInfo.setSeq(seqLong);
// String testStr = getUploadFile(fileAbsolutePath, offset);
//// System.out.println("*******************:" + testStr + "*******************");
// orderInfo.setJsonString(testStr);
//
// // 获取json格式的数据请求字符串
// String requestStr = MinoaDataAPI.getRequestStr(orderPrefix, orderInfo);
// //System.out.println("requestStr: "+requestStr);
// // 命令前缀格式不对的情况下返回false
// if (requestStr.equals("*wrong command string*")) {
// System.out.println(requestStr);
// return false;
// }
//
// // 发送数据兴趣包
// Name name = new Name(MinoaDataAPI.globalPrefixString + orderPrefix + "/" + orderInfo.getSeq());
// Interest interest = new Interest(name);
// interest.setMustBeFresh(true);
// //System.out.println("interest name: "+name.toString());
// try {
// expressTheUploadInterest(orderPrefix, interest, orderInfo,serverpath);
//
// ResponseData responseData = DataCacheQueue.getResponseDataBySeq(seqLong);
// //System.out.println("上传文件的数据回执(200表示成功)"+responseData.getResponseJsonDataString());
// JSONObject jsonObject = responseData.praseRequestData();
//
// // 解析数据
// Integer codeInteger = null;
// try {
// codeInteger = jsonObject.getInt("code");
// } catch (JSONException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// if (codeInteger == 200) {
// return true;
// }else{
// return false;
// }
// } catch (Exception e) {
// System.out.println("exception: " + e.getMessage());
// e.printStackTrace();
// return false;
// }
//
// }
//
// private static void expressTheUploadInterest(String orderPrefix, Interest interest, OrderInfo orderInfo, String serverPath){
// ResponseData responseData = new ResponseData();
// responseData.setPrefix(orderPrefix);
// byte[] requestByte = null; // 请求数据
// // 重写ondata
// try {
// // 解析并修改文件名【window转server】
// String localFilePath = "";
// String serverFilePath = "";
// Integer offsetInteger = 0;
// try {
// // 解析
// JSONObject jsonObject = new JSONObject(orderInfo.getJsonString());
// offsetInteger = jsonObject.getInt("offset");
//// System.out.println("&&&&&&&&&&&&&&&&&&上传第 " + (offsetInteger/7000) + " 片");
// localFilePath = jsonObject.getString("filename");
//// serverFilePath = serverpath + getPureFileNameFromWindows(localFilePath);
// serverFilePath = serverPath + MinoaDataAPI.getPureFileNameFromWindows(localFilePath);
// // 修改
// jsonObject.remove("filename");
// jsonObject.put("filename", serverFilePath);
// orderInfo.setJsonString(jsonObject.toString());
// System.out.println("request head str: " + orderInfo.getJsonString());
// System.out.println("head str length: "+orderInfo.getJsonString().length());
// System.out.println("head str byte length: "+ StringByteLengthUtil.getByteLength(orderInfo.getJsonString()));
// } catch (JSONException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// // 从本地读取数据
// byte[] content = new byte[10000]; // 文件分片内容
// try {
// if(offsetInteger<0){
// // 发送文件上传结束的标志【offset<0】
// int jsonLen = StringByteLengthUtil.getByteLength(orderInfo.getJsonString());
// requestByte = new byte[jsonLen];
// System.arraycopy(orderInfo.getJsonString().getBytes("utf-8"), 0, requestByte, 0, jsonLen);
// }else {
// RandomAccessFile randomAccessFile = new RandomAccessFile(localFilePath, "rw");
// // 设置文件的读取起点
// randomAccessFile.seek(offsetInteger);
// // 尝试读取数据
// int readLen = randomAccessFile.read(content, 0, 7000);
// randomAccessFile.close();
// System.out.println("file slice readLen == " + readLen);
//// int jsonLen = orderInfo.getJsonString().length();
// int jsonLen = StringByteLengthUtil.getByteLength(orderInfo.getJsonString());
// requestByte = new byte[jsonLen + 1 + readLen];
// System.arraycopy(orderInfo.getJsonString().getBytes("utf-8"), 0, requestByte, 0, jsonLen);
// requestByte[jsonLen] = 0;
// System.arraycopy(content, 0, requestByte, jsonLen + 1, readLen);
// }
//// RandomAccessFile randomAccessFile = new RandomAccessFile(localFilePath, "rw");
//// // 设置文件的读取起点
//// randomAccessFile.seek(offsetInteger);
//// // 尝试读取数据
//// int readLen = randomAccessFile.read(content, 0, 7000);
//// randomAccessFile.close();
////// System.out.println("file slice readLen == " + readLen);
//// int jsonLen= StringByteLengthUtil.getByteLength(orderInfo.getJsonString());
//// requestByte = new byte[jsonLen + 1 + readLen];
//// System.arraycopy(orderInfo.getJsonString().getBytes(), 0, requestByte, 0, jsonLen);
//// requestByte[jsonLen] = 0;
//// System.arraycopy(content, 0, requestByte, jsonLen + 1, readLen);
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// // 赋值兴趣包的附带信息,并标志区块链
//// System.out.println("requestByte-len: " + requestByte.length);
//// System.out.println("requestByte: " + requestByte);
// interest.setApplicationParameters(new Blob(requestByte));
//// System.out.println("interest.getApplicationParameters().size(): "+interest.getApplicationParameters().size());
// // 密钥“黑盒”
// try {
//// MinoaDataAPI.keyChain.sign(interest);
// KeyManager.INSTANCE.getKeyChain().sign(interest);
// } catch (PibImpl.Error e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (KeyChain.Error e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (net.named_data.jndn.security.tpm.TpmBackEnd.Error e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// // 使用匿名内部类,发送数据请求兴趣包
// MinoaDataAPI.face.expressInterest(interest, new OnData() {
// @Override
// public void onData(Interest interest, Data data) {
// // 返回成功写入或失败写入消息
// responseData.setResponseData(data.getContent().toString());
// DataCacheQueue.setResponseData(orderInfo.getSeq(), responseData);
// }
// });
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}

Some files were not shown because too many files have changed in this diff Show More