Example #1
0
        public bool Equals(ChordRealNode n1, IChordNode n2)
        {
            String strHash1 = n1.getHashedIP().ToString();
            String strHash2 = n2.getHashedIP().ToString();

            if(String.Compare(strHash1, strHash2)==0)
                return true;
            else
                return false;
        }
Example #2
0
 public void beginFindSuccessor(byte[] queryHashedKey, IChordNode queryingNode, AsyncCallback findSuccessorCallBack, Object appState, Guid relayTicket)
 {
     Console.WriteLine("ChordRealNode::beginFindSuccessor ENTER");
     engine.beginFindSuccessor(queryHashedKey, queryingNode, findSuccessorCallBack, appState, relayTicket);
 }
Example #3
0
        /* public void notify(Node possiblePred)
        {
            engine.notify(possiblePred);

        }

        private void beginJoin(IChordNode joinNode, AsyncCallback joinCallBack, Object appState)
        {
            engine.beginJoin(joinNode, joinCallBack, appState);
        }
        */
        public void beginPredecessorNotify(IChordNode possiblePred, AsyncCallback notifyCallBack, Object appState)
        {
            engine.notify(possiblePred);
            if(!(notifyCallBack==null))
            {
                IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(appState, true, true);
                notifyCallBack(res);
            }
        }
Example #4
0
            /* This is the method that the node uses to initilize its own state based on a supplied
                 * bootstrap node here, it has been suppied with a bootstrap node which will be used to
                 * initilize itself as well as tell other nodes in n/w of its existence
                 * ALGO(from Chord TR):   n.join(n′)
                 *                        predecessor = nil;
                 *                        s = n′.find successor(n);
                 *                        build fingers(s);
                 *                        successor = s;
                 */
            internal void beginJoin(IChordNode joinNode, AsyncCallback joinCallBack, Object appState)
            {
                Console.WriteLine("ChordRealNode::Engine::beginJoin ENTER");

                    predecessor = null;

                    Tashjik.Common.AsyncCallback_Object thisAppState = new Tashjik.Common.AsyncCallback_Object();
                    thisAppState.callBack = joinCallBack;
                    thisAppState.obj = appState;

                    Console.WriteLine("ChordRealNode::Engine::beginJoin before calling beginFindSuccessor ahem ahem");
                    if (joinNode == null)
                        Console.WriteLine("ChordRealNode::Engine::beginJoin joinNode ==null");

                    //queryingNode is passed as null, because it is of no use to beginFindSuccessor
                    //if we were to pass 'self', then the system would hang. This is because Engine is part of
                    //ChordRealNode. We haven't yet constructed ChordRealNode fully, and are in the process
                    //of constructing Engine, and we want to send the partially constructed ChordRealNode
                    // on a call to beginFindSuccessor
                    //
                    //What are the alternatives?
                    //1. Make JoinNode as a public method tht needs to be called after construction of ChordRealNode
                    //This may lead to maintainance issues of the calling code. What if at some later stage, someone
                    //constructs the object, but forgets to call joinNode(..). This is typical of init(..) methods
                    //which are supposed to be called by the user after constructor. Many a times, coders forget to do it.
                    //2.Have a flag internal to ChordRealNode that will signal whether the object is ready for operation.
                    //This would mean joinNode(..) has been called after construction. If this is not the case, throw an
                    //excetion. This will easily be caught during basic testing. However, it may be a maintainance problem
                    //for the maintainers of ChordRealNode itself> What if a new operation is added, and the engineer
                    //forgets to check the flag before proceeding?
                    //
                    //We are fortunate here to have a hack (a nifty solution for me), that solves a larger design problem.

                   joinNode.beginFindSuccessor(selfNodeBasic.getHashedIP(), null, new AsyncCallback(processFindSuccessorForJoin), thisAppState, new Guid("00000000-0000-0000-0000-000000000000"));
            }
Example #5
0
 public void beginFindSuccessor(IChordNode queryNode, IChordNode queryingNode, AsyncCallback findSuccessorCallBack, Object appState, Guid relayTicket)
 {
     beginFindSuccessor(queryNode.getHashedIP(), queryingNode, findSuccessorCallBack, appState, relayTicket);
 }
Example #6
0
            public Engine(ChordRealNode encapsulatingNode, IChordNode joinNode, AsyncCallback joinCallBack, Object appState)
            {
                readyForOperation = false;

                    selfNodeBasic = new Tashjik.Common.NodeBasic(Tashjik.Common.UtilityMethod.GetLocalHostIP());
                    self = encapsulatingNode;
                    for (int i = 159; i >= 0; i--)
                        finger[i] = null;

                    beginJoin(joinNode, joinCallBack, appState);
            }
Example #7
0
 public ChordRealNode(IChordNode joinNode, AsyncCallback joinCallBack, Object appState)
 {
     engine = new Engine(this, joinNode, joinCallBack, appState);
     engineMgr = EngineMgr.createEngineMgr(10000, engine);
     ChordDataStore dataStore = new ChordDataStore();
 }
Example #8
0
        public void beginFindSuccessor(byte[] queryHashedKey, IChordNode queryingNode, AsyncCallback findSuccessorCallBack, Object appState, Guid relayTicket)
        {
            //querying node is not necessary as of now, cause it doesn't matter as
            //to who raised the query....the result is being sent back to the
            //called via the callback and stateApp .. this petty knowledge is being
            //used in joinNode(queryingNode is passed as null) to overcome a deep design problem
            Console.WriteLine("ChordProxyNode::beginFindSuccessor ENTER");

            byte[] compositeMsg = UtilityMethod.convertToTabSeparatedByteArray(true, "FIND_SUCCESSOR", Encoding.ASCII.GetString(queryHashedKey));
            Console.WriteLine("ChordProxyNode::beginFindSuccessor before sendMsg to proxyController");
            proxyController.sendMsgTwoWayRelay(this, compositeMsg, 0, compositeMsg.Length, findSuccessorCallBack, appState, relayTicket);
        }
Example #9
0
        public void beginPredecessorNotify(IChordNode possiblePred, AsyncCallback notifyCallBack, Object appState)
        {
            Console.WriteLine("ChordProxyNode::beginNotify ENTER");

            byte[] compositeMsg = UtilityMethod.convertToTabSeparatedByteArray(true, "PREDECESSOR_NOTIFY", possiblePred.getIP().ToString());

            Console.WriteLine("ChordProxyNode::beginGetPredecessor before sendMsg to proxyController");
            proxyController.sendMsg(this, compositeMsg, 0, compositeMsg.Length, notifyCallBack, appState);
        }
Example #10
0
 public ChordRealNode(IChordNode joinNode, AsyncCallback joinCallBack, Object appState)
 {
     engine    = new Engine(this, joinNode, joinCallBack, appState);
     engineMgr = EngineMgr.createEngineMgr(10000, engine);
     ChordDataStore dataStore = new ChordDataStore();
 }
Example #11
0
 public void beginFindSuccessor(IChordNode queryNode, IChordNode queryingNode, AsyncCallback findSuccessorCallBack, Object appState, Guid relayTicket)
 {
     beginFindSuccessor(queryNode.getHashedIP(), queryingNode, findSuccessorCallBack, appState, relayTicket);
 }
Example #12
0
 public void predecessorNotify(IChordNode possiblePred)
 {
     engine.notify(possiblePred);
 }
Example #13
0
 public void beginFindSuccessor(byte[] queryHashedKey, IChordNode queryingNode, AsyncCallback findSuccessorCallBack, Object appState, Guid relayTicket)
 {
     Console.WriteLine("ChordRealNode::beginFindSuccessor ENTER");
     engine.beginFindSuccessor(queryHashedKey, queryingNode, findSuccessorCallBack, appState, relayTicket);
 }
Example #14
0
 //to be implemented
 public void predecessorNotify(IChordNode possiblePred)
 {
 }
Example #15
0
 public void predecessorNotify(IChordNode possiblePred)
 {
     engine.notify(possiblePred);
 }
Example #16
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);
            }
        }
Example #17
0
            public Engine(ChordRealNode encapsulatingNode)
            {
                readyForOperation = false;

                    selfNodeBasic = new Tashjik.Common.NodeBasic(Tashjik.Common.UtilityMethod.GetLocalHostIP());
                    self = encapsulatingNode;
                    predecessor = null;
                    lock (successorLock)
                    {
                        successor = self;
                    }

                    for (int i = 159; i >= 0; i--)
                        finger[i] = null;

                    //readyForOperation = true;
            }
Example #18
0
 //to be implemented
 public void predecessorNotify(IChordNode possiblePred)
 {
 }
Example #19
0
            /*
                public Node findSuccessor(byte[] queryHashedKey, Node queryingNode)
                {
                    if((Node)self<queryHashedKey && queryHashedKey<(Node)successor)
                        return successor;
                    else
                    {
                        Node closestPrecNode = findClosestPreceedingNode(queryHashedKey);
                        if (closestPrecNode==self)
                            return successor;
                        else
                        {
                            return closestPrecNode.findSuccessor(queryHashedKey, queryingNode);
                    }
                }
            }
            */
            public void beginFindSuccessor(byte[] queryHashedKey, IChordNode queryingNode, AsyncCallback findSuccessorCallBack, Object appState, Guid relayTicket)
            {
                Console.WriteLine("Chord::engine::beginFindSuccessor ENTER");
                ChordCommon.IChordNode_Object iNode_Object;
                lock (successorLock)
                {
                    if ((ChordRealNode)self < queryHashedKey && queryHashedKey < (ChordRealNode)successor)
                    {
                        Console.WriteLine("Chord::engine::beginFindSuccessor query falls inbetween node and successor");
                        if (!(findSuccessorCallBack == null))
                        {
                            iNode_Object = new ChordCommon.IChordNode_Object();
                            lock (successorLock)
                            {
                                iNode_Object.node = successor;
                            }
                            iNode_Object.obj = appState;

                            IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true);
                            findSuccessorCallBack(res);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Chord::engine::beginFindSuccessor query DOES NOT fall inbetween node and successor");
                        IChordNode closestPrecNode = findClosestPreceedingNode(queryHashedKey);
                        if (closestPrecNode == self)
                        {
                            Console.WriteLine("Chord::engine::beginFindSuccessor closestPrecNode==self");
                            if (!(findSuccessorCallBack == null))
                            {
                                Console.WriteLine("Chord::engine::beginFindSuccessor if(!(findSuccessorCallBack==null))");
                                iNode_Object = new ChordCommon.IChordNode_Object();
                                lock (successorLock)
                                {
                                    iNode_Object.node = successor;
                                }
                                iNode_Object.obj = appState;

                                Console.WriteLine("Chord::engine::beginFindSuccessor before new IChordNode_ObjectAsyncResult");
                                IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true);
                                Console.WriteLine("Chord::engine::beginFindSuccessor before calling findSuccessorCallBack");
                                findSuccessorCallBack(res);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Chord::engine::beginFindSuccessor relaying request to closestPrecNode");
                            closestPrecNode.beginFindSuccessor(queryHashedKey, queryingNode, findSuccessorCallBack, appState, relayTicket);
                        }

                    }
                }

                Console.WriteLine("Chord::engine::beginFindSuccessor EXIT");
            }
Example #20
0
            void processGetPredecessorForStabilize(IAsyncResult result)
            {
                Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize ENTER");

                    ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState);
                    Object appState = iNode_Object.obj;

                    AsyncCallback callBack = ((Tashjik.Common.AsyncCallback_Object)appState).callBack;
                    Object appState1 = ((Tashjik.Common.AsyncCallback_Object)appState).obj;

                    IChordNode x = iNode_Object.node;
                    if(x==null)
                    {
                        Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize UNKNOWN_PREDECESSOR");
                        if(callBack != null)
                        {	iNode_Object = new ChordCommon.IChordNode_Object();
                            iNode_Object.node = null;
                            iNode_Object.obj = appState1;

                            IAsyncResult res = new ChordCommon.IChordNode_ObjectAsyncResult(iNode_Object, true, true);
                    //		callBack(res);
                        }
                    }
                    else
                    {

                        Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize before condition check");
                        lock (successorLock)
                        {
                            if ((self < (IChordNode)x) && ((ChordRealNode)x/*.getHashedIP()*/ < (successor)))
                                successor = x;
                        }
                        Console.WriteLine("Chord::Engine::processGetPredecessorForStabilize before calling beginNotify on successor");

                    }
                    lock (successorLock)
                    {
                        successor.beginPredecessorNotify(self, callBack, appState1);
                    }
            }
Example #21
0
            //IPAddress possiblePredIP, byte[] possiblePredHashedIP)
            public void notify(IChordNode possiblePred)
            {
                if(predecessor==null) //|| ((/*(ChordRealNode)*/possiblePred<self) && (/*(ChordRealNode)*/predecessor<possiblePred)))
                        predecessor = possiblePred;
                    else
                    {
                        String strPossiblePredHash = possiblePred.getHashedIP().ToString();
                        String strSelfHash = self.getHashedIP().ToString();
                        String strPredecessorHash = predecessor.getHashedIP().ToString();

                        if((String.Compare(strPossiblePredHash, strSelfHash)<0) && (String.Compare(strPredecessorHash, strPossiblePredHash)<0))
                            predecessor = possiblePred;
                    }
            }
Example #22
0
            void processPingForCheckPredecessor(IAsyncResult result)
            {
                Console.WriteLine("Chord::ChordRealNode::Engine processPingForCheckPredecessor ENTER");
                    Tashjik.Common.Bool_Object thisAppState = (Tashjik.Common.Bool_Object)(result.AsyncState);
                    Tashjik.Common.AsyncCallback_Object checkPredecessorAppState = (Tashjik.Common.AsyncCallback_Object)(thisAppState.obj);

                    if(!(thisAppState.b))
                        predecessor = null;

                    //AsyncCallback callBack = ((Tashjik.Common.AsyncCallback_Object)appState).callBack;
                    //Object appState1 = ((Tashjik.Common.AsyncCallback_Object)appState).obj;

                    if(!(checkPredecessorAppState.callBack==null))
                    {
                        Console.WriteLine("Chord::ChordRealNode::Engine processPingForCheckPredecessor callBack!=null");
                        IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(checkPredecessorAppState.obj, true, true);
                        checkPredecessorAppState.callBack(res);
                    }
            }
Example #23
0
            void processFindSuccessorForJoin(IAsyncResult result)
            {
                Console.WriteLine("ChordRealNode::Engine::processFindSuccessorForJoin ENTER");

                    ChordCommon.IChordNode_Object iNode_Object = (ChordCommon.IChordNode_Object)(result.AsyncState);
                    Tashjik.Common.AsyncCallback_Object thisAppState = (Tashjik.Common.AsyncCallback_Object)(iNode_Object.obj);
                    lock (successorLock)
                    {
                        successor = iNode_Object.node;
                    }
                    Console.WriteLine("ChordRealNode::Engine::processFindSuccessorForJoin successor has been set");

                    lock (successorLock)
                    {
                        successor.beginGetFingerTable(new AsyncCallback(processGetFingerTableForJoin), thisAppState);
                    }

                    //we have found the successor, and a request has been made for its finger table
                    //once the finger table comes in, a findSiccessor call will be made to each of them
                    //do we need to wait till all of them respond? wat if a few of them go down
                    // we can't hang forever... better to return back, and allow the client to query
                    // if the queries happen immediately, tey will fail because the finger table is still empty
                    // as the finger table starts filling up, the queries will get answered better
                    //
                    // other possible solutions: wait for some time (and not indefinitely), and then allow
                    // the client to query. But how long should we wait? In the literature do we have any such
                    // approximate times by which quesries will come back? totally unpredictable I feel... depends
                    // on whether the n/w is the intyernet or a LAN, etc,.
                    //
                    // maybe we could wait till a certain number of entries inthe finger table get filled up ...
                    // maybe 60% .... but how do we decide on this number ... perhaps ChordCylinder will have
                    // data on Churn rates and can set this. Will require significant chanes to the architecture,
                    // because here the client is deciding on how long we should wait

                    AsyncCallback callBack = thisAppState.callBack;
                    Object appState1 = thisAppState.obj;

                    if (!(callBack == null))
                    {
                        IAsyncResult res = new Tashjik.Common.ObjectAsyncResult(appState1, true, true);

                        callBack(res);
                    }
            }
Example #24
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);
                }
            }
        }