mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 01:44:14 +00:00
update doip-sdk
This commit is contained in:
parent
73feba9b0e
commit
22532666dd
@ -5,7 +5,6 @@ plugins {
|
|||||||
|
|
||||||
mainClassName = 'org.bdware.server.CMHttpServer'
|
mainClassName = 'org.bdware.server.CMHttpServer'
|
||||||
|
|
||||||
apply from: '../spotless.gradle'
|
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClass = mainClassName
|
mainClass = mainClassName
|
||||||
@ -41,9 +40,9 @@ dependencies {
|
|||||||
implementation 'io.grpc:grpc-all:1.43.1'
|
implementation 'io.grpc:grpc-all:1.43.1'
|
||||||
implementation 'org.apache.velocity:velocity-engine-core:2.3'
|
implementation 'org.apache.velocity:velocity-engine-core:2.3'
|
||||||
implementation 'com.nimbusds:nimbus-jose-jwt:9.10'
|
implementation 'com.nimbusds:nimbus-jose-jwt:9.10'
|
||||||
implementation 'org.bdware.doip:doip-sdk:1.4.2'
|
implementation 'org.bdware.doip:doip-sdk:1.5.1'
|
||||||
implementation 'org.bdware.doip:doip-audit-tool:1.2.6'
|
implementation 'org.bdware.doip:doip-audit-tool:1.4.3'
|
||||||
implementation 'org.bdware.doip:bdosclient:0.0.7'
|
implementation 'org.bdware.doip:bdosclient:0.1.0'
|
||||||
implementation fileTree(dir: 'lib', include: '*.jar')
|
implementation fileTree(dir: 'lib', include: '*.jar')
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
implementation 'io.netty:netty-tcnative-boringssl-static:2.0.59.Final'
|
implementation 'io.netty:netty-tcnative-boringssl-static:2.0.59.Final'
|
||||||
|
@ -57,10 +57,12 @@ public class CMHttpServer {
|
|||||||
private static final Logger LOGGER = LogManager.getLogger(CMHttpServer.class);
|
private static final Logger LOGGER = LogManager.getLogger(CMHttpServer.class);
|
||||||
private static final String CONFIG_PATH = "cmconfig.json";
|
private static final String CONFIG_PATH = "cmconfig.json";
|
||||||
public static EventLoopGroup workerGroup = new NioEventLoopGroup();
|
public static EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
public static MultiIndexTimeRocksDBUtil nodeLogDB = new MultiIndexTimeRocksDBUtil(
|
public static MultiIndexTimeRocksDBUtil nodeLogDB =
|
||||||
|
new MultiIndexTimeRocksDBUtil(
|
||||||
"./ContractManagerDB", CMTables.LocalNodeLogDB.toString());
|
"./ContractManagerDB", CMTables.LocalNodeLogDB.toString());
|
||||||
public static URLClassLoader pluginLoader;
|
public static URLClassLoader pluginLoader;
|
||||||
private static SslContext sslContext = null;
|
private static SslContext sslContext = null;
|
||||||
|
private static CMDConf cmdConf;
|
||||||
final String PATH = "/SCIDE/SCExecutor";
|
final String PATH = "/SCIDE/SCExecutor";
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
@ -87,21 +89,23 @@ public class CMHttpServer {
|
|||||||
GlobalConf.initDOAConfig(doaConf);
|
GlobalConf.initDOAConfig(doaConf);
|
||||||
|
|
||||||
if (cmdConf.withBdledgerServer) {
|
if (cmdConf.withBdledgerServer) {
|
||||||
ContractManager.threadPool
|
ContractManager.threadPool.execute(
|
||||||
.execute(() -> NetworkManager.instance.initP2P(cmdConf.servicePort + 4));
|
() -> NetworkManager.instance.initP2P(cmdConf.servicePort + 4));
|
||||||
}
|
}
|
||||||
// 可自动运行bdledger可执行文件,也可在shell脚步中运行和停止
|
// 可自动运行bdledger可执行文件,也可在shell脚步中运行和停止
|
||||||
if (!cmdConf.withBdledgerClient.isEmpty()) {
|
if (!cmdConf.withBdledgerClient.isEmpty()) {
|
||||||
ContractManager.scheduledThreadPool.schedule(() -> {
|
ContractManager.scheduledThreadPool.schedule(
|
||||||
|
() -> {
|
||||||
File ledgerClient = new File(cmdConf.withBdledgerClient);
|
File ledgerClient = new File(cmdConf.withBdledgerClient);
|
||||||
LOGGER.debug("canRead=" + ledgerClient.canRead() + " path="
|
LOGGER.debug("canRead=" + ledgerClient.canRead() +
|
||||||
+ ledgerClient.getAbsolutePath());
|
" path=" + ledgerClient.getAbsolutePath());
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().exec(ledgerClient.getAbsolutePath());
|
Runtime.getRuntime().exec(ledgerClient.getAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.warn("start bdledger client failed: " + e.getMessage());
|
LOGGER.warn("start bdledger client failed: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}, 1, TimeUnit.SECONDS);
|
},
|
||||||
|
1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
if (cmdConf.enableEventPersistence) {
|
if (cmdConf.enableEventPersistence) {
|
||||||
ContractManager.eventPersistenceEnabled = true;
|
ContractManager.eventPersistenceEnabled = true;
|
||||||
@ -111,10 +115,13 @@ public class CMHttpServer {
|
|||||||
String[] filePaths = cmdConf.enableSsl.split(":");
|
String[] filePaths = cmdConf.enableSsl.split(":");
|
||||||
File chainedFile = new File(filePaths[0]), keyFile = new File(filePaths[1]);
|
File chainedFile = new File(filePaths[0]), keyFile = new File(filePaths[1]);
|
||||||
if (chainedFile.exists() && keyFile.exists()) {
|
if (chainedFile.exists() && keyFile.exists()) {
|
||||||
sslContext = SslContextBuilder.forServer(chainedFile, keyFile)
|
sslContext =
|
||||||
.ciphers(null,
|
SslContextBuilder.forServer(chainedFile, keyFile)
|
||||||
(ciphers, defaultCiphers, supportedCiphers) -> defaultCiphers
|
.ciphers(
|
||||||
.stream().filter(x -> null != x && !x.contains("RC4"))
|
null,
|
||||||
|
(ciphers, defaultCiphers, supportedCiphers) ->
|
||||||
|
defaultCiphers.stream()
|
||||||
|
.filter(x -> null != x && !x.contains("RC4"))
|
||||||
.toArray(String[]::new))
|
.toArray(String[]::new))
|
||||||
.build();
|
.build();
|
||||||
LOGGER.info("openssl isAvailable:" + OpenSsl.isAvailable());
|
LOGGER.info("openssl isAvailable:" + OpenSsl.isAvailable());
|
||||||
@ -136,8 +143,7 @@ public class CMHttpServer {
|
|||||||
// plugins
|
// plugins
|
||||||
CMHttpHandler.wsPluginActions = parseStrAsList(cmdConf.wsPluginActions);
|
CMHttpHandler.wsPluginActions = parseStrAsList(cmdConf.wsPluginActions);
|
||||||
TCPClientFrameHandler.clientToAgentPlugins = parseStrAsList(cmdConf.clientToAgentPlugins);
|
TCPClientFrameHandler.clientToAgentPlugins = parseStrAsList(cmdConf.clientToAgentPlugins);
|
||||||
NodeCenterClientHandler.clientToClusterPlugins =
|
NodeCenterClientHandler.clientToClusterPlugins = parseStrAsList(cmdConf.clientToClusterPlugins);
|
||||||
parseStrAsList(cmdConf.clientToClusterPlugins);
|
|
||||||
org.bdware.units.tcp.TCPClientFrameHandler.tcpPlugins = parseStrAsList(cmdConf.tcpPlugins);
|
org.bdware.units.tcp.TCPClientFrameHandler.tcpPlugins = parseStrAsList(cmdConf.tcpPlugins);
|
||||||
if (!StringUtil.isNullOrEmpty(cmdConf.debug)) {
|
if (!StringUtil.isNullOrEmpty(cmdConf.debug)) {
|
||||||
try {
|
try {
|
||||||
@ -154,39 +160,6 @@ public class CMHttpServer {
|
|||||||
LOGGER.warn(e.getMessage());
|
LOGGER.warn(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmdConf.startContract != null && cmdConf.startContract.size() > 0) {
|
|
||||||
ContractManager.scheduledThreadPool.schedule(() -> {
|
|
||||||
try {
|
|
||||||
for (JsonElement je : cmdConf.startContract) {
|
|
||||||
JsonObject jo = je.getAsJsonObject();
|
|
||||||
if (!jo.has("path"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
String path = jo.get("path").getAsString();
|
|
||||||
File f = new File(path);
|
|
||||||
if (!f.getName().endsWith(".ypk") || !f.exists())
|
|
||||||
continue;
|
|
||||||
Contract c = new Contract();
|
|
||||||
c.setScript(f.getAbsolutePath());
|
|
||||||
c.setType(ContractExecType.Sole);
|
|
||||||
if (jo.has("killBeforeStart")) {
|
|
||||||
ContractManager.instance
|
|
||||||
.stopContract(jo.get("killBeforeStart").getAsString());
|
|
||||||
}
|
|
||||||
if (jo.has("owner"))
|
|
||||||
c.setOwner(jo.get("owner").getAsString());
|
|
||||||
else
|
|
||||||
c.setOwner(UserManagerAction.getNodeManager());
|
|
||||||
if (jo.has("createParam"))
|
|
||||||
c.setCreateParam(jo.get("createParam"));
|
|
||||||
ContractManager.instance.startContract(c);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}, 10, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
if (cmdConf.datachainConf != null) {
|
if (cmdConf.datachainConf != null) {
|
||||||
GlobalConf.resetDataChain(cmdConf.datachainConf);
|
GlobalConf.resetDataChain(cmdConf.datachainConf);
|
||||||
}
|
}
|
||||||
@ -196,6 +169,23 @@ public class CMHttpServer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void startByPath(JsonObject jo) {
|
||||||
|
String path = jo.get("path").getAsString();
|
||||||
|
File f = new File(path);
|
||||||
|
if (!f.getName().endsWith(".ypk") || !f.exists())
|
||||||
|
return;
|
||||||
|
Contract c = new Contract();
|
||||||
|
c.setScript(f.getAbsolutePath());
|
||||||
|
c.setType(ContractExecType.Sole);
|
||||||
|
if (jo.has("owner"))
|
||||||
|
c.setOwner(jo.get("owner").getAsString());
|
||||||
|
else
|
||||||
|
c.setOwner(UserManagerAction.getNodeManager());
|
||||||
|
if (jo.has("createParam"))
|
||||||
|
c.setCreateParam(jo.get("createParam"));
|
||||||
|
ContractManager.instance.startContract(c);
|
||||||
|
}
|
||||||
|
|
||||||
private static String[] parseStrAsList(String str) {
|
private static String[] parseStrAsList(String str) {
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
return new String[]{};
|
return new String[]{};
|
||||||
@ -231,7 +221,7 @@ public class CMHttpServer {
|
|||||||
if (!confFile.exists() && confTemplate.exists()) {
|
if (!confFile.exists() && confTemplate.exists()) {
|
||||||
FileUtils.copyFile(confTemplate, confFile);
|
FileUtils.copyFile(confTemplate, confFile);
|
||||||
}
|
}
|
||||||
CMDConf cmdConf = CMDConf.parseFile(CONFIG_PATH);
|
cmdConf = CMDConf.parseFile(CONFIG_PATH);
|
||||||
|
|
||||||
// addDirToPath(new File("./dynamicLibrary").getAbsolutePath());
|
// addDirToPath(new File("./dynamicLibrary").getAbsolutePath());
|
||||||
|
|
||||||
@ -256,15 +246,19 @@ public class CMHttpServer {
|
|||||||
try {
|
try {
|
||||||
BufferedReader br = new BufferedReader(new FileReader(keyFile));
|
BufferedReader br = new BufferedReader(new FileReader(keyFile));
|
||||||
String pubKey = br.readLine();
|
String pubKey = br.readLine();
|
||||||
String nowManager = KeyValueDBUtil.instance.getValue(CMTables.ConfigDB.toString(),
|
String nowManager =
|
||||||
"__NodeManager__");
|
KeyValueDBUtil.instance.getValue(
|
||||||
|
CMTables.ConfigDB.toString(), "__NodeManager__");
|
||||||
// manager.key is used when node manager isn' set
|
// manager.key is used when node manager isn' set
|
||||||
if (null == nowManager || nowManager.isEmpty()) {
|
if (null == nowManager || nowManager.isEmpty()) {
|
||||||
KeyValueDBUtil.instance.setValue(CMTables.ConfigDB.toString(),
|
KeyValueDBUtil.instance.setValue(
|
||||||
"__NodeManager__", pubKey);
|
CMTables.ConfigDB.toString(), "__NodeManager__", pubKey);
|
||||||
KeyValueDBUtil.instance.setValue(CMTables.NodeRole.toString(), pubKey,
|
KeyValueDBUtil.instance.setValue(
|
||||||
|
CMTables.NodeRole.toString(), pubKey,
|
||||||
"NodeManager,ContractProvider,ContractUser,ContractInstanceManager");
|
"NodeManager,ContractProvider,ContractUser,ContractInstanceManager");
|
||||||
KeyValueDBUtil.instance.setValue(CMTables.NodeTime.toString(), pubKey,
|
KeyValueDBUtil.instance.setValue(
|
||||||
|
CMTables.NodeTime.toString(),
|
||||||
|
pubKey,
|
||||||
Long.toString(new Date().getTime()));
|
Long.toString(new Date().getTime()));
|
||||||
LOGGER.info("set node manager from manager.key");
|
LOGGER.info("set node manager from manager.key");
|
||||||
}
|
}
|
||||||
@ -272,7 +266,7 @@ public class CMHttpServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalConf.initIpPort(cmdConf.ip + ":" + cmdConf.servicePort);
|
GlobalConf.initIpPort(cmdConf.ip + ":" + cmdConf.servicePort);
|
||||||
GlobalConf.initMasterAddress(cmdConf.ip + ":" + (cmdConf.servicePort + 1));
|
//GlobalConf.initMasterAddress(cmdConf.ip + ":" + (cmdConf.servicePort + 1));
|
||||||
start(cmdConf.servicePort);
|
start(cmdConf.servicePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,8 +286,8 @@ public class CMHttpServer {
|
|||||||
// EpollServerSocketChannel
|
// EpollServerSocketChannel
|
||||||
// ContractManager.reconnectPort = (port - 18000) * 30 + 1630;
|
// ContractManager.reconnectPort = (port - 18000) * 30 + 1630;
|
||||||
// if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630;
|
// if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630;
|
||||||
File[] pluginJar =
|
File[] pluginJar = new File("./pluginLib/")
|
||||||
new File("./pluginLib/").listFiles(pathname -> pathname.getName().endsWith(".jar"));
|
.listFiles(pathname -> pathname.getName().endsWith(".jar"));
|
||||||
URL[] urls;
|
URL[] urls;
|
||||||
if (pluginJar != null && pluginJar.length > 0) {
|
if (pluginJar != null && pluginJar.length > 0) {
|
||||||
urls = new URL[pluginJar.length];
|
urls = new URL[pluginJar.length];
|
||||||
@ -322,17 +316,25 @@ public class CMHttpServer {
|
|||||||
try {
|
try {
|
||||||
ServerBootstrap b1 = new ServerBootstrap();
|
ServerBootstrap b1 = new ServerBootstrap();
|
||||||
b1.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
b1.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
||||||
b1.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
|
b1.group(bossGroup, workerGroup)
|
||||||
.localAddress(port).childHandler(new ChannelInitializer<SocketChannel>() {
|
.channel(NioServerSocketChannel.class)
|
||||||
|
.localAddress(port)
|
||||||
|
.childHandler(
|
||||||
|
new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel arg0) {
|
protected void initChannel(SocketChannel arg0) {
|
||||||
if (sslContext != null) {
|
if (sslContext != null) {
|
||||||
arg0.pipeline().addLast(new OptionalSslHandler(sslContext));
|
arg0.pipeline().addLast(new OptionalSslHandler(sslContext));
|
||||||
}
|
}
|
||||||
arg0.pipeline().addLast(trafficSharp).addLast(new HttpServerCodec())
|
arg0.pipeline()
|
||||||
|
.addLast(trafficSharp)
|
||||||
|
.addLast(new HttpServerCodec())
|
||||||
.addLast(new HttpObjectAggregator(10 * 1024 * 1024))
|
.addLast(new HttpObjectAggregator(10 * 1024 * 1024))
|
||||||
.addLast(new WebSocketServerProtocolHandler(PATH, null, true))
|
.addLast(
|
||||||
.addLast(new ChunkedWriteHandler()).addLast(serverHandler)
|
new WebSocketServerProtocolHandler(
|
||||||
|
PATH, null, true))
|
||||||
|
.addLast(new ChunkedWriteHandler())
|
||||||
|
.addLast(serverHandler)
|
||||||
.addLast(new ContractManagerFrameHandler());
|
.addLast(new ContractManagerFrameHandler());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -340,6 +342,10 @@ public class CMHttpServer {
|
|||||||
LOGGER.debug("[CMHttpServer] listen master port at:" + port);
|
LOGGER.debug("[CMHttpServer] listen master port at:" + port);
|
||||||
new HTTPServer(port + 3);
|
new HTTPServer(port + 3);
|
||||||
NetworkManager.instance.initTCP(port + 1, workerGroup);
|
NetworkManager.instance.initTCP(port + 1, workerGroup);
|
||||||
|
|
||||||
|
loadStartContractConfiguration();
|
||||||
|
|
||||||
|
|
||||||
ch.closeFuture().sync();
|
ch.closeFuture().sync();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -350,9 +356,39 @@ public class CMHttpServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadStartContractConfiguration() {
|
||||||
|
if (cmdConf.startContract != null && cmdConf.startContract.size() > 0) {
|
||||||
|
ContractManager.scheduledThreadPool.schedule(
|
||||||
|
() -> {
|
||||||
|
for (JsonElement je : cmdConf.startContract) {
|
||||||
|
try {
|
||||||
|
JsonObject jo = je.getAsJsonObject();
|
||||||
|
if (!jo.has("path"))
|
||||||
|
continue;
|
||||||
|
if (!jo.has("owner"))
|
||||||
|
jo.addProperty("owner", UserManagerAction.getNodeManager());
|
||||||
|
if (jo.has("killBeforeStart")) {
|
||||||
|
ContractManager.instance.stopContract(jo.get("killBeforeStart").getAsString());
|
||||||
|
}
|
||||||
|
if (jo.get("path").getAsString().startsWith("@")) {
|
||||||
|
jo.addProperty("bcoId", jo.get("path").getAsString().substring(1));
|
||||||
|
ContractRepositoryMain.currentHandler.startUsingJsonObject(jo);
|
||||||
|
} else {
|
||||||
|
startByPath(jo);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
10, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Sharable
|
@Sharable
|
||||||
public static class NettyConnectServerHandler extends ChannelInboundHandlerAdapter {
|
public static class NettyConnectServerHandler extends ChannelInboundHandlerAdapter {
|
||||||
public NettyConnectServerHandler(AtomicInteger connectNum) {}
|
public NettyConnectServerHandler(AtomicInteger connectNum) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
@ -17,6 +17,7 @@ import org.zz.gmhelper.SM2KeyPair;
|
|||||||
import org.zz.gmhelper.SM2Util;
|
import org.zz.gmhelper.SM2Util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class GlobalConf {
|
public class GlobalConf {
|
||||||
@ -53,7 +54,7 @@ public class GlobalConf {
|
|||||||
public String bcoDir;
|
public String bcoDir;
|
||||||
|
|
||||||
public String memoryDir;
|
public String memoryDir;
|
||||||
public String masterAddress;
|
// public String masterAddress;
|
||||||
public String ipPort;
|
public String ipPort;
|
||||||
public boolean isLAN = true;
|
public boolean isLAN = true;
|
||||||
private String nodeCenterUrl; // 从ConfigDB读。
|
private String nodeCenterUrl; // 从ConfigDB读。
|
||||||
@ -63,11 +64,14 @@ public class GlobalConf {
|
|||||||
private static GlobalConf init() {
|
private static GlobalConf init() {
|
||||||
java.util.logging.Logger.getLogger(org.bdware.bdledger.api.grpc.Client.class.getName())
|
java.util.logging.Logger.getLogger(org.bdware.bdledger.api.grpc.Client.class.getName())
|
||||||
.setLevel(Level.OFF);
|
.setLevel(Level.OFF);
|
||||||
Configurator.setLevel("io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder",
|
Configurator.setLevel(
|
||||||
|
"io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder",
|
||||||
org.apache.logging.log4j.Level.OFF);
|
org.apache.logging.log4j.Level.OFF);
|
||||||
Configurator.setLevel("io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder",
|
Configurator.setLevel(
|
||||||
|
"io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder",
|
||||||
org.apache.logging.log4j.Level.OFF);
|
org.apache.logging.log4j.Level.OFF);
|
||||||
Configurator.setLevel("io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker",
|
Configurator.setLevel(
|
||||||
|
"io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker",
|
||||||
org.apache.logging.log4j.Level.OFF);
|
org.apache.logging.log4j.Level.OFF);
|
||||||
|
|
||||||
KeyValueDBUtil.setupCM();
|
KeyValueDBUtil.setupCM();
|
||||||
@ -79,17 +83,19 @@ public class GlobalConf {
|
|||||||
String dbName = CMTables.ConfigDB.toString();
|
String dbName = CMTables.ConfigDB.toString();
|
||||||
if (!KeyValueDBUtil.instance.getKeys(dbName).contains("hasInited")) {
|
if (!KeyValueDBUtil.instance.getKeys(dbName).contains("hasInited")) {
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "hasInited", "true");
|
KeyValueDBUtil.instance.setValue(dbName, "hasInited", "true");
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "projectDir",
|
KeyValueDBUtil.instance.setValue(
|
||||||
new File("./BDWareProjectDir/").getAbsolutePath());
|
dbName, "projectDir", new File("./BDWareProjectDir/").getAbsolutePath());
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "ADSPDir",
|
KeyValueDBUtil.instance.setValue(
|
||||||
|
dbName,
|
||||||
|
"ADSPDir",
|
||||||
new File("./BDWareProjectDir/ADSPDir/").getAbsolutePath());
|
new File("./BDWareProjectDir/ADSPDir/").getAbsolutePath());
|
||||||
File f = new File("./yjs.jar");
|
File f = new File("./yjs.jar");
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "yjsPath",
|
KeyValueDBUtil.instance.setValue(
|
||||||
new File("./yjs.jar").getAbsolutePath());
|
dbName, "yjsPath", new File("./yjs.jar").getAbsolutePath());
|
||||||
} else {
|
} else {
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "yjsPath",
|
KeyValueDBUtil.instance.setValue(
|
||||||
new File("./cp/yjs.jar").getAbsolutePath());
|
dbName, "yjsPath", new File("./cp/yjs.jar").getAbsolutePath());
|
||||||
}
|
}
|
||||||
conf.keyPairStr = SM2Util.generateSM2KeyPair().toJson();
|
conf.keyPairStr = SM2Util.generateSM2KeyPair().toJson();
|
||||||
|
|
||||||
@ -105,23 +111,36 @@ public class GlobalConf {
|
|||||||
|
|
||||||
// long time = System.currentTimeMillis()+15811200000;
|
// long time = System.currentTimeMillis()+15811200000;
|
||||||
String licence =
|
String licence =
|
||||||
ByteHexUtil
|
ByteHexUtil.encode(
|
||||||
.encode(SM2Util.encrypt(conf.keyPair.getPublicKey(),
|
SM2Util.encrypt(
|
||||||
(HardwareInfo.getCPUID() + "=="
|
conf.keyPair.getPublicKey(),
|
||||||
+ (System.currentTimeMillis() + 15811200000L))
|
(HardwareInfo.getCPUID()
|
||||||
|
+ "=="
|
||||||
|
+ (System.currentTimeMillis()
|
||||||
|
+ 15811200000L))
|
||||||
.getBytes()));
|
.getBytes()));
|
||||||
LOGGER.debug("licence:" + licence);
|
LOGGER.debug("licence:" + licence);
|
||||||
|
|
||||||
LOGGER.debug(String.format("deviceName %s license %s %s==%d", deviceName, licence,
|
LOGGER.debug(
|
||||||
HardwareInfo.getCPUID(), (System.currentTimeMillis() + 15811200000L)));
|
String.format(
|
||||||
|
"deviceName %s license %s %s==%d",
|
||||||
|
deviceName,
|
||||||
|
licence,
|
||||||
|
HardwareInfo.getCPUID(),
|
||||||
|
(System.currentTimeMillis() + 15811200000L)));
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "licence", licence);
|
KeyValueDBUtil.instance.setValue(dbName, "licence", licence);
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "nodeName", deviceName.substring(0, 10));
|
KeyValueDBUtil.instance.setValue(dbName, "nodeName", deviceName.substring(0, 10));
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "masterAddress", "null");
|
KeyValueDBUtil.instance.setValue(dbName, "masterAddress", "null");
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "ipPort", "null");
|
KeyValueDBUtil.instance.setValue(dbName, "ipPort", "null");
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "nodeCenter", "ws://127.0.0.1:18005");
|
KeyValueDBUtil.instance.setValue(dbName, "nodeCenter", "ws://127.0.0.1:18005");
|
||||||
KeyValueDBUtil.instance.setValue(dbName, "datachainConf",
|
KeyValueDBUtil.instance.setValue(
|
||||||
"39.104.70.160:18091\n" + "47.98.247.70:18091\n" + "47.98.248.208:18091\n"
|
dbName,
|
||||||
+ "39.104.77.165:18091\n" + "47.98.249.131:18091");
|
"datachainConf",
|
||||||
|
"39.104.70.160:18091\n"
|
||||||
|
+ "47.98.247.70:18091\n"
|
||||||
|
+ "47.98.248.208:18091\n"
|
||||||
|
+ "39.104.77.165:18091\n"
|
||||||
|
+ "47.98.249.131:18091");
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.projectDir = KeyValueDBUtil.instance.getValue(dbName, "projectDir");
|
conf.projectDir = KeyValueDBUtil.instance.getValue(dbName, "projectDir");
|
||||||
@ -140,7 +159,7 @@ public class GlobalConf {
|
|||||||
conf.name = KeyValueDBUtil.instance.getValue(dbName, "nodeName");
|
conf.name = KeyValueDBUtil.instance.getValue(dbName, "nodeName");
|
||||||
conf.ipPort = KeyValueDBUtil.instance.getValue(dbName, "ipPort");
|
conf.ipPort = KeyValueDBUtil.instance.getValue(dbName, "ipPort");
|
||||||
conf.isLAN = "true".equals(KeyValueDBUtil.instance.getValue(dbName, "isLAN"));
|
conf.isLAN = "true".equals(KeyValueDBUtil.instance.getValue(dbName, "isLAN"));
|
||||||
conf.masterAddress = KeyValueDBUtil.instance.getValue(dbName, "masterAddress");
|
// conf.masterAddress = KeyValueDBUtil.instance.getValue(dbName, "masterAddress");
|
||||||
conf.nodeCenterUrl = KeyValueDBUtil.instance.getValue(dbName, "nodeCenter");
|
conf.nodeCenterUrl = KeyValueDBUtil.instance.getValue(dbName, "nodeCenter");
|
||||||
conf.nodeCenterWSUrl = KeyValueDBUtil.instance.getValue(dbName, "nodeCenterWS");
|
conf.nodeCenterWSUrl = KeyValueDBUtil.instance.getValue(dbName, "nodeCenterWS");
|
||||||
conf.peerID = KeyValueDBUtil.instance.getValue(dbName, "peerID");
|
conf.peerID = KeyValueDBUtil.instance.getValue(dbName, "peerID");
|
||||||
@ -192,7 +211,8 @@ public class GlobalConf {
|
|||||||
LOGGER.debug("[GlobalConf] ProjectDir Path:" + new File(conf.projectDir).getAbsolutePath());
|
LOGGER.debug("[GlobalConf] ProjectDir Path:" + new File(conf.projectDir).getAbsolutePath());
|
||||||
LOGGER.debug("[GlobalConf] publicDir Path:" + new File(conf.publicDir).getAbsolutePath());
|
LOGGER.debug("[GlobalConf] publicDir Path:" + new File(conf.publicDir).getAbsolutePath());
|
||||||
LOGGER.debug("[GlobalConf] publicDir Path:" + new File(conf.ADSPDir).getAbsolutePath());
|
LOGGER.debug("[GlobalConf] publicDir Path:" + new File(conf.ADSPDir).getAbsolutePath());
|
||||||
LOGGER.debug("[GlobalConf] publicDirCompiled Path:"
|
LOGGER.debug(
|
||||||
|
"[GlobalConf] publicDirCompiled Path:"
|
||||||
+ new File(conf.publicCompiledDir).getAbsolutePath());
|
+ new File(conf.publicCompiledDir).getAbsolutePath());
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"[GlobalConf] PersonalDir Path:" + new File(conf.privateDir).getAbsolutePath());
|
"[GlobalConf] PersonalDir Path:" + new File(conf.privateDir).getAbsolutePath());
|
||||||
@ -231,8 +251,7 @@ public class GlobalConf {
|
|||||||
private static void verifyLicence(GlobalConf conf) {
|
private static void verifyLicence(GlobalConf conf) {
|
||||||
try {
|
try {
|
||||||
// String pubkey =
|
// String pubkey =
|
||||||
// "OTIzNmUzMGNmOGI1ZjFkMDBjZjEyMWY4OThmM2ZmYTIwNjE2ODYxOWNiMDNhMTVlM2FiZTA0OThhNTlkZDg1MmRi"
|
// "OTIzNmUzMGNmOGI1ZjFkMDBjZjEyMWY4OThmM2ZmYTIwNjE2ODYxOWNiMDNhMTVlM2FiZTA0OThhNTlkZDg1MmRi" +
|
||||||
// +
|
|
||||||
// "MjA5Njc1NmM3ZDBhOWM3YTNkOTg2NWVlYzk2YzM1MmY0MDdkMGMyOTA4M2NkNDI4YmY1YjM5M2U5OTA1" +
|
// "MjA5Njc1NmM3ZDBhOWM3YTNkOTg2NWVlYzk2YzM1MmY0MDdkMGMyOTA4M2NkNDI4YmY1YjM5M2U5OTA1" +
|
||||||
// "NWE0MzM0MTJhM2Y2ZDhkZWVmZDk4MmI4NmZiZTMyYjhlMGE3ZWFmZmE5ODM3M2E4ZTRmNTYyNDgxNTY0" +
|
// "NWE0MzM0MTJhM2Y2ZDhkZWVmZDk4MmI4NmZiZTMyYjhlMGE3ZWFmZmE5ODM3M2E4ZTRmNTYyNDgxNTY0" +
|
||||||
// "Yjk2ZjFkMTZiODk2MGRhZDAwMTNjZDYwOGZmOTcxNjdiOWI1MDU1MjJlMzk0ODhmODczNDJjNWUwOGRj" +
|
// "Yjk2ZjFkMTZiODk2MGRhZDAwMTNjZDYwOGZmOTcxNjdiOWI1MDU1MjJlMzk0ODhmODczNDJjNWUwOGRj" +
|
||||||
@ -248,7 +267,10 @@ public class GlobalConf {
|
|||||||
try {
|
try {
|
||||||
// byte[] arr = key.encode(new BASE64Decoder().decodeBuffer(conf.licence));
|
// byte[] arr = key.encode(new BASE64Decoder().decodeBuffer(conf.licence));
|
||||||
// String actualKey = new String(arr);
|
// String actualKey = new String(arr);
|
||||||
String arr = new String(SM2Util.decrypt(conf.keyPair.getPrivateKeyParameter(),
|
String arr =
|
||||||
|
new String(
|
||||||
|
SM2Util.decrypt(
|
||||||
|
conf.keyPair.getPrivateKeyParameter(),
|
||||||
ByteHexUtil.decode(conf.licence)));
|
ByteHexUtil.decode(conf.licence)));
|
||||||
|
|
||||||
LOGGER.debug("[GlobalConf] actualKey:" + arr);
|
LOGGER.debug("[GlobalConf] actualKey:" + arr);
|
||||||
@ -303,30 +325,29 @@ public class GlobalConf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initMasterAddress(String val) {
|
// public static void initMasterAddress(String val) {
|
||||||
if ("null".equals(instance.masterAddress)
|
// if ("null".equals(instance.masterAddress) || instance.masterAddress.startsWith("127.0.0.1")) {
|
||||||
|| instance.masterAddress.startsWith("127.0.0.1")) {
|
// resetMasterAddress(val);
|
||||||
resetMasterAddress(val);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
public static void initDOAConfig(DOAConf doaConf) {
|
public static void initDOAConfig(DOAConf doaConf) {
|
||||||
if (instance.doaConf == null || instance.doaConf.doipAddress == null)
|
if (instance.doaConf == null || instance.doaConf.doipAddress == null)
|
||||||
resetDOAConfig(JsonUtil.toJson(doaConf));
|
resetDOAConfig(JsonUtil.toJson(doaConf));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean resetMasterAddress(String val) {
|
// public static boolean resetMasterAddress(String val) {
|
||||||
try {
|
// try {
|
||||||
instance.masterAddress = val;
|
// instance.masterAddress = val;
|
||||||
KeyValueDBUtil.instance.setValue(CMTables.ConfigDB.toString(), "masterAddress", val);
|
// KeyValueDBUtil.instance.setValue(CMTables.ConfigDB.toString(), "masterAddress", val);
|
||||||
NetworkManager.instance.reInitNodeCenter();
|
// NetworkManager.instance.reInitNodeCenter();
|
||||||
return true;
|
// return true;
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
// LOGGER.error(e.getMessage());
|
||||||
LOGGER.debug(ExceptionUtil.exceptionToString(e));
|
// LOGGER.debug(ExceptionUtil.exceptionToString(e));
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static boolean resetNodeCenter(String val) {
|
public static boolean resetNodeCenter(String val) {
|
||||||
try {
|
try {
|
||||||
@ -409,7 +430,7 @@ public class GlobalConf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void initIpPort(String val) {
|
public static void initIpPort(String val) {
|
||||||
if ("null".equals(instance.ipPort) || instance.masterAddress.startsWith("127.0.0.1")) {
|
if ("null".equals(instance.ipPort) || instance.ipPort.startsWith("127.0.0.1")) {
|
||||||
resetIpPort(val);
|
resetIpPort(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -800,7 +800,6 @@ public class CMActions implements OnHashCallback {
|
|||||||
} else {
|
} else {
|
||||||
c.setScript(args.get("script").getAsString());
|
c.setScript(args.get("script").getAsString());
|
||||||
}
|
}
|
||||||
LOGGER.info("+++++++++++++++" + args.get("script").getAsString());
|
|
||||||
if (args.has("publicKey")) {
|
if (args.has("publicKey")) {
|
||||||
c.setOwner(args.get("publicKey").getAsString());
|
c.setOwner(args.get("publicKey").getAsString());
|
||||||
} else if (args.has("owner")) {
|
} else if (args.has("owner")) {
|
||||||
|
@ -59,7 +59,8 @@ public class FileActions {
|
|||||||
ContractManagerFrameHandler handler;
|
ContractManagerFrameHandler handler;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
clearUploadFailed = new TimerTask() {
|
clearUploadFailed =
|
||||||
|
new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run(Timeout arg0) {
|
public void run(Timeout arg0) {
|
||||||
clearUploadFailed();
|
clearUploadFailed();
|
||||||
@ -84,7 +85,10 @@ public class FileActions {
|
|||||||
String fileName = compileInternal(parentPath, projectName, isPrivate, true);
|
String fileName = compileInternal(parentPath, projectName, isPrivate, true);
|
||||||
File dir;
|
File dir;
|
||||||
if (isPrivate) {
|
if (isPrivate) {
|
||||||
dir = new File(parentPath.replace(GlobalConf.instance.privateDir,
|
dir =
|
||||||
|
new File(
|
||||||
|
parentPath.replace(
|
||||||
|
GlobalConf.instance.privateDir,
|
||||||
GlobalConf.instance.privateCompiledDir));
|
GlobalConf.instance.privateCompiledDir));
|
||||||
} else {
|
} else {
|
||||||
dir = new File(GlobalConf.instance.publicCompiledDir);
|
dir = new File(GlobalConf.instance.publicCompiledDir);
|
||||||
@ -103,7 +107,9 @@ public class FileActions {
|
|||||||
return ret != null && ret.equals("locked");
|
return ret != null && ret.equals("locked");
|
||||||
}
|
}
|
||||||
|
|
||||||
@URIPath(method = org.bdware.server.http.HttpMethod.POST, value = {"/SCIDE/Upload", "/Upload"})
|
@URIPath(
|
||||||
|
method = org.bdware.server.http.HttpMethod.POST,
|
||||||
|
value = {"/SCIDE/Upload", "/Upload"})
|
||||||
public static void handleUploadRequest(ChannelHandlerContext ctx, FullHttpRequest request) {
|
public static void handleUploadRequest(ChannelHandlerContext ctx, FullHttpRequest request) {
|
||||||
// logger.info("[CMHttpHandler] handleUploadRequest : ");
|
// logger.info("[CMHttpHandler] handleUploadRequest : ");
|
||||||
// Upload method is POST
|
// Upload method is POST
|
||||||
@ -118,13 +124,17 @@ public class FileActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!transformedParam.containsKey("path") || !transformedParam.containsKey("fileName")
|
if (!transformedParam.containsKey("path")
|
||||||
|
|| !transformedParam.containsKey("fileName")
|
||||||
|| !transformedParam.containsKey("isPrivate")
|
|| !transformedParam.containsKey("isPrivate")
|
||||||
|| !transformedParam.containsKey("order") || !transformedParam.containsKey("count")
|
|| !transformedParam.containsKey("order")
|
||||||
|
|| !transformedParam.containsKey("count")
|
||||||
|| !transformedParam.containsKey("pubKey")
|
|| !transformedParam.containsKey("pubKey")
|
||||||
|| !transformedParam.containsKey("sign")) {
|
|| !transformedParam.containsKey("sign")) {
|
||||||
DefaultFullHttpResponse fullResponse = new DefaultFullHttpResponse(
|
DefaultFullHttpResponse fullResponse =
|
||||||
request.protocolVersion(), OK,
|
new DefaultFullHttpResponse(
|
||||||
|
request.protocolVersion(),
|
||||||
|
OK,
|
||||||
Unpooled.wrappedBuffer(
|
Unpooled.wrappedBuffer(
|
||||||
"{\"status\":\"false\",\"data\":\"Missing argument, please check: path, fileName, isPrivate, order, count, pubKey, sign!\"}"
|
"{\"status\":\"false\",\"data\":\"Missing argument, please check: path, fileName, isPrivate, order, count, pubKey, sign!\"}"
|
||||||
.getBytes()));
|
.getBytes()));
|
||||||
@ -137,7 +147,9 @@ public class FileActions {
|
|||||||
|
|
||||||
// 验签
|
// 验签
|
||||||
// HttpMethod method = request.method();
|
// HttpMethod method = request.method();
|
||||||
String uri = URLDecoder.decode(request.uri()).split("\\?")[1]; // http请求中规定签名必须是最后一个且公钥名必须为pubKey,否则验签失败
|
String uri =
|
||||||
|
URLDecoder.decode(request.uri())
|
||||||
|
.split("\\?")[1]; // http请求中规定签名必须是最后一个且公钥名必须为pubKey,否则验签失败
|
||||||
int index = uri.lastIndexOf('&');
|
int index = uri.lastIndexOf('&');
|
||||||
String str = uri.substring(0, index);
|
String str = uri.substring(0, index);
|
||||||
// logger.info("uri=" + uri);
|
// logger.info("uri=" + uri);
|
||||||
@ -171,8 +183,9 @@ public class FileActions {
|
|||||||
Method mm;
|
Method mm;
|
||||||
Action a = null;
|
Action a = null;
|
||||||
try {
|
try {
|
||||||
mm = FileActions.class.getDeclaredMethod("uploadFile", JsonObject.class,
|
mm =
|
||||||
ResultCallback.class);
|
FileActions.class.getDeclaredMethod(
|
||||||
|
"uploadFile", JsonObject.class, ResultCallback.class);
|
||||||
a = mm.getAnnotation(Action.class);
|
a = mm.getAnnotation(Action.class);
|
||||||
} catch (SecurityException | NoSuchMethodException e1) {
|
} catch (SecurityException | NoSuchMethodException e1) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
@ -202,17 +215,28 @@ public class FileActions {
|
|||||||
status = "accept";
|
status = "accept";
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeDBUtil.instance.put(CMTables.LocalNodeLogDB.toString(),
|
TimeDBUtil.instance.put(
|
||||||
"{\"action\":\"" + action + "\",\"pubKey\":\"" + transformedParam.get("pubKey")
|
CMTables.LocalNodeLogDB.toString(),
|
||||||
+ "\",\"status\":\"" + status + "\",\"date\":" + System.currentTimeMillis()
|
"{\"action\":\""
|
||||||
|
+ action
|
||||||
|
+ "\",\"pubKey\":\""
|
||||||
|
+ transformedParam.get("pubKey")
|
||||||
|
+ "\",\"status\":\""
|
||||||
|
+ status
|
||||||
|
+ "\",\"date\":"
|
||||||
|
+ System.currentTimeMillis()
|
||||||
+ "}");
|
+ "}");
|
||||||
|
|
||||||
// logger.info("[CMHttpHandler] flag = " + flag + " flag2 = " + flag2);
|
// logger.info("[CMHttpHandler] flag = " + flag + " flag2 = " + flag2);
|
||||||
|
|
||||||
if (!flag || !flag2) {
|
if (!flag || !flag2) {
|
||||||
DefaultFullHttpResponse fullResponse = new DefaultFullHttpResponse(
|
DefaultFullHttpResponse fullResponse =
|
||||||
request.protocolVersion(), OK, Unpooled.wrappedBuffer(
|
new DefaultFullHttpResponse(
|
||||||
"{\"status\":\"false\",\"data\":\"Permission denied!\"}".getBytes()));
|
request.protocolVersion(),
|
||||||
|
OK,
|
||||||
|
Unpooled.wrappedBuffer(
|
||||||
|
"{\"status\":\"false\",\"data\":\"Permission denied!\"}"
|
||||||
|
.getBytes()));
|
||||||
|
|
||||||
ChannelFuture f = addCrossOriginHeaderAndWrite(ctx, fullResponse);
|
ChannelFuture f = addCrossOriginHeaderAndWrite(ctx, fullResponse);
|
||||||
f.addListener(ChannelFutureListener.CLOSE);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
@ -232,7 +256,9 @@ public class FileActions {
|
|||||||
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(contractID);
|
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(contractID);
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
DefaultFullHttpResponse fullResponse =
|
DefaultFullHttpResponse fullResponse =
|
||||||
new DefaultFullHttpResponse(request.protocolVersion(), OK,
|
new DefaultFullHttpResponse(
|
||||||
|
request.protocolVersion(),
|
||||||
|
OK,
|
||||||
Unpooled.wrappedBuffer(
|
Unpooled.wrappedBuffer(
|
||||||
"{\"status\":\"false\",\"data\":\"no such contract!\"}"
|
"{\"status\":\"false\",\"data\":\"no such contract!\"}"
|
||||||
.getBytes()));
|
.getBytes()));
|
||||||
@ -241,19 +267,23 @@ public class FileActions {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!meta.contract.getOwner().equals(pubkey)) {
|
if (!meta.contract.getOwner().equals(pubkey)) {
|
||||||
DefaultFullHttpResponse fullResponse = new DefaultFullHttpResponse(
|
DefaultFullHttpResponse fullResponse =
|
||||||
request.protocolVersion(), OK, Unpooled.wrappedBuffer(
|
new DefaultFullHttpResponse(
|
||||||
"{\"status\":\"false\",\"data\":\"not owner!\"}".getBytes()));
|
request.protocolVersion(),
|
||||||
|
OK,
|
||||||
|
Unpooled.wrappedBuffer(
|
||||||
|
"{\"status\":\"false\",\"data\":\"not owner!\"}"
|
||||||
|
.getBytes()));
|
||||||
ChannelFuture f = addCrossOriginHeaderAndWrite(ctx, fullResponse);
|
ChannelFuture f = addCrossOriginHeaderAndWrite(ctx, fullResponse);
|
||||||
f.addListener(ChannelFutureListener.CLOSE);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dir = new File(GlobalConf.instance.getDBPath(), meta.getName());
|
dir = new File(GlobalConf.instance.getDBPath(), meta.getName());
|
||||||
dir = new File(dir, dirName);
|
dir = new File(dir, dirName);
|
||||||
if (!dir.exists())
|
if (!dir.exists()) dir.mkdirs();
|
||||||
dir.mkdirs();
|
|
||||||
} else {
|
} else {
|
||||||
boolean isPrivate = transformedParam.containsKey("isPrivate")
|
boolean isPrivate =
|
||||||
|
transformedParam.containsKey("isPrivate")
|
||||||
&& Boolean.parseBoolean(transformedParam.get("isPrivate"));
|
&& Boolean.parseBoolean(transformedParam.get("isPrivate"));
|
||||||
// TODO verify signature and
|
// TODO verify signature and
|
||||||
if (isPrivate) {
|
if (isPrivate) {
|
||||||
@ -268,9 +298,13 @@ public class FileActions {
|
|||||||
}
|
}
|
||||||
File target = new File(dir, fileName);
|
File target = new File(dir, fileName);
|
||||||
if (fileName.contains("..")) {
|
if (fileName.contains("..")) {
|
||||||
DefaultFullHttpResponse fullResponse = new DefaultFullHttpResponse(
|
DefaultFullHttpResponse fullResponse =
|
||||||
request.protocolVersion(), OK, Unpooled.wrappedBuffer(
|
new DefaultFullHttpResponse(
|
||||||
"{\"status\":\"false\",\"data\":\"FileName illegal!\"}".getBytes()));
|
request.protocolVersion(),
|
||||||
|
OK,
|
||||||
|
Unpooled.wrappedBuffer(
|
||||||
|
"{\"status\":\"false\",\"data\":\"FileName illegal!\"}"
|
||||||
|
.getBytes()));
|
||||||
|
|
||||||
ChannelFuture f = addCrossOriginHeaderAndWrite(ctx, fullResponse);
|
ChannelFuture f = addCrossOriginHeaderAndWrite(ctx, fullResponse);
|
||||||
f.addListener(ChannelFutureListener.CLOSE);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
@ -284,8 +318,7 @@ public class FileActions {
|
|||||||
if (order == 0) {
|
if (order == 0) {
|
||||||
try {
|
try {
|
||||||
LOGGER.debug("Path:" + target.getAbsolutePath());
|
LOGGER.debug("Path:" + target.getAbsolutePath());
|
||||||
if (!target.getParentFile().exists())
|
if (!target.getParentFile().exists()) target.getParentFile().mkdirs();
|
||||||
target.getParentFile().mkdirs();
|
|
||||||
fout = new FileOutputStream(target, false);
|
fout = new FileOutputStream(target, false);
|
||||||
fileMap.put(target.getAbsolutePath(), fout);
|
fileMap.put(target.getAbsolutePath(), fout);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
@ -297,6 +330,7 @@ public class FileActions {
|
|||||||
|
|
||||||
httpDecoder.destroy();
|
httpDecoder.destroy();
|
||||||
String retStr = "{\"status\":\"true\",\"data\":\"success\",\"handle\":\"null\"}";
|
String retStr = "{\"status\":\"true\",\"data\":\"success\",\"handle\":\"null\"}";
|
||||||
|
LOGGER.info("upload file, order/count:" + order + "/" + count);
|
||||||
if (order == count - 1) {
|
if (order == count - 1) {
|
||||||
fout = fileMap.get(target.getAbsolutePath());
|
fout = fileMap.get(target.getAbsolutePath());
|
||||||
try {
|
try {
|
||||||
@ -306,24 +340,33 @@ public class FileActions {
|
|||||||
}
|
}
|
||||||
fileMap.remove(target.getAbsolutePath());
|
fileMap.remove(target.getAbsolutePath());
|
||||||
updateTime.remove(target.getAbsolutePath());
|
updateTime.remove(target.getAbsolutePath());
|
||||||
boolean isDebug = transformedParam.containsKey("isDebug")
|
boolean isDebug =
|
||||||
|
transformedParam.containsKey("isDebug")
|
||||||
&& Boolean.parseBoolean(transformedParam.get("isDebug"));
|
&& Boolean.parseBoolean(transformedParam.get("isDebug"));
|
||||||
String doi = null;
|
String doi = null;
|
||||||
if (target.getParentFile().getParentFile()
|
String path = target.getAbsolutePath();
|
||||||
.equals(new File(GlobalConf.instance.privateDir)))
|
path = path.replaceAll("/\\./", "/");
|
||||||
|
String path2 = new File(GlobalConf.instance.privateDir).getAbsolutePath();
|
||||||
|
path2 = path2.replaceAll("/\\./", "/");
|
||||||
|
String path3 = new File(path).getParentFile().getParentFile().getAbsolutePath();
|
||||||
|
LOGGER.info("=======Target:" + target.getAbsolutePath() + " --> replaced:" + path);
|
||||||
|
LOGGER.info("=======Which file:" + path + "->" + path2 + " -> " + path3);
|
||||||
|
boolean isEqual = path2.equals(path3);
|
||||||
|
LOGGER.info("=======isEqual:" + isEqual);
|
||||||
|
if (isEqual)
|
||||||
doi = unzipIfYpk(target, dir, isDebug);
|
doi = unzipIfYpk(target, dir, isDebug);
|
||||||
if (null != doi) {
|
if (null != doi) {
|
||||||
retStr = retStr.replaceFirst("null", doi);
|
retStr = retStr.replaceFirst("null", doi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefaultFullHttpResponse fullResponse = new DefaultFullHttpResponse(
|
DefaultFullHttpResponse fullResponse =
|
||||||
|
new DefaultFullHttpResponse(
|
||||||
request.protocolVersion(), OK, Unpooled.wrappedBuffer(retStr.getBytes()));
|
request.protocolVersion(), OK, Unpooled.wrappedBuffer(retStr.getBytes()));
|
||||||
ChannelFuture f = addCrossOriginHeaderAndWrite(ctx, fullResponse);
|
ChannelFuture f = addCrossOriginHeaderAndWrite(ctx, fullResponse);
|
||||||
f.addListener(ChannelFutureListener.CLOSE);
|
f.addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ChannelFuture addCrossOriginHeaderAndWrite(ChannelHandlerContext ctx,
|
private static ChannelFuture addCrossOriginHeaderAndWrite(ChannelHandlerContext ctx, DefaultFullHttpResponse fullResponse) {
|
||||||
DefaultFullHttpResponse fullResponse) {
|
|
||||||
fullResponse.headers().add("Access-Control-Allow-Origin", "*");
|
fullResponse.headers().add("Access-Control-Allow-Origin", "*");
|
||||||
fullResponse.headers().add("Access-Control-Allow-Methods", "*");
|
fullResponse.headers().add("Access-Control-Allow-Methods", "*");
|
||||||
return ctx.write(fullResponse);
|
return ctx.write(fullResponse);
|
||||||
@ -342,11 +385,14 @@ public class FileActions {
|
|||||||
|
|
||||||
private static String unzipIfYpk(File target, File dir, boolean isDebug) {
|
private static String unzipIfYpk(File target, File dir, boolean isDebug) {
|
||||||
// [FileAction] unzipIfYpk,
|
// [FileAction] unzipIfYpk,
|
||||||
// target:/data/bdwaas/bdcontract/./BDWareProjectDir/private/045eeda3a001faad9d636ab1e973599ea87338a9576756eb10ceeca6083c1f76aac5cd201eab21c41342eb8aac40e9b283f0b6eae019644cdcc0a9f9aeb73de8fc/ContractUNknown.ypk
|
// target:/data/bdwaas/bdcontract/./BDWareProjectDir/private/045eeda3a001faad9d636ab1e973599ea87338a9576756eb10ceeca6083c1f76aac5cd201eab21c41342eb8aac40e9b283f0b6eae019644cdcc0a9f9aeb73de8fc/ContractUNknown.ypk targetDir:/data/bdwaas/bdcontract/./BDWareProjectDir/private/045eeda3a001faad9d636ab1e973599ea87338a9576756eb10ceeca6083c1f76aac5cd201eab21c41342eb8aac40e9b283f0b6eae019644cdcc0a9f9aeb73de8fc/ContractUNknown
|
||||||
// targetDir:/data/bdwaas/bdcontract/./BDWareProjectDir/private/045eeda3a001faad9d636ab1e973599ea87338a9576756eb10ceeca6083c1f76aac5cd201eab21c41342eb8aac40e9b283f0b6eae019644cdcc0a9f9aeb73de8fc/ContractUNknown
|
LOGGER.info(
|
||||||
LOGGER.info("[FileAction] unzipIfYpk, date:"
|
"[FileAction] unzipIfYpk, date:"
|
||||||
+ new SimpleDateFormat("MM-dd hh:mm:ss").format(new Date()) + " -> target:"
|
+ new SimpleDateFormat("MM-dd hh:mm:ss").format(new Date())
|
||||||
+ target.getAbsolutePath() + " dir:" + dir.getAbsolutePath());
|
+ " -> target:"
|
||||||
|
+ target.getAbsolutePath()
|
||||||
|
+ " dir:"
|
||||||
|
+ dir.getAbsolutePath());
|
||||||
if (target.getParentFile().equals(dir)) {
|
if (target.getParentFile().equals(dir)) {
|
||||||
if (target.getName().endsWith(".ypk")) {
|
if (target.getName().endsWith(".ypk")) {
|
||||||
String dirName = target.getName().substring(0, target.getName().length() - 4);
|
String dirName = target.getName().substring(0, target.getName().length() - 4);
|
||||||
@ -360,8 +406,11 @@ public class FileActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
targetDir.mkdirs();
|
targetDir.mkdirs();
|
||||||
LOGGER.info("[FileAction] unzipIfYpk, target:" + target.getAbsolutePath()
|
LOGGER.info(
|
||||||
+ " targetDir:" + targetDir.getAbsolutePath());
|
"[FileAction] unzipIfYpk, target:"
|
||||||
|
+ target.getAbsolutePath()
|
||||||
|
+ " targetDir:"
|
||||||
|
+ targetDir.getAbsolutePath());
|
||||||
YJSPacker.unpack(target.getAbsolutePath(), targetDir.getAbsolutePath());
|
YJSPacker.unpack(target.getAbsolutePath(), targetDir.getAbsolutePath());
|
||||||
final File tempDir = targetDir;
|
final File tempDir = targetDir;
|
||||||
ContractManager.threadPool.execute(() -> startIfManifestDetected(tempDir, isDebug));
|
ContractManager.threadPool.execute(() -> startIfManifestDetected(tempDir, isDebug));
|
||||||
@ -379,7 +428,8 @@ public class FileActions {
|
|||||||
String doi = "86.5000.470/do." + geneRandomID();
|
String doi = "86.5000.470/do." + geneRandomID();
|
||||||
jo.addProperty("doi", doi);
|
jo.addProperty("doi", doi);
|
||||||
}
|
}
|
||||||
ContractManager.threadPool.execute(() -> {
|
ContractManager.threadPool.execute(
|
||||||
|
() -> {
|
||||||
try {
|
try {
|
||||||
GRPCPool.instance.reRegister(jo.get("doi").getAsString());
|
GRPCPool.instance.reRegister(jo.get("doi").getAsString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -410,8 +460,9 @@ public class FileActions {
|
|||||||
LOGGER.info("startContractProcess:" + targetDir);
|
LOGGER.info("startContractProcess:" + targetDir);
|
||||||
Contract c = new Contract();
|
Contract c = new Contract();
|
||||||
c.setType(ContractExecType.Sole);
|
c.setType(ContractExecType.Sole);
|
||||||
String ypkPath = FileActions
|
String ypkPath =
|
||||||
.autoCompile(targetDir.getParentFile().getAbsolutePath(), contractName);
|
FileActions.autoCompile(
|
||||||
|
targetDir.getParentFile().getAbsolutePath(), contractName);
|
||||||
c.setScript(ypkPath);
|
c.setScript(ypkPath);
|
||||||
c.setOwner(owner);
|
c.setOwner(owner);
|
||||||
c.setDebug(isDebug);
|
c.setDebug(isDebug);
|
||||||
@ -446,8 +497,8 @@ public class FileActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeChunk(ChannelHandlerContext ctx, HttpPostRequestDecoder httpDecoder,
|
private static void writeChunk(
|
||||||
File file) {
|
ChannelHandlerContext ctx, HttpPostRequestDecoder httpDecoder, File file) {
|
||||||
try {
|
try {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
@ -480,8 +531,8 @@ public class FileActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String compileInternal(String parPath, String projectName, boolean isPrivate,
|
private static String compileInternal(
|
||||||
boolean isAuto) {
|
String parPath, String projectName, boolean isPrivate, boolean isAuto) {
|
||||||
File project = new File(parPath, projectName);
|
File project = new File(parPath, projectName);
|
||||||
try {
|
try {
|
||||||
if (project.isDirectory()) {
|
if (project.isDirectory()) {
|
||||||
@ -493,7 +544,10 @@ public class FileActions {
|
|||||||
File dir;
|
File dir;
|
||||||
|
|
||||||
if (isPrivate) {
|
if (isPrivate) {
|
||||||
dir = new File(parPath.replace(GlobalConf.instance.privateDir,
|
dir =
|
||||||
|
new File(
|
||||||
|
parPath.replace(
|
||||||
|
GlobalConf.instance.privateDir,
|
||||||
GlobalConf.instance.privateCompiledDir));
|
GlobalConf.instance.privateCompiledDir));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -501,10 +555,13 @@ public class FileActions {
|
|||||||
}
|
}
|
||||||
tempZip = new File(dir, projectName + "_" + time + isAutoStr + ".ypk");
|
tempZip = new File(dir, projectName + "_" + time + isAutoStr + ".ypk");
|
||||||
if (isAuto) {
|
if (isAuto) {
|
||||||
File[] files = dir
|
File[] files =
|
||||||
.listFiles(pathname -> pathname.getName().startsWith(projectName + "_")
|
dir.listFiles(
|
||||||
|
pathname ->
|
||||||
|
pathname.getName().startsWith(projectName + "_")
|
||||||
&& pathname.getName().endsWith("_Auto.ypk"));
|
&& pathname.getName().endsWith("_Auto.ypk"));
|
||||||
if (files != null && files.length == 1
|
if (files != null
|
||||||
|
&& files.length == 1
|
||||||
&& !changeSet.contains(project.getAbsolutePath())) {
|
&& !changeSet.contains(project.getAbsolutePath())) {
|
||||||
return files[0].getName();
|
return files[0].getName();
|
||||||
} else if (files != null) {
|
} else if (files != null) {
|
||||||
@ -529,7 +586,8 @@ public class FileActions {
|
|||||||
Map<String, String> header = new HashMap<>();
|
Map<String, String> header = new HashMap<>();
|
||||||
header.put("accept", "*/*");
|
header.put("accept", "*/*");
|
||||||
header.put("connection", "Keep-Alive");
|
header.put("connection", "Keep-Alive");
|
||||||
header.put("user-agent",
|
header.put(
|
||||||
|
"user-agent",
|
||||||
" Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36)");
|
" Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36)");
|
||||||
// header.put("Content-Type", "application/json");
|
// header.put("Content-Type", "application/json");
|
||||||
return header;
|
return header;
|
||||||
@ -604,8 +662,7 @@ public class FileActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String toProjectName(String path) {
|
private static String toProjectName(String path) {
|
||||||
if (path.startsWith("/"))
|
if (path.startsWith("/")) path = path.substring(1);
|
||||||
path = path.substring(1);
|
|
||||||
return path.replaceAll("/.*$", "");
|
return path.replaceAll("/.*$", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,7 +781,9 @@ public class FileActions {
|
|||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while ((s = br.readLine()) != null) {
|
while ((s = br.readLine()) != null) {
|
||||||
if (s.equals("{") || s.equals("}") || s.equals("")
|
if (s.equals("{")
|
||||||
|
|| s.equals("}")
|
||||||
|
|| s.equals("")
|
||||||
|| s.trim().startsWith("\"doi\":\"")
|
|| s.trim().startsWith("\"doi\":\"")
|
||||||
|| s.trim().startsWith("\"doipFlag\":\"")) {
|
|| s.trim().startsWith("\"doipFlag\":\"")) {
|
||||||
continue;
|
continue;
|
||||||
@ -803,8 +862,8 @@ public class FileActions {
|
|||||||
returnFileListResponse(resultCallback, response, dirs, f);
|
returnFileListResponse(resultCallback, response, dirs, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void returnFileListResponse(ResultCallback resultCallback, Response response,
|
private void returnFileListResponse(
|
||||||
List<String> dirs, File f) {
|
ResultCallback resultCallback, Response response, List<String> dirs, File f) {
|
||||||
if (f.exists() && f.isDirectory()) {
|
if (f.exists() && f.isDirectory()) {
|
||||||
for (File subFile : f.listFiles()) {
|
for (File subFile : f.listFiles()) {
|
||||||
dirs.add(subFile.getName());
|
dirs.add(subFile.getName());
|
||||||
@ -846,8 +905,7 @@ public class FileActions {
|
|||||||
String fileName = subFile.getName();
|
String fileName = subFile.getName();
|
||||||
dirs.add(fileName);
|
dirs.add(fileName);
|
||||||
}
|
}
|
||||||
} else
|
} else dirs.add(project);
|
||||||
dirs.add(project);
|
|
||||||
}
|
}
|
||||||
response.data = JsonUtil.toJson(dirs);
|
response.data = JsonUtil.toJson(dirs);
|
||||||
}
|
}
|
||||||
@ -1147,8 +1205,7 @@ public class FileActions {
|
|||||||
// e.setData("{}".getBytes());
|
// e.setData("{}".getBytes());
|
||||||
// contractDO.addElements(e);
|
// contractDO.addElements(e);
|
||||||
// //
|
// //
|
||||||
// DOAClient.getGlobalInstance().create(DOIPMainServer.repoIdentifier,
|
// DOAClient.getGlobalInstance().create(DOIPMainServer.repoIdentifier, contractDO);
|
||||||
// contractDO);
|
|
||||||
// DoipClient doipClient =
|
// DoipClient doipClient =
|
||||||
//
|
//
|
||||||
// DoipClient.createByRepoUrlAndMsgFmt(
|
// DoipClient.createByRepoUrlAndMsgFmt(
|
||||||
@ -1168,34 +1225,52 @@ public class FileActions {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if (args.has("projectDOI"))
|
if (args.has("projectDOI"))
|
||||||
manifestFout.write(("{\n \"main\":\"" + fileName + ".yjs\",\n"
|
manifestFout.write(
|
||||||
+ " \"doipFlag\":true,\n" + " \"doi\":\""
|
("{\n \"main\":\""
|
||||||
+ args.get("projectDOI").getAsString() + "\",\n"
|
+ fileName
|
||||||
+ " \"authInfoPersistDOI\":\"" + authInfoPersistDOI
|
+ ".yjs\",\n"
|
||||||
+ "\"\n}").getBytes());
|
+ " \"doipFlag\":true,\n"
|
||||||
|
+ " \"doi\":\""
|
||||||
|
+ args.get("projectDOI").getAsString()
|
||||||
|
+ "\",\n"
|
||||||
|
+ " \"authInfoPersistDOI\":\""
|
||||||
|
+ authInfoPersistDOI
|
||||||
|
+ "\"\n}")
|
||||||
|
.getBytes());
|
||||||
else
|
else
|
||||||
manifestFout.write(("{\n \"main\":\"" + fileName + ".yjs\",\n"
|
manifestFout.write(
|
||||||
+ " \"authInfoPersistDOI\":\"" + authInfoPersistDOI
|
("{\n \"main\":\""
|
||||||
+ "\"\n}").getBytes());
|
+ fileName
|
||||||
|
+ ".yjs\",\n"
|
||||||
|
+ " \"authInfoPersistDOI\":\""
|
||||||
|
+ authInfoPersistDOI
|
||||||
|
+ "\"\n}")
|
||||||
|
.getBytes());
|
||||||
|
|
||||||
YJSPacker.unpack(
|
YJSPacker.unpack(
|
||||||
new File("./WebContent/ProjectTemplate/naiveDAC.zip")
|
new File("./WebContent/ProjectTemplate/naiveDAC.zip")
|
||||||
.getAbsolutePath(),
|
.getAbsolutePath(),
|
||||||
newFile.getPath() + "/naiveDAC");
|
newFile.getPath() + "/naiveDAC");
|
||||||
mainyjsFout
|
mainyjsFout.write(
|
||||||
.write(("import \"naiveDAC/naiveDAC.yjs\"\n\n").getBytes());
|
("import \"naiveDAC/naiveDAC.yjs\"\n\n").getBytes());
|
||||||
mainyjsFout.write(("contract " + fileName
|
mainyjsFout.write(
|
||||||
|
("contract "
|
||||||
|
+ fileName
|
||||||
+ "{\n function onCreate(){\n initDAC(requester);\n }\n}")
|
+ "{\n function onCreate(){\n initDAC(requester);\n }\n}")
|
||||||
.getBytes());
|
.getBytes());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (args.has("projectDOI"))
|
if (args.has("projectDOI"))
|
||||||
manifestFout.write(("{\n \"main\":\"" + fileName
|
manifestFout.write(
|
||||||
|
("{\n \"main\":\""
|
||||||
|
+ fileName
|
||||||
+ ".yjs\",\n \"doipFlag\":true,\n \"doi\":\""
|
+ ".yjs\",\n \"doipFlag\":true,\n \"doi\":\""
|
||||||
+ args.get("projectDOI").getAsString() + "\"\n}")
|
+ args.get("projectDOI").getAsString()
|
||||||
|
+ "\"\n}")
|
||||||
.getBytes());
|
.getBytes());
|
||||||
else
|
else
|
||||||
manifestFout.write(("{\n \"main\":\"" + fileName + ".yjs\"\n}")
|
manifestFout.write(
|
||||||
|
("{\n \"main\":\"" + fileName + ".yjs\"\n}")
|
||||||
.getBytes());
|
.getBytes());
|
||||||
mainyjsFout.write(("contract " + fileName + "{\n\n}").getBytes());
|
mainyjsFout.write(("contract " + fileName + "{\n\n}").getBytes());
|
||||||
}
|
}
|
||||||
@ -1258,7 +1333,10 @@ public class FileActions {
|
|||||||
|
|
||||||
File f = new File(parPath + "/" + oldFile);
|
File f = new File(parPath + "/" + oldFile);
|
||||||
if (!oldFile.contains("..") && f.exists()) {
|
if (!oldFile.contains("..") && f.exists()) {
|
||||||
LOGGER.debug("[FileController] delete:" + f.getAbsolutePath() + " exists:"
|
LOGGER.debug(
|
||||||
|
"[FileController] delete:"
|
||||||
|
+ f.getAbsolutePath()
|
||||||
|
+ " exists:"
|
||||||
+ f.exists());
|
+ f.exists());
|
||||||
if (f.isDirectory()) {
|
if (f.isDirectory()) {
|
||||||
deleteDir(f);
|
deleteDir(f);
|
||||||
@ -1397,8 +1475,10 @@ public class FileActions {
|
|||||||
// 文本文件
|
// 文本文件
|
||||||
if (!path.contains("..") && isTextFile(path)) {
|
if (!path.contains("..") && isTextFile(path)) {
|
||||||
LOGGER.debug("[FileActions] 上传文本文件类型 : ");
|
LOGGER.debug("[FileActions] 上传文本文件类型 : ");
|
||||||
BufferedWriter bw = new BufferedWriter(
|
BufferedWriter bw =
|
||||||
new FileWriter(target.getAbsolutePath() + "/" + fileName, isAppend));
|
new BufferedWriter(
|
||||||
|
new FileWriter(
|
||||||
|
target.getAbsolutePath() + "/" + fileName, isAppend));
|
||||||
bw.write(content);
|
bw.write(content);
|
||||||
bw.close();
|
bw.close();
|
||||||
} else { // 其他类型文件
|
} else { // 其他类型文件
|
||||||
@ -1435,8 +1515,7 @@ public class FileActions {
|
|||||||
|
|
||||||
private String getPubkey(JsonObject args) {
|
private String getPubkey(JsonObject args) {
|
||||||
try {
|
try {
|
||||||
if (handler != null)
|
if (handler != null) return handler.getPubKey();
|
||||||
return handler.getPubKey();
|
|
||||||
return args.get("pubKey").getAsString();
|
return args.get("pubKey").getAsString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -1579,8 +1658,9 @@ public class FileActions {
|
|||||||
if (null != ypkPath) {
|
if (null != ypkPath) {
|
||||||
try {
|
try {
|
||||||
ret.put("ypk", new File(ypkPath).getName());
|
ret.put("ypk", new File(ypkPath).getName());
|
||||||
ret.put("permissions", JsonUtil
|
ret.put(
|
||||||
.parseStringAsJsonObject(CMActions.manager.parseYpkPermissions(ypkPath)));
|
"permissions",
|
||||||
|
JsonUtil.parseStringAsJsonObject(CMActions.manager.parseYpkPermissions(ypkPath)));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
|
@ -90,8 +90,7 @@ public class ManagerActions {
|
|||||||
data = status = GlobalConf.resetNodeName(val);
|
data = status = GlobalConf.resetNodeName(val);
|
||||||
break;
|
break;
|
||||||
case "masterAddress":
|
case "masterAddress":
|
||||||
data = status = GlobalConf.resetMasterAddress(val);
|
// data = status = GlobalConf.resetMasterAddress(val);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
status = false;
|
status = false;
|
||||||
data = "unsupported key:" + key;
|
data = "unsupported key:" + key;
|
||||||
@ -119,6 +118,7 @@ public class ManagerActions {
|
|||||||
data.put("expireTime", new Date(GlobalConf.instance.expireTime) + "");
|
data.put("expireTime", new Date(GlobalConf.instance.expireTime) + "");
|
||||||
data.put("nodeName", GlobalConf.instance.name);
|
data.put("nodeName", GlobalConf.instance.name);
|
||||||
data.put("doipConfig", GlobalConf.instance.doaConf);
|
data.put("doipConfig", GlobalConf.instance.doaConf);
|
||||||
|
data.put("nodePubKey", GlobalConf.instance.keyPair.getPublicKeyStr());
|
||||||
ReplyUtil.replyWithStatus(resultCallback, "onLoadConfig", true, data);
|
ReplyUtil.replyWithStatus(resultCallback, "onLoadConfig", true, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ public class ManagerActions {
|
|||||||
data.put("clusterConnected",
|
data.put("clusterConnected",
|
||||||
String.valueOf(NetworkManager.instance.isConnectedToNodeCenter()));
|
String.valueOf(NetworkManager.instance.isConnectedToNodeCenter()));
|
||||||
data.put("nodePubKey", GlobalConf.instance.keyPair.getPublicKeyStr());
|
data.put("nodePubKey", GlobalConf.instance.keyPair.getPublicKeyStr());
|
||||||
data.put("masterAddress", GlobalConf.instance.masterAddress);
|
// data.put("masterAddress", GlobalConf.instance.masterAddress);
|
||||||
data.put("nodeCenterWS", GlobalConf.getNodeCenterWSUrl());
|
data.put("nodeCenterWS", GlobalConf.getNodeCenterWSUrl());
|
||||||
ReplyUtil.replyWithStatus(resultCallback, "onLoadNodeConfig", true, data);
|
ReplyUtil.replyWithStatus(resultCallback, "onLoadNodeConfig", true, data);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class BCOManager {
|
|||||||
this.keyPair = keyPair;
|
this.keyPair = keyPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String download(String bCoId) {
|
public String download(String bcoId) {
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
EndpointConfig config = new EndpointConfig();
|
EndpointConfig config = new EndpointConfig();
|
||||||
config.routerURI = GlobalConf.instance.doaConf.lhsAddress;
|
config.routerURI = GlobalConf.instance.doaConf.lhsAddress;
|
||||||
@ -40,11 +40,11 @@ public class BCOManager {
|
|||||||
client = new CodeRepoClient(codeRepoDoid, irpClient, keyPair);
|
client = new CodeRepoClient(codeRepoDoid, irpClient, keyPair);
|
||||||
}
|
}
|
||||||
YPKInfo ypkInfo = new YPKInfo();
|
YPKInfo ypkInfo = new YPKInfo();
|
||||||
client.retrieveBCO(bCoId, new DoipMessageCallback() {
|
client.retrieveBCO(bcoId, new DoipMessageCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(DoipMessage doipMessage) {
|
public void onResult(DoipMessage doipMessage) {
|
||||||
String body = doipMessage.body.getDataAsJsonString();
|
String body = doipMessage.body.getDataAsJsonString();
|
||||||
LOGGER.info("Retrieve " + bCoId + " Result:" + body);
|
LOGGER.info("Retrieve " + bcoId + " Result:" + body);
|
||||||
YPKInfo parsed = new Gson().fromJson(body, YPKInfo.class);
|
YPKInfo parsed = new Gson().fromJson(body, YPKInfo.class);
|
||||||
if (parsed != null && parsed.md5 != null
|
if (parsed != null && parsed.md5 != null
|
||||||
&& parsed.status == UploadingStatus.Finished) {
|
&& parsed.status == UploadingStatus.Finished) {
|
||||||
@ -58,23 +58,21 @@ public class BCOManager {
|
|||||||
synchronized (ypkInfo) {
|
synchronized (ypkInfo) {
|
||||||
try {
|
try {
|
||||||
if (ypkInfo.status == null)
|
if (ypkInfo.status == null)
|
||||||
ypkInfo.wait(1000L);
|
ypkInfo.wait(4000L);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.info("Download:" + new Gson().toJson(ypkInfo));
|
LOGGER.info("Download:" + new Gson().toJson(ypkInfo));
|
||||||
|
|
||||||
if (ypkInfo.status == UploadingStatus.Finished) {
|
if (ypkInfo.status == UploadingStatus.Finished) {
|
||||||
File target = getYpkFile(ypkInfo);
|
File target = getYpkFile(ypkInfo);
|
||||||
if (target.exists() && (client.calFileMd5(target.getAbsolutePath()) + ".ypk")
|
if (target.exists() && (client.calFileMd5(target.getAbsolutePath()) + ".ypk")
|
||||||
.equals(target.getName()))
|
.equals(target.getName()))
|
||||||
return target.getAbsolutePath();
|
return target.getAbsolutePath();
|
||||||
DownloadProgressChecker checker = new DownloadProgressChecker();
|
DownloadProgressChecker checker = new DownloadProgressChecker();
|
||||||
client.downloadYPK(bCoId, checker, target);
|
client.downloadYPK(bcoId, checker, target);
|
||||||
LOGGER.info("start Download:" + new Gson().toJson(ypkInfo));
|
LOGGER.info("start Download:" + new Gson().toJson(ypkInfo));
|
||||||
checker.waitForResult(30000);
|
checker.waitForResult(30000);
|
||||||
LOGGER.info("checker:" + checker.isSuccess);
|
LOGGER.info("checker:" + checker.isSuccess);
|
||||||
|
|
||||||
if (checker.isSuccess)
|
if (checker.isSuccess)
|
||||||
return target.getAbsolutePath();
|
return target.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
package org.bdware.server.doip;
|
package org.bdware.server.doip;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.*;
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.doip.audit.server.DefaultRepoHandlerInjector;
|
import org.bdware.doip.audit.server.DefaultRepoHandlerInjector;
|
||||||
import org.bdware.doip.codec.digitalObject.DigitalObject;
|
import org.bdware.doip.codec.digitalObject.DigitalObject;
|
||||||
import org.bdware.doip.codec.digitalObject.DoType;
|
import org.bdware.doip.codec.digitalObject.DoType;
|
||||||
import org.bdware.doip.codec.digitalObject.Element;
|
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
|
||||||
@ -18,6 +14,7 @@ import org.bdware.doip.codec.operations.BasicOperations;
|
|||||||
import org.bdware.doip.endpoint.server.DoipServiceInfo;
|
import org.bdware.doip.endpoint.server.DoipServiceInfo;
|
||||||
import org.bdware.doip.endpoint.server.Op;
|
import org.bdware.doip.endpoint.server.Op;
|
||||||
import org.bdware.doip.endpoint.server.RepositoryHandlerBase;
|
import org.bdware.doip.endpoint.server.RepositoryHandlerBase;
|
||||||
|
import org.bdware.irp.stateinfo.StateInfoBase;
|
||||||
import org.bdware.sc.ContractClient;
|
import org.bdware.sc.ContractClient;
|
||||||
import org.bdware.sc.ContractMeta;
|
import org.bdware.sc.ContractMeta;
|
||||||
import org.bdware.sc.ContractStatusEnum;
|
import org.bdware.sc.ContractStatusEnum;
|
||||||
@ -32,7 +29,6 @@ import org.bdware.sc.util.JsonUtil;
|
|||||||
import org.bdware.server.GlobalConf;
|
import org.bdware.server.GlobalConf;
|
||||||
import org.bdware.server.action.CMActions;
|
import org.bdware.server.action.CMActions;
|
||||||
import org.zz.gmhelper.SM2KeyPair;
|
import org.zz.gmhelper.SM2KeyPair;
|
||||||
import org.zz.gmhelper.SM2Util;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -40,9 +36,10 @@ import java.io.PrintStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.bdware.server.doip.ContractRepositoryMain.currentIrpClient;
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
public class ContractRepositoryHandler extends RepositoryHandlerBase
|
public class ContractRepositoryHandler extends RepositoryHandlerBase implements DefaultRepoHandlerInjector {
|
||||||
implements DefaultRepoHandlerInjector {
|
|
||||||
BCOManager bcoManager;
|
BCOManager bcoManager;
|
||||||
static Logger LOGGER = LogManager.getLogger(ContractRepositoryHandler.class);
|
static Logger LOGGER = LogManager.getLogger(ContractRepositoryHandler.class);
|
||||||
|
|
||||||
@ -50,8 +47,7 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
super(info);
|
super(info);
|
||||||
GlobalConf.DOAConf doaConf = GlobalConf.instance.doaConf;
|
GlobalConf.DOAConf doaConf = GlobalConf.instance.doaConf;
|
||||||
String bcoDir = GlobalConf.instance.bcoDir;
|
String bcoDir = GlobalConf.instance.bcoDir;
|
||||||
bcoManager = new BCOManager(doaConf.repoDoid, new File(bcoDir), doaConf.lhsAddress,
|
bcoManager = new BCOManager(doaConf.repoDoid, new File(bcoDir), doaConf.lhsAddress, GlobalConf.instance.keyPair);
|
||||||
GlobalConf.instance.keyPair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -62,9 +58,7 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
@Override
|
@Override
|
||||||
public DoipMessage handleListOps(DoipMessage doipMessage) {
|
public DoipMessage handleListOps(DoipMessage doipMessage) {
|
||||||
if (!GlobalConf.instance.doaConf.repoDoid.equals(doipMessage.header.parameters.id)) {
|
if (!GlobalConf.instance.doaConf.repoDoid.equals(doipMessage.header.parameters.id)) {
|
||||||
return replyStringWithStatus(doipMessage,
|
return replyStringWithStatus(doipMessage, "unsupported doid:" + doipMessage.header.parameters.id, DoipResponseCode.DoNotFound);
|
||||||
"unsupported doid:" + doipMessage.header.parameters.id,
|
|
||||||
DoipResponseCode.DoNotFound);
|
|
||||||
}
|
}
|
||||||
JsonArray ops = new JsonArray();
|
JsonArray ops = new JsonArray();
|
||||||
ops.add(BasicOperations.Hello.getName());
|
ops.add(BasicOperations.Hello.getName());
|
||||||
@ -75,17 +69,13 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
@Override
|
@Override
|
||||||
public DoipMessage handleCreate(DoipMessage doipMessage) {
|
public DoipMessage handleCreate(DoipMessage doipMessage) {
|
||||||
if (!GlobalConf.instance.doaConf.repoDoid.equals(doipMessage.header.parameters.id)) {
|
if (!GlobalConf.instance.doaConf.repoDoid.equals(doipMessage.header.parameters.id)) {
|
||||||
return replyStringWithStatus(doipMessage,
|
return replyStringWithStatus(doipMessage, "unsupported doid:" + doipMessage.header.parameters.id, DoipResponseCode.DoNotFound);
|
||||||
"unsupported doid:" + doipMessage.header.parameters.id,
|
|
||||||
DoipResponseCode.DoNotFound);
|
|
||||||
}
|
}
|
||||||
//TODD 验证签名。完事后进入
|
//TODD 验证签名。完事后进入
|
||||||
if (doipMessage.credential != null && doipMessage.credential.getSigner() != null) {
|
if (doipMessage.credential != null && doipMessage.credential.getSigner() != null) {
|
||||||
String permissions = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(),
|
String permissions = KeyValueDBUtil.instance.getValue(CMTables.NodeRole.toString(), doipMessage.credential.getSigner());
|
||||||
doipMessage.credential.getSigner());
|
|
||||||
if (!permissions.contains("ContractInstanceManager")) {
|
if (!permissions.contains("ContractInstanceManager")) {
|
||||||
return replyStringWithStatus(doipMessage, "permission denied, role:" + permissions,
|
return replyStringWithStatus(doipMessage, "permission denied, role:" + permissions, DoipResponseCode.Declined);
|
||||||
DoipResponseCode.Declined);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DigitalObject digitalObject = null;
|
DigitalObject digitalObject = null;
|
||||||
@ -95,65 +85,98 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
return replyStringWithStatus(doipMessage, "exception:" + new String(bo.toByteArray()),
|
return replyStringWithStatus(doipMessage, "exception:" + new String(bo.toByteArray()), DoipResponseCode.Invalid);
|
||||||
DoipResponseCode.Invalid);
|
|
||||||
}
|
}
|
||||||
|
digitalObject.attributes.addProperty("owner", doipMessage.credential.getSigner());
|
||||||
|
try {
|
||||||
digitalObject.attributes.addProperty("verifiedPubKey", doipMessage.credential.getSigner());
|
String result = startUsingJsonObject(digitalObject.attributes);
|
||||||
String path = null;
|
|
||||||
LOGGER.info("create BDO, bCoId:" + digitalObject.attributes.get("bCoId").getAsString());
|
|
||||||
if (digitalObject.attributes.has("bCoId"))
|
|
||||||
path = bcoManager.download(digitalObject.attributes.get("bCoId").getAsString());
|
|
||||||
|
|
||||||
if (path == null) {
|
|
||||||
return replyStringWithStatus(doipMessage,
|
|
||||||
"exception, failed to locate bCoId:"
|
|
||||||
+ digitalObject.attributes.get("bCoId").getAsString(),
|
|
||||||
DoipResponseCode.Invalid);
|
|
||||||
}
|
|
||||||
digitalObject.attributes.addProperty("path", path);
|
|
||||||
Contract c = new Contract();
|
|
||||||
if (digitalObject.attributes.has("contractExecType"))
|
|
||||||
c.setType(ContractExecType
|
|
||||||
.valueOf(digitalObject.attributes.get("contractExecType").getAsString()));
|
|
||||||
else
|
|
||||||
c.setType(ContractExecType.Sole);
|
|
||||||
if (digitalObject.attributes.has("shardingId"))
|
|
||||||
c.setShardingId(
|
|
||||||
Integer.valueOf(digitalObject.attributes.get("shardingId").getAsString()));
|
|
||||||
else
|
|
||||||
c.setShardingId(-1);
|
|
||||||
c.setScript(path);
|
|
||||||
c.setOwner(doipMessage.credential.getSigner());
|
|
||||||
if (digitalObject.attributes.has("createParam")) {
|
|
||||||
c.setCreateParam(digitalObject.attributes.get("createParam"));
|
|
||||||
|
|
||||||
}
|
|
||||||
SM2KeyPair sm2Key;
|
|
||||||
if (digitalObject.attributes.has("sm2KeyPair"))
|
|
||||||
sm2Key = SM2KeyPair.fromJson(
|
|
||||||
digitalObject.attributes.get("sm2KeyPair").getAsJsonObject().toString());
|
|
||||||
else
|
|
||||||
sm2Key = SM2Util.generateSM2KeyPair();
|
|
||||||
String contractID = String.valueOf(sm2Key.getPublicKeyStr().hashCode());
|
|
||||||
|
|
||||||
c.setID(contractID); // contractID是根据hash算出来的
|
|
||||||
c.setKey(sm2Key.getPrivateKeyStr());
|
|
||||||
c.setPublicKey(sm2Key.getPublicKeyStr());
|
|
||||||
if (c.getCreateParam() != null && c.getCreateParam().isJsonObject()) {
|
|
||||||
c.getCreateParam().getAsJsonObject().addProperty("repoId",
|
|
||||||
GlobalConf.instance.doaConf.repoDoid + "/" + c.getID());
|
|
||||||
}
|
|
||||||
registerBDOID(contractID);
|
|
||||||
|
|
||||||
String result = CMActions.manager.startContract(c);
|
|
||||||
//Please note startContractByYPK is invoked in sync mode method.
|
//Please note startContractByYPK is invoked in sync mode method.
|
||||||
return replyStringWithStatus(doipMessage, result, DoipResponseCode.Success);
|
return replyStringWithStatus(doipMessage, result, DoipResponseCode.Success);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return replyStringWithStatus(doipMessage, e.getMessage(), DoipResponseCode.MoreThanOneErrors);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerBDOID(String contractID) {
|
}
|
||||||
// TODO
|
|
||||||
|
public String startUsingJsonObject(JsonObject attributes) {
|
||||||
|
LOGGER.info("create BDO, bCcoId:" + attributes.get("bcoId").getAsString());
|
||||||
|
String path = null;
|
||||||
|
if (attributes.has("bcoId"))
|
||||||
|
path = bcoManager.download(attributes.get("bcoId").getAsString());
|
||||||
|
if (path == null) {
|
||||||
|
throw new IllegalArgumentException("exception, failed to locate bcoId:" + attributes.get("bcoId").getAsString());
|
||||||
|
}
|
||||||
|
attributes.addProperty("path", path);
|
||||||
|
Contract c = new Contract();
|
||||||
|
if (attributes.has("contractExecType"))
|
||||||
|
c.setType(ContractExecType.valueOf(attributes.get("contractExecType").getAsString()));
|
||||||
|
else c.setType(ContractExecType.Sole);
|
||||||
|
if (attributes.has("shardingId"))
|
||||||
|
c.setShardingId(Integer.valueOf(attributes.get("shardingId").getAsString()));
|
||||||
|
else c.setShardingId(-1);
|
||||||
|
c.setScript(path);
|
||||||
|
c.setOwner(attributes.get("owner").getAsString());
|
||||||
|
if (attributes.has("createParam")) {
|
||||||
|
c.setCreateParam(attributes.get("createParam"));
|
||||||
|
|
||||||
|
}
|
||||||
|
SM2KeyPair sm2Key = null;
|
||||||
|
if (attributes.has("sm2KeyPair"))
|
||||||
|
sm2Key = SM2KeyPair.fromJson(attributes.get("sm2KeyPair").getAsJsonObject().toString());
|
||||||
|
if (sm2Key == null)
|
||||||
|
CMActions.manager.allocateKeyIfNotExists(c);
|
||||||
|
else {
|
||||||
|
c.setKey(sm2Key.getPrivateKeyStr());
|
||||||
|
c.setPublicKey(sm2Key.getPublicKeyStr());
|
||||||
|
String contractID = String.valueOf(sm2Key.getPublicKeyStr().hashCode());
|
||||||
|
c.setID(contractID); // contractID是根据hash算出来的
|
||||||
|
}
|
||||||
|
String result = CMActions.manager.startContract(c);
|
||||||
|
registerBDOID(c.getID(), c.getPublicKey(), attributes.get("bcoId").getAsString(), result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerBDOID(String contractID, String contractPubKey, String bcoId, String startResult) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
JsonObject startResultJO = JsonParser.parseString(startResult).getAsJsonObject();
|
||||||
|
if (!startResultJO.get("status").getAsString().equals("Success"))
|
||||||
|
return;
|
||||||
|
int doipPort = 0;
|
||||||
|
if (startResultJO.has("doipStartPort"))
|
||||||
|
doipPort = startResultJO.get("doipStartPort").getAsInt();
|
||||||
|
if (startResultJO.has("doipListenPort"))
|
||||||
|
doipPort = startResultJO.get("doipListenPort").getAsInt();
|
||||||
|
StateInfoBase base = new StateInfoBase();
|
||||||
|
String repoId = GlobalConf.instance.doaConf.repoDoid;
|
||||||
|
String uri = GlobalConf.instance.doaConf.doipAddress;
|
||||||
|
int lastPos = uri.lastIndexOf(":");
|
||||||
|
base.identifier = repoId + "/" + contractID;
|
||||||
|
base.handleValues = new JsonObject();
|
||||||
|
base.handleValues.addProperty("bdwType", "BDO");
|
||||||
|
base.handleValues.addProperty("bcoId", bcoId);
|
||||||
|
base.handleValues.addProperty("repoId", repoId);
|
||||||
|
base.handleValues.addProperty("date", System.currentTimeMillis());
|
||||||
|
if (doipPort > 0) {
|
||||||
|
base.handleValues.addProperty("address", uri.substring(0, lastPos + 1) + doipPort);
|
||||||
|
base.handleValues.addProperty("version", "2.1");
|
||||||
|
base.handleValues.addProperty("protocol", "DOIP");
|
||||||
|
}
|
||||||
|
base.handleValues.addProperty("pubKey", contractPubKey);
|
||||||
|
StateInfoBase oldBase = currentIrpClient.resolve(base.identifier, false);
|
||||||
|
String registerResult = null;
|
||||||
|
LOGGER.info("base:" + oldBase == null ? "NULL" : JsonUtil.toPrettyJson(oldBase));
|
||||||
|
if (oldBase == null)
|
||||||
|
registerResult = currentIrpClient.register(base);
|
||||||
|
else
|
||||||
|
registerResult = currentIrpClient.reRegister(base);
|
||||||
|
// LOGGER.info("TORegister:" + new GsonBuilder().setPrettyPrinting().create().toJson(base));
|
||||||
|
LOGGER.info(base.identifier + " register result:" + registerResult);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// irp
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -169,12 +192,10 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
//TODO judge whethere the do exists
|
//TODO judge whethere the do exists
|
||||||
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(id);
|
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(id);
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return replyStringWithStatus(doipMessage, "can't locate do",
|
return replyStringWithStatus(doipMessage, "can't locate do", DoipResponseCode.DoNotFound);
|
||||||
DoipResponseCode.DoNotFound);
|
|
||||||
}
|
}
|
||||||
if (meta.getStatus() == ContractStatusEnum.KILLED) {
|
if (meta.getStatus() == ContractStatusEnum.KILLED) {
|
||||||
return replyStringWithStatus(doipMessage, "already deleted!",
|
return replyStringWithStatus(doipMessage, "already deleted!", DoipResponseCode.Declined);
|
||||||
DoipResponseCode.Declined);
|
|
||||||
}
|
}
|
||||||
DoipMessage[] content = new DoipMessage[1];
|
DoipMessage[] content = new DoipMessage[1];
|
||||||
JsonObject jo = new JsonObject();
|
JsonObject jo = new JsonObject();
|
||||||
@ -185,31 +206,38 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DoipMessage handleRetrieve(DoipMessage doipMessage) {
|
public DoipMessage handleRetrieve(DoipMessage doipMessage) {
|
||||||
|
if (doipMessage.header.parameters.id.equals(GlobalConf.instance.doaConf.repoDoid)) {
|
||||||
|
if (doipMessage.header.parameters.attributes == null || !doipMessage.header.parameters.attributes.has("element"))
|
||||||
|
return retrieveList(doipMessage);
|
||||||
|
else
|
||||||
|
return retrieveBDO(doipMessage, doipMessage.header.parameters.attributes.get("element").getAsString());
|
||||||
|
} else return replyStringWithStatus(doipMessage, "no such do", DoipResponseCode.Declined);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private DoipMessage retrieveBDO(DoipMessage doipMessage, String idOrName) {
|
||||||
ContractClient client = null;
|
ContractClient client = null;
|
||||||
try {
|
try {
|
||||||
client = CMActions.manager.getContractClientByDoi(doipMessage.header.parameters.id);
|
client = CMActions.manager.getContractClientByDoi(idOrName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
String doid = doipMessage.header.parameters.id;
|
String doid = idOrName;
|
||||||
int off = doid.lastIndexOf("/");
|
int off = doid.lastIndexOf("/");
|
||||||
if (off > 0)
|
if (off > 0) doid = doid.substring(off + 1);
|
||||||
doid = doid.substring(off + 1);
|
|
||||||
client = CMActions.manager.getContractClientByDoi(doid);
|
client = CMActions.manager.getContractClientByDoi(doid);
|
||||||
}
|
}
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
return replyStringWithStatus(doipMessage, "Contract instance not exist!",
|
return replyStringWithStatus(doipMessage, "BDO instance not exist!", DoipResponseCode.DoNotFound);
|
||||||
DoipResponseCode.DoNotFound);
|
|
||||||
}
|
}
|
||||||
byte[] data = doipMessage.body.getEncodedData();
|
byte[] data = doipMessage.body.getEncodedData();
|
||||||
|
|
||||||
if (data == null || data.length == 0) {
|
if (data == null || data.length == 0) {
|
||||||
DigitalObject contractDO = contract2DigitalObject(client);
|
JsonObject contractDO = contract2DigitalObject(client);
|
||||||
return replyDO(doipMessage, contractDO);
|
return replyString(doipMessage, contractDO.toString());
|
||||||
} else {
|
} else {
|
||||||
JsonObject jo = JsonUtil.parseStringAsJsonObject(new String(data));
|
JsonObject jo = JsonUtil.parseStringAsJsonObject(new String(data));
|
||||||
List<JsonElement> result = new ArrayList<>();
|
List<JsonElement> result = new ArrayList<>();
|
||||||
jo.addProperty("contractID", client.contractMeta.getID());
|
jo.addProperty("bdoSuffix", client.contractMeta.getID());
|
||||||
CMActions.executeContractInternal(jo, new ResultCallback() {
|
CMActions.executeContractInternal(jo, new ResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(JsonObject str) {
|
public void onResult(JsonObject str) {
|
||||||
@ -236,8 +264,7 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
result.add(new JsonPrimitive("Timeout!"));
|
result.add(new JsonPrimitive("Timeout!"));
|
||||||
retStatus = DoipResponseCode.MoreThanOneErrors;
|
retStatus = DoipResponseCode.MoreThanOneErrors;
|
||||||
}
|
}
|
||||||
DigitalObject digitalObject =
|
DigitalObject digitalObject = new DigitalObject(doipMessage.header.parameters.id, DoType.DO);
|
||||||
new DigitalObject(doipMessage.header.parameters.id, DoType.DO);
|
|
||||||
digitalObject.addAttribute("status", retStatus.getName());
|
digitalObject.addAttribute("status", retStatus.getName());
|
||||||
digitalObject.addAttribute("result", result.get(0));
|
digitalObject.addAttribute("result", result.get(0));
|
||||||
|
|
||||||
@ -245,50 +272,62 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private DigitalObject contract2DigitalObject(ContractClient contractClient) {
|
private DoipMessage retrieveList(DoipMessage message) {
|
||||||
DigitalObject contractDO = new DigitalObject(contractClient.getContractID(), DoType.DO);
|
JsonArray listDO = new JsonArray();
|
||||||
contractDO.addAttribute("contractName", contractClient.getContractName());
|
for (String key : CMActions.manager.statusRecorder.getStatus().keySet()) {
|
||||||
// contractDO.addAttribute("script",contract.contract.getScriptStr());
|
ContractClient contractClient = CMActions.manager.getContractClientByDoi(key);
|
||||||
contractDO.addAttribute("owner", contractClient.contractMeta.contract.getOwner());
|
if (contractClient != null) {
|
||||||
|
JsonObject ele = new JsonObject();
|
||||||
|
ele.addProperty("suffix", contractClient.getContractID());
|
||||||
|
ele.addProperty("bdoName", contractClient.contractMeta.getName());
|
||||||
|
ele.addProperty("status", contractClient.contractMeta.getStatus().toString());
|
||||||
|
listDO.add(ele);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return replyString(message, listDO.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonObject contract2DigitalObject(ContractClient contractClient) {
|
||||||
|
JsonObject contractDO = new JsonObject();
|
||||||
|
contractDO.addProperty("suffix", contractClient.getContractID());
|
||||||
|
contractDO.addProperty("bdoName", contractClient.getContractName());
|
||||||
|
contractDO.addProperty("owner", contractClient.contractMeta.contract.getOwner());
|
||||||
|
JsonArray operations = new JsonArray();
|
||||||
|
contractDO.add("operations", operations);
|
||||||
for (FunctionDesp f : contractClient.getExportedFunctions()) {
|
for (FunctionDesp f : contractClient.getExportedFunctions()) {
|
||||||
Element fe = new Element(f.functionName, "function");
|
JsonObject jo = new JsonObject();
|
||||||
fe.setAttribute("annotation", JsonUtil.toJson(f.annotations));
|
jo.addProperty("opeationName", f.functionName);
|
||||||
contractDO.addElements(fe);
|
jo.add("annotation", JsonUtil.parseObject(f.annotations));
|
||||||
|
operations.add(jo);
|
||||||
}
|
}
|
||||||
return contractDO;
|
return contractDO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Op(op = BasicOperations.Extension, name = "call")
|
@Op(op = BasicOperations.Extension, name = "call")
|
||||||
public DoipMessage handleCall(DoipMessage doipMessage) {
|
public DoipMessage handleCall(DoipMessage doipMessage) {
|
||||||
ContractClient cc =
|
ContractClient cc = CMActions.manager.getContractClientByDoi(doipMessage.header.parameters.id);
|
||||||
CMActions.manager.getContractClientByDoi(doipMessage.header.parameters.id);
|
|
||||||
if (cc == null)
|
if (cc == null)
|
||||||
return replyStringWithStatus(doipMessage, "Contract instance not exist!",
|
return replyStringWithStatus(doipMessage, "Contract instance not exist!", DoipResponseCode.DoNotFound);
|
||||||
DoipResponseCode.DoNotFound);
|
|
||||||
// todo transform doipMessage to args
|
// todo transform doipMessage to args
|
||||||
JsonObject args = doipMessage.header.parameters.attributes;
|
JsonObject args = doipMessage.header.parameters.attributes;
|
||||||
ContractRequest cr = new ContractRequest();
|
ContractRequest cr = new ContractRequest();
|
||||||
|
|
||||||
cr.setContractID(cc.getContractID());
|
cr.setContractID(cc.getContractID());
|
||||||
if (args.has("withDynamicAnalysis"))
|
if (args.has("withDynamicAnalysis")) cr.withDynamicAnalysis = args.get("withDynamicAnalysis").getAsBoolean();
|
||||||
cr.withDynamicAnalysis = args.get("withDynamicAnalysis").getAsBoolean();
|
|
||||||
if (args.has("withEvaluatesAnalysis"))
|
if (args.has("withEvaluatesAnalysis"))
|
||||||
cr.withEvaluatesAnalysis = args.get("withEvaluatesAnalysis").getAsBoolean();
|
cr.withEvaluatesAnalysis = args.get("withEvaluatesAnalysis").getAsBoolean();
|
||||||
|
|
||||||
if (args.get("elementID") == null)
|
if (args.get("elementID") == null)
|
||||||
return replyStringWithStatus(doipMessage, "missing elementID",
|
return replyStringWithStatus(doipMessage, "missing elementID", DoipResponseCode.Invalid);
|
||||||
DoipResponseCode.Invalid);
|
|
||||||
cr.setAction(args.get("elementID").getAsString());
|
cr.setAction(args.get("elementID").getAsString());
|
||||||
|
|
||||||
if (doipMessage.body.getEncodedData() != null)
|
if (doipMessage.body.getEncodedData() != null) cr.setArg(new String(doipMessage.body.getEncodedData()));
|
||||||
cr.setArg(new String(doipMessage.body.getEncodedData()));
|
|
||||||
|
|
||||||
if (doipMessage.credential != null && doipMessage.credential.getSigner() != null)
|
if (doipMessage.credential != null && doipMessage.credential.getSigner() != null)
|
||||||
cr.setRequesterDOI(doipMessage.credential.getSigner());
|
cr.setRequesterDOI(doipMessage.credential.getSigner());
|
||||||
|
|
||||||
String reqID;
|
String reqID;
|
||||||
if (args.has("requestID"))
|
if (args.has("requestID")) reqID = args.get("requestID").getAsString();
|
||||||
reqID = args.get("requestID").getAsString();
|
|
||||||
else {
|
else {
|
||||||
reqID = System.currentTimeMillis() + "_" + (int) (Math.random() * 1000);
|
reqID = System.currentTimeMillis() + "_" + (int) (Math.random() * 1000);
|
||||||
args.addProperty("requestID", reqID);
|
args.addProperty("requestID", reqID);
|
||||||
@ -315,8 +354,7 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectListOps(DoipMessage doipMessage,
|
public void injectListOps(DoipMessage doipMessage, DoipMessageFactory.DoipMessageBuilder builder) {
|
||||||
DoipMessageFactory.DoipMessageBuilder builder) {
|
|
||||||
builder.setDoipMessage(handleListOps(doipMessage));
|
builder.setDoipMessage(handleListOps(doipMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,14 +364,12 @@ public class ContractRepositoryHandler extends RepositoryHandlerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectRetrieve(DoipMessage doipMessage,
|
public void injectRetrieve(DoipMessage doipMessage, DoipMessageFactory.DoipMessageBuilder builder) {
|
||||||
DoipMessageFactory.DoipMessageBuilder builder) {
|
|
||||||
builder.setDoipMessage(handleRetrieve(doipMessage));
|
builder.setDoipMessage(handleRetrieve(doipMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void injectDelete(DoipMessage doipMessage,
|
public void injectDelete(DoipMessage doipMessage, DoipMessageFactory.DoipMessageBuilder builder) {
|
||||||
DoipMessageFactory.DoipMessageBuilder builder) {
|
|
||||||
builder.setDoipMessage(handleDelete(doipMessage));
|
builder.setDoipMessage(handleDelete(doipMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.doip.audit.EndpointConfig;
|
import org.bdware.doip.audit.EndpointConfig;
|
||||||
|
import org.bdware.doip.audit.client.AuditIrpClient;
|
||||||
import org.bdware.doip.audit.server.AuditDoipServer;
|
import org.bdware.doip.audit.server.AuditDoipServer;
|
||||||
import org.bdware.doip.audit.writer.AuditType;
|
import org.bdware.doip.audit.writer.AuditType;
|
||||||
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
import org.bdware.doip.codec.doipMessage.DoipMessage;
|
||||||
@ -27,6 +28,8 @@ public class ContractRepositoryMain {
|
|||||||
static AuditDoipServer currentServer;
|
static AuditDoipServer currentServer;
|
||||||
static LocalDoipFrowarder forwarder;
|
static LocalDoipFrowarder forwarder;
|
||||||
static final String repoType = "BDRepo";
|
static final String repoType = "BDRepo";
|
||||||
|
public static AuditIrpClient currentIrpClient;
|
||||||
|
public static ContractRepositoryHandler currentHandler;
|
||||||
|
|
||||||
public static void start() {
|
public static void start() {
|
||||||
try {
|
try {
|
||||||
@ -34,8 +37,7 @@ public class ContractRepositoryMain {
|
|||||||
String url = GlobalConf.instance.doaConf.doipAddress;
|
String url = GlobalConf.instance.doaConf.doipAddress;
|
||||||
forwarder = new LocalDoipFrowarder();
|
forwarder = new LocalDoipFrowarder();
|
||||||
if (url == null || GlobalConf.instance.doaConf.repoDoid.isEmpty()) {
|
if (url == null || GlobalConf.instance.doaConf.repoDoid.isEmpty()) {
|
||||||
LOGGER.warn("missing args, failed to start! url:" + url + " doid:"
|
LOGGER.warn("missing args, failed to start! url:" + url + " doid:" + GlobalConf.instance.doaConf.repoDoid);
|
||||||
+ GlobalConf.instance.doaConf.repoDoid);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (currentServer != null) {
|
if (currentServer != null) {
|
||||||
@ -43,31 +45,29 @@ public class ContractRepositoryMain {
|
|||||||
}
|
}
|
||||||
List<DoipListenerConfig> infos = new ArrayList<>();
|
List<DoipListenerConfig> infos = new ArrayList<>();
|
||||||
infos.add(new DoipListenerConfig(url, "2.1"));
|
infos.add(new DoipListenerConfig(url, "2.1"));
|
||||||
DoipServiceInfo info = new DoipServiceInfo(GlobalConf.instance.doaConf.repoDoid,
|
DoipServiceInfo info = new DoipServiceInfo(GlobalConf.instance.doaConf.repoDoid, GlobalConf.instance.keyPair.getPublicKeyStr(), repoType, infos);
|
||||||
GlobalConf.instance.keyPair.getPublicKeyStr(), repoType, infos);
|
|
||||||
EndpointConfig config = new EndpointConfig();
|
EndpointConfig config = new EndpointConfig();
|
||||||
config.publicKey = GlobalConf.instance.keyPair.getPublicKeyStr();
|
config.publicKey = GlobalConf.instance.keyPair.getPublicKeyStr();
|
||||||
config.privateKey = GlobalConf.instance.keyPair.getPrivateKeyStr();
|
config.privateKey = GlobalConf.instance.keyPair.getPrivateKeyStr();
|
||||||
config.auditType = AuditType.None;
|
config.auditType = AuditType.None;
|
||||||
config.routerURI = GlobalConf.instance.doaConf.lhsAddress;
|
config.routerURI = GlobalConf.instance.doaConf.lhsAddress;
|
||||||
config.repoName = GlobalConf.instance.doaConf.repoName;
|
config.repoName = GlobalConf.instance.doaConf.repoName;
|
||||||
|
currentIrpClient = new AuditIrpClient(config);
|
||||||
currentServer = new AuditDoipServer(config, info);
|
currentServer = new AuditDoipServer(config, info);
|
||||||
currentServer.setRepositoryHandler(new ContractRepositoryHandler(info));
|
currentHandler = new ContractRepositoryHandler(info);
|
||||||
|
currentServer.setRepositoryHandler(currentHandler);
|
||||||
DoipRequestHandler requestCallback = currentServer.getRequestCallback();
|
DoipRequestHandler requestCallback = currentServer.getRequestCallback();
|
||||||
SM2Signer signer = new SM2Signer(SM2KeyPair.fromJson(new Gson().toJson(config)));
|
SM2Signer signer = new SM2Signer(SM2KeyPair.fromJson(new Gson().toJson(config)));
|
||||||
DelegateDoipHandler delegateHandler = new DelegateDoipHandler(requestCallback) {
|
DelegateDoipHandler delegateHandler = new DelegateDoipHandler(requestCallback) {
|
||||||
@Override
|
@Override
|
||||||
protected DoipMessage delegateMessage(ChannelHandlerContext context,
|
protected DoipMessage delegateMessage(ChannelHandlerContext context, DoipMessage message) {
|
||||||
DoipMessage message) {
|
DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
|
||||||
DoipMessageFactory.DoipMessageBuilder builder =
|
|
||||||
new DoipMessageFactory.DoipMessageBuilder();
|
|
||||||
builder.createResponse(DoipResponseCode.DelegateRequired, message);
|
builder.createResponse(DoipResponseCode.DelegateRequired, message);
|
||||||
String id = message.header.parameters.id;
|
String id = message.header.parameters.id;
|
||||||
id = id.replaceAll(".*/", "");
|
id = id.replaceAll(".*/", "");
|
||||||
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(id);
|
ContractMeta meta = CMActions.manager.statusRecorder.getContractMeta(id);
|
||||||
if (enableDelegate(meta)) {
|
if (enableDelegate(meta)) {
|
||||||
LOGGER.info("delegate:" + message.requestID);
|
LOGGER.info("delegate:" + message.requestID + " --> doipPort:" + meta.contract.getDoipPort());
|
||||||
|
|
||||||
//if port is near cmhttp server port
|
//if port is near cmhttp server port
|
||||||
builder.addAttributes("port", meta.contract.getDoipPort());
|
builder.addAttributes("port", meta.contract.getDoipPort());
|
||||||
DoipMessage ret;
|
DoipMessage ret;
|
||||||
@ -77,7 +77,7 @@ public class ContractRepositoryMain {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("forward:" + message.requestID);
|
LOGGER.info("forward:" + message.requestID + " --> doipPort:" + meta.contract.getDoipPort());
|
||||||
return forwarder.forward(meta, message);
|
return forwarder.forward(meta, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +105,7 @@ public class ContractRepositoryMain {
|
|||||||
|
|
||||||
private static boolean enableDelegate(ContractMeta meta) {
|
private static boolean enableDelegate(ContractMeta meta) {
|
||||||
int port = meta.contract.getDoipPort();
|
int port = meta.contract.getDoipPort();
|
||||||
|
|
||||||
int delta = Integer.valueOf(GlobalConf.instance.ipPort.split(":")[1]) - port;
|
int delta = Integer.valueOf(GlobalConf.instance.ipPort.split(":")[1]) - port;
|
||||||
return Math.abs(delta) < 200;
|
return Math.abs(delta) < 200;
|
||||||
}
|
}
|
||||||
|
@ -123,8 +123,11 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
setNodeID.put("id", keyPair.getPublicKeyStr());
|
setNodeID.put("id", keyPair.getPublicKeyStr());
|
||||||
String signature = "no signature";
|
String signature = "no signature";
|
||||||
try {
|
try {
|
||||||
byte[] sig = SM2Util.sign(keyPair.getPrivateKeyParameter(),
|
byte[] sig =
|
||||||
(keyPair.getPublicKeyStr() + json.get("session").getAsString()).getBytes());
|
SM2Util.sign(
|
||||||
|
keyPair.getPrivateKeyParameter(),
|
||||||
|
(keyPair.getPublicKeyStr() + json.get("session").getAsString())
|
||||||
|
.getBytes());
|
||||||
signature = ByteUtils.toHexString(sig);
|
signature = ByteUtils.toHexString(sig);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -133,7 +136,8 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
setNodeID.put("nodeName", GlobalConf.instance.name);
|
setNodeID.put("nodeName", GlobalConf.instance.name);
|
||||||
setNodeID.put("peerID", GlobalConf.instance.peerID);
|
setNodeID.put("peerID", GlobalConf.instance.peerID);
|
||||||
setNodeID.put("ipPort", GlobalConf.instance.ipPort);
|
setNodeID.put("ipPort", GlobalConf.instance.ipPort);
|
||||||
setNodeID.put("masterAddress", GlobalConf.instance.masterAddress);
|
setNodeID.put("masterAddress", GlobalConf.instance.ipPort);
|
||||||
|
// setNodeID.put("masterAddress", GlobalConf.instance.masterAddress);
|
||||||
|
|
||||||
sendMsg(JsonUtil.toJson(setNodeID));
|
sendMsg(JsonUtil.toJson(setNodeID));
|
||||||
}
|
}
|
||||||
@ -145,8 +149,8 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
|
|
||||||
@Action
|
@Action
|
||||||
public void syncPong(JsonObject json, ResultCallback resultCallback) {
|
public void syncPong(JsonObject json, ResultCallback resultCallback) {
|
||||||
sync.wakeUp(json.get("requestID").getAsString(),
|
sync.wakeUp(
|
||||||
"{\"status\":\"Success\",\"result\":\"a\"}");
|
json.get("requestID").getAsString(), "{\"status\":\"Success\",\"result\":\"a\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean syncPing() {
|
public boolean syncPing() {
|
||||||
@ -169,9 +173,12 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void listCMInfo() {
|
public void listCMInfo() {
|
||||||
sendMsg("{\"action\":\"listCMInfo\",\"pubKey\":\""
|
sendMsg(
|
||||||
|
"{\"action\":\"listCMInfo\",\"pubKey\":\""
|
||||||
+ KeyValueDBUtil.instance.getValue(CMTables.ConfigDB.toString(), "pubKey")
|
+ KeyValueDBUtil.instance.getValue(CMTables.ConfigDB.toString(), "pubKey")
|
||||||
+ "\",\"requestID\":\"" + System.currentTimeMillis() + "\"}");
|
+ "\",\"requestID\":\""
|
||||||
|
+ System.currentTimeMillis()
|
||||||
|
+ "\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Action
|
@Action
|
||||||
@ -223,8 +230,7 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
@Action(async = true)
|
@Action(async = true)
|
||||||
public void publishEventFromCenter(JsonObject jo, ResultCallback rcb) {
|
public void publishEventFromCenter(JsonObject jo, ResultCallback rcb) {
|
||||||
if (jo.has("event")) {
|
if (jo.has("event")) {
|
||||||
CMActions.manager
|
CMActions.manager.deliverEvent(JsonUtil.fromJson(jo.get("event").getAsString(), REvent.class));
|
||||||
.deliverEvent(JsonUtil.fromJson(jo.get("event").getAsString(), REvent.class));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,8 +278,7 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
String requestID = jo.get("requestID").getAsString();
|
String requestID = jo.get("requestID").getAsString();
|
||||||
String requesterNodeID = jo.get("requesterNodeID").getAsString();
|
String requesterNodeID = jo.get("requesterNodeID").getAsString();
|
||||||
String crStr = jo.get("contractRequest").getAsString();
|
String crStr = jo.get("contractRequest").getAsString();
|
||||||
CMActions.manager.executeLocallyAsync(JsonUtil.fromJson(crStr, ContractRequest.class),
|
CMActions.manager.executeLocallyAsync(JsonUtil.fromJson(crStr, ContractRequest.class), new ResultCallback() {
|
||||||
new ResultCallback() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onResult(String str) {
|
public void onResult(String str) {
|
||||||
JsonObject ret = new JsonObject();
|
JsonObject ret = new JsonObject();
|
||||||
@ -360,8 +365,8 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
if (!cr.result.equals(JsonNull.INSTANCE)) {
|
if (!cr.result.equals(JsonNull.INSTANCE)) {
|
||||||
try {
|
try {
|
||||||
JsonObject jo = cr.result.getAsJsonObject();
|
JsonObject jo = cr.result.getAsJsonObject();
|
||||||
NetworkManager.instance.updateAgentRouter(jo.get("pubKey").getAsString(),
|
NetworkManager.instance.updateAgentRouter(
|
||||||
jo.get("masterAddress").getAsString());
|
jo.get("pubKey").getAsString(), jo.get("masterAddress").getAsString());
|
||||||
NetworkManager.instance.connectToAgent(jo.get("pubKey").getAsString(), null);
|
NetworkManager.instance.connectToAgent(jo.get("pubKey").getAsString(), null);
|
||||||
return "success";
|
return "success";
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -385,17 +390,18 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
if (!cr.result.equals(JsonNull.INSTANCE)) {
|
if (!cr.result.equals(JsonNull.INSTANCE)) {
|
||||||
try {
|
try {
|
||||||
JsonObject jo = cr.result.getAsJsonObject();
|
JsonObject jo = cr.result.getAsJsonObject();
|
||||||
NetworkManager.instance.updateAgentRouter(jo.get("pubKey").getAsString(),
|
NetworkManager.instance.updateAgentRouter(
|
||||||
jo.get("masterAddress").getAsString());
|
jo.get("pubKey").getAsString(), jo.get("masterAddress").getAsString());
|
||||||
NetworkManager.instance.connectToAgent(jo.get("pubKey").getAsString(), null);
|
NetworkManager.instance.connectToAgent(jo.get("pubKey").getAsString(), null);
|
||||||
LOGGER.info(String.format("the master of contract %s: pubKey=%s address=%s",
|
LOGGER.info(
|
||||||
contractID, jo.get("pubKey").getAsString(),
|
String.format("the master of contract %s: pubKey=%s address=%s",
|
||||||
|
contractID,
|
||||||
|
jo.get("pubKey").getAsString(),
|
||||||
jo.get("masterAddress").getAsString()));
|
jo.get("masterAddress").getAsString()));
|
||||||
contractID2PubKey.put(contractID, jo.get("pubKey").getAsString());
|
contractID2PubKey.put(contractID, jo.get("pubKey").getAsString());
|
||||||
return jo.get("pubKey").getAsString();
|
return jo.get("pubKey").getAsString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn(
|
LOGGER.warn("the master of contract " + contractID + " is null! " + e.getMessage());
|
||||||
"the master of contract " + contractID + " is null! " + e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -414,8 +420,8 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
startCheck = true;
|
startCheck = true;
|
||||||
for (MultiContractMeta meta : CMActions.manager.multiContractRecorder.getStatus()
|
for (MultiContractMeta meta :
|
||||||
.values()) {
|
CMActions.manager.multiContractRecorder.getStatus().values()) {
|
||||||
String contractID = meta.getContractID();
|
String contractID = meta.getContractID();
|
||||||
LOGGER.info("check master of contract " + contractID);
|
LOGGER.info("check master of contract " + contractID);
|
||||||
ContractMeta cmeta = CMActions.manager.statusRecorder.getContractMeta(meta.getID());
|
ContractMeta cmeta = CMActions.manager.statusRecorder.getContractMeta(meta.getID());
|
||||||
@ -429,21 +435,20 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
// 该合约可能在这个节点崩溃期间已经被终止,不存在了,这个节点不用恢复这个合约了,直接从数据库中删除
|
// 该合约可能在这个节点崩溃期间已经被终止,不存在了,这个节点不用恢复这个合约了,直接从数据库中删除
|
||||||
LOGGER.info("该合约在集群已经不存在!");
|
LOGGER.info("该合约在集群已经不存在!");
|
||||||
KeyValueDBUtil.instance.delete(CMTables.UnitContracts.toString(), contractID);
|
KeyValueDBUtil.instance.delete(CMTables.UnitContracts.toString(), contractID);
|
||||||
if (KeyValueDBUtil.instance.containsKey(CMTables.CheckPointLastHash.toString(),
|
if (KeyValueDBUtil.instance.containsKey(
|
||||||
contractID)) {
|
CMTables.CheckPointLastHash.toString(), contractID)) {
|
||||||
KeyValueDBUtil.instance.delete(CMTables.CheckPointLastHash.toString(),
|
KeyValueDBUtil.instance.delete(
|
||||||
contractID);
|
CMTables.CheckPointLastHash.toString(), contractID);
|
||||||
}
|
}
|
||||||
if (KeyValueDBUtil.instance.containsKey(CMTables.LastExeSeq.toString(),
|
if (KeyValueDBUtil.instance.containsKey(
|
||||||
contractID)) {
|
CMTables.LastExeSeq.toString(), contractID)) {
|
||||||
KeyValueDBUtil.instance.delete(CMTables.LastExeSeq.toString(), contractID);
|
KeyValueDBUtil.instance.delete(CMTables.LastExeSeq.toString(), contractID);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
MasterClientRecoverMechAction.recoverSet.add(contractID);
|
MasterClientRecoverMechAction.recoverSet.add(contractID);
|
||||||
|
|
||||||
LOGGER.info("queryUnitContractsID master为" + master.substring(0, 5) + " -> 合约id:"
|
LOGGER.info("queryUnitContractsID master为" + master.substring(0, 5) + " -> 合约id:" + contractID);
|
||||||
+ contractID);
|
|
||||||
RecoverMechTimeRecorder.queryMasterFinish = System.currentTimeMillis();
|
RecoverMechTimeRecorder.queryMasterFinish = System.currentTimeMillis();
|
||||||
queryUnitContractsID2(contractID, master);
|
queryUnitContractsID2(contractID, master);
|
||||||
}
|
}
|
||||||
@ -484,7 +489,9 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
|
|
||||||
@Action(async = true)
|
@Action(async = true)
|
||||||
public void requestLog(JsonObject json, ResultCallback rc) {
|
public void requestLog(JsonObject json, ResultCallback rc) {
|
||||||
if (!json.has("requestID") || !json.has("contractID") || !json.has("offset")
|
if (!json.has("requestID")
|
||||||
|
|| !json.has("contractID")
|
||||||
|
|| !json.has("offset")
|
||||||
|| !json.has("count")) {
|
|| !json.has("count")) {
|
||||||
LOGGER.debug(
|
LOGGER.debug(
|
||||||
"[CMClientController] missing arguments, requestID / contractID / offset / count");
|
"[CMClientController] missing arguments, requestID / contractID / offset / count");
|
||||||
@ -624,8 +631,8 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
MasterElectTimeRecorder.slaveConnectFinish = System.currentTimeMillis();
|
MasterElectTimeRecorder.slaveConnectFinish = System.currentTimeMillis();
|
||||||
|
|
||||||
// 开启master恢复
|
// 开启master恢复
|
||||||
MasterServerRecoverMechAction.newMasterRecover(contractID,
|
MasterServerRecoverMechAction.newMasterRecover(
|
||||||
json.get("members").getAsString(), onlineMembers);
|
contractID, json.get("members").getAsString(), onlineMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean waitForConnection(List<String> nodeNames) {
|
private boolean waitForConnection(List<String> nodeNames) {
|
||||||
@ -645,8 +652,7 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -662,8 +668,7 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
String distributeID = null;
|
String distributeID = null;
|
||||||
if (json.has("distributeID"))
|
if (json.has("distributeID"))
|
||||||
distributeID = json.get("distributeID").getAsString();
|
distributeID = json.get("distributeID").getAsString();
|
||||||
else
|
else distributeID = json.get("responseID").getAsString();
|
||||||
distributeID = json.get("responseID").getAsString();
|
|
||||||
ResultCallback to = distributeReqMap.get(distributeID);
|
ResultCallback to = distributeReqMap.get(distributeID);
|
||||||
distributeReqMap.remove(distributeID);
|
distributeReqMap.remove(distributeID);
|
||||||
to.onResult(json.get("content").getAsString());
|
to.onResult(json.get("content").getAsString());
|
||||||
@ -715,10 +720,12 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
public void NCStartElect(JsonObject jo, ResultCallback result) {
|
public void NCStartElect(JsonObject jo, ResultCallback result) {
|
||||||
String conID = jo.get("contractID").getAsString();
|
String conID = jo.get("contractID").getAsString();
|
||||||
String uniNumber = null;
|
String uniNumber = null;
|
||||||
if (jo.has("nuiNumber"))
|
if (jo.has("nuiNumber")) uniNumber = jo.get("nuiNumber").getAsString();
|
||||||
uniNumber = jo.get("nuiNumber").getAsString();
|
|
||||||
ContractClient cc = CMActions.manager.getClient(conID);
|
ContractClient cc = CMActions.manager.getClient(conID);
|
||||||
LOGGER.info("[CMClientController] NCStartElect : contractID=" + conID + " client==null:"
|
LOGGER.info(
|
||||||
|
"[CMClientController] NCStartElect : contractID="
|
||||||
|
+ conID
|
||||||
|
+ " client==null:"
|
||||||
+ (null == cc));
|
+ (null == cc));
|
||||||
|
|
||||||
// 不是自己本地的合约
|
// 不是自己本地的合约
|
||||||
@ -793,12 +800,11 @@ public class NodeCenterClientController implements NodeCenterConn {
|
|||||||
boolean isAppend = args.get("isAppend").getAsBoolean();
|
boolean isAppend = args.get("isAppend").getAsBoolean();
|
||||||
boolean isDone = args.get("isDone").getAsBoolean();
|
boolean isDone = args.get("isDone").getAsBoolean();
|
||||||
boolean isPrivate = args.get("isPrivate").getAsBoolean();
|
boolean isPrivate = args.get("isPrivate").getAsBoolean();
|
||||||
LOGGER.debug(String.format("isAppend=%b isDone=%b isPrivate=%b", isAppend, isDone,
|
LOGGER.debug(
|
||||||
isPrivate));
|
String.format("isAppend=%b isDone=%b isPrivate=%b", isAppend, isDone, isPrivate));
|
||||||
String path = GlobalConf.instance.publicCompiledDir;
|
String path = GlobalConf.instance.publicCompiledDir;
|
||||||
if (isPrivate && args.has("pubKey")) {
|
if (isPrivate && args.has("pubKey")) {
|
||||||
path = GlobalConf.instance.privateCompiledDir + "/"
|
path = GlobalConf.instance.privateCompiledDir + "/" + args.get("pubKey").getAsString();
|
||||||
+ args.get("pubKey").getAsString();
|
|
||||||
}
|
}
|
||||||
File dir = new File(path);
|
File dir = new File(path);
|
||||||
if (!dir.exists()) {
|
if (!dir.exists()) {
|
||||||
|
@ -44,8 +44,7 @@ public class NetworkManager {
|
|||||||
//Manage server->client connection;
|
//Manage server->client connection;
|
||||||
public static final Map<String, AgentConnector> CONNECTORS = new ConcurrentHashMap<>();
|
public static final Map<String, AgentConnector> CONNECTORS = new ConcurrentHashMap<>();
|
||||||
//Manage client->server connection;
|
//Manage client->server connection;
|
||||||
public static final Map<String, TCPServerFrameHandler> SERVER_CONNECTORS =
|
public static final Map<String, TCPServerFrameHandler> SERVER_CONNECTORS = new ConcurrentHashMap<>();
|
||||||
new ConcurrentHashMap<>();
|
|
||||||
public static final String NODE_CENTER_CLIENT = "NODE_CENTER_CLIENT";
|
public static final String NODE_CENTER_CLIENT = "NODE_CENTER_CLIENT";
|
||||||
public static final String P2P_GRPC_CLIENT = "P2P_GRPC_CLIENT";
|
public static final String P2P_GRPC_CLIENT = "P2P_GRPC_CLIENT";
|
||||||
private static final Map<String, String> slaverRouter = new HashMap<>();
|
private static final Map<String, String> slaverRouter = new HashMap<>();
|
||||||
@ -60,13 +59,18 @@ public class NetworkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void reconnectAgent(String master) {
|
public static void reconnectAgent(String master) {
|
||||||
LOGGER.debug(String.format("master=%s\t%s", master, JsonUtil.toJson(slaverRouter)));
|
LOGGER.debug(
|
||||||
|
String.format("master=%s\t%s",
|
||||||
|
master,
|
||||||
|
JsonUtil.toJson(slaverRouter)));
|
||||||
try {
|
try {
|
||||||
NetworkManager.AgentConnector conn;
|
NetworkManager.AgentConnector conn;
|
||||||
synchronized (conn = NetworkManager.CONNECTORS.get(master)) {
|
synchronized (conn = NetworkManager.CONNECTORS.get(master)) {
|
||||||
if (!conn.handler.isOpen()) {
|
if (!conn.handler.isOpen()) {
|
||||||
String[] ipAndPort = slaverRouter.get(master).split(":");
|
String[] ipAndPort = slaverRouter.get(master).split(":");
|
||||||
conn.bootstrap.connect(ipAndPort[0], Integer.parseInt(ipAndPort[1])).sync()
|
conn.bootstrap
|
||||||
|
.connect(ipAndPort[0], Integer.parseInt(ipAndPort[1]))
|
||||||
|
.sync()
|
||||||
.channel();
|
.channel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,14 +94,17 @@ public class NetworkManager {
|
|||||||
nodeCenterClientHandler = ControllerManager.createNodeCenterClientHandler();
|
nodeCenterClientHandler = ControllerManager.createNodeCenterClientHandler();
|
||||||
EventLoopGroup group = new NioEventLoopGroup();
|
EventLoopGroup group = new NioEventLoopGroup();
|
||||||
b.group(group);
|
b.group(group);
|
||||||
b.channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
|
b.channel(NioSocketChannel.class)
|
||||||
|
.handler(
|
||||||
|
new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel ch) {
|
protected void initChannel(SocketChannel ch) {
|
||||||
ChannelPipeline p = ch.pipeline();
|
ChannelPipeline p = ch.pipeline();
|
||||||
p.addLast(new DelimiterCodec()).addLast(nodeCenterClientHandler);
|
p.addLast(new DelimiterCodec()).addLast(nodeCenterClientHandler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ContractManager.scheduledThreadPool.scheduleWithFixedDelay(() -> {
|
ContractManager.scheduledThreadPool.scheduleWithFixedDelay(
|
||||||
|
() -> {
|
||||||
try {
|
try {
|
||||||
// manager.clearCache();
|
// manager.clearCache();
|
||||||
String URL = GlobalConf.getNodeCenterUrl();
|
String URL = GlobalConf.getNodeCenterUrl();
|
||||||
@ -113,13 +120,20 @@ public class NetworkManager {
|
|||||||
nodeCenterClientHandler.close();
|
nodeCenterClientHandler.close();
|
||||||
assert null != uri;
|
assert null != uri;
|
||||||
b.connect(uri.getHost(), uri.getPort()).sync().channel();
|
b.connect(uri.getHost(), uri.getPort()).sync().channel();
|
||||||
LOGGER.info("connect to node center: " + uri.getHost() + ":" + uri.getPort());
|
LOGGER.info(
|
||||||
|
"connect to node center: "
|
||||||
|
+ uri.getHost()
|
||||||
|
+ ":"
|
||||||
|
+ uri.getPort());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// e.printStackTrace();
|
// e.printStackTrace();
|
||||||
LOGGER.warn("connecting to node center failed! " + e.getMessage());
|
LOGGER.warn("connecting to node center failed! " + e.getMessage());
|
||||||
}
|
}
|
||||||
}, 0, 30 + (int) (20 * Math.random()), TimeUnit.SECONDS);
|
},
|
||||||
|
4,
|
||||||
|
30 + (int) (20 * Math.random()),
|
||||||
|
TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -128,13 +142,17 @@ public class NetworkManager {
|
|||||||
ServerBootstrap b = new ServerBootstrap();
|
ServerBootstrap b = new ServerBootstrap();
|
||||||
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||||
b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
||||||
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
|
b.group(bossGroup, workerGroup)
|
||||||
.option(ChannelOption.SO_BACKLOG, 100).localAddress(port)
|
.channel(NioServerSocketChannel.class)
|
||||||
|
.option(ChannelOption.SO_BACKLOG, 100)
|
||||||
|
.localAddress(port)
|
||||||
.childOption(ChannelOption.SO_KEEPALIVE, true)
|
.childOption(ChannelOption.SO_KEEPALIVE, true)
|
||||||
.childHandler(new ChannelInitializer<SocketChannel>() {
|
.childHandler(
|
||||||
|
new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel arg0) {
|
protected void initChannel(SocketChannel arg0) {
|
||||||
arg0.pipeline().addLast(new DelimiterCodec())
|
arg0.pipeline()
|
||||||
|
.addLast(new DelimiterCodec())
|
||||||
.addLast(new TCPServerFrameHandler());
|
.addLast(new TCPServerFrameHandler());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -156,8 +174,9 @@ public class NetworkManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void waitForNodeCenterConnected() {
|
public void waitForNodeCenterConnected() {
|
||||||
for (int i = 0; i < 10 && null != nodeCenterClientHandler
|
for (int i = 0;
|
||||||
&& !nodeCenterClientHandler.isConnected(); i++) {
|
i < 10 && null != nodeCenterClientHandler && !nodeCenterClientHandler.isConnected();
|
||||||
|
i++) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@ -214,7 +233,9 @@ public class NetworkManager {
|
|||||||
connector.handler = handler;
|
connector.handler = handler;
|
||||||
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000);
|
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000);
|
||||||
b.group(CMHttpServer.workerGroup);
|
b.group(CMHttpServer.workerGroup);
|
||||||
b.channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
|
b.channel(NioSocketChannel.class)
|
||||||
|
.handler(
|
||||||
|
new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
protected void initChannel(SocketChannel ch) {
|
protected void initChannel(SocketChannel ch) {
|
||||||
ChannelPipeline p = ch.pipeline();
|
ChannelPipeline p = ch.pipeline();
|
||||||
@ -286,10 +307,12 @@ public class NetworkManager {
|
|||||||
Bootstrap b = new Bootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
final TCPClientFrameHandler handler = new TCPClientFrameHandler(peer);
|
final TCPClientFrameHandler handler = new TCPClientFrameHandler(peer);
|
||||||
//tcpClientMap.put(peer, handler);
|
//tcpClientMap.put(peer, handler);
|
||||||
b.group(group).channel(NioSocketChannel.class)
|
b.group(group)
|
||||||
|
.channel(NioSocketChannel.class)
|
||||||
.remoteAddress(new InetSocketAddress(host, port))
|
.remoteAddress(new InetSocketAddress(host, port))
|
||||||
.option(ChannelOption.TCP_NODELAY, true)
|
.option(ChannelOption.TCP_NODELAY, true)
|
||||||
.handler(new ChannelInitializer<SocketChannel>() {
|
.handler(
|
||||||
|
new ChannelInitializer<SocketChannel>() {
|
||||||
@Override
|
@Override
|
||||||
public void initChannel(SocketChannel ch) throws Exception {
|
public void initChannel(SocketChannel ch) throws Exception {
|
||||||
ch.pipeline()
|
ch.pipeline()
|
||||||
@ -345,16 +368,17 @@ public class NetworkManager {
|
|||||||
LOGGER.info("send msg to itself " + msg);
|
LOGGER.info("send msg to itself " + msg);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// tcpClientFrameHandler = NetworkManager.instance.tcpClientMap.getOrDefault(peer,
|
// tcpClientFrameHandler = NetworkManager.instance.tcpClientMap.getOrDefault(peer, null);
|
||||||
// null);
|
|
||||||
if (peerID2TCPAddress.containsKey(peer)) {
|
if (peerID2TCPAddress.containsKey(peer)) {
|
||||||
//recreateTCPClient(peer);
|
//recreateTCPClient(peer);
|
||||||
// instance.tcpClientMap.put(peer, tcpClientFrameHandler);
|
// instance.tcpClientMap.put(peer, tcpClientFrameHandler);
|
||||||
UnitMessage unitMessage = msg.toBuilder().clearReceiver().addReceiver(peer).build();
|
UnitMessage unitMessage =
|
||||||
|
msg.toBuilder().clearReceiver().addReceiver(peer).build();
|
||||||
LOGGER.info("send msg by p2p to " + peer);
|
LOGGER.info("send msg by p2p to " + peer);
|
||||||
JavaContractServiceGrpcServer.sendMsg(unitMessage);
|
JavaContractServiceGrpcServer.sendMsg(unitMessage);
|
||||||
} else {
|
} else {
|
||||||
UnitMessage unitMessage = msg.toBuilder().clearReceiver().addReceiver(peer).build();
|
UnitMessage unitMessage =
|
||||||
|
msg.toBuilder().clearReceiver().addReceiver(peer).build();
|
||||||
LOGGER.info("send msg by p2p to " + peer);
|
LOGGER.info("send msg by p2p to " + peer);
|
||||||
JavaContractServiceGrpcServer.sendMsg(unitMessage);
|
JavaContractServiceGrpcServer.sendMsg(unitMessage);
|
||||||
}
|
}
|
||||||
|
@ -14,4 +14,11 @@ public class ByteTest {
|
|||||||
String b64 = ByteUtil.encodeBASE64(ByteUtils.fromHexString(hexStr));
|
String b64 = ByteUtil.encodeBASE64(ByteUtils.fromHexString(hexStr));
|
||||||
System.out.println(URLEncoder.encode(b64));
|
System.out.println(URLEncoder.encode(b64));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void strReplace() {
|
||||||
|
String path = "/aba/dad/./adfa.zip";
|
||||||
|
path = path.replaceAll("/\\./", "/");
|
||||||
|
System.out.println(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user