Example #1
0
Record::Record(XnUInt8* pData, XnUInt32 nMaxSize) : 
	m_pData(pData),
	m_nMaxSize(nMaxSize),
	m_nReadOffset(0)
{
	XN_ASSERT(m_pData != NULL);
	XN_ASSERT(m_nMaxSize >= HEADER_SIZE);
	SetNodeID(INVALID_NODE_ID);
	SetPayloadSize(0);
	SetUndoRecordPos(0);
}
Example #2
0
clNode::clNode(void)
{
  try
  {
    SetObjectType(otNode);
    SetNodeID(0);
    ResetHaloNode();
    ResetBoundaryNode();
  }

  catch(clExceptionTree EX)
  {
    EX.AddMethodToTree("clNode::clNode");
    throw EX;
  }
}
Example #3
0
clNode::clNode(const int ID, const dMatrix &m)
{
  try
  {
    SetObjectType(otNode);
    SetNodeID(ID);
    ResetHaloNode();
    ResetBoundaryNode();
    SetCoordinates(m);
  }

  catch(clExceptionTree EX)
  {
    EX.AddMethodToTree("clNode::clNode");
    throw EX;
  }
}
Example #4
0
clNode& clNode::Assign(const clNode &source)
{
  try
  {
    SetNodeID(source.GetNodeID());
    coord = source.GetCoordinates();

    if (source.IsHaloNode())
    {
      SetHaloNode();
    }
    else
    {
      ResetHaloNode();
    }

    if (source.IsBoundaryNode())
    {
      SetBoundaryNode();
    }
    else
    {
      ResetBoundaryNode();
    }

    elementIDList.clear();

    for(int e=0; e<source.GetNumberElements(); e++)
    {
      AddElementID(source.GetElementID(e));
    }
  }

  catch(clExceptionTree EX)
  {
    EX.AddMethodToTree("clNode::Assign");
    throw EX;
  }

  return(*this);
}
Example #5
0
bool ClusterConnection::OnMessage(ReadBuffer& msg)
{
    uint64_t            otherNodeID;
    uint64_t            otherClusterID;
    ReadBuffer          buffer;
    ClusterConnection*  dup;
    int                 read;

    //Log_Debug("ClusterConnection::OnMessage");

    if (progress == ClusterConnection::INCOMING)
    {
        // we have no incoming connections if we don't have a nodeID
        ASSERT(transport->IsAwaitingNodeID() == false);

        // the node at the other end is awaiting its nodeID
        if (msg.GetCharAt(0) == '*')
        {
            read = msg.Readf("*:%#R", &buffer);
            if (read != (int) msg.GetLength())
            {
                // protocol error
                GetSocket().GetEndpoint(endpoint);
                Log_Message("[%s] Cluster protocol error, disconnecting...", endpoint.ToString());
                transport->DeleteConnection(this);
                return true;
            }
            
            if (!endpoint.Set(buffer, true))
            {
                Log_Message("[%R] Cluster invalid network address", &buffer);
                transport->DeleteConnection(this);
                return true;                
            }
            
            progress = ClusterConnection::AWAITING_NODEID;
            Log_Trace("Conn is awaiting nodeID at %s", endpoint.ToString());

            transport->AddConnection(this);
            if (transport->OnAwaitingNodeID(endpoint))
            {
                Log_Trace();
                transport->DeleteConnection(this);
                return true;
            }
            if (nodeID == UNDEFINED_NODEID)
                Log_Message("[%s] Cluster unknown node connected <=", endpoint.ToString());
            else
                Log_Message("[%s] Cluster node %U connected <=", endpoint.ToString(), nodeID);
            return false;
        }
        
        // both ends have nodeIDs
        read = msg.Readf("%U:%U:%#R", &otherClusterID, &otherNodeID, &buffer);
        if (read != (int) msg.GetLength())
        {
            // protocol error
            GetSocket().GetEndpoint(endpoint);
            Log_Message("[%s] Cluster protocol error, disconnecting...", endpoint.ToString());
            transport->DeleteConnection(this);
            return true;
        }
        
        if (otherClusterID > 0)
        {
            if (transport->GetClusterID() == 0)
            {
                // the other side has a clusterID, I don't, so set mine
                // if I'm a config server:
                //   the clusterID also needs to be set in REPLICATON_CONFIG,
                //   this is set in ConfigServer::OnConnectionReady()
                // if I'm a shard server:
                //   the controllers will send a SetNodeID message, which
                //   contains the clusterID, so I'll be fine
                transport->SetClusterID(otherClusterID);
            }
            else
            {
                if (otherClusterID != transport->GetClusterID())
                {
                    Log_Message("[%R] Cluster invalid configuration, disconnecting...", &buffer);
                    Log_Debug("mine: %U != controller %U", transport->GetClusterID(), otherClusterID);
            
                    transport->DeleteConnection(this);          // drop this
                    return true;
                }
            }
        }
        
        dup = transport->GetConnection(otherNodeID);
        if (dup)
        {
            // if the other connections isn't ready yet, drop it
            // OR
            // the other connection is ready
            // in this case, kill the connection that was initiated by higher nodeID
            // in other words, since this is an incoming connection:
            // if nodeID[of initiator] > transport->GetSelfNodeID(): drop

            if (dup->progress != READY || otherNodeID > transport->GetSelfNodeID())
            {
                Log_Trace("delete dup");
                transport->DeleteConnection(dup);       // drop dup
            }
            else if (otherNodeID != transport->GetSelfNodeID())
            {
                Log_Trace("delete this");
                transport->DeleteConnection(this);      // drop this
                return true;
            }
        }
        progress = ClusterConnection::READY;
        SetNodeID(otherNodeID);
        if (!endpoint.Set(buffer, true))
        {
            Log_Message("[%R] Cluster invalid network address", &buffer);
            transport->DeleteConnection(this);
            return true;                
        }

        // check if the other side is not sending its localhost address, when they are on 
        // different nodes
        if (endpoint.GetAddress() == Endpoint::GetLoopbackAddress() && 
         transport->GetSelfEndpoint().GetAddress() != Endpoint::GetLoopbackAddress())
        {
            Log_Message("[%R] Cluster invalid network address", &buffer);
            transport->DeleteConnection(this);
            return true;
        }
        
        Log_Trace("Conn READY to node %U at %s", nodeID, endpoint.ToString());
        if (nodeID != transport->GetSelfNodeID())
        {
            if (nodeID == UNDEFINED_NODEID)
                Log_Message("[%s] Cluster unknown node connected <=", endpoint.ToString());
            else
                Log_Message("[%s] Cluster node %U connected <=", endpoint.ToString(), nodeID);
        }
        
        transport->AddConnection(this);
        transport->OnWriteReadyness(this);
        transport->OnConnectionReady(nodeID, endpoint);
    }
    else if (progress == ClusterConnection::OUTGOING)
        ASSERT_FAIL();
    else
        transport->OnMessage(nodeID, msg); // pass msg to upper layer
    
    return false;
}