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");
_;
}
}
This diff is collapsed.
......@@ -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 maxId() external view returns (uint256) {
return id;
function getAppInfo(
uint256 appId
) external view returns (string memory name, string memory version) {
name = appNameInfo[appId];
version = appVersionInfo[appId];
}
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);
}
This diff is collapsed.
......@@ -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++) {
let res = await constantContract.setConstMap(constantArr[i - 1], i);
await res.wait();
console.log("Add constant index:", 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