protected override void OnReceivedData(byte[] data, IPEndPoint ep, UInt16 proxyId, bool isText) { UdpSession session = getSession(proxyId); if (session == null) { return; } OnReceivedData(new ReceivedDataEventArgs(data, session, isText)); session.RaiseReceivedData(data, isText); lock (session) { session.ReceivedBytes += (data == null ? 0 : data.Length); session.LastReceiveTime = DateTime.Now; session.ActiveTime = DateTime.Now; } session = getSession(0); if (session != null) { lock (session) { session.ActiveTime = DateTime.Now; } } }
public UdpSession CreateProxySession() { UdpSession session = SessionFactory.CreateSession(this, Target as DnsEndPoint); session.ProxyID = GetProxyID(); lock (proxySessionList) { proxySessionList.Add(session); } bool isConnected = ConnectedSync(session.ProxyID); if (isConnected) { return(session); } else { lock (proxySessionList) { proxySessionList.Remove(session); } return(null); } }
public ReceivedDataEventArgs(Byte[] data, UdpSession session, bool isText) { Data = data; if (Data == null) { Data = new byte[0]; } Session = session; IsText = isText; }
public UdpServerSocketProxy(UdpSocketServer server, UdpClient client, UdpSession session) { Server = server; Session = session; IsConnected = true; Client = client; //Client = new UdpClient(sourcePort); //Client.DontFragment = true; // Client = new UdpClient(); FrameWrapper.AddRange(server.FrameWrapper); Target = session.Target; }
protected override void OnSendPackageError(UdpPackage package, EndPoint target, UInt16 proxyId) { UdpSession session = getSession(proxyId); if (session == null) { return; } lock (session) { session.ErrorBytes += (package.Data == null ? 0 : package.Data.Length); } }
private UdpSession getSession(UInt16 proxyId) { UdpSession session = null; if (proxyId == 0) { session = Session; } else { lock (proxySessionList) { session = proxySessionList.FirstOrDefault(x => x.ProxyID == proxyId); } } return(session); }
protected override void OnSendedPackage(UdpPackage package, EndPoint target, UInt16 proxyId) { UdpSession session = getSession(proxyId); if (session == null) { return; } lock (session) { session.SendedBytes += (package.Data == null ? 0 : package.Data.Length); session.ActiveTime = DateTime.Now; session.LastSendTime = DateTime.Now; } session = getSession(0); if (session != null) { lock (session) { session.ActiveTime = DateTime.Now; } } }
protected virtual void Close(bool isNotify, UInt16 proxyId) { if (proxyId == 0) { if (Interlocked.Exchange(ref mainCloseSignal, 1) == 1) { return; } lock (timerLocker) { if (checkTimer != null) { checkTimer.Dispose(); checkTimer = null; Logger.Trace("关闭Ping"); } } List <UdpSession> sl = null; lock (proxySessionList) { sl = proxySessionList.ToList(); } sl.ForEach(s => { Close(isNotify, s.ProxyID); }); if (RealTarget != null) { RemoveCachePackage(RealTarget); } } if (isNotify) { UdpFrame frame = new UdpFrame(0, 0, 0, UdpCommand.Close, null, proxyId); try { InnerSendFrame(frame, Target); } catch (SocketException) { } } if (Client != null && proxyId == 0) { Client.Close(); } if (proxyId == 0) { bool oldConnected = IsConnected; IsConnected = false; StopReceive(); StopSend(); if (oldConnected) { OnClosed(); Session.OnClosed(); } Interlocked.Exchange(ref mainCloseSignal, 0); } else { UdpSession proxySession = null; lock (proxySessionList) { proxySession = proxySessionList.FirstOrDefault(x => x.ProxyID == proxyId); if (proxySession != null) { proxySessionList.Remove(proxySession); } } if (proxySession != null) { proxySession.OnClosed(); } } }