Пример #1
0
        public override void notifyTwoWayReplyReceived(IPAddress fromIP, byte[] buffer, int offset, int size, AsyncCallback originalRequestCallBack, Object originalAppState)
        {
            Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived ENTER");
            String[] split = splitMsgBuffer(buffer, offset, size);
            if(String.Compare(split[0], "FIND_SUCCESSOR_REPLY") == 0)
            {
                Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived FIND_SUCCESSOR_RECEIVED");
                String strSuccessorIP = split[1];
                Console.Write("ChordProxyNode::notifyTwoWayReplyReceived SuccessorIP = ");
                Console.WriteLine(strSuccessorIP);

                IPAddress successorIP = UtilityMethod.convertStrToIP(strSuccessorIP);

                ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object();
                iNode_Object.node = (IChordNode)(proxyController.getProxyNode(successorIP));
                iNode_Object.obj = originalAppState;

                Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNode_Object, false, false);
                if(originalRequestCallBack != null)
                    originalRequestCallBack(objectAsyncResult);
            }
            else if(String.Compare(split[0], "GET_PREDECESSOR_REPLY")==0)
            {
                Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived GET_PREDECESSOR_RECEIVED");
                String strPredecessorIP = split[1];
                ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object();

                if(String.Compare(strPredecessorIP, "UNKNOWN_PREDECESSOR")==0)
                {
                    Console.Write("ChordProxyNode::notifyTwoWayReplyReceived PREDECESSOR_UNKNOWN");
                    iNode_Object.node = null;

                }
                else
                {
                    Console.Write("ChordProxyNode::notifyTwoWayReplyReceived PredecessorIP = ");
                    Console.WriteLine(strPredecessorIP);

                    IPAddress predecessorIP = UtilityMethod.convertStrToIP(strPredecessorIP);

                    iNode_Object.node = (IChordNode)(proxyController.getProxyNode(predecessorIP));
                }
                iNode_Object.obj = originalAppState;

                Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNode_Object, false, false);
                if(originalRequestCallBack != null)
                    originalRequestCallBack(objectAsyncResult);
            }
            else if (String.Compare(split[0], "GET_FINGERTABLE_REPLY") == 0)
            {
                Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived GET_FINGERTABLE_RECEIVED");

                String strPredecessorIP = split[1];
                IChordNode[] fingerTable = new IChordNode[split.Length - 1];
                for (int i = 1; i < 161; i++)
                {
                    if (split[i] == "NULL")
                        fingerTable[i - 1] = null;
                    else
                      fingerTable[i - 1] = (IChordNode)(proxyController.getProxyNode(UtilityMethod.convertStrToIP(split[i].ToString())));
                }
                ChordCommon.IChordNodeArray_Object iNodeArray_Object = new ChordCommon.IChordNodeArray_Object();
                iNodeArray_Object.nodeArray = fingerTable;
                iNodeArray_Object.obj = originalAppState;

                Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNodeArray_Object, false, false);
                if (originalRequestCallBack != null)
                    originalRequestCallBack(objectAsyncResult);
            }
        }
Пример #2
0
        public override void notifyTwoWayReplyReceived(IPAddress fromIP, byte[] buffer, int offset, int size, AsyncCallback originalRequestCallBack, Object originalAppState)
        {
            Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived ENTER");
            String[] split = splitMsgBuffer(buffer, offset, size);
            if (String.Compare(split[0], "FIND_SUCCESSOR_REPLY") == 0)
            {
                Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived FIND_SUCCESSOR_RECEIVED");
                String strSuccessorIP = split[1];
                Console.Write("ChordProxyNode::notifyTwoWayReplyReceived SuccessorIP = ");
                Console.WriteLine(strSuccessorIP);

                IPAddress successorIP = UtilityMethod.convertStrToIP(strSuccessorIP);

                ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object();
                iNode_Object.node = (IChordNode)(proxyController.getProxyNode(successorIP));
                iNode_Object.obj  = originalAppState;

                Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNode_Object, false, false);
                if (originalRequestCallBack != null)
                {
                    originalRequestCallBack(objectAsyncResult);
                }
            }
            else if (String.Compare(split[0], "GET_PREDECESSOR_REPLY") == 0)
            {
                Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived GET_PREDECESSOR_RECEIVED");
                String strPredecessorIP = split[1];
                ChordCommon.IChordNode_Object iNode_Object = new ChordCommon.IChordNode_Object();

                if (String.Compare(strPredecessorIP, "UNKNOWN_PREDECESSOR") == 0)
                {
                    Console.Write("ChordProxyNode::notifyTwoWayReplyReceived PREDECESSOR_UNKNOWN");
                    iNode_Object.node = null;
                }
                else
                {
                    Console.Write("ChordProxyNode::notifyTwoWayReplyReceived PredecessorIP = ");
                    Console.WriteLine(strPredecessorIP);

                    IPAddress predecessorIP = UtilityMethod.convertStrToIP(strPredecessorIP);

                    iNode_Object.node = (IChordNode)(proxyController.getProxyNode(predecessorIP));
                }
                iNode_Object.obj = originalAppState;

                Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNode_Object, false, false);
                if (originalRequestCallBack != null)
                {
                    originalRequestCallBack(objectAsyncResult);
                }
            }
            else if (String.Compare(split[0], "GET_FINGERTABLE_REPLY") == 0)
            {
                Console.WriteLine("ChordProxyNode::notifyTwoWayReplyReceived GET_FINGERTABLE_RECEIVED");

                String       strPredecessorIP = split[1];
                IChordNode[] fingerTable      = new IChordNode[split.Length - 1];
                for (int i = 1; i < 161; i++)
                {
                    if (split[i] == "NULL")
                    {
                        fingerTable[i - 1] = null;
                    }
                    else
                    {
                        fingerTable[i - 1] = (IChordNode)(proxyController.getProxyNode(UtilityMethod.convertStrToIP(split[i].ToString())));
                    }
                }
                ChordCommon.IChordNodeArray_Object iNodeArray_Object = new ChordCommon.IChordNodeArray_Object();
                iNodeArray_Object.nodeArray = fingerTable;
                iNodeArray_Object.obj       = originalAppState;

                Tashjik.Common.ObjectAsyncResult objectAsyncResult = new Tashjik.Common.ObjectAsyncResult(iNodeArray_Object, false, false);
                if (originalRequestCallBack != null)
                {
                    originalRequestCallBack(objectAsyncResult);
                }
            }
        }