Commit 02016346 authored by duanjinfei's avatar duanjinfei

change program

parent ec2188dd
......@@ -28,6 +28,8 @@ contract Admin is Ownable {
contract AuthVerify is Admin {
mapping(string => address) authVerify;
mapping(address => bool) nodeVerify;
function addCaller(
string[] memory keys,
address[] memory caller
......@@ -37,10 +39,20 @@ contract AuthVerify is Admin {
}
}
function addNode(address[] memory nodes) external onlyOwner {
for (uint i = 0; i < nodes.length; i++) {
nodeVerify[nodes[i]] = true;
}
}
function getCaller(string memory key) external view returns (address) {
return authVerify[key];
}
function onlyNode(address node) external view returns (bool) {
return nodeVerify[node];
}
function onlyCaller(
string memory key,
address caller
......@@ -67,4 +79,9 @@ contract Callee is Admin {
);
_;
}
modifier onlyNode() {
require(_const.onlyNode(msg.sender), "The caller isn't belong to node");
_;
}
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "./BaseAuth.sol";
contract CloudApplication is Callee {
constructor(address const) Callee(const) {}
mapping(string => bool) appIsExists;
string[] internal appIds;
mapping(string => mapping(uint8 => string)) nodeNetworkInfo;
mapping(string => mapping(uint8 => string[])) nodeStunAndTurn;
mapping(string => string[]) app_node;
mapping(string => mapping(string => bool)) isAppBindToNode;
mapping(string => string[]) node_app;
mapping(string => mapping(uint8 => string)) appInfo;
mapping(string => mapping(uint8 => bool)) appSupport;
function getAppIds(
uint8 start,
uint8 count
) external view returns (string[] memory res) {
uint256 vmIdCount = appIds.length;
uint256 end = start + count;
if (end > vmIdCount) {
end = vmIdCount;
}
res = new string[](end - start);
if (vmIdCount >= start) {
for (uint8 i = start; i < end; i++) {
res[i - start] = appIds[i];
}
}
return res;
}
function addNodeNetworkInfo(
string memory nodeId,
string memory externalIp,
string memory serverPort,
string[] memory stunIp,
string[] memory turnIp,
string[] memory turnUser,
string[] memory turnPwd,
string memory signallingHttpIp,
string memory signallingWsIp
) external {
require(bytes(nodeId).length > 0, "nodeId cannot be empty");
require(bytes(externalIp).length > 0, "externalIp cannot be empty");
require(bytes(serverPort).length > 0, "serverPort cannot be empty");
require(turnIp.length == turnUser.length, "");
require(turnUser.length == turnPwd.length, "");
nodeNetworkInfo[nodeId][_const.EXTERNAL_IP()] = externalIp;
nodeNetworkInfo[nodeId][_const.SERVER_PORT()] = serverPort;
for (uint i = 0; i < stunIp.length; i++) {
nodeStunAndTurn[nodeId][_const.STUN_IP()].push(stunIp[i]);
}
for (uint i = 0; i < turnIp.length; i++) {
nodeStunAndTurn[nodeId][_const.TURN_IP()].push(turnIp[i]);
}
for (uint i = 0; i < turnUser.length; i++) {
nodeStunAndTurn[nodeId][_const.TURN_USER()].push(turnUser[i]);
}
for (uint i = 0; i < turnPwd.length; i++) {
nodeStunAndTurn[nodeId][_const.TURN_PWD()].push(turnPwd[i]);
}
nodeNetworkInfo[nodeId][_const.SINGALLING_HTTP_IP()] = signallingHttpIp;
nodeNetworkInfo[nodeId][_const.SINGALLING_WS_IP()] = signallingWsIp;
}
function getNodeNetwork(
string memory nodeId
)
external
view
returns (
string memory externalIp,
string memory serverPort,
string[] memory stunIp,
string[] memory turnIp,
string[] memory turnUser,
string[] memory turnPwd,
string memory signallingHttpIp,
string memory signallingWsIp
)
{
externalIp = nodeNetworkInfo[nodeId][_const.EXTERNAL_IP()];
serverPort = nodeNetworkInfo[nodeId][_const.SERVER_PORT()];
string[] memory stunIpArr = nodeStunAndTurn[nodeId][_const.STUN_IP()];
stunIp = new string[](stunIpArr.length);
for (uint i = 0; i < stunIpArr.length; i++) {
stunIp[i] = stunIpArr[i];
}
string[] memory turnIpArr = nodeStunAndTurn[nodeId][_const.TURN_IP()];
string[] memory turnUserArr = nodeStunAndTurn[nodeId][
_const.TURN_USER()
];
string[] memory turnPwdArr = nodeStunAndTurn[nodeId][_const.TURN_PWD()];
turnIp = new string[](turnIpArr.length);
turnUser = new string[](turnUserArr.length);
turnPwd = new string[](turnPwdArr.length);
for (uint i = 0; i < turnIpArr.length; i++) {
turnIp[i] = turnIpArr[i];
}
for (uint i = 0; i < turnUserArr.length; i++) {
turnUser[i] = turnUserArr[i];
}
for (uint i = 0; i < turnPwdArr.length; i++) {
turnPwd[i] = turnPwdArr[i];
}
signallingHttpIp = nodeNetworkInfo[nodeId][_const.SINGALLING_HTTP_IP()];
signallingWsIp = nodeNetworkInfo[nodeId][_const.SINGALLING_WS_IP()];
}
function getNodeIds(
string memory appId,
uint8 start,
uint8 count
) external view returns (string[] memory res) {
uint256 vmIdCount = app_node[appId].length;
uint256 end = start + count;
if (end > vmIdCount) {
end = vmIdCount;
}
res = new string[](end - start);
if (vmIdCount >= start) {
for (uint8 i = start; i < end; i++) {
res[i - start] = app_node[appId][i];
}
}
return res;
}
function isAppBoundToNode(
string memory appId,
string memory nodeId
) external view returns (bool) {
return isAppBindToNode[nodeId][appId];
}
function batchAddAppInfo(
string memory nodeId,
string[] memory appId,
string[] memory name,
string[] memory version,
string[] memory status,
string[] memory resolutionRatio,
string[] memory fps,
string[] memory gamePads,
string[] memory isHdrSupported
) external {
for (uint i = 0; i < appId.length; i++) {
require(bytes(nodeId).length > 0, "nodeId cannot be empty");
require(bytes(appId[i]).length > 0, "appId cannot be empty");
require(bytes(name[i]).length > 0, "name cannot be empty");
require(bytes(version[i]).length > 0, "version cannot be empty");
require(bytes(status[i]).length > 0, "status cannot be empty");
require(
bytes(resolutionRatio[i]).length > 0,
"resolutionRatio cannot be empty"
);
require(bytes(fps[i]).length > 0, "fps cannot be empty");
require(
bytes(isHdrSupported[i]).length > 0,
"isHdrSupported cannot be empty"
);
if (!appIsExists[appId[i]]) {
appIsExists[appId[i]] = true;
appIds.push(appId[i]);
}
if (!isAppBindToNode[nodeId][appId[i]]) {
app_node[appId[i]].push(nodeId);
node_app[nodeId].push(appId[i]);
isAppBindToNode[nodeId][appId[i]] = true;
}
appInfo[appId[i]][_const.NAME()] = name[i];
appInfo[appId[i]][_const.VERSION()] = version[i];
appInfo[appId[i]][_const.STATUS()] = status[i];
appInfo[appId[i]][_const.RESOLUTION_RATIO()] = resolutionRatio[i];
appInfo[appId[i]][_const.FPS()] = fps[i];
appInfo[appId[i]][_const.GAME_PADS()] = gamePads[i];
appInfo[appId[i]][_const.IS_HDR_SUPPORTED()] = isHdrSupported[i];
}
}
function addAppInfo(
string memory nodeId,
string memory appId,
string memory name,
string memory version,
string memory status,
string memory resolutionRatio,
string memory fps,
string memory gamePads,
string memory isHdrSupported
) external {
require(bytes(nodeId).length > 0, "nodeId cannot be empty");
require(bytes(appId).length > 0, "appId cannot be empty");
require(bytes(name).length > 0, "name cannot be empty");
require(bytes(version).length > 0, "version cannot be empty");
require(bytes(status).length > 0, "status cannot be empty");
require(
bytes(resolutionRatio).length > 0,
"resolutionRatio cannot be empty"
);
require(bytes(fps).length > 0, "fps cannot be empty");
require(bytes(gamePads).length > 0, "gamePads cannot be empty");
require(
bytes(isHdrSupported).length > 0,
"isHdrSupported cannot be empty"
);
if (!appIsExists[appId]) {
appIsExists[appId] = true;
app_node[appId].push(nodeId);
appIds.push(appId);
}
if (!isAppBindToNode[nodeId][appId]) {
node_app[nodeId].push(appId);
isAppBindToNode[nodeId][appId] = true;
}
appInfo[appId][_const.NAME()] = name;
appInfo[appId][_const.VERSION()] = version;
appInfo[appId][_const.STATUS()] = status;
appInfo[appId][_const.RESOLUTION_RATIO()] = resolutionRatio;
appInfo[appId][_const.FPS()] = fps;
appInfo[appId][_const.GAME_PADS()] = gamePads;
appInfo[appId][_const.IS_HDR_SUPPORTED()] = isHdrSupported;
}
function getAppIdsForNode(
string memory nodeId,
uint8 start,
uint8 count
) external view returns (string[] memory res) {
uint256 vmIdCount = node_app[nodeId].length;
uint256 end = start + count;
if (end > vmIdCount) {
end = vmIdCount;
}
res = new string[](end - start);
if (vmIdCount >= start) {
for (uint8 i = start; i < end; i++) {
res[i - start] = node_app[nodeId][i];
}
}
return res;
}
function getAppInfo(
string memory appId
)
external
view
returns (
string memory name,
string memory version,
string memory status,
string memory resolutionRatio,
string memory fps,
string memory gamePads,
string memory isHdrSupported
)
{
require(appIsExists[appId], "The app info isn't exists");
name = appInfo[appId][_const.NAME()];
version = appInfo[appId][_const.VERSION()];
status = appInfo[appId][_const.STATUS()];
resolutionRatio = appInfo[appId][_const.RESOLUTION_RATIO()];
fps = appInfo[appId][_const.FPS()];
gamePads = appInfo[appId][_const.GAME_PADS()];
isHdrSupported = appInfo[appId][_const.IS_HDR_SUPPORTED()];
}
}
......@@ -17,14 +17,6 @@ contract CloudConstant is AuthVerify {
}
// Common Key
function CREATING() external view returns (uint8) {
return constMap["creating"];
}
function CREATED() external view returns (uint8) {
return constMap["created"];
}
function USER() external view returns (uint8) {
return constMap["user"];
}
......@@ -57,10 +49,6 @@ contract CloudConstant is AuthVerify {
return constMap["progress"];
}
function IS_EXISTS() external view returns (uint8) {
return constMap["is_exists"];
}
// VM NET INFO KEY
function EXTERNAL_IP() external view returns (uint8) {
return constMap["external_ip"];
......@@ -148,24 +136,60 @@ contract CloudConstant is AuthVerify {
return constMap["nps_ssh_start_port"];
}
function SINGALLING_PORT() external view returns (uint8) {
return constMap["signalling_port"];
function SINGALLING_HTTP_IP() external view returns (uint8) {
return constMap["signalling_http_ip"];
}
function SINGALLING_WS_IP() external view returns (uint8) {
return constMap["signalling_ws_ip"];
}
function TURN_IP() external view returns (uint8) {
return constMap["turn_ip"];
}
function TURN_PORT() external view returns (uint8) {
return constMap["turn_port"];
}
function TURN_USER() external view returns (uint8) {
return constMap["turn_user"];
}
function TURN_PWD() external view returns (uint8) {
return constMap["turn_pwd"];
}
function STUN_IP() external view returns (uint8) {
return constMap["stun_ip"];
}
function STUN_PORT() external view returns (uint8) {
return constMap["stun_port"];
}
function SERVER_PORT() external view returns (uint8) {
return constMap["server_port"];
}
function VERSION() external view returns (uint8) {
return constMap["version"];
}
function SUPPORT_TYPE() external view returns (uint8) {
return constMap["support_type"];
function RESOLUTION_RATIO() external view returns (uint8) {
return constMap["resolution_ratio"];
}
function IS_HDR_SUPPORTED() external view returns (uint8) {
return constMap["is_hdr_supported"];
}
function FPS() external view returns (uint8) {
return constMap["fps"];
}
function GAME_PADS() external view returns (uint8) {
return constMap["game_pads"];
}
function ENABLE() external pure returns (uint8) {
......
......@@ -6,136 +6,120 @@ import "./BaseAuth.sol";
contract CloudGateway is Callee {
constructor(address const) Callee(const) {}
uint256 public gatewayCount = 0;
mapping(string => mapping(uint8 => string)) public gatewayData;
address[] public gatewayMsgSenders;
mapping(address => mapping(uint256 => string)) public gatewayData;
mapping(string => mapping(uint256 => uint256)) public usedGatewayNode;
event AddGateWayEvent(
address owner,
string externalIp,
string stunPort,
string turnPort,
string npsSshStartPort,
string npsSshEndPort,
string npsVncStartPort,
string npsVncEndPort,
string signallingPort
string npsStartPort,
string npsEndPort
);
function addGateway(
string memory externalIp,
string memory stunPort,
function addStunServerInfo(
string memory gateWayId,
string memory stunIp,
string memory stunPort
) external {
gatewayData[gateWayId][_const.STUN_IP()] = stunIp;
gatewayData[gateWayId][_const.STUN_PORT()] = stunPort;
}
function addSignallingServerInfo(
string memory gateWayId,
string memory signallingHttpIp,
string memory signallingWsIp
) external {
gatewayData[gateWayId][_const.SINGALLING_HTTP_IP()] = signallingHttpIp;
gatewayData[gateWayId][_const.SINGALLING_WS_IP()] = signallingWsIp;
}
function addTurnServerInfo(
string memory gateWayId,
string memory turnIp,
string memory turnPort,
string memory turnUserName,
string memory turnPwd
) external {
gatewayData[gateWayId][_const.TURN_IP()] = turnIp;
gatewayData[gateWayId][_const.TURN_PORT()] = turnPort;
gatewayData[gateWayId][_const.TURN_USER()] = turnUserName;
gatewayData[gateWayId][_const.TURN_PWD()] = turnPwd;
}
function addNpsServerInfo(
string memory gateWayId,
string memory npsIp,
string memory npsSshStartPort,
string memory npsSshEndPort,
string memory npsVncStartPort,
string memory npsVncEndPort,
string memory signallingPort
string memory npsVncEndPort
) external {
gatewayMsgSenders.push(msg.sender);
gatewayData[msg.sender][_const.EXTERNAL_IP()] = externalIp;
gatewayData[msg.sender][_const.STUN_PORT()] = stunPort;
gatewayData[msg.sender][_const.TURN_PORT()] = turnPort;
gatewayData[msg.sender][_const.NPS_SSH_START_PORT()] = npsSshStartPort;
gatewayData[msg.sender][_const.NPS_SSH_END_PORT()] = npsSshEndPort;
gatewayData[msg.sender][_const.NPS_VNC_START_PORT()] = npsVncStartPort;
gatewayData[msg.sender][_const.NPS_VNC_END_PORT()] = npsVncEndPort;
gatewayData[msg.sender][_const.SINGALLING_PORT()] = signallingPort;
gatewayCount++;
emit AddGateWayEvent(
msg.sender,
externalIp,
stunPort,
turnPort,
npsSshStartPort,
npsSshEndPort,
npsVncStartPort,
npsVncEndPort,
signallingPort
);
gatewayData[gateWayId][_const.EXTERNAL_IP()] = npsIp;
gatewayData[gateWayId][_const.NPS_SSH_START_PORT()] = npsSshStartPort;
gatewayData[gateWayId][_const.NPS_SSH_END_PORT()] = npsSshEndPort;
gatewayData[gateWayId][_const.NPS_VNC_START_PORT()] = npsVncStartPort;
gatewayData[gateWayId][_const.NPS_VNC_END_PORT()] = npsVncEndPort;
}
function getStunInfo(
string memory gatewayId
) external view returns (string memory stunIp, string memory stunPort) {
stunIp = gatewayData[gatewayId][_const.STUN_IP()];
stunPort = gatewayData[gatewayId][_const.STUN_PORT()];
}
function getGateWay(
address acc
function getTurnInfo(
string memory gatewayId
)
external
view
returns (
string memory ip,
string memory stunPort,
string memory turnIp,
string memory turnPort,
string memory turnUser,
string memory turnPwd
)
{
turnIp = gatewayData[gatewayId][_const.TURN_IP()];
turnPort = gatewayData[gatewayId][_const.TURN_PORT()];
turnUser = gatewayData[gatewayId][_const.TURN_USER()];
turnPwd = gatewayData[gatewayId][_const.TURN_PWD()];
}
function getNpsServerInfo(
string memory gatewayId
)
external
view
returns (
string memory npsIp,
string memory npsSshStartPort,
string memory npsSshEndPort,
string memory npsVncStratPort,
string memory npsVncEndPort,
string memory signallingPort
string memory npsVncStartPort,
string memory npsVncEndPort
)
{
ip = gatewayData[acc][_const.EXTERNAL_IP()];
stunPort = gatewayData[acc][_const.STUN_PORT()];
turnPort = gatewayData[acc][_const.TURN_PORT()];
npsSshStartPort = gatewayData[acc][_const.NPS_SSH_START_PORT()];
npsSshEndPort = gatewayData[acc][_const.NPS_SSH_END_PORT()];
npsVncStratPort = gatewayData[acc][_const.NPS_VNC_START_PORT()];
npsVncEndPort = gatewayData[acc][_const.NPS_VNC_END_PORT()];
signallingPort = gatewayData[acc][_const.SINGALLING_PORT()];
npsIp = gatewayData[gatewayId][_const.EXTERNAL_IP()];
npsSshStartPort = gatewayData[gatewayId][_const.NPS_SSH_START_PORT()];
npsSshEndPort = gatewayData[gatewayId][_const.NPS_SSH_END_PORT()];
npsVncStartPort = gatewayData[gatewayId][_const.NPS_VNC_START_PORT()];
npsVncEndPort = gatewayData[gatewayId][_const.NPS_VNC_END_PORT()];
}
function setUsedGateWay(
string memory gateWayId,
uint256 nodeId,
uint256 port
) external {
usedGatewayNode[gateWayId][nodeId] = port;
}
// function getGateways()
// external
// view
// returns (
// string[] memory ipArr,
// string[] memory stunPortArr,
// string[] memory turnPortArr,
// string[] memory npsSshStartPortArr,
// string[] memory npsSshEndPortArr,
// string[] memory npsVncStartPortArr,
// string[] memory npsVncEndPortArr,
// string[] memory signallingPortArr
// )
// {
// uint256 length = gatewayMsgSenders.length;
// ipArr = new string[](length);
// stunPortArr = new string[](length);
// turnPortArr = new string[](length);
// npsSshStartPortArr = new string[](length);
// npsSshEndPortArr = new string[](length);
// npsVncStartPortArr = new string[](length);
// npsVncEndPortArr = new string[](length);
// signallingPortArr = new string[](length);
// uint8 externalIpConst = _const.EXTERNAL_IP();
// uint8 stunPortConst = _const.STUN_PORT();
// uint8 turnPortConst = _const.TURN_PORT();
// uint8 npsSshStartPortConst = _const.NPS_SSH_START_PORT();
// uint8 npsSshEndPortConst = _const.NPS_SSH_END_PORT();
// uint8 npsVncStartPortConst = _const.NPS_VNC_START_PORT();
// uint8 npsVncEndPortConst = _const.NPS_VNC_END_PORT();
// uint8 signallingPortConst = _const.SINGALLING_PORT();
// for (uint8 i = 0; i < length; i++) {
// ipArr[i] = gatewayData[gatewayMsgSenders[i]][externalIpConst];
// ipArr[i] = gatewayData[gatewayMsgSenders[i]][stunPortConst];
// stunPortArr[i] = gatewayData[gatewayMsgSenders[i]][turnPortConst];
// turnPortArr[i] = gatewayData[gatewayMsgSenders[i]][
// npsSshStartPortConst
// ];
// npsSshStartPortArr[i] = gatewayData[gatewayMsgSenders[i]][
// npsSshEndPortConst
// ];
// npsSshEndPortArr[i] = gatewayData[gatewayMsgSenders[i]][
// npsVncStartPortConst
// ];
// npsVncStartPortArr[i] = gatewayData[gatewayMsgSenders[i]][
// npsVncEndPortConst
// ];
// npsVncEndPortArr[i] = gatewayData[gatewayMsgSenders[i]][
// signallingPortConst
// ];
// signallingPortArr[i] = gatewayData[gatewayMsgSenders[i]][
// signallingPortConst
// ];
// }
// }
function getUsedGateWay(
string memory gatewayId,
uint256 nodeId
) external view returns (uint256) {
return usedGatewayNode[gatewayId][nodeId];
}
}
......@@ -6,13 +6,13 @@ import "./BaseAuth.sol";
contract CloudHost is Callee {
constructor(address const) Callee(const) {}
uint256 IdIncrement = 0;
uint256 internal IdIncrement = 0;
mapping(uint256 => mapping(uint256 => string)) public hostData;
mapping(uint256 => address) public globalIdMap;
event AddCreateVmEvent(string ip, string vmId);
event AddCreateVmEvent(string indexed ip, string vmId);
event UpdateHostResourceInfoEvent(
uint256 hostId,
......@@ -32,13 +32,12 @@ contract CloudHost is Callee {
address global_identify,
string memory host_name,
string memory cluster_id
) public returns (uint256, address) {
) external {
IdIncrement++;
hostData[IdIncrement][_const.NAME()] = host_name;
hostData[IdIncrement][_const.CLUSTER()] = cluster_id;
globalIdMap[IdIncrement] = global_identify;
emit AddHostEvent(IdIncrement, global_identify);
return (IdIncrement, global_identify);
}
function addHostResouce(
......
......@@ -6,25 +6,98 @@ import "./BaseAuth.sol";
contract CloudSystem is Callee {
constructor(address const) Callee(const) {}
uint256 id = 1;
mapping(uint256 => uint256) vm_system;
mapping(uint256 => mapping(uint8 => string)) systemInfo;
mapping(uint256 => string) systemNameInfo;
function addSystem(
mapping(uint256 => string) systemVersionInfo;
mapping(uint256 => uint8) systemSupportInfo;
mapping(uint256 => string) systemStorageInfo;
mapping(uint256 => uint256[]) system_app;
mapping(uint256 => string) appNameInfo;
mapping(uint256 => string) appVersionInfo;
function bindSystemVm(uint256 vmId, uint256 systemId) external {
vm_system[vmId] = systemId;
}
function getSysId(uint256 vmId) external view returns (uint256) {
return vm_system[vmId];
}
function bindSystemApp(uint256 systemId, uint256 appId) external {
system_app[systemId].push(appId);
}
function getAppId(
uint256 sysId,
uint8 start,
uint8 count
) external view returns (uint256[] memory res) {
uint256 appCount = system_app[sysId].length;
uint256 end = start + count;
if (end > appCount) {
end = appCount;
}
res = new uint256[](end - start);
if (appCount >= start) {
for (uint8 i = start; i < end; i++) {
res[i - start] = system_app[sysId][i];
}
}
return res;
}
function addSystemInfo(
uint256 sysId,
string memory name,
string memory version,
string memory supportType
uint8 supportType,
string memory ipfsUrl
) external {
systemInfo[id][_const.NAME()] = name;
systemInfo[id][_const.VERSION()] = version;
systemInfo[id][_const.SUPPORT_TYPE()] = supportType;
require(supportType == 1 || supportType == 2 || supportType == 3, "");
systemNameInfo[sysId] = name;
systemVersionInfo[sysId] = version;
systemSupportInfo[sysId] = supportType;
systemStorageInfo[sysId] = ipfsUrl;
}
function getSystem() external pure returns (string memory) {
return "";
function getSystemInfo(
uint256 sysId
)
external
view
returns (
string memory name,
string memory version,
uint8 supportType,
string memory ipfsUrl
)
{
name = systemNameInfo[sysId];
version = systemVersionInfo[sysId];
supportType = systemSupportInfo[sysId];
ipfsUrl = systemStorageInfo[sysId];
}
function getAppInfo(
uint256 appId
) external view returns (string memory name, string memory version) {
name = appNameInfo[appId];
version = appVersionInfo[appId];
}
function maxId() external view returns (uint256) {
return id;
function addAppInfo(
uint256 appId,
string memory name,
string memory version
) external {
appNameInfo[appId] = name;
appVersionInfo[appId] = version;
}
}
......@@ -3,7 +3,7 @@ pragma solidity ^0.8.9;
import "./BaseAuth.sol";
contract CloudVmCreate is Callee {
contract CloudVmTask is Callee {
constructor(address const) Callee(const) {}
mapping(address => string[]) public taskOwnerMapping;
......
......@@ -7,14 +7,12 @@ interface ICloudConstant {
address caller
) external view returns (bool);
function onlyNode(address caller) external view returns (bool);
function getCaller(string memory key) external view returns (address);
// Common Key
function CREATING() external view returns (uint8);
function CREATED() external view returns (uint8);
function USER() external view returns (uint8);
function PASSWORD() external view returns (uint8);
......@@ -31,8 +29,6 @@ interface ICloudConstant {
function PROGRESS() external view returns (uint8);
function IS_EXISTS() external view returns (uint8);
// VM NET INFO KEY
function EXTERNAL_IP() external view returns (uint8);
......@@ -78,12 +74,24 @@ interface ICloudConstant {
function NPS_SSH_START_PORT() external view returns (uint8);
function SINGALLING_PORT() external view returns (uint8);
function SINGALLING_HTTP_IP() external view returns (uint8);
function SINGALLING_WS_IP() external view returns (uint8);
function TURN_IP() external view returns (uint8);
function TURN_PORT() external view returns (uint8);
function TURN_USER() external view returns (uint8);
function TURN_PWD() external view returns (uint8);
function STUN_IP() external view returns (uint8);
function STUN_PORT() external view returns (uint8);
function SERVER_PORT() external view returns (uint8);
function ENABLE() external pure returns (uint8);
function DISABLE() external pure returns (uint8);
......@@ -94,5 +102,11 @@ interface ICloudConstant {
function VERSION() external view returns (uint8);
function SUPPORT_TYPE() external view returns (uint8);
function RESOLUTION_RATIO() external view returns (uint8);
function IS_HDR_SUPPORTED() external view returns (uint8);
function FPS() external view returns (uint8);
function GAME_PADS() external view returns (uint8);
}
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.4.25;
library LibString {
function lenOfChars(string memory src) internal pure returns (uint) {
uint i = 0;
uint length = 0;
bytes memory string_rep = bytes(src);
//UTF-8 skip word
while (i < string_rep.length) {
i += utf8CharBytesLength(string_rep, i);
length++;
}
return length;
}
function lenOfBytes(string memory src) internal pure returns (uint) {
bytes memory srcb = bytes(src);
return srcb.length;
}
function startWith(
string memory src,
string memory prefix
) internal pure returns (bool) {
bytes memory src_rep = bytes(src);
bytes memory prefix_rep = bytes(prefix);
if (src_rep.length < prefix_rep.length) {
return false;
}
uint needleLen = prefix_rep.length;
for (uint i = 0; i < needleLen; i++) {
if (src_rep[i] != prefix_rep[i]) return false;
}
return true;
}
function endWith(
string memory src,
string memory tail
) internal pure returns (bool) {
bytes memory src_rep = bytes(src);
bytes memory tail_rep = bytes(tail);
if (src_rep.length < tail_rep.length) {
return false;
}
uint srcLen = src_rep.length;
uint needleLen = tail_rep.length;
for (uint i = 0; i < needleLen; i++) {
if (src_rep[srcLen - needleLen + i] != tail_rep[i]) return false;
}
return true;
}
function equal(
string memory self,
string memory other
) internal pure returns (bool) {
bytes memory self_rep = bytes(self);
bytes memory other_rep = bytes(other);
if (self_rep.length != other_rep.length) {
return false;
}
uint selfLen = self_rep.length;
for (uint i = 0; i < selfLen; i++) {
if (self_rep[i] != other_rep[i]) return false;
}
return true;
}
function equalNocase(
string memory self,
string memory other
) internal pure returns (bool) {
return compareNocase(self, other) == 0;
}
function empty(string memory src) internal pure returns (bool) {
bytes memory src_rep = bytes(src);
if (src_rep.length == 0) return true;
for (uint i = 0; i < src_rep.length; i++) {
bytes1 b = src_rep[i];
if (
b != 0x20 &&
b != bytes1(0x09) &&
b != bytes1(0x0A) &&
b != bytes1(0x0D)
) return false;
}
return true;
}
function concat(
string memory self,
string memory str
) internal pure returns (string memory _ret) {
_ret = new string(bytes(self).length + bytes(str).length);
uint selfptr;
uint strptr;
uint retptr;
assembly {
selfptr := add(self, 0x20)
strptr := add(str, 0x20)
retptr := add(_ret, 0x20)
}
memcpy(retptr, selfptr, bytes(self).length);
memcpy(retptr + bytes(self).length, strptr, bytes(str).length);
}
//start is char index, not bytes1 index
function substrByCharIndex(
string memory self,
uint start,
uint len
) internal pure returns (string memory) {
if (len == 0) return "";
//start - bytePos
//len - byteLen
uint bytePos = 0;
uint byteLen = 0;
uint i = 0;
uint chars = 0;
bytes memory self_rep = bytes(self);
bool startMet = false;
//UTF-8 skip word
while (i < self_rep.length) {
if (chars == start) {
bytePos = i;
startMet = true;
}
if (chars == (start + len)) {
byteLen = i - bytePos;
}
i += utf8CharBytesLength(self_rep, i);
chars++;
}
if (chars == (start + len)) {
byteLen = i - bytePos;
}
require(startMet, "start index out of range");
require(byteLen != 0, "len out of range");
string memory ret = new string(byteLen);
uint selfptr;
uint retptr;
assembly {
selfptr := add(self, 0x20)
retptr := add(ret, 0x20)
}
memcpy(retptr, selfptr + bytePos, byteLen);
return ret;
}
function compare(
string memory self,
string memory other
) internal pure returns (int8) {
bytes memory selfb = bytes(self);
bytes memory otherb = bytes(other);
//bytes1 by bytes1
for (uint i = 0; i < selfb.length && i < otherb.length; i++) {
bytes1 b1 = selfb[i];
bytes1 b2 = otherb[i];
if (b1 > b2) return 1;
if (b1 < b2) return -1;
}
//and length
if (selfb.length > otherb.length) return 1;
if (selfb.length < otherb.length) return -1;
return 0;
}
function compareNocase(
string memory self,
string memory other
) internal pure returns (int8) {
bytes memory selfb = bytes(self);
bytes memory otherb = bytes(other);
for (uint i = 0; i < selfb.length && i < otherb.length; i++) {
bytes1 b1 = selfb[i];
bytes1 b2 = otherb[i];
bytes1 ch1 = b1 | 0x20;
bytes1 ch2 = b2 | 0x20;
if (ch1 >= "a" && ch1 <= "z" && ch2 >= "a" && ch2 <= "z") {
if (ch1 > ch2) return 1;
if (ch1 < ch2) return -1;
} else {
if (b1 > b2) return 1;
if (b1 < b2) return -1;
}
}
if (selfb.length > otherb.length) return 1;
if (selfb.length < otherb.length) return -1;
return 0;
}
function toUppercase(
string memory src
) internal pure returns (string memory) {
bytes memory srcb = bytes(src);
for (uint i = 0; i < srcb.length; i++) {
bytes1 b = srcb[i];
if (b >= "a" && b <= "z") {
b &= bytes1(0xDF); // -32
srcb[i] = b;
}
}
return src;
}
function toLowercase(
string memory src
) internal pure returns (string memory) {
bytes memory srcb = bytes(src);
for (uint i = 0; i < srcb.length; i++) {
bytes1 b = srcb[i];
if (b >= "A" && b <= "Z") {
b |= 0x20;
srcb[i] = b;
}
}
return src;
}
/**
* Index Of
*
* Locates and returns the position of a character within a string
*
* @param src When being used for a data type this is the extended object
* otherwise this is the string acting as the haystack to be
* searched
* @param value The needle to search for, at present this is currently
* limited to one character
* @return int The position of the needle starting from 0 and returning -1
* in the case of no matches found
*/
function indexOf(
string memory src,
string memory value
) internal pure returns (int) {
return indexOf(src, value, 0);
}
/**
* Index Of
*
* Locates and returns the position of a character within a string starting
* from a defined offset
*
* @param src When being used for a data type this is the extended object
* otherwise this is the string acting as the haystack to be
* searched
* @param value The needle to search for, at present this is currently
* limited to one character
* @param offset The starting point to start searching from which can start
* from 0, but must not exceed the length of the string
* @return int The position of the needle starting from 0 and returning -1
* in the case of no matches found
*/
function indexOf(
string memory src,
string memory value,
uint offset
) internal pure returns (int) {
bytes memory srcBytes = bytes(src);
bytes memory valueBytes = bytes(value);
assert(valueBytes.length == 1);
for (uint i = offset; i < srcBytes.length; i++) {
if (srcBytes[i] == valueBytes[0]) {
return int(i);
}
}
return -1;
}
function split(
string memory src,
string memory separator
) internal pure returns (string[] memory splitArr) {
bytes memory srcBytes = bytes(src);
uint offset = 0;
uint splitsCount = 1;
int limit = -1;
while (offset < srcBytes.length - 1) {
limit = indexOf(src, separator, offset);
if (limit == -1) break;
else {
splitsCount++;
offset = uint(limit) + 1;
}
}
splitArr = new string[](splitsCount);
offset = 0;
splitsCount = 0;
while (offset < srcBytes.length - 1) {
limit = indexOf(src, separator, offset);
if (limit == -1) {
limit = int(srcBytes.length);
}
string memory tmp = new string(uint(limit) - offset);
bytes memory tmpBytes = bytes(tmp);
uint j = 0;
for (uint i = offset; i < uint(limit); i++) {
tmpBytes[j++] = srcBytes[i];
}
offset = uint(limit) + 1;
splitArr[splitsCount++] = string(tmpBytes);
}
return splitArr;
}
//------------HELPER FUNCTIONS----------------
function utf8CharBytesLength(
bytes memory stringRep,
uint ptr
) internal pure returns (uint) {
if ((stringRep[ptr] >> 7) == bytes1(0)) return 1;
if ((stringRep[ptr] >> 5) == bytes1(0x06)) return 2;
if ((stringRep[ptr] >> 4) == bytes1(0x0e)) return 3;
if ((stringRep[ptr] >> 3) == bytes1(0x1e)) return 4;
return 1;
}
function memcpy(uint dest, uint src, uint len) private pure {
// Copy word-length chunks while possible
for (; len >= 32; len -= 32) {
assembly {
mstore(dest, mload(src))
}
dest += 32;
src += 32;
}
// Copy remaining bytes
uint mask = 256 ** (32 - len) - 1;
assembly {
let srcpart := and(mload(src), not(mask))
let destpart := and(mload(dest), mask)
mstore(dest, or(destpart, srcpart))
}
}
}
......@@ -17,7 +17,7 @@ module.exports = {
settings: {
optimizer: {
enabled: true,
runs: 200
runs: 300
}
},
networks: {
......@@ -35,7 +35,14 @@ module.exports = {
},
local: {
accounts: [privateKey],
url: 'http://192.168.1.125:7545',
url: 'http://192.168.1.120:7545',
gas: 1100000,
gasLimit: 11000000,
gasPrice: 110000000,
},
remote: {
accounts: [privateKey],
url: 'http://124.193.167.71:7545',
gas: 11000000,
gasLimit: 110000000,
gasPrice: 1100000000,
......
const getContractFactory = require("./deploy");
async function main() {
let appContract = await getContractFactory("CloudApplication");
// await addNodeNetworkInfo(appContract);
// await getNodeNetworkInfo(appContract);
await getAppInfo(appContract);
}
async function getNodeNetworkInfo(appContract) {
let nodeId = "111";
let res = await appContract.getNodeNetwork(nodeId);
console.log("res:", res);
}
async function getAppInfo(appContract) {
let appId = "0xAA28Df7fe41320432fa4efC2798B3CaF9300A218_4_1577243657_0";
let res = await appContract.getAppInfo(appId);
console.log("res:", res);
}
async function addNodeNetworkInfo(appContract) {
let nodeId = "111";
let res = await appContract.addNodeNetworkInfo(nodeId, "222", "3333", ["111", "222"], ["333", "444"], ["22", "44"], ["33", "55"], "0000");
await res.wait();
console.log("add success");
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
\ No newline at end of file
......@@ -4,8 +4,6 @@ async function main() {
let constantContract = await getContractFactory("CloudConstant");
let constantArr = [
"creating",
"created",
"user",
"password",
"cluster",
......@@ -14,7 +12,6 @@ async function main() {
"name",
"stage",
"progress",
"is_exists",
"external_ip",
"internal_ip",
"external_ssh_port",
......@@ -36,15 +33,31 @@ async function main() {
"nps_vnc_start_port",
"nps_ssh_end_port",
"nps_ssh_start_port",
"signalling_port",
"signalling_http_ip",
"signalling_ws_ip",
"turn_ip",
"turn_port",
"stun_port"
"turn_user",
"turn_pwd",
"stun_ip",
"stun_port",
"server_port",
"version",
"resolution_ratio",
"is_hdr_supported",
"fps",
"game_pads"
];
for (let i = 1; i <= constantArr.length; i++) {
try {
let res = await constantContract.setConstMap(constantArr[i - 1], i);
await res.wait();
console.log("Add constant index:", i);
} catch (error) {
console.log("set const map error:", error);
continue;
}
}
let EX_SSH_START_PORT = await constantContract.EX_SSH_PORT();
......
const getContractFactory = require("./deploy");
async function main() {
let vmCreateContract = await getContractFactory("CloudVmCreate");
let vmCreateContract = await getContractFactory("CloudVmTask");
let taskId = "111-222-254";
// await AddVirtualMachine(vmCreateContract, taskId);
// await GetVmId(vmCreateContract, taskId);
......
const hre = require("hardhat");
let isDeploy = true;
let isDeploy = false;
let contractName = [
"CloudConstant",
// "CloudGateway",
// "CloudScheduler",
"CloudVm",
"CloudVmCreate",
// "CloudHost"
"CloudVmTask",
// "CloudHost",
"CloudApplication"
];
// let contractAddress = [
// "0x511017c4A67e6f3DAb0158538d72568D74C5909C",
// // "0x993C630B94E4FfC2e9Cd39F9B5D65cE8c0B5B425",
// // "0x06425aa6a39E7eB09fC1E12C9653A1efA80ba46d",
// "0x15A5aac5D5bc2B7D0389a1054701a6583169FB00",
// "0xFAbE2869D0E0a13b6776C31bD78505Ed9c2FAbec",
// // "0xF465eD8D34653Dc984d47c7Bb91890e7cDfCB297"
// ];
let contractAddress = [
"0xA427EC72294E9A8fA652CD6649689e35F3632A21",
"0x7cd6941Af75A7D1575038d69F56175b4204eaeC6",
// "0x993C630B94E4FfC2e9Cd39F9B5D65cE8c0B5B425",
// "0x06425aa6a39E7eB09fC1E12C9653A1efA80ba46d",
"0x94F0EaC13064181C94a8D25DCaf9FAD8C97e105F",
"0x01AB479187FBcd228BF808C9c2B2c1D655029444",
"0x72d036c860D66EA0e741Acd5569099C264bE5616",
"0xd5271d2e46d5704587329FbfaB73E0290E64532A",
// "0xF465eD8D34653Dc984d47c7Bb91890e7cDfCB297"
"0x47ee3dAEE376836b38960dA1068aC4ffEf04f6DA"
];
async function deployConst() {
......@@ -66,8 +58,8 @@ async function getContractFactory(param) {
async function main() {
if (isDeploy) {
// let constAddress = await deployConst();
await deployOtherContract("0xA427EC72294E9A8fA652CD6649689e35F3632A21", contractName);
let constAddress = await deployConst();
await deployOtherContract(constAddress, contractName);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment