private void ExecuteThread(object obj) { try { // Data CommandState state = (CommandState)obj; // Request Entity entity = state.Target; TunnelComponent tunnel = entity.Get <TunnelComponent>(); SearchRequestCommand cmdRequest = new SearchRequestCommand(entity, tunnel.Connection); string jsonData = cmdRequest.Execute(state.Data); if (string.IsNullOrEmpty(jsonData)) { return; } // Response entity = state.Source; tunnel = entity.Get <TunnelComponent>(); SearchResponseCommand cmdResponse = new SearchResponseCommand(entity, tunnel.Connection); HttpCode code = cmdResponse.Execute(state.Id, jsonData); if (code == HttpCode.Ok) { SearchListComponent download = entity.Get <SearchListComponent>(); download.Add(state.Target); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session) { // Connect NetworkChannel channel = new NetworkChannel(Connection); // Request JsonTunnelRequestMessage jsonRequestMessage = JsonTunnelRequestMessage.Parse(jsonRequest.Message); // Data Entity entity = session.Owner; TunnelComponent tunnel = new TunnelComponent(Connection); entity.Add(tunnel); // Response JsonTunnelResponseMessage jsonResponseMessage = new JsonTunnelResponseMessage(); JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage); HttpResponse httpResponse = new HttpResponse() { Data = session.Encrypt(jsonResponse) }; channel.Send(httpResponse); #if DEBUG Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse); #endif }
public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session) { // Connect NetworkChannel channel = new NetworkChannel(Connection); // Request JsonBrowseRequestMessage jsonRequestMessage = JsonBrowseRequestMessage.Parse(jsonRequest.Message); JsonClient jsonClient = jsonRequestMessage.Client; if (jsonClient == null) { channel.SendNotFound(); return; } Entity entity = ClientMap.Get(jsonClient.Id); if (entity == null) { channel.SendNotFound(); return; } // Command TunnelComponent tunnel = entity.Get <TunnelComponent>(); BrowseRequestCommand command = new BrowseRequestCommand(entity, tunnel.Connection); string jsonData = command.Execute(jsonRequest.Data); if (string.IsNullOrEmpty(jsonData)) { channel.SendNotFound(); return; } // Response JsonBrowseResponseMessage jsonResponseMessage = new JsonBrowseResponseMessage(); JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage, jsonData); HttpResponse httpResponse = new HttpResponse() { Data = session.Encrypt(jsonResponse) }; channel.Send(httpResponse); #if DEBUG Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse); #endif }
private void ExecuteThread(object obj) { try { CommandState state = (CommandState)obj; Entity entity = state.Entity; TunnelComponent tunnel = entity.Get <TunnelComponent>(); DownloadRequestCommand command = new DownloadRequestCommand(entity, tunnel.Connection); command.Execute(state.Id, state.Data, state.Chunk); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session) { // Connect NetworkChannel channel = new NetworkChannel(Connection); // Request JsonInfoRequestMessage jsonRequestMessage = JsonInfoRequestMessage.Parse(jsonRequest.Message); // Data HttpCode code = HttpCode.Ok; Entity entity = session.Owner; TunnelComponent tunnel = entity.Get <TunnelComponent>(); if (tunnel != null) { PingRequestCommand command = new PingRequestCommand(entity, tunnel.Connection); code = command.Execute(); if (code == HttpCode.Ok) { entity.Update(); } } // Response JsonInfoResponseMessage jsonResponseMessage = new JsonInfoResponseMessage() { Entities = Server.Entities, Sessions = Server.Sessions, Clients = Server.Clients, Groups = Server.Groups }; JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage); HttpResponse httpResponse = new HttpResponse(code) { Data = session.Encrypt(jsonResponse) }; channel.Send(httpResponse); #if DEBUG Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse); #endif }
public void Execute(HttpRequest httpRequest, JsonPacket jsonRequest, SessionComponent session) { Clear(); // Connect NetworkChannel channel = new NetworkChannel(Connection); // Request JsonSearchRequestMessage jsonRequestMessage = JsonSearchRequestMessage.Parse(jsonRequest.Message); // Data Entity entity = session.Owner; GroupComponent group = entity.Get <GroupComponent>(); EntityList entities = GroupList.Get(group.Id); if (entities == null) { channel.SendNotFound(); return; } // Response string jsonId = SecurityUtil.CreateKeyString(); JsonSearchResponseMessage jsonResponseMessage = new JsonSearchResponseMessage(jsonId); JsonPacket jsonResponse = new JsonPacket(jsonResponseMessage); HttpResponse httpResponse = new HttpResponse() { Data = session.Encrypt(jsonResponse) }; channel.Send(httpResponse); // Optimization: Keep track of the search list for faster downloads SearchListComponent download = entity.Get <SearchListComponent>(); download.Clear(); // Command lock (entities) { foreach (Entity e in entities) { // Do not search yourself if (entity.Id.Equals(e.Id)) { continue; } TunnelComponent tunnel = e.Get <TunnelComponent>(); if (!tunnel.Connected) { continue; } CommandState state = new CommandState() { Id = jsonId, Data = jsonRequest.Data, Source = entity, Target = e }; Thread thread = new Thread(new ParameterizedThreadStart(ExecuteThread)) { Priority = ThreadPriority.BelowNormal, IsBackground = true }; thread.Start(state); } } #if DEBUG Log.Add(httpRequest, httpResponse, jsonRequest, jsonResponse); #endif }