Пример #1
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);
        }
Пример #2
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());
            }
        }