Exemple #1
0
        private void ChangeLabel(MPLSPacket packet)
        {
            int oldPort  = packet.DestinationPort;
            int oldLabel = packet.GetLabelFromStack();

            int[] FIBOutput = fib.GetOutput(oldPort, oldLabel, packet.ipPacket.destinationAddress);
            int   port      = FIBOutput[0];
            int   label     = FIBOutput[1];

            packet.DestinationPort = port;
            LogClass.WhiteLog("MPLSPacket from inPort " + oldPort + ": old label = " + oldLabel);
            if (label != 0)
            {
                packet.PutLabelOnStack(label);
                Console.WriteLine("            | new label = " + label);
            }
            else
            {
                Console.WriteLine("            | old label removed");
            }

            if (fib.LookForLabelToBeAdded(oldPort, oldLabel) != 0)
            {
                int addingLabel = fib.LookForLabelToBeAdded(oldPort, oldLabel);
                packet.PutLabelOnStack(fib.LookForLabelToBeAdded(oldPort, oldLabel));
                LogClass.Log("Starting new tunnel with label " + addingLabel);
                ChangeLabel(packet);
            }
            else if (fib.LookForLabelToBeRemoved(oldPort, oldLabel) != 0)
            {
                LogClass.Log("Ending tunnel");
                ChangeLabel(packet);
            }
        }
    // 指令請求, 回復success / error / norespond
    public String SendRequestWithUrl(string Url, string strCommand)
    {
        string data = GetStringWithUrl(Url, strCommand);

        try
        {
            JObject jObj = JObject.Parse(data);

            var result = (string)jObj.Descendants()
                         .OfType <JProperty>()
                         .Where(p => p.Name == "state")
                         .First().Value;

            return(result);
        }
        catch (Exception e)
        {
            LogClass logClass = new LogClass();
            logClass.Log(e.Source + "發生錯誤,原因" + e.Message);

            Newtonsoft.Json.JsonReaderException jsexp = new Newtonsoft.Json.JsonReaderException();
            StreamWriter streamWriter = new StreamWriter("LOG.txt");
            streamWriter.WriteLine(jsexp.ToString());
            streamWriter.WriteLine(data);
            streamWriter.Close();

            return(null);
        }
    }
        public void SendEmail(string to, string subject, string body, string from, string password)
        {
            try
            {
                MailMessage email = new MailMessage();
                SmtpClient  smtp  = new SmtpClient();
                smtp.Host = "smtp.gmail.com";

                // set up the Gmail server
                smtp.EnableSsl             = true;
                smtp.Port                  = 587;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential(from, password);
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;

                // draft the email
                MailAddress fromAddress = new MailAddress(from);
                email.From = fromAddress;
                email.To.Add(to);
                email.Subject = subject;
                email.Body    = body;

                smtp.Send(email);
            }
            catch (Exception e)
            {
                LogClass logClass = new LogClass();
                logClass.Log("Error sending email - carring on any ways - " + e);
            }
        }
Exemple #4
0
 public static void userAuthentication(string userName)
 {
     if (AddressesTable.isUserAuthenticated(userName))
     {
         LogClass.Log(userName + " authentication successful.");
     }
 }
Exemple #5
0
        public void DeleteLink(string begin, string end)
        {
            Link linkToBeDeleted = links.Find(x => (x.FirstSNPP.Address == begin && x.SecondSNPP.Address == end));

            deletedLinks.Add(linkToBeDeleted);
            links.Remove(linkToBeDeleted);
            LogClass.Log("[RC] Removed link: " + linkToBeDeleted.FirstSNPP.Address + " - " + linkToBeDeleted.SecondSNPP.Address + " from RC.");
        }
    private static string ReadStreamFromResponse(WebResponse response)
    {
        using (Stream responseStream = response.GetResponseStream())
            // Pipe the stream to a higher level stream reader with the required encoding format.
            using (StreamReader objReader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8")))
            {
                String data = objReader.ReadToEnd();
                try
                {
                    if (data == null || data.Length == 0)
                    {
                        return(null);
                    }


                    while (true)
                    {
                        if (data[0] != '{')
                        {
                            data = data.Substring(1);
                        }
                        else
                        {
                            break;
                        }
                    }

                    return(data);
                }
                catch (Exception e)
                {
                    LogClass logClass = new LogClass();
                    logClass.Log("Exception:" + e.Message);
                    logClass.Log(" API Connect GetString Error" + data);
                    return(null);
                }
            }

        /*
         * using (StreamReader sr = new StreamReader(responseStream))
         * {
         *  //Need to return this response
         *  string strContent = sr.ReadToEnd();
         *  return strContent;
         * }*/
    }
Exemple #7
0
    public static void actionLog()
    {
        LogClass logClass = new LogClass();
        string   strMSG   = "";

        ScreenShotService.ScreenShotClass serviceScreenShot = new ScreenShotService.ScreenShotClass();
        serviceScreenShot.CaptureScreen(objConfig.ScreenShotPath);
        strMSG = "Logging addtional card infomation. \r\n" + getCardDetails();
        logClass.Log(strMSG);
    }
Exemple #8
0
        public static bool SendConnectionRequest(SNP pathBegin, SNP pathEnd, SubnetworkAddress subnetworkAddress)
        {
            Tuple <SNP, SNP> connTuple = new Tuple <SNP, SNP>(pathBegin, pathEnd);
            bool             hasValue  = SocketsByAddress.TryGetValue(subnetworkAddress, out childSubSocket);

            if (hasValue)
            {
                if (pathBegin.Deleting)
                {
                    childSubSocket.SendObject(DELETE_CONNECTION_REQUEST, connTuple);
                }
                else
                {
                    childSubSocket.SendObject(CONNECTION_REQUEST_FROM_CC, connTuple);
                }

                while (!(acked || nacked))
                {
                    Thread.Sleep(30);
                }

                if (acked)
                {
                    if (pathBegin.Deleting)
                    {
                        LogClass.MagentaLog("Subnetwork " + subnetworkAddress.subnetAddress + " deleted connection between: " + pathBegin.Address + " and " + pathEnd.Address);
                    }
                    else
                    {
                        LogClass.GreenLog("Subnetwork " + subnetworkAddress.subnetAddress + " set connection between: " + pathBegin.Address + " and " + pathEnd.Address);
                    }
                    acked = false;
                    return(true);
                }
                else if (nacked)
                {
                    if (pathBegin.Deleting)
                    {
                        LogClass.Log("Subnetwork " + subnetworkAddress.subnetAddress + " can't delete the connection between: " + pathBegin.Address + " and " + pathEnd.Address);
                    }
                    else
                    {
                        LogClass.Log("Subnetwork " + subnetworkAddress.subnetAddress + " can't set up the connection between: " + pathBegin.Address + " and " + pathEnd.Address);
                    }
                    nacked = false;
                    return(false);
                }
            }
            else
            {
                LogClass.Log("Can't find subnetwork: " + subnetworkAddress.ToString());
            }
            return(false);
        }
Exemple #9
0
 protected DataSet loadByPrimaryKey(string key)
 {
     string[] options = new string[2];
     options[0] = key;
     try
     {
         //localCN.Open();
         //localCN.ConnectionString = connectionString;
         string stmt = prepareStatement(loadStmt, options);
         System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(stmt, GlobalShared.CN.ConnectionString);
         DataSet ds = new DataSet(DS_DATA_SET);
         da.Fill(ds, DS_DATA_SET);
         ColumnCount = ds.Tables[0].Columns.Count;
         return(ds);
     }
     catch (System.Data.SqlClient.SqlException ex)
     {
         MessageBox.Show("Error while retrieving record from " + localTable + ": " + ex.Message);
         return(null);
     }
     catch (System.Exception ex)
     {
         ErrorMessage = ex.Message;
         Log.Log((int)LogClass.logType.ErrorCondition, "Error while retrieveing record from " + localTable + ": " + ex.Message);
         return(null);
     }
     finally
     {
         try
         {
             if (localCN.State == ConnectionState.Open)
             {
                 localCN.Close();
             }
         }
         catch
         {
         }
     }
 }
Exemple #10
0
        public bool DeletePeerCoordinationIn(SNP pathBegin, string pathEnd)
        {
            LogClass.Log("[DEBUG] incoming deletepeercoordination from" + pathBegin.Address + " to " + pathEnd);
            List <SNP> SNPList = null;

            foreach (string[] key in existingConnections.Keys)
            {
                if ((key[0] == pathBegin.Address && key[1] == pathEnd) || (key[1] == pathBegin.Address && key[0] == pathEnd))
                {
                    SNPList = existingConnections[key];
                }
            }

            //w kazdym SNP ustaw "deleting" na true
            SNPList.ForEach(x => x.Deleting = true);

            //usuniecie alokacji w LRM
            for (int index = 0; index < SNPList.Count; index += 2)
            {
                SNP SNPpathBegin = SNPList[index];
                SNP SNPpathEnd   = SNPList[index + 1];
                DeleteLinkConnectionRequest(SNPpathBegin, SNPpathEnd);
            }

            //Wysłanie DeleteConnectionRequesta do podsieci, jeżeli na liscie SNP znajdą się 2 adresy brzegowe tej podsieci

            for (int index = 0; index < SNPList.Count - 1; index++)
            {
                SNP SNPpathBegin = SNPList[index];
                for (int jndex = index + 1; jndex < SNPList.Count; jndex++)
                {
                    SNP SNPpathEnd = SNPList[jndex];
                    if (BelongsToSubnetwork(SNPpathBegin, SNPpathEnd))
                    {
                        if (DeleteConnectionRequestOut(SNPpathBegin, SNPpathEnd))
                        {
                            LogClass.Log("Deleting " + SNPpathBegin.Address + " - " + SNPpathEnd.Address + " successful.");
                        }
                        else
                        {
                            LogClass.Log("Epic fail xD");
                            return(false);
                        }
                    }
                }
            }


            return(true);  //Jesli polaczenie zestawiono poprawnie
        }
    public JObject GetJObjectSelectSQLWithUrl(string strUrl, string sql_query)
    {
        try
        {
            JObject jObj = GetJObjectWithUrl(strUrl, "api_lottery.php?action=getFreeList&select_str=" + sql_query);

            return(jObj);
        }
        catch (Exception e)
        {
            LogClass logClass = new LogClass();
            logClass.Log(e.Source + "發生錯誤,原因" + e.Message + "SQL:" + sql_query);
            return(null);
        }
    }
Exemple #12
0
        public static void SendDeleteConnectionRequest(string pathBeginAddress, string pathEndAddress, SubnetworkAddress subnetAddress)
        {
            Tuple <string, string> deleteTuple = new Tuple <string, string>(pathBeginAddress, pathEndAddress);
            CSocket childSubSocket;
            bool    hasValue = SocketsByAddress.TryGetValue(subnetAddress, out childSubSocket);

            if (hasValue)
            {
                childSubSocket.SendObject(DELETE_CONNECTION_REQUEST, deleteTuple);
            }
            else
            {
                LogClass.Log("Can't find subnetwork: " + subnetAddress.ToString());
            }
        }
    // 指令請求, 回復success / error / norespond
    public String SendRequest(string strCommand)
    {
        /*
         * sURL = BaseURL + strCommand;
         *
         * WebRequest wrGETURL;
         * wrGETURL = WebRequest.Create(sURL);
         *
         * Stream objStream;
         * objStream = wrGETURL.GetResponse().GetResponseStream();
         * StreamReader objReader = new StreamReader(objStream);
         *
         *
         *
         *
         * var data = objReader.ReadToEnd();
         * if (data == null) return "norespond";
         */

        string data = GetStringWithUrl(BaseURL, strCommand);

        try
        {
            JObject jObj = JObject.Parse(data);

            var result = (string)jObj.Descendants()
                         .OfType <JProperty>()
                         .Where(p => p.Name == "state")
                         .First().Value;

            return(result);
        }
        catch (Exception e)
        {
            LogClass logClass = new LogClass();
            logClass.Log(e.Source + "發生錯誤,原因" + e.Message);

            Newtonsoft.Json.JsonReaderException jsexp = new Newtonsoft.Json.JsonReaderException();
            StreamWriter streamWriter = new StreamWriter("LOG.txt");
            streamWriter.WriteLine(jsexp.ToString());
            streamWriter.WriteLine(data);
            streamWriter.Close();

            return(null);
        }
    }
Exemple #14
0
        private static void ProcessConnectInformation(CSocket connectedSocket)
        {
            Tuple <string, object>      received            = connectedSocket.ReceiveObject();
            Dictionary <string, string> receivedInformation = (Dictionary <string, string>)received.Item2;

            if (receivedInformation.Count == 0)
            {
                toNCCSocket = connectedSocket;
            }
            else
            {
                String            operatedSubnetwork     = receivedInformation[OPERATED_SUBNETWORK];
                String            operatedSubnetworkMask = receivedInformation[OPERATED_SUBNETWORK_MASK];
                SubnetworkAddress connectedSubnetAddress = new SubnetworkAddress(operatedSubnetwork, operatedSubnetworkMask);
                SocketsByAddress.Add(connectedSubnetAddress, connectedSocket);
                LogClass.Log("Subnetwork " + operatedSubnetwork + " connected.");
            }
        }
Exemple #15
0
        public bool DeleteConnectionRequestOut(SNP pathBegin, SNP pathEnd)
        {
            LogClass.Log("[DEBUG] sending delete connection request out between " + pathBegin.Address + " and " + pathEnd.Address);
            //wysyla do cc poziom niżej wiadomosc usuwaj jak szalony konik
            IPAddress subnetworkAddress     = null;
            IPAddress subnetworkAddressMask = null;

            foreach (SubnetworkAddress sub in ContainedSubnetworksAddresses)
            {
                if (IPAddressExtensions.IsInSameSubnet(sub.subnetAddress, IPAddress.Parse(pathBegin.Address), sub.subnetMask))
                {
                    subnetworkAddress     = sub.subnetAddress;
                    subnetworkAddressMask = sub.subnetMask;
                }
            }
            SubnetworkAddress subnetAddress = new SubnetworkAddress(subnetworkAddress.ToString(), subnetworkAddressMask.ToString());

            SubnetworkServer.SendConnectionRequest(pathBegin, pathEnd, subnetAddress);
            return(true);
        }
    public JObject StringConvertJObj(string strJson)
    {
        try
        {
            JObject jObj = JObject.Parse(strJson.ToString());
            return(jObj);
        }
        catch (Exception e)
        {
            LogClass logClass = new LogClass();
            logClass.Log(e.Source + "發生錯誤,原因" + e.Message);

            Newtonsoft.Json.JsonReaderException jsexp = new Newtonsoft.Json.JsonReaderException();
            StreamWriter streamWriter = new StreamWriter("LOG.txt");
            streamWriter.WriteLine(jsexp.ToString());
            streamWriter.WriteLine(strJson);
            streamWriter.Close();

            return(null);
        }
    }
    public JObject GetJObject(string strCommand)
    {
        string data = GetStringWithUrl(BaseURL, strCommand);

        try
        {
            JObject jObj = JObject.Parse(data.ToString());
            return(jObj);
        }
        catch (Exception e)
        {
            LogClass logClass = new LogClass();
            logClass.Log(e.Source + "發生錯誤,原因" + e.Message);

            Newtonsoft.Json.JsonReaderException jsexp = new Newtonsoft.Json.JsonReaderException();
            StreamWriter streamWriter = new StreamWriter("LOG.txt");
            streamWriter.WriteLine(jsexp.ToString());
            streamWriter.WriteLine(data);
            streamWriter.Close();

            return(null);
        }
    }
Exemple #18
0
 static void ExecuteCommand(string command)
 {
     //Execute in new CMD window incase of error or hang
     try
     {
         //Setup command
         ProcessStartInfo processInfo;
         Process          process;
         processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
         processInfo.CreateNoWindow  = true;
         processInfo.UseShellExecute = true;
         //Execute command
         process = Process.Start(processInfo);
         //Don't want to wait for exit incase bat hangs give it two minutes then carry on
         CountDown(objConfig.Delay / 2, "Waiting for half a delay period for " + command + " to have time to finish.");
         process.Close();
     }
     catch (Exception e)
     {
         LogClass logClass = new LogClass();
         logClass.Log("Error executing - " + command + "\r\nError - " + e);
     }
 }
Exemple #19
0
        public bool ConnectionRequestFromCC(SNP pathBegin, SNP pathEnd)
        {
            List <SNPP> SNPPList = RouteTableQuery(pathBegin.Address, pathEnd.Address, pathBegin.OccupiedCapacity);

            //Lista SNP dla tworzonego aktualnie polaczenia
            List <SNP> SNPList = new List <SNP>();

            SNPList.Add(pathBegin);
            SNPList.Add(pathEnd);

            for (int index = 0; index < SNPPList.Count; index += 2)
            {
                SNPP             SNPPpathBegin = SNPPList[index];
                SNPP             SNPPpathEnd   = SNPPList[index + 1];
                Tuple <SNP, SNP> SNPpair       = LinkConnectionRequest(SNPPpathBegin, SNPPpathEnd, pathBegin.OccupiedCapacity);
                SNPList.Add(SNPpair.Item1);
                SNPList.Add(SNPpair.Item2);
            }

            //Zapamietaj SNPlist z polaczeniem mdzy takimi adresami
            existingConnections.Add(new string[] { pathBegin.Address, pathEnd.Address }, SNPList);

            //Wysłanie ConnectionRequesta do podsieci, jeżeli na liscie SNP zajdą się 2 adresy brzegowe tej podsieci
            List <SNP> connected = new List <SNP>();

            for (int index = 0; index < SNPList.Count - 1; index++)
            {
                SNP SNPpathBegin = SNPList[index];
                for (int jndex = index + 1; jndex < SNPList.Count; jndex++)
                {
                    SNP SNPpathEnd = SNPList[jndex];
                    if (BelongsToSubnetwork(SNPpathBegin, SNPpathEnd))
                    {
                        if (ConnectionRequestOut(SNPpathBegin, SNPpathEnd))
                        {
                            connected.Add(SNPpathBegin);
                            connected.Add(SNPpathEnd);
                            LogClass.Log("Subnetwork Connection set properly.");
                        }
                        else
                        {
                            connected.ForEach(x => x.Deleting = true);
                            for (int i = 0; i < connected.Count; i += 2)
                            {
                                DeleteLinkConnectionRequest(connected.ElementAt(i), connected.ElementAt(i + 1));
                            }
                            for (int i = 0; i < connected.Count; i += 2)
                            {
                                ConnectionRequestOut(connected.ElementAt(i), connected.ElementAt(i + 1));
                            }
                            SubnetworkServer.callIgnoreLinkInRC(SNPpathBegin);
                            SubnetworkServer.callIgnoreLinkInRC(SNPpathEnd);

                            LogClass.Log("Epic fail.");
                            return(false);
                        }
                    }
                }
            }

            return(true);  //Jesli polaczenie zestawiono poprawnie
        }
Exemple #20
0
 public void UpdateFIB(List <Entry> table)
 {
     fib.UpdateRoutingTable(table);
     LogClass.Log("Updating FIB in inPort " + portNumber);
     fib.DisplayFIB(portNumber);
 }
    public String GetStringWithUrl(string strUrl, string strCommand)
    {
        LogClass log = new LogClass();

        sURL = strUrl + strCommand;

        log.Log(sURL);
#if ASYNC
        try
        {
            var task = MakeAsyncRequest(sURL, "text/html");

            return(task.Result);
        }
        catch (Exception e)
        {
            LogClass logClass = new LogClass();
            logClass.Log("Exception:" + e.Message);
            logClass.Log(" API Connect GetString Error" + sURL);
            return(null);
        }
        //Console.WriteLine("Got response of {0}", task.Result);
#else
        //HttpClient httpClient = new HttpClient();

        // Create a 'WebRequest' object with the specified url.
        WebRequest myWebRequest = WebRequest.Create(sURL);

        // Send the 'WebRequest' and wait for response.
        WebResponse myWebResponse = myWebRequest.GetResponse();
        //myWebRequest.Method = WebRequestMethods.Http.Post;

        // Obtain a 'Stream' object associated with the response object.
        Stream ReceiveStream = myWebResponse.GetResponseStream();

        Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

        // Pipe the stream to a higher level stream reader with the required encoding format.
        StreamReader objReader = new StreamReader(ReceiveStream, encode);

        /*
         * sURL = BaseURL + strCommand;
         *
         * WebRequest wrGETURL;
         * wrGETURL = WebRequest.Create(sURL);
         *
         * Stream objStream;
         * objStream = wrGETURL.GetResponse().GetResponseStream();
         * StreamReader objReader = new StreamReader(objStream);
         */
        String data = objReader.ReadToEnd();
        try
        {
            if (data == null || data.Length == 0)
            {
                return(null);
            }


            while (true)
            {
                if (data[0] != '{')
                {
                    data = data.Substring(1);
                }
                else
                {
                    break;
                }
            }

            return(data);

            /*
             * string data2;
             * if (data[0] != '{')
             * {
             *  data2 = data.Substring(1);
             * }
             * else
             * {
             *  data2 = data;
             * }
             * return data2;
             */
        }
        catch (Exception e)
        {
            LogClass logClass = new LogClass();
            logClass.Log("Exception:" + e.Message);
            logClass.Log(" API Connect GetString Error" + data);
            return(null);
        }
#endif
    }
Exemple #22
0
        public bool PeerCoordinationIn(SNP pathBegin, string pathEnd)
        {
            LogClass.Log("[DEBUG] incoming peercoordination from" + pathBegin.Address + " to " + pathEnd);
            string[] existingConnKey     = new string[] { pathBegin.Address, pathEnd };
            string   beginAddressForDict = pathBegin.Address;
            //Lista SNP dla tworzonego aktualnie polaczenia
            List <SNP> SNPList = new List <SNP>();

            //sprawdza, z ktorej domeny przyszedl SNP i podmienia jego adres na adres swojego SNPP brzegowego
            foreach (SubnetworkAddress domainAddress in OtherDomainSNPPAddressTranslation.Keys)
            {
                if (IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(pathBegin.Address), domainAddress.subnetAddress, domainAddress.subnetMask))
                {
                    Tuple <IPAddress, IPAddress> foundTranslation = OtherDomainSNPPAddressTranslation[domainAddress].Find(x => x.Item1.ToString() == pathBegin.Address);
                    IPAddress translatedAddress = foundTranslation.Item2;
                    Console.WriteLine("TRANSALATED FROM" + pathBegin.Address + " TO " + translatedAddress.ToString());
                    pathBegin.Address = translatedAddress.ToString();
                }
            }
            Console.WriteLine("DEFENITELY TRANSALATED TO " + pathBegin.Address);
            //przepustowosc bierzemy z przekazanego SNP

            SNPList.Add(new SNP(pathBegin.Label, pathBegin.Address, pathBegin.OccupiedCapacity, null, null));
            SNPList.Add(new SNP(0, pathEnd, pathBegin.OccupiedCapacity, pathBegin.PathBegin, pathBegin.PathEnd));

            //Zapamietaj SNPlist z polaczeniem mdzy takimi adresami
            existingConnections.Add(existingConnKey, SNPList);

            List <SNPP> SNPPList = RouteTableQuery(pathBegin.Address, pathEnd, pathBegin.OccupiedCapacity);

            for (int index = 0; index < SNPPList.Count; index += 2)
            {
                SNPP             SNPPpathBegin = SNPPList[index];
                SNPP             SNPPpathEnd   = SNPPList[index + 1];
                Tuple <SNP, SNP> SNPpair       = LinkConnectionRequest(SNPPpathBegin, SNPPpathEnd, pathBegin.OccupiedCapacity);
                SNPList.Add(SNPpair.Item1);
                SNPList.Add(SNPpair.Item2);
            }

            //Wysłanie ConnectionRequesta do podsieci, jeżeli na liscie SNP zajdą się 2 adresy brzegowe tej podsieci
            List <SNP> connected = new List <SNP>();

            for (int index = 0; index < SNPList.Count - 1; index++)
            {
                SNP SNPpathBegin = SNPList[index];
                for (int jndex = index + 1; jndex < SNPList.Count; jndex++)
                {
                    SNP SNPpathEnd = SNPList[jndex];

                    if (BelongsToSubnetwork(SNPpathBegin, SNPpathEnd))
                    {
                        LogClass.WhiteLog("[DEBUG] Sending ConnectionRequest between" + SNPpathBegin.Address + SNPpathEnd.Deleting + "and" + SNPpathEnd.Address + SNPpathBegin.Deleting);
                        if (ConnectionRequestOut(SNPpathBegin, SNPpathEnd))
                        {
                            connected.Add(SNPpathBegin);
                            connected.Add(SNPpathEnd);
                            LogClass.Log("Subnetwork Connection set properly.");
                        }
                        else
                        {
                            connected.ForEach(x => x.Deleting = true);
                            for (int i = 0; i < connected.Count; i += 2)
                            {
                                DeleteLinkConnectionRequest(connected.ElementAt(i), connected.ElementAt(i + 1));
                            }

                            for (int i = 0; i < connected.Count; i += 2)
                            {
                                ConnectionRequestOut(connected.ElementAt(i), connected.ElementAt(i + 1));
                                LogClass.WhiteLog("[DEBUG] Sending DeleteConnectionRequest between" + SNPpathBegin.Address + SNPpathEnd.Deleting + "and" + SNPpathEnd.Address + SNPpathBegin.Deleting);
                            }
                            SubnetworkServer.callIgnoreLinkInRC(SNPpathBegin);
                            SubnetworkServer.callIgnoreLinkInRC(SNPpathEnd);

                            LogClass.Log("Epic fail.");
                            return(false);
                        }
                    }
                }
            }

            return(true);  //Jesli polaczenie zestawiono poprawnie
        }
Exemple #23
0
    public static int intTestCount = 0;            //Just a global variable for counting test loops please ignore my poor coding standards
    static void Main()
    {
        try
        {
            //Declaring and initilizing some stuff probaly more stuff then i need
            EmailClass emailClass = new EmailClass();
            LogClass   logClass   = new LogClass();
            string[]   strUtilization;
            int        intStrikes      = 0;
            int        intMissing      = 0;
            bool       bReboot         = false;
            bool       bAddStrike      = false;
            string     strMsg          = "";
            bool       bRestartedMiner = false;
            int        intEvents       = 10;
            //Get config values from the config file
            try
            {
                getConfig();
            }
            catch (Exception e)
            {
                logClass.Log("Error loading config. Check config file exiting program - " + e);
                Environment.Exit(1);
            }
            logClass.Log("Starting process assuming reboot because I don't feel like checking.");
            //Send Email starting up
            if (objConfig.SendEmail != "no")
            {
                logClass.Log("Sending Email");
                emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "Monitoring is starting", "Monitoring is starting", objConfig.FromEmailAddress, objConfig.FromEmailPassword);
            }
            //Half a delay checks to give the computer time to get going. Added fancy count down.
            CountDown(objConfig.Delay / 2);
            //Delete old log files
            logClass.DeleteOldLogs(3);
            //If startup bat present run it
            if (objConfig.StartBat != "")
            {
                try
                {
                    logClass.Log("Starting miner command - " + objConfig.StartBat);
                    ExecuteCommand(objConfig.StartBat);
                }
                catch (Exception e)
                {
                    logClass.Log("Error starting miner- attemping notification - " + e);
                    if (objConfig.SendEmail != "no")
                    {
                        emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "Miner failed to start", "Miner failed to start check log", objConfig.FromEmailAddress, objConfig.FromEmailPassword);
                    }
                }
            }
            if (objConfig.ProdOrTest == "test")
            {
                logClass.Log("\r\nUsing Test Data!!!\r\n");
            }
            //Loop till something breaks
            while (!bReboot)
            {
                //Clear message for every loop
                strMsg = "";
                //Decide if we are using real values or test values
                if (objConfig.ProdOrTest != "test")
                {
                    strUtilization = getUtilization();
                }
                else
                {
                    strUtilization = testgetUtilization();
                }
                //Convert the string utilizations into ints so we can do some math.
                int[] intUtilization = Array.ConvertAll(strUtilization, delegate(string s) { return(int.Parse(s)); });
                //Make sure all cards are utilized above threshold
                if (checkUtilization(intUtilization, ref strMsg))
                {
                    bAddStrike = true;
                }
                //Make sure all cards are present
                else if (intUtilization.Length < objConfig.NumberOfGPUS)
                {
                    bAddStrike = true;
                    intMissing = objConfig.NumberOfGPUS - intUtilization.Length;
                    strMsg     = strMsg + "\r\nThe Ugly - " + intMissing + " GPUs are missing \r\n";
                }
                //Clean run new batter clear the board
                else
                {
                    //If there was strike log the next good run before clearing the board
                    if (intStrikes > 0)
                    {
                        logClass.Log(strMsg);
                        intStrikes = 0;
                    }
                    else
                    {
                        Console.Write("\r\n" + DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt") + " - " + strMsg);
                    }
                    bRestartedMiner = false;
                }
                //If Error Log int
                if (strMsg.Contains("Bad") || strMsg.Contains("Ugly"))
                {
                    logClass.Log(strMsg);
                }
                //If error and internet is up count it as strike
                if (bAddStrike)
                {
                    //Check for internet connection before looking for strikes. If not internet/pool then no need to try anything.
                    if (CheckForInternetConnection())
                    {
                        intStrikes++;
                    }
                    else
                    {
                        logClass.Log("Internet check failed strike not counted.");
                    }
                }
                //Check if we need attempt to restart computer
                if (intStrikes >= objConfig.ComputerStrikes)
                {
                    bReboot = true;
                }
                //Check if we need to attempt to restart miner
                else if (intStrikes >= objConfig.MinerStrikes)
                {
                    //If restart bat present execute it
                    if (objConfig.RestartBat != "")
                    {
                        try
                        {
                            if (!bRestartedMiner)
                            {
                                bRestartedMiner = true;
                                logClass.Log("Restarting miner command - " + objConfig.StartBat);
                                actionLog();
                                ExecuteCommand(objConfig.RestartBat);
                                if (objConfig.SendEmail != "no")
                                {
                                    emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + " Restarting Miner Program", logClass.returnEvents(intEvents), objConfig.FromEmailAddress, objConfig.FromEmailPassword);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            logClass.Log("Error - attemping notification if enabled - " + e);
                            if (objConfig.SendEmail != "no")
                            {
                                emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "Miner failed to restart", "Miner failed to restart. Monitoring will continue and computer restart may be attempted if enabled.\r\n" + logClass.returnEvents(intEvents), objConfig.FromEmailAddress, objConfig.FromEmailPassword);
                            }
                        }
                    }
                    else
                    {
                        logClass.Log("Miner strike set but no bat file provided!");
                    }
                }

                //sleep for the set delay
                CountDown(objConfig.Delay);
            }
            //Well crap we made it out time to reboot
            actionLog();
            if (objConfig.Restart != "no")
            {
                //Send Email something went wrong
                if (objConfig.SendEmail != "no")
                {
                    logClass.Log("Sending Email");
                    emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "struck out rebooting", "Rebooting\r\n" + logClass.returnEvents(intEvents), objConfig.FromEmailAddress, objConfig.FromEmailPassword);
                }
                logClass.Log("Attemping reboot with force");
                strMsg = "-r -f -t 60 -c \"" + strMsg + "\"";
                System.Diagnostics.Process.Start("shutdown.exe", strMsg);
            }
            else
            {
                logClass.Log("Computer struck out but reboot is disabled.");
                if (objConfig.SendEmail != "no")
                {
                    emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "struck out", "Reboot is diabled taking no farther action to be taken. Stopping monitoring \r\n" + logClass.returnEvents(intEvents), objConfig.FromEmailAddress, objConfig.FromEmailPassword);
                }
            }
        }
        catch (Exception e)
        {
            LogClass logClass = new LogClass();
            logClass.Log("Fatal exception - " + e);
        }
    }
Exemple #24
0
    //Reads values from the file and puts them in the global object
    public static void getConfig()
    {
        LogClass logClass = new LogClass();

        logClass.Log("***Starting Config****");
        string strNumberOfGPUS = ConfigurationManager.AppSettings.Get("NumberOfGPUS");

        logClass.Log("Number of GPUS - " + strNumberOfGPUS);
        string strDelay = ConfigurationManager.AppSettings.Get("Delay");

        logClass.Log("Delay between checks - " + strDelay + " minutes");
        string strToEmailAddress = ConfigurationManager.AppSettings.Get("ToEmailAddress");

        logClass.Log("Notification to email - " + Mask(strToEmailAddress, 2));
        string strFromEmailAddress = ConfigurationManager.AppSettings.Get("FromEmailAddress");

        logClass.Log("Notification from email - " + Mask(strFromEmailAddress, 2));
        string strFromEmailPassword = ConfigurationManager.AppSettings.Get("FromEmailPassword");

        logClass.Log("Notification from email password - " + Mask(strFromEmailPassword));
        string strProdOrTest = ConfigurationManager.AppSettings.Get("ProdOrTest");

        logClass.Log("Prod or Test - " + strProdOrTest);
        string strSendEmail = ConfigurationManager.AppSettings.Get("SendEmail");

        logClass.Log("Sending notification emails - " + strSendEmail);
        string strComputerStrikes = ConfigurationManager.AppSettings.Get("ComputerStrikes");

        logClass.Log("How many strikes before restarting - " + strComputerStrikes);
        string strMinerStrikes = ConfigurationManager.AppSettings.Get("MinerStrikes");

        logClass.Log("How many strikes before executing restart bat - " + strMinerStrikes);
        string strRestartBat = ConfigurationManager.AppSettings.Get("RestartBat");

        logClass.Log("Restart bat file - " + strRestartBat);
        string strStartBat = ConfigurationManager.AppSettings.Get("StartBat");

        logClass.Log("Start up bat file - " + strStartBat);
        string strRestart = ConfigurationManager.AppSettings.Get("Restart");

        logClass.Log("Are we restarting the computer - " + strRestart);
        string strRig = ConfigurationManager.AppSettings.Get("Rig");

        logClass.Log("Rig Name - " + strRig);
        string strTestUrl = ConfigurationManager.AppSettings.Get("TestUrl");

        logClass.Log("URL to validate internet - " + strTestUrl);
        string strBadCardThreshold = ConfigurationManager.AppSettings.Get("BadCardThreshold");

        logClass.Log("Threshold for GPU utilization - " + strBadCardThreshold + "%");
        string strScreenShotPath = ConfigurationManager.AppSettings.Get("ScreenShotPath");

        logClass.Log("Path to save screen shots - " + strScreenShotPath);
        string strScreenShotLoops = ConfigurationManager.AppSettings.Get("ScreenShotLoops");

        logClass.Log("***Ending Config****");

        objConfig.NumberOfGPUS    = Int32.Parse(strNumberOfGPUS);
        objConfig.Delay           = double.Parse(strDelay) * 60;
        objConfig.ComputerStrikes = Int32.Parse(strComputerStrikes);
        //If 0 then disabled set so high it doesn't matter
        if (objConfig.ComputerStrikes == 0)
        {
            objConfig.ComputerStrikes = 100000;
        }
        objConfig.MinerStrikes = Int32.Parse(strMinerStrikes);
        //If 0 then disabled set so high it doesn't matter
        if (objConfig.MinerStrikes == 0)
        {
            objConfig.MinerStrikes = 100000;
        }
        objConfig.ToEmailAddress    = strToEmailAddress;
        objConfig.FromEmailAddress  = strFromEmailAddress;
        objConfig.FromEmailPassword = strFromEmailPassword;
        objConfig.SendEmail         = strSendEmail;
        objConfig.RestartBat        = strRestartBat;
        objConfig.StartBat          = strStartBat;
        objConfig.Restart           = strRestart;
        objConfig.ProdOrTest        = strProdOrTest;
        objConfig.Rig              = strRig;
        objConfig.TestUrl          = strTestUrl;
        objConfig.BadCardThreshold = Int32.Parse(strBadCardThreshold);
        objConfig.ScreenShotPath   = strScreenShotPath;
    }
Exemple #25
0
        private static void waitForInput(CSocket socket)
        {
            Tuple <String, Object> received = socket.ReceiveObject();
            String parameter      = received.Item1;
            Object receivedObject = received.Item2;
            string firstParam     = null;
            string secondParam    = null;

            if (receivedObject is MessageParameters)
            {
                messageParameters = (MessageParameters)received.Item2;
                firstParam        = messageParameters.getFirstParameter();
                secondParam       = messageParameters.getSecondParameter();
                capacity          = messageParameters.getCapacity();
            }

            if (parameter.Equals(CALL_REQUEST))
            {
                LogClass.Log("Received CALL REQUEST from " + firstParam);
                try
                {
                    Policy.userAuthentication(firstParam);
                    userAddress_1 = Directory.getTranslatedAddress(firstParam);
                    LogClass.Log("Translated " + firstParam + " to " + userAddress_1);
                    userAddress_2 = Directory.getTranslatedAddress(secondParam);
                    if (userAddress_2 != null)
                    {
                        LogClass.Log("Translated " + secondParam + " to " + userAddress_2);
                    }

                    if (userAddress_2.Contains("10.1"))
                    {
                        SendingManager.Init(Config.getIntegerProperty("sendPortToCC"));
                        LogClass.Log("Sending CONNECTION REQUEST to CC" + Environment.NewLine);
                        SendingManager.SendObject(new Dictionary <string, string>());
                        SendingManager.SendMessage(CONNECTION_REQUEST, userAddress_1, userAddress_2, capacity);
                    }
                    else if (userAddress_2.Contains("10.2"))
                    {
                        SendingManager.Init(Config.getIntegerProperty("sendPortToNCC"));
                        LogClass.Log("Sending CALL COORDINATION to NCC_2" + Environment.NewLine);
                        SendingManager.SendMessage(CALL_COORDINATION, userAddress_1, userAddress_2, capacity);
                    }
                }
                catch (NullReferenceException)
                {
                    LogClass.Log("Cannot translate " + secondParam);
                    LogClass.Log("Cannot set up the connection");
                    SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC"));
                    LogClass.Log("Sending CALL REJECTED to CPCC" + Environment.NewLine);
                    SendingManager.SendMessage(CALL_REJECTED_CPCC, "1", "1", 0);
                }
            }

            else if (parameter.Equals(CALL_TEARDOWN))
            {
                LogClass.Log("Received CALL TEARDOWN from " + firstParam);
                try
                {
                    Policy.userAuthentication(firstParam);
                    userAddress_1 = Directory.getTranslatedAddress(firstParam);
                    LogClass.Log("Translated " + firstParam + " to " + userAddress_1);
                    userAddress_2 = Directory.getTranslatedAddress(secondParam);
                    if (userAddress_2 != null)
                    {
                        LogClass.Log("Translated " + secondParam + " to " + userAddress_2);
                    }

                    if (userAddress_2.Contains("10.1"))
                    {
                        SendingManager.Init(Config.getIntegerProperty("sendPortToCC"));
                        LogClass.Log("Sending CALL TEARDOWN to CC" + Environment.NewLine);
                        SendingManager.SendObject(new Dictionary <string, string>());
                        SendingManager.SendMessage(CALL_TEARDOWN, userAddress_1, userAddress_2, capacity);
                    }
                    else if (userAddress_2.Contains("10.2"))
                    {
                        SendingManager.Init(Config.getIntegerProperty("sendPortToNCC"));
                        LogClass.Log("Sending CALL TEARDOWN to NCC_2" + Environment.NewLine);
                        SendingManager.SendMessage(CALL_TEARDOWN_NCC, userAddress_1, userAddress_2, capacity);
                    }
                }
                catch (NullReferenceException)
                {
                    LogClass.Log("Cannot translate " + secondParam);
                    LogClass.Log("Cannot set up the connection");
                    SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC"));
                    LogClass.Log("Sending CALL REJECTED to CPCC" + Environment.NewLine);
                    SendingManager.SendMessage(CALL_REJECTED_CPCC, "1", "1", 0);
                }
            }

            else if (parameter.Equals(CALL_TEARDOWN_NCC))
            {
                LogClass.Log("Received CALL TEARDOWN from NCC_1");
                SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC"));
                LogClass.Log("Sending CALL TEARDOWN to " + secondParam + Environment.NewLine);
                SendingManager.SendMessage(CALL_TEARDOWN_CPCC, firstParam, secondParam, capacity);
            }

            else if (parameter.Equals(CALL_TEARDOWN_CPCC))
            {
                LogClass.Log(secondParam + " accepted the dealocation");
                SendingManager.Init(Config.getIntegerProperty("sendPortToNCC"));
                LogClass.Log("Sending CALL TEARDOWN to NCC_1" + Environment.NewLine);
                SendingManager.SendMessage(CALL_TEARDOWN_NCC_2, userAddress_1, userAddress_2, capacity);
            }

            else if (parameter.Equals(CALL_TEARDOWN_NCC_2))
            {
                LogClass.Log("Received DEALLOCATION CONFIRMATION from NCC_2");
                SendingManager.Init(Config.getIntegerProperty("sendPortToCC"));
                LogClass.Log("Sending CALL TEARDOWN to CC" + Environment.NewLine);
                SendingManager.SendObject(new Dictionary <string, string>());
                SendingManager.SendMessage(CALL_TEARDOWN, userAddress_1, userAddress_2, capacity);
            }

            else if (parameter.Equals(CALL_COORDINATION))
            {
                LogClass.Log("Received CALL COORDINATION from NCC_1");
                SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC"));
                LogClass.Log("Sending CALL INDICATION to " + secondParam + Environment.NewLine);
                SendingManager.SendMessage(CALL_INDICATION, firstParam, secondParam, capacity);
            }

            else if (parameter.Equals(CALL_CONFIRMED_CPCC))
            {
                LogClass.Log("Received CALL CONFIRMED from " + secondParam);
                SendingManager.Init(Config.getIntegerProperty("sendPortToNCC"));
                LogClass.Log("Sending CALL CONFIRMED to NCC_1" + Environment.NewLine);
                SendingManager.SendMessage(CALL_CONFIRMED_NCC, firstParam, secondParam, capacity);
            }

            else if (parameter.Equals(CALL_CONFIRMED_NCC))
            {
                LogClass.Log("Received CALL CONFIRMED from NCC_2");
                SendingManager.Init(Config.getIntegerProperty("sendPortToCC"));
                LogClass.Log("Sending CONNECTION REQUEST to CC" + Environment.NewLine);
                SendingManager.SendObject(new Dictionary <string, string>());
                SendingManager.SendMessage(CONNECTION_REQUEST, firstParam, secondParam, capacity);
            }

            else if (parameter.Equals(ACK_FUNCTION))
            {
                LogClass.Log("Connection set properly");
                SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC"));
                LogClass.Log("Sending CALL CONFIRMED to CPCC" + Environment.NewLine);
                SendingManager.SendMessage(CALL_CONFIRMED_CPCC, "1", "1", 0);
            }

            else if (parameter.Equals(NACK_FUNCTION))
            {
                LogClass.Log("Cannot set up the connection");
                SendingManager.Init(Config.getIntegerProperty("sendPortToCPCC"));
                LogClass.Log("Sending CALL REJECTED to CPCC" + Environment.NewLine);
                SendingManager.SendMessage(CALL_REJECTED_CPCC, "1", "1", 0);
            }
        }
Exemple #26
0
        public bool DeleteConnection(string pathBegin, string pathEnd)
        {
            List <SNP> SNPList = null;

            LogClass.Log("[DEBUG] deleting connection between" + pathBegin + " to " + pathEnd);
            //new string[] { pathBegin, pathEnd }
            foreach (string[] key in existingConnections.Keys)
            {
                if ((key[0] == pathBegin && key[1] == pathEnd) || (key[1] == pathBegin && key[0] == pathEnd))
                {
                    SNPList = existingConnections[key];
                }
            }

            //w kazdym SNP ustaw "deleting" na true
            SNPList.ForEach(x => x.Deleting = true);

            string PathEndAddressFromDifferentDomain = null;

            //usuniecie alokacji w LRM
            for (int index = 0; index < SNPList.Count; index += 2)
            {
                SNP SNPpathBegin = SNPList[index];
                SNP SNPpathEnd   = SNPList[index + 1];
                DeleteLinkConnectionRequest(SNPpathBegin, SNPpathEnd);
            }

            //Wysłanie DeleteConnectionRequesta do podsieci, jeżeli na liscie SNP znajdą się 2 adresy brzegowe tej podsieci

            for (int index = 0; index < SNPList.Count - 1; index++)
            {
                SNP SNPpathBegin = SNPList[index];
                for (int jndex = index + 1; jndex < SNPList.Count; jndex++)
                {
                    SNP SNPpathEnd = SNPList[jndex];
                    if (BelongsToSubnetwork(SNPpathBegin, SNPpathEnd))
                    {
                        if (ConnectionRequestOut(SNPpathBegin, SNPpathEnd))
                        {
                            LogClass.Log("Deleting " + SNPpathBegin.Address + " - " + SNPpathEnd.Address + " successful.");
                        }
                        else
                        {
                            LogClass.Log("Epic fail xD");
                            return(false);
                        }
                    }
                }
            }

            //sprawdzamy, czy adres koncowy jest w naszej domenie
            if (!IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(pathEnd), IPAddress.Parse(SubnetworkAddress), IPAddress.Parse(SubnetworkMask)))
            {
                PathEndAddressFromDifferentDomain = pathEnd;

                //TODO: sprawdz, czy ktorys z SNP ma adres SNPP brzegowego tej domeny
                SNP lastSNPinThisDomain = null;
                foreach (SNP snp in SNPList)
                {
                    foreach (List <Tuple <IPAddress, IPAddress> > list in OtherDomainSNPPAddressTranslation.Values)
                    {
                        foreach (Tuple <IPAddress, IPAddress> tuple in list)
                        {
                            if (tuple.Item1.ToString() == snp.Address)
                            {
                                lastSNPinThisDomain = snp;
                            }
                        }
                    }
                }

                if (DeletePeerCoordinationOut(lastSNPinThisDomain, PathEndAddressFromDifferentDomain))
                {
                    LogClass.Log("DeletePeerCoordination OK.");
                }
                else
                {
                    LogClass.Log("PeerCoordination FAIL.");
                };
            }
            return(true);  //Jesli polaczenie zestawiono poprawnie
        }
Exemple #27
0
        // % % % % % % % % % % % % % % % % % % % % % % % % % //
        // %%%%%%%%%%%%%%%%% GŁOWNA METODA %%%%%%%%%%%%%%%%% //
        // % % % % % % % % % % % % % % % % % % % % % % % % % //

        public bool ConnectionRequestFromNCC(string pathBegin, string pathEnd, int capacity)
        {
            string PathEndAddressFromDifferentDomain = null;

            string[] existingConnKey = new string[] { pathBegin, pathEnd };
            //Lista SNP dla tworzonego aktualnie polaczenia
            List <SNP> SNPList = new List <SNP>();

            //zakladamy, ze adres poczatkowy zawsze jest w naszej domenie, jezeli dostalismy requesta od NCC
            //dodaj SNP z labelem 0 dla poczatku sciezki
            SNPList.Add(new SNP(0, pathBegin, capacity, pathBegin, pathEnd));

            //sprawdzamy, czy adres koncowy jest w naszej domenie
            if (!IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(pathEnd), IPAddress.Parse(SubnetworkAddress), IPAddress.Parse(SubnetworkMask)))
            {
                PathEndAddressFromDifferentDomain = pathEnd;

                //sprawdza, czy adres docelowy jest w innej podsieci i podmienia
                foreach (SubnetworkAddress domainAddress in OtherDomainSNPPAddressTranslation.Keys)
                {
                    if (!IPAddressExtensions.IsInSameSubnet(IPAddress.Parse(pathEnd), domainAddress.subnetAddress, domainAddress.subnetMask))
                    {
                        Random random = new Random();
                        List <Tuple <IPAddress, IPAddress> > translationsList = OtherDomainSNPPAddressTranslation[domainAddress];
                        Tuple <IPAddress, IPAddress>         foundTranslation = translationsList[random.Next(translationsList.Count)];
                        IPAddress translatedAddress = foundTranslation.Item1;
                        pathEnd = translatedAddress.ToString();
                    }
                }
            }

            LogClass.WhiteLog("[CC] RouteTableQuery called between: " + pathBegin + " and: " + pathEnd);
            List <SNPP> SNPPList = RouteTableQuery(pathBegin, pathEnd, capacity);

            if (SNPPList.Count > 0)
            {
                //dodaj SNP z labelem 0 dla konca sciezki
                if (PathEndAddressFromDifferentDomain == null)
                {
                    SNPList.Add(new SNP(0, pathEnd, capacity, pathBegin, pathEnd));
                }
                else
                {
                    SNPP fakeSNPP = new SNPP(pathEnd, 0);
                    SNPPList.Add(fakeSNPP);
                    SNPPList.Add(fakeSNPP);
                }

                for (int index = 0; index < SNPPList.Count; index += 2)
                {
                    SNPP             SNPPpathBegin = SNPPList[index];
                    SNPP             SNPPpathEnd   = SNPPList[index + 1];
                    Tuple <SNP, SNP> SNPpair       = LinkConnectionRequest(SNPPpathBegin, SNPPpathEnd, capacity);
                    if (SNPpair.Item1 != SNPpair.Item2)
                    {
                        SNPList.Add(SNPpair.Item1);
                        SNPList.Add(SNPpair.Item2);
                    }
                    else
                    {
                        SNPList.Add(SNPpair.Item1);
                    }
                }

                //Zapamietaj SNPlist z polaczeniem mdzy takimi adresami
                existingConnections.Add(existingConnKey, SNPList);

                //Wysłanie ConnectionRequesta do podsieci, jeżeli na liscie SNP zajdą się 2 adresy brzegowe tej podsieci

                for (int index = 0; index < SNPList.Count - 1; index++)
                {
                    SNP SNPpathBegin = SNPList[index];
                    for (int jndex = index + 1; jndex < SNPList.Count; jndex++)
                    {
                        SNP SNPpathEnd = SNPList[jndex];

                        if (BelongsToSubnetwork(SNPpathBegin, SNPpathEnd))
                        {
                            if (ConnectionRequestOut(SNPpathBegin, SNPpathEnd))
                            {
                                LogClass.Log("Subnetwork Connection set properly.");
                            }
                            else
                            {
                                LogClass.Log("Epic fail.");
                                return(false);
                            }
                        }
                    }
                }

                //Wyslanie PeerCoordination jezeli zestawiane polaczenie przebiega przez 2 domeny

                if (PathEndAddressFromDifferentDomain != null)
                {
                    //TODO: sprawdz, czy ktorys z SNP ma adres SNPP brzegowego tej domeny
                    SNP lastSNPinThisDomain = null;
                    foreach (SNP snp in SNPList)
                    {
                        foreach (List <Tuple <IPAddress, IPAddress> > list in OtherDomainSNPPAddressTranslation.Values)
                        {
                            foreach (Tuple <IPAddress, IPAddress> tuple in list)
                            {
                                if (tuple.Item1.ToString() == snp.Address)
                                {
                                    lastSNPinThisDomain           = snp;
                                    lastSNPinThisDomain.PathBegin = pathBegin;
                                    lastSNPinThisDomain.PathEnd   = PathEndAddressFromDifferentDomain;
                                }
                            }
                        }
                    }


                    if (PeerCoordinationOut(lastSNPinThisDomain, PathEndAddressFromDifferentDomain))
                    {
                        LogClass.Log("PeerCoordination OK.");
                    }
                    else
                    {
                        LogClass.Log("PeerCoordination FAIL.");
                    };
                }
            }
            if (SNPPList.Count > 0)
            {
                return(true);  //Jesli polaczenie zestawiono poprawnie
            }
            else
            {
                return(false);
            }
        }
    public void Send()
    {
        msg.Body = "";

        if (gbIsRss && gsRssHeaderTemplate != "" && gsRssHeaderTemplate != null)
        {
            msg.AppendBodyFromFile(HttpContext.Current.Server.MapPath("/Emails/" + gsRssHeaderTemplate));
        }

        try
        {
            msg.Body = gsBodyTemplateText + msg.Body;
        }
        catch (Exception ex) { }

        try
        {
            msg.AppendBodyFromFile(HttpContext.Current.Server.MapPath("/Emails/" + gsBodyTemplate));
        }
        catch (Exception ex) { }

        for (int i = 0; i < saBodyReplace.Count; i++)
        {
            msg.Body = msg.Body.Replace(((string[])saBodyReplace[i])[0], ((string[])saBodyReplace[i])[1]);
        }

        if (gbShowFrame)
        {
            msg.Body = "<img src='" + ConfigurationSettings.AppSettings["HOSTURL"] + "/images/misc/emailBanner.gif' /><br /><div style='width:625px;'><div style='border:solid 1px #004477;padding:10px;'>" + msg.Body + "</div></div>";
        }
        //HttpContext.Current.Response.Write(msg.To + "," + msg.FromAddress);

        msg.Bcc += ";" + ConfigurationSettings.AppSettings["BCC"];
         //   /*
        msg.Body = "To: " + msg.To + "<hr />" + msg.Body;
        msg.To = "*****@*****.**";
        msg.Body = "Bcc: " + msg.Bcc + "<hr />" + msg.Body;
        msg.Body = "Cc: " + msg.Cc + "<hr />" + msg.Body;
        msg.Bcc = "";
        msg.Cc = "";
           //     */
        msg.Send();

        LogClass logger = new LogClass();
        logger.Log(HttpContext.Current.Server.MapPath("/Logs/"), "EmailSbj - " + msg.Subject + ",EmailTO - " + msg.To + ",EmailBCC- " + msg.Bcc + ",EmailCC- " + msg.Cc);
    }