/// <summary> /// Gets the user storing the file at recovery time /// </summary> /// <param name="nodeName">username for storing user</param> /*private void GetSource(string nodeName){ * PeerNode source = null; * action = ActionType.Restore; * * if (GetClientEvent != null) * source = GetClientEvent(nodeName); * if (source != null){ * SendMessage("LET" + " " + this.IP + " " + this.Name + " " + this.PubKey); * if(LogEvent != null) LogEvent(source.Name, false, "LET" + " " + this.IP + " " + this.Name + " " + this.PubKey); * } * else{ * SendMessage("405"); * if(LogEvent != null) LogEvent(nodeName, false, "405"); * } * }*/ internal void SendSession(PeerSession session, SessionType type, bool isIndexSession) { string action = string.Empty; MessageContext ctx = MessageContext.Generic; session.Kind = type; bool synchronous = false; if (type == SessionType.Backup) { ctx = MessageContext.Task; action = "ASKSTORAGE"; } else if (type == SessionType.Store) { action = "STORE"; // wait for confirmation that the receive/store session has been started on storage node. // We avoid client node to connect to a storage node that is not yet ready. synchronous = true; } SendMessage(new NodeMessage { Context = ctx, TaskId = session.TaskId, Action = action, Data = session.ToJson <PeerSession>(), Data2 = isIndexSession.ToString(), Synchroneous = synchronous }); }
/// <summary> /// Send used space Hub, in order to update storagegroup available space /// </summary> public void SendSessionUpdate(PeerSession s) { this.StorageSize -= s.RealHandledData; HubWrite(new NodeMessage { Context = MessageContext.Task, TaskId = s.TaskId, Action = "SESSION", Data = s.ToJson <PeerSession>() //Data2 = sessionId+"" }); }
/// <summary> /// Request a destination for data chunks. /// Hub replies with Session object. /// </summary> private static void AskStorage(PeerSession s, int parallelism, bool isIndex, bool alternateRequest) { string action = "ASKSTORAGE"; if (isIndex) { action = "INDEXSTORAGE"; } HubWrite(new NodeMessage { Context = MessageContext.Task, Action = action, TaskId = s.TaskId, Data = s.ToJson <PeerSession>(), Data2 = string.Format("{0} {1}", parallelism, alternateRequest) }); }