/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession ID. </param> /// <param name="status">Status of response. </param> /// <param name="endPoint">endpoint of the intercept response</param> public LspInterceptionResponse(LspSession session, int status, ProtocolEndPoint endPoint) : base(LspMessageType.InterceptionResponse) { this.session = session; this.status = status; this.interceptedEndPoint = endPoint; }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession ID. </param> /// <param name="status">Status of response. </param> /// <param name="endPoint">endpoint of the intercept response</param> public LspInterceptionResponse(LspSession session, int status, ProtocolEndPoint endPoint) : base(LspMessageType.InterceptionResponse) { this.session = session; this.status = status; this.interceptedEndPoint = endPoint; }
/// <summary> /// Retrieve the real remote endpoint address that replaced by the LspClient endpoint. /// </summary> /// <param name="socketToRetrieve">Socket of Local LspClient. </param> /// <param name="destinationEndpoint">destination endpoint of the connection. </param> /// <returns>Local IPEndPoint.</returns> internal IPEndPoint RetrieveRemoteEndPoint(Socket socketToRetrieve, out IPEndPoint destinationEndpoint) { destinationEndpoint = null; if (disposed) { return(null); } if (!isConnected) { Connect(); } IPEndPoint remoteEndPoint = socketToRetrieve.RemoteEndPoint as IPEndPoint; //find the session by EndPoint if (this[socketToRetrieve.LocalEndPoint as IPEndPoint, StackTransportType.Tcp] != null) { remoteEndPoint = GetMappedIPEndPoint((IPEndPoint)socketToRetrieve.LocalEndPoint, socketToRetrieve.RemoteEndPoint as IPEndPoint, StackTransportType.Tcp); if (remoteEndPoint == null) { LspSession session = this[socketToRetrieve.LocalEndPoint as IPEndPoint, StackTransportType.Tcp].lspSession; IPEndPoint lspClientEndPoint = socketToRetrieve.RemoteEndPoint as IPEndPoint; //retrieve the remote EndPoint LspRetrieveEndPointRequest request = new LspRetrieveEndPointRequest(session, lspClientEndPoint); InternalSend(request.Encode()); byte[] recvBuf; int recvLen = LspMessage.ReceiveWholeMessage(this.socket, Marshal.SizeOf(typeof(LspRetrieveEndPointResponseMsg)), out recvBuf); if (recvLen != Marshal.SizeOf(typeof(LspRetrieveEndPointResponseMsg))) { throw new InvalidOperationException("Failed to retrieve remote endpoint"); } LspRetrieveEndPointResponse response = LspRetrieveEndPointResponse.Decode(recvBuf) as LspRetrieveEndPointResponse; if (response == null || response.Status != 0) { throw new InvalidOperationException("Failed to retrieve remote endpoint"); } //map from local endpoint to real endpoint this.SetMappedIPEndPoint((IPEndPoint)socketToRetrieve.LocalEndPoint, lspClientEndPoint, response.RemoteClientEndPoint, StackTransportType.Tcp); remoteEndPoint = response.RemoteClientEndPoint; destinationEndpoint = response.DestinationEndPoint; } } return(remoteEndPoint); }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession. </param> /// <param name="status">Status of response. </param> /// <param name="endPoint">source endpoint. </param> /// <param name="destEndPoint">destination endpoint. </param> public LspRetrieveEndPointResponse(LspSession session, int status, IPEndPoint endPoint, IPEndPoint destEndPoint) : base(LspMessageType.RetrieveEndPointResponse) { this.session = session; this.status = status; this.remoteClientEndPoint = endPoint; this.destinationEndPoint = destEndPoint; }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession. </param> /// <param name="status">Status of response. </param> /// <param name="endPoint">source endpoint. </param> /// <param name="destEndPoint">destination endpoint. </param> public LspRetrieveEndPointResponse(LspSession session, int status, IPEndPoint endPoint, IPEndPoint destEndPoint) : base(LspMessageType.RetrieveEndPointResponse) { this.session = session; this.status = status; this.remoteClientEndPoint = endPoint; this.destinationEndPoint = destEndPoint; }
internal void UnblockTraffic(IPEndPoint localServerEndpoint, StackTransportType transportType) { if (disposed) { return; } String strKey = null; foreach (KeyValuePair <string, LspSessionInfoCollection> kvp in sessionMap) { //sessionMap key is local listening endpoint //sessionMap value is remote intertecpted endpoint if (kvp.Value.lspSession.InterceptedEndPoint.protocolType == transportType && kvp.Value.lspSession.InterceptedEndPoint.endPoint.Equals(localServerEndpoint)) { LspSession session = kvp.Value.lspSession; if (!isConnected) { Connect(); } LspUnblockRequest request = new LspUnblockRequest(session); InternalSend(request.Encode()); byte[] recvBuf; int recvLen = LspMessage.ReceiveWholeMessage(this.socket, Marshal.SizeOf(typeof(LspUnblockResponseMsg)), out recvBuf); if (recvLen != Marshal.SizeOf(typeof(LspUnblockResponseMsg))) { throw new InvalidOperationException("UnBlockTraffic failed"); } LspUnblockResponse response = LspUnblockResponse.Decode(recvBuf) as LspUnblockResponse; strKey = kvp.Key; if (response == null || response.Status != 0) { throw new InvalidOperationException("UnBlockTraffic failed"); } break; } } //remove it from session map if (strKey != null) { sessionMap.Remove(strKey); } }
internal void ChangeToBlockingMode(IPEndPoint localServerEndpoint, StackTransportType transportType) { if (disposed) { return; } if (!isConnected) { Connect(); } foreach (KeyValuePair <string, LspSessionInfoCollection> kvp in sessionMap) { //sessionMap key is local listening endpoint //sessionMap value is remote intertecpted endpoint if (kvp.Value.lspSession.InterceptedEndPoint.protocolType == transportType && kvp.Value.lspSession.InterceptedEndPoint.endPoint.Equals(localServerEndpoint)) { LspSession session = kvp.Value.lspSession; LspBlockRequest request = new LspBlockRequest(session); InternalSend(request.Encode()); byte[] recvBuf; int recvLen = LspMessage.ReceiveWholeMessage(this.socket, Marshal.SizeOf(typeof(LspBlockResponseMsg)), out recvBuf); if (recvLen != Marshal.SizeOf(typeof(LspBlockResponseMsg))) { throw new InvalidOperationException("BlockTraffic failed"); } LspBlockResponse response = LspBlockResponse.Decode(recvBuf) as LspBlockResponse; if (response == null || response.Status != 0) { throw new InvalidOperationException("BlockTraffic failed"); } return; } } throw new InvalidOperationException("The specified endpoint isn't in intercepted mode"); }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession. </param> /// <param name="status">Status of response. </param> public LspUnblockResponse(LspSession session, int status) : base(LspMessageType.UnblockResponse) { this.session = session; this.status = status; }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession</param> public LspBlockRequest(LspSession session) : base(LspMessageType.BlockRequest) { this.session = session; }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession</param> /// <param name="lspClientEndPoint">IPEndPoint of LspClient. </param> public LspRetrieveEndPointRequest(LspSession session, IPEndPoint lspClientEndPoint) : base(LspMessageType.RetrieveEndPointRequest) { this.session = session; this.lspClientEndPoint = lspClientEndPoint; }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession. </param> /// <param name="status">Status of response. </param> public LspUnblockResponse(LspSession session, int status) : base(LspMessageType.UnblockResponse) { this.session = session; this.status = status; }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession</param> public LspBlockRequest(LspSession session) : base(LspMessageType.BlockRequest) { this.session = session; }
/// <summary> /// Constructor. /// </summary> /// <param name="session">LspSession</param> /// <param name="lspClientEndPoint">IPEndPoint of LspClient. </param> public LspRetrieveEndPointRequest(LspSession session, IPEndPoint lspClientEndPoint) : base(LspMessageType.RetrieveEndPointRequest) { this.session = session; this.lspClientEndPoint = lspClientEndPoint; }