public static void ConnectAsync(this EndPoint remoteEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol, ConnectedCallback callback, object state) { var e = CreateSocketAsyncEventArgs(remoteEndPoint, callback, state); e.SocketClientAccessPolicyProtocol = clientAccessPolicyProtocol; Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, e); }
static public bool CheckEndPoint(EndPoint endpoint, SocketClientAccessPolicyProtocol protocol) { // if needed transform the DnsEndPoint into a usable IPEndPoint IPEndPoint ip = (endpoint as IPEndPoint); if (ip == null) { throw new ArgumentException("endpoint"); } // find the policy (cached or to be downloaded) associated with the endpoint string address = ip.Address.ToString(); ClientAccessPolicy policy = null; if (!socket_policies.TryGetValue(address, out policy)) { policy = CreateForEndPoint(ip, protocol); socket_policies.Add(address, policy); } // no access granted if no policy is available if (policy == null) { return(false); } // does the policy allows access ? return(policy.IsAllowed(ip)); }
public SocketAsyncEventArgs() { Worker = new Socket.Worker(this); AcceptSocket = null; Buffer = null; BufferList = null; BytesTransferred = 0; Count = 0; DisconnectReuseSocket = false; LastOperation = SocketAsyncOperation.None; Offset = 0; RemoteEndPoint = null; #if !NET_2_1 SendPacketsElements = null; SendPacketsFlags = TransmitFileOptions.UseDefaultWorkerThread; #endif SendPacketsSendSize = -1; SocketError = SocketError.Success; SocketFlags = SocketFlags.None; UserToken = null; #if MOONLIGHT && !INSIDE_SYSTEM policy_protocol = SocketClientAccessPolicyProtocol.Tcp; #endif }
private ComplexSocket(EndPoint endPoint, bool isControlSocket, int receiveBufferSize, int sendBufferSize, SocketClientAccessPolicyProtocol socketClientAccessPolicyProtocol) { this._endPoint = endPoint; this._isControlSocket = isControlSocket; this._socketClientAccessPolicyProtocol = socketClientAccessPolicyProtocol; this._socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) { ReceiveBufferSize = receiveBufferSize, SendBufferSize = sendBufferSize }; }
public static ClientAccessPolicy CreateForEndPoint(IPEndPoint endpoint, SocketClientAccessPolicyProtocol protocol) { Stream s = null; switch (protocol) { case SocketClientAccessPolicyProtocol.Tcp: s = GetPolicyStream(endpoint); break; case SocketClientAccessPolicyProtocol.Http: // <quote>It will NOT attempt to download the policy via the custom TCP protocol if the // policy check fails.</quote> // http://blogs.msdn.com/ncl/archive/2010/04/15/silverlight-4-socket-policy-changes.aspx string url = String.Format("http://{0}:80{1}", endpoint.Address.ToString(), CrossDomainPolicyManager.ClientAccessPolicyFile); s = GetPolicyStream(new Uri(url)); break; } if ((s == null) || (s.Length == 0)) { return(null); } ClientAccessPolicy policy = null; try { policy = (ClientAccessPolicy)ClientAccessPolicy.FromStream(s); } catch (Exception ex) { Console.WriteLine(String.Format("CrossDomainAccessManager caught an exception while reading {0}: {1}", endpoint, ex.Message)); // and ignore. } return(policy); }
public HttpConnectProxy(EndPoint proxyEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol, int receiveBufferSize) : base(proxyEndPoint, clientAccessPolicyProtocol) { m_ReceiveBufferSize = receiveBufferSize; }
public HttpConnectProxy(EndPoint proxyEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol) : this(proxyEndPoint, clientAccessPolicyProtocol, 128) { }
public Socks5Connector(EndPoint proxyEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol, string username, string password) : base(proxyEndPoint, clientAccessPolicyProtocol)
public static ClientAccessPolicy CreateForEndPoint (IPEndPoint endpoint, SocketClientAccessPolicyProtocol protocol) { Stream s = null; switch (protocol) { case SocketClientAccessPolicyProtocol.Tcp: s = GetPolicyStream (endpoint); break; case SocketClientAccessPolicyProtocol.Http: // <quote>It will NOT attempt to download the policy via the custom TCP protocol if the // policy check fails.</quote> // http://blogs.msdn.com/ncl/archive/2010/04/15/silverlight-4-socket-policy-changes.aspx string url = String.Format ("http://{0}:80{1}", endpoint.Address.ToString (), CrossDomainPolicyManager.ClientAccessPolicyFile); s = GetPolicyStream (new Uri (url)); break; } if ((s == null) || (s.Length == 0)) return null; ClientAccessPolicy policy = null; try { policy = (ClientAccessPolicy) ClientAccessPolicy.FromStream (s); } catch (Exception ex) { Console.WriteLine (String.Format ("CrossDomainAccessManager caught an exception while reading {0}: {1}", endpoint, ex.Message)); // and ignore. } return policy; }
public Socks4aConnector(EndPoint proxyEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol, string userID) : base(proxyEndPoint, clientAccessPolicyProtocol, userID) { }
public Socks5Connector(EndPoint proxyEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol) : base(proxyEndPoint, clientAccessPolicyProtocol) { }
public ProxyConnectorBase(EndPoint proxyEndPoint, SocketClientAccessPolicyProtocol clientAccessPolicyProtocol) { ProxyEndPoint = proxyEndPoint; ClientAccessPolicyProtocol = clientAccessPolicyProtocol; }
public SocketAsyncEventArgs () { Worker = new Socket.Worker (this); AcceptSocket = null; Buffer = null; BufferList = null; BytesTransferred = 0; Count = 0; DisconnectReuseSocket = false; LastOperation = SocketAsyncOperation.None; Offset = 0; RemoteEndPoint = null; #if !NET_2_1 SendPacketsElements = null; SendPacketsFlags = TransmitFileOptions.UseDefaultWorkerThread; #endif SendPacketsSendSize = -1; SocketError = SocketError.Success; SocketFlags = SocketFlags.None; UserToken = null; #if MOONLIGHT && !INSIDE_SYSTEM policy_protocol = SocketClientAccessPolicyProtocol.Tcp; #endif }
static public bool CheckEndPoint (EndPoint endpoint, SocketClientAccessPolicyProtocol protocol) { // if needed transform the DnsEndPoint into a usable IPEndPoint IPEndPoint ip = (endpoint as IPEndPoint); if (ip == null) throw new ArgumentException ("endpoint"); // find the policy (cached or to be downloaded) associated with the endpoint string address = ip.Address.ToString (); ClientAccessPolicy policy = null; if (!socket_policies.TryGetValue (address, out policy)) { policy = CreateForEndPoint (ip, protocol); socket_policies.Add (address, policy); } // no access granted if no policy is available if (policy == null) return false; // does the policy allows access ? return policy.IsAllowed (ip); }