public ServerCommunicationHandler(MainWindow main_window, CancellationToken cancel_token, Tunnel.TunnelManager tunnel_manager, UserManager user_manager, IPEndPoint server_endpoint)
 {
     _main_window = main_window;
     _cancel_token = cancel_token;
     _tunnel_manager = tunnel_manager;
     _server_endpoint = server_endpoint;
     _server_connection = new TcpClient();
     _messages = new List<Message>();
     _user_manager = user_manager;
 }
Esempio n. 2
0
            private void HandleData(byte[] data, Tunnel tunnel, IPEndPoint ip_endpoint)
            {
                if (ip_endpoint.Address.Equals(_server_endpoint.Address))
                {
                    if (tunnel.state != TunnelState.InformedServer)
                    {
                        Trace.TraceError("Received unexpected message from server on a tunnel socket");
                        return; // Continue
                    }

                    throw new NotImplementedException("Read data from server, open connection to remote");
                }
                else if (tunnel.tunnel_connection != null && ip_endpoint.Address.Equals(tunnel.tunnel_connection.Client.RemoteEndPoint))
                {
                    if (tunnel.state < TunnelState.Connecting)
                    {
                        Trace.TraceError("Received message from remote endpoint before expected");
                        return; // Continue
                    }
                    else if (tunnel.state == TunnelState.Connecting || tunnel.state == TunnelState.Halfway)
                    {
                        throw new NotImplementedException("See if it's a ping or a pong and act accordingly");
                        // State to change to when we receive ping/pong and we're connecting/halfway:
                        //          Connecting      Halfway
                        // Ping     Halfway         Halfway
                        // Pong     Connected       Connected
                    }
                }
                else
                {
                    // Assume that it's coming from the local host
                    // TODO: Figure out how to verify it's from the local host
                    throw new NotImplementedException("Forward data");
                }
            }
Esempio n. 3
0
 /// <summary>
 /// Add a new tunnel to the manager for the manager to take care of.
 /// </summary>
 public void AddTunnel(Tunnel tunnel)
 {
     lock (_tunnels_to_add)
         _tunnels_to_add.Add(tunnel);
 }