prune old doi logic

This commit is contained in:
CaiHQ 2023-03-31 17:10:40 +08:00
parent e76865fb09
commit af298b6ae7
8 changed files with 78 additions and 16 deletions

View File

@ -40,8 +40,8 @@ dependencies {
implementation 'io.grpc:grpc-all:1.43.1'
implementation 'org.apache.velocity:velocity-engine-core:2.3'
implementation 'com.nimbusds:nimbus-jose-jwt:9.10'
implementation 'org.bdware.doip:doip-sdk:1.3.8'
implementation 'org.bdware.doip:doip-audit-tool:1.2.0'
implementation 'org.bdware.doip:doip-sdk:1.3.9'
implementation 'org.bdware.doip:doip-audit-tool:1.2.1'
implementation 'org.bdware.doip:bdosclient:0.0.2'
implementation fileTree(dir: 'lib', include: '*.jar')
testImplementation 'junit:junit:4.13.2'

View File

@ -1320,7 +1320,7 @@ public class CMActions implements OnHashCallback {
String ret;
try {
ContractClient cc = manager.getClient(args.get("id").getAsString());
ret = cc.getContractDOI();
ret = cc.getContractID();
} catch (Exception e) {
ByteArrayOutputStream bo = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(bo));

View File

@ -416,7 +416,7 @@ public class FileActions {
c.setScript(ypkPath);
c.setOwner(owner);
c.setDebug(isDebug);
CMActions.manager.startContractAndRedirect(c, System.out, null); // createPS()
CMActions.manager.startContractAndRedirect(c, System.out); // createPS()
}
} catch (Exception e) {
e.printStackTrace();

View File

@ -207,15 +207,6 @@ public class MasterWSAction {
// NetworkManager.instance.sendToNodeCenter(JsonUtil.toJson(requestConnect)); // 向NC发
//waitForConnection(nodeNames);
LOGGER.debug(JsonUtil.toPrettyJson(requestConnect));
ContractManager.threadPool.execute(() -> {
// 多点合约更新repository信息
if (contract.getDOI() != null && !contract.getDOI().equals("null")) {
LOGGER.info("multipoint contract doi register");
GRPCPool.instance.reRegister(contract.getDOI());
} else {
LOGGER.info("multipoint contract don't update register " + (null == contract.getDOI() ? "null" : contract.getDOI()));
}
});
final long curr = System.currentTimeMillis();
String requestID = curr + "_" + (int) (Math.random() * 10000);
ResultCollector collector = new ResultCollector(requestID, new ResultCallback() {

View File

@ -7,7 +7,6 @@ import com.google.gson.JsonPrimitive;
import io.netty.channel.ChannelHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.doip.audit.EndpointConfig;
import org.bdware.doip.audit.server.DefaultRepoHandlerInjector;
import org.bdware.doip.codec.digitalObject.DigitalObject;
import org.bdware.doip.codec.digitalObject.DoType;
@ -205,7 +204,7 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase implements
}
private DigitalObject contract2DigitalObject(ContractClient contractClient) {
DigitalObject contractDO = new DigitalObject(contractClient.getContractDOI(), DoType.DO);
DigitalObject contractDO = new DigitalObject(contractClient.getContractID(), DoType.DO);
contractDO.addAttribute("contractName", contractClient.getContractName());
// contractDO.addAttribute("script",contract.contract.getScriptStr());
contractDO.addAttribute("owner", contractClient.contractMeta.contract.getOwner());

View File

@ -1,15 +1,25 @@
package org.bdware.server.doip;
import com.google.gson.Gson;
import io.netty.channel.ChannelHandlerContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.doip.audit.EndpointConfig;
import org.bdware.doip.audit.server.AuditDoipServer;
import org.bdware.doip.audit.writer.AuditType;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
import org.bdware.doip.encrypt.SM2Signer;
import org.bdware.doip.endpoint.server.DoipListenerConfig;
import org.bdware.doip.endpoint.server.DoipRequestHandler;
import org.bdware.doip.endpoint.server.DoipServiceInfo;
import org.bdware.sc.ContractMeta;
import org.bdware.server.GlobalConf;
import org.bdware.server.action.CMActions;
import org.zz.gmhelper.SM2KeyPair;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -40,6 +50,47 @@ public class ContractRepositoryMain {
config.repoName = GlobalConf.instance.doaConf.repoName;
currentServer = new AuditDoipServer(config, info);
currentServer.setRepositoryHandler(new ContractRepositoryHandler(info));
DoipRequestHandler requestCallback = currentServer.getRequestCallback();
SM2Signer signer = new SM2Signer(SM2KeyPair.fromJson(new Gson().toJson(config)));
DelegateDoipHandler delegateHandler = new DelegateDoipHandler(requestCallback) {
@Override
protected DoipMessage delegateMessage(ChannelHandlerContext context, DoipMessage message) {
DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
builder.createResponse(DoipResponseCode.DelegateRequired, message);
String id = message.header.parameters.id;
id = id.replaceAll(".*/", "");
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(id);
builder.addAttributes("port", meta.contract.getDoipPort());
DoipMessage ret;
if (message.credential != null && message.credential.getSigner() != null) {
if (signer.verifyMessage(message)) {
ret = builder.create();
} else {
DoipMessageFactory.DoipMessageBuilder builder2 = new DoipMessageFactory.DoipMessageBuilder();
DoipMessageFactory.DoipMessageBuilder resp = builder2.createResponse(DoipResponseCode.UnAuth_Client, message);
resp.setBody("verify failed".getBytes(StandardCharsets.UTF_8));
ret = resp.create();
}
signer.signMessage(ret);
} else {
ret = builder.create();
}
return ret;
}
@Override
public boolean accept(ChannelHandlerContext context, DoipMessage message) {
String id = message.header.parameters.id;
if (id != null) {
id = id.replaceAll(".*/", "");
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(id);
if (meta != null)
return true;
}
return false;
}
};
currentServer.setRequestCallback(delegateHandler);
currentServer.start();
} catch (Exception e) {
e.printStackTrace();

View File

@ -0,0 +1,22 @@
package org.bdware.server.doip;
import io.netty.channel.ChannelHandlerContext;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.endpoint.server.DoipRequestHandler;
public abstract class DelegateDoipHandler implements DoipRequestHandler {
private final DoipRequestHandler original;
public DelegateDoipHandler(DoipRequestHandler original) {
this.original = original;
}
public DoipMessage onRequest(ChannelHandlerContext context, DoipMessage doipMessage) {
if (accept(context, doipMessage)) {
return delegateMessage(context, doipMessage);
} else return original.onRequest(context, doipMessage);
}
protected abstract DoipMessage delegateMessage(ChannelHandlerContext context, DoipMessage message);
public abstract boolean accept(ChannelHandlerContext context, DoipMessage message);
}

View File

@ -246,7 +246,6 @@ public class NodeCenterClientController implements NodeCenterConn {
resp.addProperty("pubkey", meta.contract.getPublicKey());
resp.addProperty("name", meta.getName());
resp.addProperty("buildTime", meta.contract.getBuildTime());
resp.addProperty("doi", meta.contract.getDOI());
ZipFile zipFile = new ZipFile(new File(meta.contract.getScriptStr()));
ZipEntry zipEntry = zipFile.getEntry("/assets/README.md");
if (null == zipEntry) {