/// Method: IsRegister /// Last Modified: 11/29/09 /// <summary> /// Determines if the XML String is the register object /// in XML form. /// </summary> /// ----------------------------------------------------- /// PRECONDITIONS: Review the parameters statement. /// ----------------------------------------------------- /// Parameters: /// <param name="sXML"> /// A string that contains the XML data. /// </param> /// ----------------------------------------------------- /// POSTCONDITIONS: Refer to the return statement. /// ----------------------------------------------------- /// Return Value: /// bool -- Returns true if the XML supplied is this /// object in XML form. public static bool IsRegister(String sXML) { Register r = new Register(null, -1, "", ""); return r.IsXmlObject(sXML); }
/// Last Modified: 10/24/10 /// <summary> /// This event is triggered when the child is requesting /// to unregister with the parent. /// </summary> /// ----------------------------------------------------- /// PRECONDITIONS: Refer to the following arguments. /// ----------------------------------------------------- /// Parameters: /// <param name="p"> /// A packet that contains information about the event. /// </param> /// ----------------------------------------------------- /// POSTCONDITIONS: NA -- No postconditions exist. /// ----------------------------------------------------- /// Return Value: protected override void OnRequestToUnregister(Packet p) { //Obtain the register message. Register r = new Register(p.Msg); //Unregister the child node and obtain the link. UnregisterEndPoint(p.SourceName); try { //Notify all children of the new node. NotifyAllChildrenOfNodeEvent(p.SourceName, false); //Update listeners of the node event. OnNodeEvent(NodeEvent.UNREGISTERED, p.SourceName, ""); } catch (NodeException ne) { Close(); OnNodeEvent(NodeEvent.NETWORK_ERROR, GetNodeType(), ne.Message); } }
/// Last Modified: 10/24/10 /// <summary> /// Attempts to unregister the child with the parent. /// </summary> /// ----------------------------------------------------- /// PRECONDITIONS: The child must be registered with the parent. /// ----------------------------------------------------- /// Parameters: /// ----------------------------------------------------- /// POSTCONDITIONS: NA -- No postconditions exist. /// ----------------------------------------------------- /// Exceptions: /// 1) NodeSocketInvalid /// 2) NodeUnknownException /// ----------------------------------------------------- /// Return Value: private void UnregisterWithParent() { //Only attempt to unregister the child if the parent is valid. if (m_iepParentNode != null) { Register r = new Register(NodeSocket.GetLocalIP(), HostPort, "", GetNodeType()); //Create a new packet to send to the parent. Packet p = new Packet( Packet.EventTag.Unregister, //Protocol NodeName, //SrcName -- Unique name to un-register the node with. ParentNode.GetNodeType(), //DestName -- Not used in registration. r.ToString(), //Msg LogicalTime); //Logical Time. //Send the packet synchronously. SendToParent(p); } //END OF if (m_iepParentNode != null)... }
/// Last Modified: 10/24/10 /// <summary> /// This event is triggered when a child is requesting /// to register with the parent node. /// </summary> /// ----------------------------------------------------- /// PRECONDITIONS: Refer to the following arguments. /// ----------------------------------------------------- /// Parameters: /// <param name="p"> /// A packet that contains information about the event. /// </param> /// ----------------------------------------------------- /// POSTCONDITIONS: NA -- No postconditions exist. /// ----------------------------------------------------- /// Return Value: /// <returns> /// Returns true if the child could be registered. /// </returns> protected override bool OnRequestToRegister(Packet p) { //Obtain the register message. Register r = new Register(p.Msg); //Generate message to display. string sMsg = r.IPAddress.ToString() + ":" + r.Port.ToString(); try { //Update the states based on the link. if (RegisterEndPoint(p.SourceName, new IPEndPoint(r.IPAddress, r.Port))) { //temporarily package all of the user's into a tilde delimited string and attach // it to the message. StringBuilder sb = new StringBuilder(); foreach (KeyValuePair<string, IPEndPoint> kvp in m_iepRoutingTable) if (kvp.Key != p.SourceName) sb.Append(((sb.Length > 0) ? "~" : "") + kvp.Key); //Notify the child of registration. NotifyChildOfRegistration(r.IPAddress, r.Port, p.SourceName, true, sb.ToString()); //Notify all children of the new node. NotifyAllChildrenOfNodeEvent(p.SourceName, true); //Update listeners of the node event. OnNodeEvent(NodeEvent.REGISTERED, p.SourceName, sMsg); return true; } else { //Notify the child of the failure. NotifyChildOfRegistration(r.IPAddress, r.Port, p.SourceName, false, NodeEvent.ALREADY_REGISTERED.ToString()); //Update listeners of the node event. OnNodeEvent(NodeEvent.ALREADY_REGISTERED, p.SourceName, sMsg); } //END OF if (RegisterEndPoint(p.SourceName, new IPEndPoint(r.IPAddress, r.Port)))... } catch (NodeException ne) { Close(); OnNodeEvent(NodeEvent.NETWORK_ERROR, GetNodeType(), ne.Message); } //All other conditions are a failure. return false; }
/// Last Modified: 10/24/10 /// <summary> /// Attempts to register the child node with the parent. /// </summary> /// ----------------------------------------------------- /// PRECONDITIONS: Refer to the following arguments. /// ----------------------------------------------------- /// Parameters: /// <param name="ipAddr"> /// Contains the IPAddress of the parent. /// </param> /// <param name="nPort"> /// Contains the port of the parent. /// </param> /// ----------------------------------------------------- /// POSTCONDITIONS: NA -- No postconditions exist. /// ----------------------------------------------------- /// Exceptions: /// 1) NodeSocketInvalid /// 2) NodeUnknownException /// ----------------------------------------------------- /// Return Value: private void RegisterWithParent(IPAddress ipAddr, int nPort) { //Create the parent endpoint. m_iepParentNode = new IPEndPoint(ipAddr, nPort); Register r = new Register(NodeSocket.GetLocalIP(), HostPort, "", GetNodeType()); //Create a new packet to send to the parent. Packet p = new Packet( Packet.EventTag.Register, //Protocol NodeName, //SrcName -- Unique name to register the node with. ParentNode.GetNodeType(), //DestName -- Not used in registration. r.ToString(), //Msg LogicalTime); //Logical Time. //Send the packet synchronously. SendToParent(p); }