Ejemplo n.º 1
0
        public void Start()
        {
            routingStatusLabel.Text = "Starting...";
            appButton.Enabled       = (appId != 0);
            mapper                    = new MeshMapper();
            mapper.xdebug             = xdebug;
            mapper.inaddrany          = inaddrany;
            mapper.certhash           = certhash;
            mapper.onStateMsgChanged += Mapper_onStateMsgChanged;
            string serverurl = "wss://" + host + "/meshrelay.ashx?auth=" + Uri.EscapeDataString(authCookie) + "&nodeid=" + node.nodeid;

            if (protocol == 1)
            {
                serverurl += ("&tcpport=" + remotePort);
                if (remoteIP != null)
                {
                    serverurl += "&tcpaddr=" + remoteIP;
                }
            }
            else if (protocol == 2)
            {
                serverurl += ("&udpport=" + remotePort);
                if (remoteIP != null)
                {
                    serverurl += "&udpaddr=" + remoteIP;
                }
            }
            mapper.start(protocol, localPort, serverurl, remotePort, remoteIP);
            UpdateInfo();
        }
Ejemplo n.º 2
0
        private void UClientEndReadWS(IAsyncResult ar)
        {
            // Fetch the state
            object[]        args    = (object[])ar.AsyncState;
            MeshMapper      mm      = (MeshMapper)args[0];
            webSocketClient wc      = (webSocketClient)args[1];
            UdpClient       uclient = (UdpClient)args[2];
            int             counter = wc.id;

            byte[] buf = null;
            try
            {
                // Read the data
                if (uclient != null)
                {
                    buf = uclient.EndReceive(ar, ref wc.endpoint);
                }
            }
            catch (Exception) { ShutdownClients(null, uclient, wc, counter); return; }

            if (buf != null)
            {
                mm.bytesToServer           += buf.Length;
                mm.bytesToServerCompressed += wc.SendBinary(buf, 0, buf.Length); // TODO: Do Async
                try { uclient.BeginReceive(new AsyncCallback(UClientEndReadWS), new object[] { mm, wc, uclient }); } catch (Exception) { }
            }
        }
Ejemplo n.º 3
0
 public void Stop()
 {
     routingStatusLabel.Text   = "Stopped.";
     appButton.Enabled         = false;
     mapper.onStateMsgChanged -= Mapper_onStateMsgChanged;
     mapper.stop();
     mapper = null;
 }
Ejemplo n.º 4
0
 private void closeButton_Click(object sender, EventArgs e)
 {
     if (mapper != null)
     {
         mapper.stop();
         mapper = null;
     }
     parent.removeMap(this);
 }
 public void Stop()
 {
     routingStatusLabel.Text = Properties.Resources.Stopped;
     appButton.Enabled       = false;
     if (mapper != null)
     {
         mapper.onStateMsgChanged -= Mapper_onStateMsgChanged; mapper.stop(); mapper = null;
     }
     if (stats != null)
     {
         stats.Close(); stats = null;
     }
 }
Ejemplo n.º 6
0
        // Read from the local client
        private void ClientEndReadWS(IAsyncResult ar)
        {
            // Fetch the state
            object[]        args   = (object[])ar.AsyncState;
            MeshMapper      mm     = (MeshMapper)args[0];
            webSocketClient wc     = (webSocketClient)args[1];
            TcpClient       client = (TcpClient)args[2];

            byte[] buf     = (byte[])args[3];
            int    counter = wc.id;

            int len = 0;

            try
            {
                // Read the data
                if (client != null && client.Connected == true)
                {
                    len = client.GetStream().EndRead(ar);
                }
            }
            catch (Exception) { ShutdownClients(client, null, wc, counter); return; }

            //Debug("#" + counter + ": ClientEndRead(" + len + ") - Local Read");
            if (len > 0)
            {
                // Forward the data & read again
                try
                {
                    mm.bytesToServer           += len;
                    mm.bytesToServerCompressed += wc.SendBinary(buf, 0, len); // TODO: Do Async
                    try { client.GetStream().BeginRead(buf, 0, buf.Length, new AsyncCallback(ClientEndReadWS), new object[] { mm, wc, client, buf }); } catch (Exception) { }
                }
                catch (Exception)
                {
                    ShutdownClients(client, null, wc, counter);
                    return;
                }
            }
            else
            {
                ShutdownClients(client, null, wc, counter);
                return;
            }
        }
        public void Start()
        {
            routingStatusLabel.Text = Properties.Resources.Starting;
            appButton.Enabled       = (appId != 0);
            mapper                    = new MeshMapper();
            mapper.xdebug             = xdebug;
            mapper.inaddrany          = inaddrany;
            mapper.certhash           = certhash;
            mapper.onStateMsgChanged += Mapper_onStateMsgChanged;
            string serverurl;
            int    keyIndex = host.IndexOf("?key=");

            if (keyIndex >= 0)
            {
                serverurl = "wss://" + host.Substring(0, keyIndex) + "/meshrelay.ashx?nodeid=" + node.nodeid + "&key=" + host.Substring(keyIndex + 5);
            }
            else
            {
                serverurl = "wss://" + host + "/meshrelay.ashx?nodeid=" + node.nodeid;
            }
            if (protocol == 1)
            {
                serverurl += ("&tcpport=" + remotePort);
                if (remoteIP != null)
                {
                    serverurl += "&tcpaddr=" + remoteIP;
                }
            }
            else if (protocol == 2)
            {
                serverurl += ("&udpport=" + remotePort);
                if (remoteIP != null)
                {
                    serverurl += "&udpaddr=" + remoteIP;
                }
            }
            mapper.start(parent.meshcentral, protocol, localPort, serverurl, remotePort, remoteIP);
            UpdateInfo();
        }
Ejemplo n.º 8
0
            public bool StartEx(MeshMapper parent, Uri url, string certhash, int counter)
            {
                if (state != 0)
                {
                    return(false);
                }
                state         = 1;
                this.parent   = parent;
                this.url      = url;
                this.counter  = counter;
                this.certhash = certhash;
                if (client != null)
                {
                    this.stream = client.GetStream();
                }
                Uri proxyUri = null;

                ++parent.totalConnectCounter;
                parent.UpdateInfo();

                // Check if we need to use a HTTP proxy (Auto-proxy way)
                try
                {
                    RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
                    Object      x           = registryKey.GetValue("AutoConfigURL", null);
                    if ((x != null) && (x.GetType() == typeof(string)))
                    {
                        string proxyStr = GetProxyForUrlUsingPac("http" + ((url.Port == 80) ? "" : "s") + "://" + url.Host + ":" + url.Port, x.ToString());
                        if (proxyStr != null)
                        {
                            proxyUri = new Uri("http://" + proxyStr);
                        }
                    }
                }
                catch (Exception) { proxyUri = null; }

                // Check if we need to use a HTTP proxy (Normal way)
                if (proxyUri == null)
                {
                    var proxy = System.Net.HttpWebRequest.GetSystemWebProxy();
                    proxyUri = proxy.GetProxy(url);
                    if ((url.Host.ToLower() == proxyUri.Host.ToLower()) && (url.Port == proxyUri.Port))
                    {
                        proxyUri = null;
                    }
                }

                if (proxyUri != null)
                {
                    // Proxy in use
                    proxyInUse = true;
                    wsclient   = new TcpClient();
                    wsclient.BeginConnect(proxyUri.Host, proxyUri.Port, new AsyncCallback(OnConnectSink), this);
                }
                else
                {
                    // No proxy in use
                    proxyInUse = false;
                    wsclient   = new TcpClient();
                    wsclient.BeginConnect(url.Host, url.Port, new AsyncCallback(OnConnectSink), this);
                }
                return(true);
            }
Ejemplo n.º 9
0
 public bool Start(MeshMapper parent, Uri url, string certhash, UdpClient client, int counter)
 {
     this.uclient = client;
     return(StartEx(parent, url, certhash, counter));
 }