Ejemplo n.º 1
0
        /// <summary>
        /// Do not create links of your own.
        /// </summary>
        /// <param name="Pcol">The PortalCollection.</param>
        public Link(PortalCollection Pcol)
        {
            lock (SendData_Lock)
            {
                int counter = 0;
                for (int x = 0; x < 256; x++)
                {
                    if (Pcol.PortalArray[x] != null)
                    {
                        counter++;
                    }
                }
                //Debug.WriteLine("Portal counter is "+ counter);
                SendDataPortalArrayOUTPUT = new Queue <Packet_Send> [counter];

                counter = 0;
                for (int x = 0; x < 256; x++)
                {
                    if (Pcol.PortalArray[x] != null)
                    {
                        SendDataPortalArray[x] = new Queue <Packet_Send>();

                        SendDataPortalArrayOUTPUT[counter] = SendDataPortalArray[x];
                        //Debug.WriteLine("Mapping Portal ID from "+x+" to "+ counter);
                        counter++;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Connect to a Vaser server via SSL.
        /// </summary>
        /// <param name="IP">Hostname or IP-Address.</param>
        /// <param name="RemotePort">Target port of the remote server.</param>
        /// <param name="PColl">The Portal Collection.</param>
        /// <param name="SSL">The SSL connectionsettings.</param>
        /// <returns>Returns the link of the connection.</returns>
        /// <exception cref="System.Net.Sockets.SocketException">Thrown if vaser is unable to create a socket or a connection.</exception>
        public static Link ConnectClient(string IP, int RemotePort, PortalCollection PColl, VaserSSLClient SSL)
        {
            if (SSL == null)
            {
                throw new Exception("Missing SSL options in ConnectClient(...)");
            }
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                Task   t      = client.ConnectAsync(IP, RemotePort);
                t.Wait();
                if (client.Connected)
                {
                    PColl._Active = true;
                    Connection con = new Connection(client, false, VaserOptions.ModeSSL, PColl, null, null, null, SSL);

                    return(con.link);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Opens an kerberos encrypted connection to a server.
        /// </summary>
        /// <param name="IP">Hostname or IP-Address.</param>
        /// <param name="RemotePort">Target port of the remote server.</param>
        /// <param name="PColl">The Portal Collection.</param>
        /// <param name="Kerberos">The Kerberos connectionsettings.</param>
        /// <returns>Returns the link of the connection.</returns>
        /// <exception cref="System.Net.Sockets.SocketException">Thrown if vaser is unable to create a socket or a connection.</exception>
        public static Link ConnectClient(string IP, int RemotePort, PortalCollection PColl, VaserKerberosClient Kerberos)
        {
            //if (Mode == VaserOptions.ModeSSL) throw new Exception("Missing X509Certificate2");
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                Task   t      = client.ConnectAsync(IP, RemotePort);
                t.Wait();
                if (client.Connected)
                {
                    PColl._Active = true;
                    Connection con = new Connection(client, false, VaserOptions.ModeKerberos, PColl, null, null, Kerberos, null);

                    return(con.link);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new SSL Server and listen for clients.
 /// </summary>
 /// <param name="LocalAddress">IPAddress.Any</param>
 /// <param name="Port">The local port of the server.</param>
 /// <param name="PColl">The PortalCollection.</param>
 /// <param name="SSL">SSL connection settings.</param>
 public VaserServer(IPAddress LocalAddress, int Port, PortalCollection PColl, VaserSSLServer SSL)
 {
     if (SSL == null)
     {
         throw new Exception("Missing SSL options in VaserServer(...)");
     }
     if (PColl == null)
     {
         throw new Exception("PortalCollection is needed!");
     }
     try
     {
         _vSSL           = SSL;
         ServerOption    = VaserOptions.ModeSSL;
         PColl.Active    = true;
         PCollection     = PColl;
         _socketListener = new StreamSocketListener();
         _socketListener.ConnectionReceived += SocketListener_ConnectionReceived;
         _Port = Port.ToString();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new connection for processing data
        /// </summary>
        public Connection(Socket client, bool _IsServer, VaserOptions Mode, PortalCollection PColl, VaserKerberosServer KerberosS, VaserSSLServer SSLS, VaserKerberosClient KerberosC, VaserSSLClient SSLC, VaserServer srv = null)
        {
            IsServer          = _IsServer;
            StreamIsConnected = true;

            _rms2 = new MemoryStream();
            _rbr2 = new BinaryReader(_rms2);


            _Mode        = Mode;
            _PCollection = PColl;

            _vSSLS      = SSLS;
            _vKerberosS = KerberosS;
            _vSSLC      = SSLC;
            _vKerberosC = KerberosC;

            _SocketTCPClient             = client;
            _SocketTCPClient.LingerState = new LingerOption(true, 0);

            server = srv;

            IPv4Address = ((IPEndPoint)client.RemoteEndPoint).Address;

            link = new Link(PColl)
            {
                Connect = this
            };
            if (Mode == VaserOptions.ModeNotEncrypted)
            {
                mySendNotEncryptedCallback    = new AsyncCallback(SendNotEncryptedCallback);
                myReceiveNotEncryptedCallback = new AsyncCallback(ReceiveNotEncryptedCallback);
            }
            if (Mode == VaserOptions.ModeKerberos)
            {
                mySendKerberosCallback    = new AsyncCallback(SendKerberosCallback);
                myReceiveKerberosCallback = new AsyncCallback(ReceiveKerberosCallback);
            }

            if (Mode == VaserOptions.ModeSSL)
            {
                mySendSSLCallback    = new AsyncCallback(SendSSLCallback);
                myReceiveSSLCallback = new AsyncCallback(ReceiveSSLCallback);
            }
            if (_IsServer)
            {
                ThreadPool.QueueUserWorkItem(HandleClientComm);
            }
            else
            {
                HandleClientComm(null);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new unencrypted TCP server and listen for clients.
        /// </summary>
        /// <param name="LocalAddress">The local IP-Address for listening - IPAddress.Any</param>
        /// <param name="Port">The local port of the server.</param>
        /// <param name="PColl">The Portal Collection</param>
        public VaserServer(IPAddress LocalAddress, int Port, PortalCollection PColl)
        {
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                ServerOption = VaserOptions.ModeNotEncrypted;
                PColl.Active = true;
                PCollection  = PColl;
                _TCPListener = new TcpListener(LocalAddress, Port);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new internal pipe server for a client.
        /// </summary>
        /// <param name="Pipename">The name of the pipe.</param>
        /// <param name="PColl">The PortalCollection.</param>
        public VaserServer(string Pipename, PortalCollection PColl)
        {
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                ServerOption = VaserOptions.ModeNamedPipeServerStream;
                PColl.Active = true;
                PCollection  = PColl;

                _pipeServer = new NamedPipeServerStream(Pipename);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new unencrypted TCP server and listen for clients.
        /// </summary>
        /// <param name="LocalAddress">The local IP-Address for listening - IPAddress.Any</param>
        /// <param name="Port">The local port of the server.</param>
        /// <param name="PColl">The Portal Collection</param>
        public VaserServer(int Port, PortalCollection PColl)
        {
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                ServerOption    = VaserOptions.ModeNotEncrypted;
                PColl.Active    = true;
                PCollection     = PColl;
                _socketListener = new StreamSocketListener();
                _socketListener.ConnectionReceived += SocketListener_ConnectionReceived;
                _Port = Port.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a new connection for processing data
        /// </summary>
        public Connection(StreamSocket client, bool _IsServer, VaserOptions Mode, PortalCollection PColl, VaserKerberosServer KerberosS, VaserSSLServer SSLS, VaserKerberosClient KerberosC, VaserSSLClient SSLC, VaserServer srv = null)
        {
            IsServer          = _IsServer;
            StreamIsConnected = true;

            _rms2 = new MemoryStream();
            _rbr2 = new BinaryReader(_rms2);


            _Mode        = Mode;
            _PCollection = PColl;

            _vSSLS      = SSLS;
            _vKerberosS = KerberosS;
            _vSSLC      = SSLC;
            _vKerberosC = KerberosC;

            _SocketTCPClient = client;

            server = srv;
            //Debug.WriteLine("Init Options Done");
            IPv4Address = client.Information.RemoteAddress;

            link = new Link(PColl)
            {
                Connect = this
            };
            //Debug.WriteLine("Create Link Done");

            //Debug.WriteLine("Init Connection class DONE");
            if (_IsServer)
            {
                //Debug.WriteLine("Send to HandleClientComm");
                IAsyncAction asyncAction = ThreadPool.RunAsync(HandleClientComm);
            }
            else
            {
                HandleClientComm(null);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new connection for processing data
        /// </summary>
        public Connection(Socket client, bool _IsServer, VaserOptions Mode, PortalCollection PColl, VaserKerberosServer KerberosS, VaserSSLServer SSLS, VaserKerberosClient KerberosC, VaserSSLClient SSLC, VaserServer srv = null)
        {
            IsServer          = _IsServer;
            StreamIsConnected = true;


            _rms2 = new MemoryStream();
            _rbr2 = new BinaryReader(_rms2);



            _Mode        = Mode;
            _PCollection = PColl;

            _vSSLS      = SSLS;
            _vKerberosS = KerberosS;
            _vSSLC      = SSLC;
            _vKerberosC = KerberosC;

            client.SendBufferSize = 65007;
            _SocketTCPClient      = client;

            server = srv;

            IPv4Address = ((IPEndPoint)client.RemoteEndPoint).Address;

            link         = new Link(PColl);
            link.Connect = this;

            if (_IsServer)
            {
                ThreadPool.QueueUserWorkItem(HandleClientComm);
            }
            else
            {
                HandleClientComm(null);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates a new SSL Server and listen for clients.
 /// </summary>
 /// <param name="LocalAddress">IPAddress.Any</param>
 /// <param name="Port">The local port of the server.</param>
 /// <param name="PColl">The PortalCollection.</param>
 /// <param name="SSL">SSL connection settings.</param>
 public VaserServer(IPAddress LocalAddress, int Port, PortalCollection PColl, VaserSSLServer SSL)
 {
     if (SSL == null)
     {
         throw new Exception("Missing SSL options in VaserServer(...)");
     }
     if (PColl == null)
     {
         throw new Exception("PortalCollection is needed!");
     }
     try
     {
         _vSSL        = SSL;
         ServerOption = VaserOptions.ModeSSL;
         PColl.Active = true;
         PCollection  = PColl;
         _TCPListener = new TcpListener(LocalAddress, Port);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a new Kerberos Server and listen for clients.
        /// </summary>
        /// <param name="LocalAddress">IPAddress.Any</param>
        /// <param name="Port">The local port of the server.</param>
        /// <param name="PColl">The PortalCollection.</param>
        /// <param name="Kerberos">Kerberos connection settings.</param>
        public VaserServer(IPAddress LocalAddress, int Port, PortalCollection PColl, VaserKerberosServer Kerberos)
        {
            if (Kerberos == null)
            {
                throw new Exception("Missing Kerberos options in VaserServer(...)");
            }
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                _vKerberos   = Kerberos;
                ServerOption = VaserOptions.ModeKerberos;
                PColl.Active = true;
                PCollection  = PColl;
                _TCPListener = new TcpListener(LocalAddress, Port);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Opens an unencrypted connection to a server.
        /// </summary>
        /// <param name="IP">Hostname or IP-Address.</param>
        /// <param name="RemotePort">Target port of the remote server.</param>
        /// <param name="PColl">The Portal Collection.</param>
        /// <returns>Returns the link of the connection.</returns>
        /// <exception cref="System.Net.Sockets.SocketException">Thrown if vaser is unable to create a socket or a connection.</exception>
        public static async System.Threading.Tasks.Task <Link> ConnectClient(string IP, int RemotePort, PortalCollection PColl)
        {
            //if (Mode == VaserOptions.ModeSSL) throw new Exception("Missing X509Certificate2");
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                //Debug.WriteLine("Connecting");
                StreamSocket client = new StreamSocket();
                Windows.Networking.HostName serverHost = new Windows.Networking.HostName(IP);
                await client.ConnectAsync(serverHost, RemotePort.ToString(), SocketProtectionLevel.PlainSocket);

                //Debug.WriteLine("Connected");
                PColl._Active = true;
                //Debug.WriteLine("Create Connection class");
                Connection con = new Connection(client, false, VaserOptions.ModeNotEncrypted, PColl, null, null, null, null);
                //Debug.WriteLine("Create Connection class DONE" );

                return(con.link);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Opens an kerberos encrypted connection to a server.
        /// </summary>
        /// <param name="IP">Hostname or IP-Address.</param>
        /// <param name="RemotePort">Target port of the remote server.</param>
        /// <param name="PColl">The Portal Collection.</param>
        /// <param name="Kerberos">The Kerberos connectionsettings.</param>
        /// <returns>Returns the link of the connection.</returns>
        /// <exception cref="System.Net.Sockets.SocketException">Thrown if vaser is unable to create a socket or a connection.</exception>

        /*public static Link ConnectClient(string IP, int RemotePort, PortalCollection PColl, VaserKerberosClient Kerberos)
         * {
         *  //if (Mode == VaserOptions.ModeSSL) throw new Exception("Missing X509Certificate2");
         *  if (PColl == null) throw new Exception("PortalCollection is needed!");
         *
         *  try
         *  {
         *      //TcpClient client = new TcpClient();
         *      Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         *      StreamSocket s = new StreamSocket();
         *      client.Connect(IP, Port);
         *      if (client.Connected)
         *      {
         *          StreamSocket client = new StreamSocket();
         *          Windows.Networking.HostName serverHost = new Windows.Networking.HostName(IP);
         *          await client.ConnectAsync(serverHost, RemotePort.ToString(), SocketProtectionLevel.);
         *
         *          PColl._Active = true;
         *          Connection con = new Connection(client, false, VaserOptions.ModeKerberos, PColl, null, null, Kerberos, null);
         *
         *          lock (Link._Static_ThreadLock)
         *          {
         *              Link.LinkList.Add(con.link);
         *          }
         *
         *          return con.link;
         *      }
         *      else
         *      {
         *          return null;
         *      }
         *  }
         *  catch (Exception e)
         *  {
         *      throw e;
         *  }
         * }*/

        /// <summary>
        /// Connect to a Vaser server via SSL.
        /// </summary>
        /// <param name="IP">Hostname or IP-Address.</param>
        /// <param name="RemotePort">Target port of the remote server.</param>
        /// <param name="PColl">The Portal Collection.</param>
        /// <param name="SSL">The SSL connectionsettings.</param>
        /// <returns>Returns the link of the connection.</returns>
        /// <exception cref="System.Net.Sockets.SocketException">Thrown if vaser is unable to create a socket or a connection.</exception>
        public static async System.Threading.Tasks.Task <Link> ConnectClient(string IP, int RemotePort, PortalCollection PColl, VaserSSLClient SSL)
        {
            if (SSL == null)
            {
                throw new Exception("Missing SSL options in ConnectClient(...)");
            }
            if (PColl == null)
            {
                throw new Exception("PortalCollection is needed!");
            }

            try
            {
                StreamSocket client = new StreamSocket();
                Windows.Networking.HostName serverHost = new Windows.Networking.HostName(IP);
                await client.ConnectAsync(serverHost, RemotePort.ToString(), SocketProtectionLevel.Tls12);

                PColl._Active = true;
                Connection con = new Connection(client, false, VaserOptions.ModeSSL, PColl, null, null, null, SSL);

                return(con.link);
            }
            catch (Exception e)
            {
                throw e;
            }
        }