Ejemplo n.º 1
0
        private void HandleGenericRequest(NodeMessage message)
        {
            try{
                //string[] decoded;
                string[] decoded2 = new string[0];

                /*if(message.Data != null)
                 *      decoded = message.Data.Split(new char[]{' '});*/
                if (message.Data2 != null)
                {
                    decoded2 = message.Data2.Split(new char[] { ' ' });
                }
                switch (message.Action)
                {
                case "AVAILABLEQUOTA":
                    this.StorageUsed = long.Parse(message.Data);
                    break;

                case "BROWSE":                         // hub asks to browse a FS path
                    HubWrite(new NodeMessage {
                        Context      = MessageContext.Generic,
                        Synchroneous = true,
                        Id           = message.Id,
                        Action       = "BROWSE",
                        Data         = PathBrowser.GetPathBrowser().Browse(message.Data).ToJson <BrowseNode>()
                    });
                    break;

                case "BROWSESPECIALOBJECTS":
                    HubWrite(new NodeMessage {
                        Context      = MessageContext.Generic,
                        Id           = message.Id,
                        Action       = "BROWSESPECIALOBJECTS",
                        Synchroneous = true,
                        Data         = ObjectsBrowser.BuildObjectsList()                        //.ToJson<BrowseNode>()
                    });
                    break;

                case "BROWSEINDEX":
                    HubWrite(new NodeMessage {
                        Context      = MessageContext.Generic,
                        TaskId       = message.TaskId,
                        Id           = message.Id,
                        Action       = "BROWSEINDEX",
                        Synchroneous = true,
                        Data         = IndexBrowser.Browse(message.TaskId, message.Data, long.Parse(decoded2[0]), decoded2[1]).ToJson <BrowseNode>()
                    });
                    break;

                case "CONFIGURATION":                         // Hub sends requested configuration upon successful authentication
                    this.Configuration = message.Data.FromJson <NodeConfig>();
                    Utilities.ConfigManager.BuildConfFromHub(Configuration);
                    this.ApplyConf();
                    // We check for storage sub-directories, and create them if needed
                    if (Utilities.Storage.MakeStorageDirs())
                    {
                        StartStorageListener();
                    }
                    break;

                case "STORE":                        //Receive and store chunks
                    StartStoreSession(message.Data.FromJson <PeerSession>());
                    HubWrite(new NodeMessage {       // send confirmation, since "STORE" messages a re synchronous
                        Context      = MessageContext.Generic,
                        TaskId       = message.TaskId,
                        Id           = message.Id,
                        Action       = "STORE",
                        Synchroneous = true
                    });
                    break;

                case "DELETECHUNK":                         // delete 1 stored chunk (housekeeping operation)
                    ReceiveDelete(message.Data.FromJson <PeerSession>(), message.Data2);
                    break;

                /*case "VMS":
                 *      Virtualization.VirtualMachinesManager vmm = new Node.Virtualization.VirtualMachinesManager();
                 *
                 *      HubWrite("VMS "+vmm.BuildVmsJson());
                 *      break;*/

                default:
                    throw new ProtocolViolationException(message);
                }
            }
            catch (Exception ex) {
                Logger.Append(Severity.ERROR, "message '" + message.ToString() + "' :" + ex.Message + " ---- " + ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
 private static void HubWrite(NodeMessage message)
 {
     HubWrite(message.ToJson <NodeMessage>());
 }