public DataChain(int chainId, uint chainIndex, Node.Node node, CoreChain coreChain, ServiceChain serviceChain, ChainKeyStore keyStore, int attachementKey) : base(ChainType.Data, chainId, chainIndex, node) { _coreChain = coreChain; _serviceChain = serviceChain; Attachements = node.AttachementManager; ChainKeyIndex = keyStore.KeyIndex; ChainKey = keyStore.DecryptedKey; KeyStore = keyStore; AttachementKey = attachementKey; var endPoints = new HashSet <AvailableEndPoint>(); var chainInfo = _coreChain.GetChainInfo(ChainId); if (chainInfo != null) { var cep = chainInfo.GetPublicEndpoints(); foreach (var ep in cep) { var e = new Uri(ep); if (IsValidAvailableEndPoint(e)) { endPoints.Add(new AvailableEndPoint(e)); } } } AvailableEndpoints = new List <AvailableEndPoint>(endPoints); }
public ModelLoadManager LoadLocal() { if (localPrefab != null) { // Load object specific content GameObject localModel = GameObject.Instantiate(localPrefab); localModel.name = "X3D Parent"; Collider collider = localModel.transform.GetChild(0).GetComponent <Collider>(); ObjectInfo info = localModel.GetComponent <ObjectInfo>(); info.Bounds = collider.bounds; AttachementManager attachmentManager = localModel.AddComponent <AttachementManager>(); attachmentManager.Init(); CreateBoundingBox(localModel, info.Bounds); CreateGamificationGame(info.ModelName.ToLower()); if (callback != null) { callback(); } } else { Debug.Log("Tried to load local null model"); } return(this); }
public ActionResult GetAttachement(int chainid, long chainindex, int attachementkey, long transactionid, string name) { if (!AttachementItem.IsNameValid(name)) { return(BadRequest()); } var path = _node.AttachementManager.GetAttachementPath(chainid, (uint)chainindex, attachementkey, transactionid, name); return(PhysicalFile(path, "application/octet-stream", AttachementManager.GetAttachementFileName(transactionid, name))); }
public ClientServer(Node.Node node) { _chainManager = node.ChainManager; _configuration = node.NodeConfiguration; _attachementManager = node.AttachementManager; _transactionManager = node.TransactionManager; _pubsub = node.PubSub; _pubsub.Subscribe <BlockEvent <CoreBlock> >(this, NewCoreBlock); _pubsub.Subscribe <BlockEvent <ServiceBlock> >(this, NewServiceBlock); _pubsub.Subscribe <BlockEvent <DataBlock> >(this, NewDataBlock); }
/// <summary> /// Get the necessary components: the collider of the bounding box and its annotationManager /// </summary> public void Start() { coll = GetComponent <BoxCollider>(); attachementManager = gameObject.GetComponentInChildren <AttachementManager>(); x3dParent = transform.Find("Content/X3D Parent"); if (x3dParent != null) { objectInfo = x3dParent.GetComponent <ObjectInfo>(); } tapToPlace = GetComponent <CustomTapToPlace>(); transformationManager = GetComponent <TransformationManager>(); info = GetComponent <BoundingBoxInfo>(); }
/// <summary> /// Creates Gameobjects from the pieces of the X3DObject /// </summary> /// <returns>The parent GameObject which contains all pieces as children</returns> public GameObject CreateGameObjects() { // create the parent object parent = new GameObject("X3D Parent"); ObjectInfo objInfo = parent.AddComponent <ObjectInfo>(); objInfo.ModelName = ModelName; AttachementManager attachementManager = parent.AddComponent <AttachementManager>(); parentBounds = new Bounds(); foreach (X3DPiece piece in pieces) { List <GameObject> pieceObjects = piece.CreateGameObject(shader); foreach (GameObject subObject in pieceObjects) { Renderer renderer = subObject.GetComponent <Renderer>(); parentBounds.Encapsulate(renderer.bounds); // assign the parent subObject.transform.parent = parent.transform; // assign the TapNotifier; it can notfiy the parents about tap events TapNotifier tapNotifier = subObject.AddComponent <TapNotifier>(); } } objInfo.Bounds = parentBounds; // initialize the attachement manager => this creates the annotation manager and informs the tap notifier attachementManager.Init(); // normalize size so that maximum axis size is 1 float max = Math.Max(Math.Max(parentBounds.size.x, parentBounds.size.y), parentBounds.size.z); float factor = 1 / max; parent.transform.localScale = new Vector3( parent.transform.localScale.x * factor, parent.transform.localScale.y * factor, parent.transform.localScale.z * factor); parentBounds.size *= factor; // reset any offset so that the object is centered parent.transform.localPosition -= parentBounds.center * factor; return(parent); }
public Task <byte[]> GetLocalAttachementData(long transactionId, int attachementKey, string name) { var path = Path.Combine(AttachementManager.GetAttachementPath(ChainId, ChainIndex, attachementKey), AttachementManager.GetAttachementFileName(transactionId, name)); return(_storage.ReadFileBytesAsync(path)); }
public string GetLocalAttachementPath(long transactionId, int attachementKey, string name) { return(Path.Combine(_storage.Root.FullName, AttachementManager.GetAttachementPath(ChainId, ChainIndex, attachementKey), AttachementManager.GetAttachementFileName(transactionId, name))); }
public async Task <bool> Start(string[] args, CancellationTokenSource quiteToken) { _quitToken = quiteToken; if (_quitToken.IsCancellationRequested) { return(false); } var dataPath = "heleusdata"; var genesis = false; var sync = false; var run = false; var init = false; var newChainConfig = false; if (args.Length == 1) { dataPath = args[0]; run = true; } else if (args.Length == 2) { dataPath = args[0]; var cmd = args[1]; if (cmd == "init") { init = true; } else if (cmd == "run") { run = true; } else if (cmd == "sync") { sync = true; } else if (cmd == "chainconfig") { newChainConfig = true; } else if (cmd == "genesis") { genesis = true; } else { Usage(); return(false); } } else { Usage(); return(false); } if ((run || sync) && !File.Exists(Path.Combine(dataPath, $"{nameof(NodeConfig).ToLower()}.txt"))) { Usage(); var dp = new DirectoryInfo(dataPath); Log.Error($"Data path {dp.FullName} not initalized.", this); return(false); } Storage = new Storage(dataPath); if (!Storage.IsWriteable) { Log.Fatal($"Data path {Storage.Root} is not writeable!", this); return(false); } if (genesis) { Storage.DeleteDirectory("cache"); Storage.DeleteDirectory("chains"); } PubSub = Log.PubSub = new PubSub(); Log.Write($"Starting Heleus Node (Version {Program.Version})."); Log.Trace($"PID {System.Diagnostics.Process.GetCurrentProcess().Id}"); Log.Write($"Data path is '{Storage.Root.FullName}'."); var config = Config.Load <NodeConfig>(Storage); Log.AddIgnoreList(config.LogIgnore); Log.LogLevel = config.LogLevel; if (Program.IsDebugging) { Log.LogLevel = LogLevels.Trace; } if (newChainConfig) { var chainConfig = Config.Load <ChainConfig>(Storage, true); //if (chainConfig.Chains.Count == 0) { Log.Write("Chain config generated."); chainConfig.Chains.Add(new ChainConfig.ChainInfo { ChainKeys = new List <ChainConfig.ChainKeyInfo> { new ChainConfig.ChainKeyInfo { ChainKey = string.Empty, ChainKeyPassword = string.Empty, AttachementKey = -1 } } }); Config.Save(chainConfig); } return(false); } if (init) { Log.Write("Config file generated."); return(false); } if (!genesis) { if (config.NetworkPublicKey.IsNullOrEmpty()) { Log.Write("Network key not set. Querying beacon nodes."); var beacons = config.BeaconNodes; foreach (var beacon in beacons) { Log.Write($"Querying beacon node {beacon}."); var client = new NodeClient(new Uri(beacon)); var nodeInfo = (await client.DownloadNodeInfo()).Data; if (nodeInfo != null) { config.NetworkPublicKey = nodeInfo.NetworkKey.HexString; Config.Save(config); Log.Write($"Network key set to {config.NetworkPublicKey}."); break; } } } if (config.NetworkPublicKey.IsNullOrEmpty()) { Log.Write("No valid network key found or set.", this); return(false); } } NodeConfiguration = new NodeConfiguration(config, Config.Load <CoreKeyConfig>(Storage, false), Config.Load <ChainConfig>(Storage, false)); Host = new Host(config); AttachementManager = new AttachementManager(this); ChainManager = new ChainManager(this); if (!await ChainManager.Initalize()) { return(false); } if (genesis) { var result = GenesisBlock.Generate(Storage); var blockData = new BlockData <CoreBlock>(result.Block, result.Signature); await ChainManager.Start(false); await ChainManager.CoreChain.BlockStorage.StoreBlock(blockData); ChainManager.ConsumeBlockData(blockData); Log.Write($"Genesis block and keys generated. Network public key: {result.NetworkPublicKey.HexString}."); var coreKeyConfig = Config.Load <CoreKeyConfig>(Storage); coreKeyConfig.Key = result.NetworkVoteKey.HexString; coreKeyConfig.Password = result.NetworkVotePassword; config.NetworkPublicKey = result.NetworkPublicKey.HexString; Config.Save(config); Config.Save(coreKeyConfig); await ChainManager.Stop(); await ChainManager.Start(true); if (result.ServiceTransactions.Count > 0) { foreach (var serviceTransactions in result.ServiceTransactions) { var chainId = serviceTransactions.Key; var transactions = serviceTransactions.Value; var serviceChain = ChainManager.GetServiceChain(chainId); var maintainChain = ChainManager.GetMaintainChain(chainId); if (serviceChain != null) { var generator = new ServiceBlockGenerator(ChainManager.CoreChain, serviceChain, maintainChain, null); foreach (var transaction in transactions) { generator.ConsumeTransaction(transaction); } var serviceBlock = generator.GenerateBlock(0, 0); var serviceBlockData = new BlockData <ServiceBlock>(serviceBlock, new BlockSignatures(serviceBlock)); await serviceChain.BlockStorage.StoreBlock(serviceBlockData); serviceChain.ConsumeBlockData(serviceBlockData); } } } await ChainManager.Stop(); return(false); } SyncManager = new SyncManager(this); await SyncManager.Start(); //if (!await SyncManager.Start()) // return false; if (sync) { Log.Write("Sync done."); return(false); } AttachementManager.Start(); Kademlia = new Kademlia(Storage, this); TransactionManager = new TransactionManager(this); CouncilManager = new CouncilManager(this); NodeServer = new NodeServer(this, config.MaxIncomingConnections, config.MaxOutgoingConnectoins); ClientServer = new ClientServer(this); if (Host.EnableRemoteServices) { ServiceServer = new ServiceServer(); } await(Host as Host).Start(this); return(true); }