for(int i = 1; i < allmetadata.size()+1; i++){
namesToDelete[i] = allmetadata.get(i-1).getVersionFileId();
}
DepSkySCloudManager manager = getDriverManagerByDriverId(metadataReply.cloudId);
CloudRequest r = new CloudRequest(DepSkySCloudManager.DEL_CONT,
metadataReply.sequence, manager.driver.getSessionKey(),
metadataReply.container,namesToDelete,metadataReply.reg,
DepSkySManager.DELETE_ALL, false);
manager.doRequest(r);
return ;
}
//if is a read MAtching operation
if(metadataReply.hashMatching != null){
for(int i = 0; i < allmetadata.size(); i++){
if(Arrays.equals(allmetadata.get(i).getAllDataHash(), metadataReply.hashMatching)){
dm = allmetadata.get(i);
datareplied = dm.getMetadata();
if (datareplied.length() < 1) {
throw new Exception("invalid metadata size received");
}
cont = allmetadata.size()+1;
}
}
if(cont < allmetadata.size()+1 )
throw new Exception("no matching version available");
}else{ //if is a normal read (last version read)
dm = allmetadata.getFirst();
datareplied = dm.getMetadata();
if (datareplied.length() < 1) {
throw new Exception("invalid metadata size received");
}
}
byte[] mdinfo = datareplied.getBytes();
byte[] signature = dm.getsignature();
Properties props = new Properties();
props.load(new ByteArrayInputStream(mdinfo));
//METADATA info
String verNumber = props.getProperty("versionNumber");
String verHash = props.getProperty("versionHash");
String verValueFileId = props.getProperty("versionFileId");
String verPVSSinfo = props.getProperty("versionPVSSinfo");
String verECinfo = props.getProperty("versionECinfo");
long versionfound = Long.parseLong(verNumber);
//extract client id
Long writerId = versionfound % MAX_CLIENTS;
//metadata signature check
if (!verifyMetadataSignature(writerId.intValue(), mdinfo, signature) ||
!verifyMetadataSignature(writerId.intValue(), metadataInit, allMetadataSignature)) {
//invalid signature
System.out.println("...........................");
throw new Exception("Signature verification failed for " + metadataReply);
}
//set the data unit to the protocol in use
if ((verPVSSinfo != null || verECinfo != null)/* && metadataReply.reg.info == null*/) {
if(verPVSSinfo != null && verECinfo == null){
metadataReply.reg.setUsingSecSharing(true);
metadataReply.reg.setPVSSinfo(verPVSSinfo.split(";"));
}
if(verECinfo != null && verPVSSinfo == null){
metadataReply.reg.setUsingErsCodes(true);
if(metadataReply.protoOp == DepSkySManager.READ_PROTO){
metadataReply.reg.setErCodesReedSolMeta(verECinfo);
}
}
if(verECinfo != null && verPVSSinfo !=null){
metadataReply.reg.setUsingPVSS(true);
metadataReply.reg.setPVSSinfo(verPVSSinfo.split(";"));
if(metadataReply.protoOp == DepSkySManager.READ_PROTO){
metadataReply.reg.setErCodesReedSolMeta(verECinfo);
}
}
}
long ts = versionfound - writerId;//remove client id from versionNumber
metadataReply.setVersionNumber(ts + "");//version received
metadataReply.setVersionHash(verHash);
metadataReply.setValueFileId(verValueFileId);//added
if(metadataReply.protoOp == DepSkySManager.ACL_PROTO){
depskys.dataReceived(metadataReply);
return;
}
if (metadataReply.protoOp == DepSkySManager.WRITE_PROTO) {
if(metadataReply.cloudId.equals("cloud1")){
cloud1.put(metadataReply.container, allmetadata);
}else if(metadataReply.cloudId.equals("cloud2")){
cloud2.put(metadataReply.container, allmetadata);
}else if(metadataReply.cloudId.equals("cloud3")){
cloud3.put(metadataReply.container, allmetadata);
}else if(metadataReply.cloudId.equals("cloud4")){
cloud4.put(metadataReply.container, allmetadata);
}
// if (metadataReply.sequence < 0) {
// //System.out.println("read metadata, now sending write value...");
// DepSkySCloudManager manager = getDriverManagerByDriverId(metadataReply.cloudId);
// CloudRequest r = new CloudRequest(DepSkySCloudManager.NEW_DATA,
// metadataReply.sequence, manager.driver.getSessionKey(),
// metadataReply.container,
// metadataReply.reg.getGivenVersionValueDataFileName(ts + ""),
// depskys.testData, null,
// metadataReply.reg, metadataReply.protoOp, false,
// ts + "", verHash, metadataReply.allDataHash);
// r.setStartTime(metadataReply.startTime);
// r.setMetadataReceiveTime(metadataReply.metadataReceiveTime);
// manager.doRequest(r);//request valuedata file
// return;
// }
depskys.dataReceived(metadataReply);
return;
}
synchronized (this) {
if (metadataReply.sequence == depskys.lastReadMetadataSequence) {
if (depskys.lastMetadataReplies == null) {
depskys.lastMetadataReplies = new ArrayList<CloudReply>();
}
depskys.lastMetadataReplies.add(metadataReply);
metadataReply.reg.setCloudVersion(metadataReply.cloudId, ts);
//System.out.println("IN:CLOUD VERSION " + ts + " for " + metadataReply.cloudId);
}
if (metadataReply.sequence >= 0
&& canReleaseAndReturn(metadataReply)) {
//check release
return;
}
if (!depskys.sendingParallelRequests() && depskys.sentOne) {
// depskys.dataReceived(metadataReply);
} else {
depskys.sentOne = true;
DepSkySCloudManager manager = getDriverManagerByDriverId(metadataReply.cloudId);
CloudRequest r = new CloudRequest(DepSkySCloudManager.GET_DATA,
metadataReply.sequence, manager.driver.getSessionKey(),
metadataReply.container, verValueFileId, null, null,
metadataReply.reg, metadataReply.protoOp, false,
ts + "", verHash, null);
r.setStartTime(metadataReply.startTime);
r.setMetadataReceiveTime(metadataReply.metadataReceiveTime);
manager.doRequest(r);//request valuedata file
}
}//end synch this
} catch (Exception ex) {