public void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { if (e.Session.Authentication != AuthenticationType.security && e.Message is Authentication) { Authentication authentication = (Authentication)e.Message; if (!authentication.Token.VerifyMd5Hash(authentication.NodeID + TokenKey)) { Loger.Process(LogType.ERROR, "[{0}] node from {1} authentication error", authentication.NodeID, e.Session.RemoteEndPoint); e.Session.Dispose(); } else { e.Session.Authentication = AuthenticationType.security; Loger.Process(LogType.INFO, "[{0}] node from {1} authentication success", authentication.NodeID, e.Session.RemoteEndPoint); mRemoteNodeSessions[authentication.NodeID] = e.Session; e.Session["NODEID"] = authentication.NodeID; INodeConnection connection = mRemoteNodeCenter.Get(authentication.NodeID); if (connection != null) { connection.SyncSubscriber(); } } return; } if (e.Session.Authentication != AuthenticationType.security) { Loger.Process(LogType.ERROR, "[{0}] session authentication error", e.Session.RemoteEndPoint); e.Session.Dispose(); } else { ProcessMessage(server, e.Session, e.Message); } }
public void OnNodeRegiste(NodeRegister register) { PacketDecodeCompletedEventArgs e = RouteCenter.CurrentContext.GetToken <PacketDecodeCompletedEventArgs>(); Loger.Process(LogType.INFO, "note {0} registed from {1}", register.Name, e.Session.RemoteEndPoint); mNodeManager.Register(register, e.Session); }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { base.SessionPacketDecodeCompleted(server, e); //Console.WriteLine(e.Message); // server.Send(e.Message, e.Session); mClient.Send(e.Message); }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { HttpToken token = (HttpToken)e.Session.Tag; if (token.WebSocket) { OnReceiveWebSocketData(e.Session, (WebSockets.DataFrame)e.Message); } else { HttpRequest request = (HttpRequest)e.Message; request.Server = this; HttpResponse response = request.CreateResponse(); token.KeepAlive = request.KeepAlive; if (token.FirstRequest && string.Compare(request.Header[HeaderType.UPGRADE], "websocket", true) == 0) { token.FirstRequest = false; OnWebSocketConnect(request, response); } else { token.FirstRequest = false; if (string.IsNullOrEmpty(request.Ext) && request.BaseUrl != "/") { mActionFactory.Execute(request, response, this); } else { OnProcessResource(request, response); } } } }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { if (Options.SessionTimeOut > 0 && Options.Statistical) { BaseServer.UpdateSession(e.Session); } OnRequestHandler(e); }
/// <summary> /// 缓存Session /// </summary> /// <param name="Provider"></param> /// <param name="Event"></param> public static void ExecutePacketCache(SocketMiddleData Provider, PacketDecodeCompletedEventArgs Event) { if (Provider.SendType == SendTypeEnum.Init) { var Keys = Provider.MiddleResult.SocketJsonData.ToModel <Dictionary <string, List <string> > >().Keys.ToList(); PacketCache.Add(string.Join(",", Keys), Event); } }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { if (ServerConfig.SessionTimeOut > 0) { BaseServer.UpdateSession(e.Session); } OnRequestHandler(e); }
/// <summary> /// <see cref="TcpServer.OnPacketDecodeCompleted"/> call /// </summary> /// <param name="server"></param> /// <param name="e"></param> public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { if (Options.SessionTimeOut > 0) { BaseServer.UpdateSession(e.Session); } /// http call to =>> <see cref="OnHttpRequest"/> OnRequestHandler(e); }
private void OnRequestHandler(PacketDecodeCompletedEventArgs e) { try { HttpToken token = (HttpToken)e.Session.Tag; if (token.WebSocket) { OnWebSocketRequest(token.Request, e.Session, (WebSockets.DataFrame)e.Message); } else { HttpRequest request = (HttpRequest)e.Message; if (EnableLog(LogType.Info)) { mServer.Log(LogType.Info, null, $"HTTP {request.ID} {request.RemoteIPAddress} {request.Method} {request.Url}"); } if (EnableLog(LogType.Debug)) { mServer.Log(LogType.Debug, e.Session, $"HTTP {request.ID} {request.RemoteIPAddress} {request.Method} {request.Url} detail {request.ToString()}"); } request.Server = this; HttpResponse response = request.CreateResponse(); token.KeepAlive = request.KeepAlive; if (token.FirstRequest && string.Compare(request.Header[HeaderTypeFactory.UPGRADE], "websocket", true) == 0) { token.FirstRequest = false; OnWebSocketConnect(request, response); } else { token.FirstRequest = false; if (!Options.IOQueueEnabled) { OnHttpRequest(request, response); } else { IOQueueProcessArgs args = new IOQueueProcessArgs { Request = request, Response = response }; token.IOQueue.Enqueue(args); } } } } catch (Exception e_) { if (EnableLog(LogType.Error)) { mServer.Error(e_, e.Session, $"HTTP {e.Session.RemoteEndPoint} {0} OnRequestHandler error {e_.Message}@{e_.StackTrace}"); } } }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { if (e.Message is SearchEmployee) { OnSearchEmployee((SearchEmployee)e.Message, server, e.Session); } else if (e.Message is SearchCustomer) { OnSearchCustomer((SearchCustomer)e.Message, server, e.Session); } }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { HttpRequest request = (HttpRequest)e.Message; if (!request.KeepAlive) { e.Session.Tag = "close"; } HttpResponse response = request.CreateResponse(); mActionFactory.Execute(request, response, this); }
private void OnRequestHandler(object state) { PacketDecodeCompletedEventArgs e = (PacketDecodeCompletedEventArgs)state; try { System.Threading.Interlocked.Increment(ref mTotalRequests); HttpToken token = (HttpToken)e.Session.Tag; if (token.WebSocket) { OnWebSocketRequest(e.Session, (WebSockets.DataFrame)e.Message); } else { HttpRequest request = (HttpRequest)e.Message; if (request.ClientIPAddress == null) { IPEndPoint IP = e.Session.RemoteEndPoint as IPEndPoint; if (IP != null) { string ipstr = IP.Address.ToString() + ":" + IP.Port.ToString(); request.Header.Add(HeaderTypeFactory.CLIENT_IPADDRESS, ipstr); } } if (EnableLog(LogType.Info)) { mServer.Log(LogType.Info, e.Session, "{0} {1} {2}", request.ClientIPAddress, request.Method, request.Url); } if (EnableLog(LogType.Debug)) { mServer.Log(LogType.Debug, e.Session, "{0} {1}", request.ClientIPAddress, request.ToString()); } request.Server = this; HttpResponse response = request.CreateResponse(); token.KeepAlive = request.KeepAlive; if (token.FirstRequest && string.Compare(request.Header[HeaderTypeFactory.UPGRADE], "websocket", true) == 0) { token.FirstRequest = false; OnWebSocketConnect(request, response); } else { token.FirstRequest = false; OnHttpRequest(request, response); } } } catch (Exception e_) { mServer.Error(e_, e.Session, "{0} OnRequestHandler error {1}", e.Session.RemoteEndPoint, e.Message); } }
public void OnProcessRegiste(Network.ProcessRegister register) { Loger.Process(LogType.INFO, "{0} process registed", register.Name); PacketDecodeCompletedEventArgs e = (PacketDecodeCompletedEventArgs)RouteCenter.CurrentContext.Token; Process.TestProcessAgent agent = AgentManager.GetAgent(register.Name); agent.Session = e.Session; if (agent.TestCase != null) { agent.Run(agent.TestCase.TestCase, agent.TestCase.Users, agent.TestCase.Config); Loger.Process(LogType.INFO, "{0} process runing {1} test case", register.Name, agent.TestCase.TestCase); } }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { HttpRequest request = (HttpRequest)e.Message; if (!request.KeepAlive) { e.Session.Tag = "close"; } HttpResponse response = request.CreateResponse(); response.Body = DateTime.Now.ToString(); server.Send(response, e.Session); base.SessionPacketDecodeCompleted(server, e); }
private void OnPacketDecodeCompleted(object server, PacketDecodeCompletedEventArgs e) { try { if (Handler != null) { Handler.SessionPacketDecodeCompleted(this, e); } } catch (Exception e_) { Error(e_, null, "{0} session packet message process error !", e.Session.RemoteEndPoint); } }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { WebSocketToken token = (WebSocketToken)e.Session.Tag; HttpRequest request = e.Message as HttpRequest; if (request != null) { token.ConnectionRequest = request; OnWebSocketConnect(request, request.CreateResponse()); } else { OnReceiveWebSocketData(token.ConnectionRequest, (DataFrame)e.Message); } }
public RunTestcaseResponse OnRunTest(RunTestcase e) { PacketDecodeCompletedEventArgs pdce = RouteCenter.CurrentContext.GetToken <PacketDecodeCompletedEventArgs>(); Loger.Process(LogType.INFO, "runing {0}:{1} with {2}", e.UnitTest, e.TestCase, string.Join(",", e.Nodes)); RunTestcaseResponse result = new Network.RunTestcaseResponse(); foreach (string node in e.Nodes) { NodeAgent agent = NodeManager.Get(node); agent.RunTest(e); } mUnitTestManagers[e.UnitTest] = pdce.Session; return(result); }
public override void SessionPacketDecodeCompleted(IServer Server, PacketDecodeCompletedEventArgs Event) { SocketMiddleData AcceptData; if (Event.Message is SocketMiddleData) { AcceptData = (SocketMiddleData)Event.Message; } else { AcceptData = Event.Message.ToString().ToModel <SocketMiddleData>(); } ExecuteDependency.ExecutePacketCache(AcceptData, Event); ExecuteDependency.ExecuteInternalInfo(Event, AcceptData); }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { base.SessionPacketDecodeCompleted(server, e); List <Employee> items = new List <Employee>(); SearchEmployee search = (SearchEmployee)e.Message; if (search.Quantity > mEmployees.Count) { search.Quantity = mEmployees.Count; } for (int i = 0; i < search.Quantity; i++) { items.Add(mEmployees[i]); } server.Send(items, e.Session); }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { HttpToken token = (HttpToken)e.Session.Tag; HttpRequest request = (HttpRequest)e.Message; HttpResponse response = request.CreateResponse(); token.KeepAlive = request.KeepAlive; if (string.IsNullOrEmpty(request.Ext) && request.BaseUrl != "/") { mActionFactory.Execute(request, response, this); } else { OnProcessResource(request, response); } }
public void OnSyncUnitTest(SyncUnitTest e) { PacketDecodeCompletedEventArgs token = RouteCenter.CurrentContext.GetToken <PacketDecodeCompletedEventArgs>(); SyncMonitor monitor = new Center.SyncMonitor(); monitor.Message = e; monitor.Sessioin = token.Session; monitor.Center = this; monitor.Completed = OnSyncCompleted; mSyncMonitor[e.ID] = monitor; foreach (string node in e.Nodes) { monitor.Nodes.Add(this.NodeManager.Get(node)); } monitor.Execute(); }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { System.Threading.Interlocked.Increment(ref mRequests); HttpToken token = (HttpToken)e.Session.Tag; if (token.WebSocket) { OnReceiveWebSocketData(e.Session, (WebSockets.DataFrame)e.Message); } else { HttpRequest request = (HttpRequest)e.Message; if (EnableLog(LogType.Info)) { mServer.Log(LogType.Info, e.Session, "{0} Http {1} {2}", request.ClientIPAddress, request.Method, request.Url); } if (EnableLog(LogType.Debug)) { mServer.Log(LogType.Info, e.Session, "{0} {1}", request.ClientIPAddress, request.ToString()); } request.Server = this; if (request.ClientIPAddress == null) { request.Header.Add(HeaderType.CLIENT_IPADDRESS, ((IPEndPoint)e.Session.RemoteEndPoint).Address.ToString()); } HttpResponse response = request.CreateResponse(); token.KeepAlive = request.KeepAlive; if (token.FirstRequest && string.Compare(request.Header[HeaderType.UPGRADE], "websocket", true) == 0) { token.FirstRequest = false; OnWebSocketConnect(request, response); } else { token.FirstRequest = false; if (string.IsNullOrEmpty(request.Ext) && request.BaseUrl != "/") { mActionFactory.Execute(request, response, this); } else { OnProcessResource(request, response); } } } }
public void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { if (e.Message is Register) { OnRegiste(e.Message as Register, e); } else { if (e.Session.Authentication == AuthenticationType.security) { mRouteCenter.Invoke(e.Message, e); } else { e.Session.Dispose(); } } }
private void OnRequestHandler(object state) { PacketDecodeCompletedEventArgs e = (PacketDecodeCompletedEventArgs)state; try { System.Threading.Interlocked.Increment(ref mTotalRequests); HttpToken token = (HttpToken)e.Session.Tag; if (token.WebSocket) { OnWebSocketRequest(e.Session, (WebSockets.DataFrame)e.Message); } else { HttpRequest request = (HttpRequest)e.Message; if (EnableLog(LogType.Info)) { mServer.Log(LogType.Info, e.Session, $"{request.RemoteIPAddress} {request.Method} {request.Url} request"); } if (EnableLog(LogType.Debug)) { mServer.Log(LogType.Debug, e.Session, $"{request.RemoteIPAddress} {request.Method} {request.Url} request detail {request.ToString()}"); } request.Server = this; HttpResponse response = request.CreateResponse(); token.KeepAlive = request.KeepAlive; if (token.FirstRequest && string.Compare(request.Header[HeaderTypeFactory.UPGRADE], "websocket", true) == 0) { token.FirstRequest = false; OnWebSocketConnect(request, response); } else { token.FirstRequest = false; OnHttpRequest(request, response); } } } catch (Exception e_) { mServer.Error(e_, e.Session, "{0} OnRequestHandler error {1}", e.Session.RemoteEndPoint, e.Message); } }
private void OnPacketDecodeCompleted(object server, PacketDecodeCompletedEventArgs e) { try { if (Handler != null) { if (EnableLog(LogType.Debug)) { Log(LogType.Debug, e.Session, "{0} session packet decode completed {1}", e.Session.RemoteEndPoint, e.Message.GetType()); } Handler.SessionPacketDecodeCompleted(this, e); } } catch (Exception e_) { if (EnableLog(LogType.Error)) { Error(e_, e.Session, "{0} session packet message process error !", e.Session.RemoteEndPoint); } } }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { if (e.Message is C0C1) { Console.WriteLine("Get C0C1"); SessionStatus[e.Session.ID] = HandshakeStatus.RTMP_HANDSHAKE_1; var bytes = RtmpHandshake.GetS01Async(); e.Session.Stream.ToPipeStream().Write(bytes, 0, bytes.Length); e.Session.Stream.Flush(); } else if (e.Message is C2) { Console.WriteLine("Get C2 "); Console.WriteLine("Handshake Done"); SessionStatus[e.Session.ID] = HandshakeStatus.RTMP_HANDSHAKE_2; var bytes = RtmpHandshake.GetS2Async(); e.Session.Stream.ToPipeStream().Write(bytes, 0, bytes.Length); e.Session.Stream.Flush(); } base.SessionPacketDecodeCompleted(server, e); }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { base.SessionPacketDecodeCompleted(server, e); Console.WriteLine(e.Message); SearchEmployee search = (SearchEmployee)e.Message; if (search.Size > 1) { List <Employee> items = new List <Employee>(); for (int i = 0; i < search.Size; i++) { items.Add(Employee.GetEmployee()); } server.Send(items, e.Session); } else { Employee item = Employee.GetEmployee(); server.Send(item, e.Session); } }
public override void SessionPacketDecodeCompleted(IServer server, PacketDecodeCompletedEventArgs e) { System.Threading.Interlocked.Increment(ref mTotalRequests); HttpToken token = (HttpToken)e.Session.Tag; if (token.WebSocket) { OnWebSocketRequest(e.Session, (WebSockets.DataFrame)e.Message); } else { HttpRequest request = (HttpRequest)e.Message; if (request.ClientIPAddress == null) { request.Header.Add(HeaderTypeFactory.CLIENT_IPADDRESS, e.Session.RemoteEndPoint.ToString()); } if (EnableLog(LogType.Info)) { mServer.Log(LogType.Info, e.Session, "{0} {1} {2}", request.ClientIPAddress, request.Method, request.Url); } if (EnableLog(LogType.Debug)) { mServer.Log(LogType.Debug, e.Session, "{0} {1}", request.ClientIPAddress, request.ToString()); } request.Server = this; HttpResponse response = request.CreateResponse(); token.KeepAlive = request.KeepAlive; if (token.FirstRequest && string.Compare(request.Header[HeaderTypeFactory.UPGRADE], "websocket", true) == 0) { token.FirstRequest = false; OnWebSocketConnect(request, response); } else { token.FirstRequest = false; OnHttpRequest(request, response); } } }
public override void Execute(MethodContext context) { PacketDecodeCompletedEventArgs e = (PacketDecodeCompletedEventArgs)context.Token; Network.MessageBase msg = (Network.MessageBase)context.Message; try { base.Execute(context); if (context.Result != null) { msg.Reply((Network.MessageBase)context.Result, e.Session); } else { msg.ReplySuccess(e.Session); } } catch (Exception e_) { msg.ReplyError(e_.Message, e.Session); } }
/// <summary> /// 处理内部消息 /// </summary> /// <param name="Param"></param> public static void ExecuteInternalInfo(PacketDecodeCompletedEventArgs Event, SocketMiddleData Param) { switch (Param.SendType) { case SendTypeEnum.Init: InitHandler.ExecuteSocketApiJson(Param.MiddleResult); break; case SendTypeEnum.InternalInfo: InternalHandler.ExecuteSocketIniternalInfo(Param, PacketCache); break; case SendTypeEnum.RequestInfo: RequestHandler.ExecuteSocketRequest(Event, Param); break; case SendTypeEnum.CallBack: CallHandler.ExecuteSocketCallBack(PacketCache.Values.ToList(), Param); break; default: break; } }