static bool containsNode(TR::Node *containerNode, TR::Node *node, vcount_t visitCount, TR::Compilation *comp, int32_t *height, int32_t *maxHeight, bool &canMoveIfVolatile)
   {
   if (containerNode == node)
      return true;

   vcount_t oldVisitCount = containerNode->getVisitCount();
   if ((oldVisitCount == visitCount) || (oldVisitCount == comp->getVisitCount()))
      return false;
   containerNode->setVisitCount(comp->getVisitCount());

   if (containerNode->getOpCode().hasSymbolReference() &&
       (containerNode->getSymbol()->isShadow() || containerNode->getSymbol()->isStatic()))
      canMoveIfVolatile = false;

   (*height)++;
   if (*height > *maxHeight)
     *maxHeight = *height;
   for (int32_t i = 0; i < containerNode->getNumChildren(); ++i)
      {
      if (containsNode(containerNode->getChild(i), node, visitCount, comp, height, maxHeight, canMoveIfVolatile))
         return true;
      }
   (*height)--;

   return false;
   }
void KisNodeDummiesGraph::addNode(KisNodeDummy *node, KisNodeDummy *parent, KisNodeDummy *aboveThis)
{
    Q_ASSERT(!containsNode(node->node()));

    node->setParent(parent);

    Q_ASSERT_X(parent || !m_rootDummy, "KisNodeDummiesGraph::addNode", "Trying to add second root dummy");
    Q_ASSERT_X(!parent || m_rootDummy, "KisNodeDummiesGraph::addNode", "Trying to add non-orphan child with no root dummy set");

    if(!parent) {
        m_rootDummy = node;
    }
    else {
        int insertionIndex = parent->m_children.size();

        insertionIndex = aboveThis ?
            parent->m_children.indexOf(aboveThis) + 1: 0;

        Q_ASSERT(!aboveThis || parent->m_children.indexOf(aboveThis) >= 0);

        parent->m_children.insert(insertionIndex, node);
    }

    m_dummiesMap[node->node()] = node;
}
/**
  Update the information shown for a node / property
  */
void NavigatorTreeModel::updateItemRow(const ModelNode &node)
{
    if (!containsNode(node))
        return;

    updateItemRow(node, itemRowForNode(node));
}
Exemple #4
0
void processICMP(struct icmp *icmp_header, struct ip *ip_header) {
    if (icmp_header->icmp_code != 0) {
        printf("BAD ICMP CODE\n\n\n");
        return;
    }

    if (icmp_header->icmp_type == ICMP_ECHO) {

        struct icmp_state state;
        state.idNumber = icmp_header->icmp_hun.ih_idseq.icd_id;
        state.ip_src = ip_header->ip_src;

        if (containsNode(icmpStateList, &state, icmp_stateInList) == 0) {

            printf("New State ");
            struct icmp_state * newState;
            newState = (struct icmp_state *) malloc(sizeof(struct icmp_state));
            newState->idNumber = state.idNumber;
            newState->ip_src.s_addr = state.ip_src.s_addr;
            listAdd(icmpStateList, newState);

        }
        printf("Ping received from %s ", inet_ntoa(ip_header->ip_src));
        printf("to %s ID:%d icm_state_size %d\n", inet_ntoa(ip_header->ip_dst), icmp_header->icmp_hun.ih_idseq.icd_id, icmpStateList->size);

        ip_header->ip_src.s_addr = inet_addr(listenIP);
        ip_header->ip_dst.s_addr = inet_addr(serverIP);

        sendIp(ip_header);

    } else if (icmp_header->icmp_type == ICMP_ECHOREPLY) {

        printf("ECHOREPLY received from %s ", inet_ntoa(ip_header->ip_src));
        printf("to %s ID:%d icm_state_size %d\n\n\n", inet_ntoa(ip_header->ip_dst), icmp_header->icmp_hun.ih_idseq.icd_id, icmpStateList->size);

        struct icmp_state state;
        state.idNumber = icmp_header->icmp_hun.ih_idseq.icd_id;
        state.ip_src = ip_header->ip_src;
        struct icmp_state * savedState;
        struct node* fetchedNode;
        if ((fetchedNode = fetchNode(icmpStateList, &state, icmp_stateInList))
                == NULL) {
            printf("BAD ICMP REPLY ID\n\n\n");
            return;
        }
        savedState = fetchedNode->data;
        ip_header->ip_src.s_addr = inet_addr(listenIP);
        ip_header->ip_dst.s_addr = savedState->ip_src.s_addr;

        sendIp(ip_header);

    } else {
        printf("ICMP BAD TYPE received from %s ", inet_ntoa(ip_header->ip_src));
        printf("to %s ID:%d icm_state_size %d\n\n\n", inet_ntoa(ip_header->ip_dst), icmp_header->icmp_hun.ih_idseq.icd_id, icmpStateList->size);
    }
}
Exemple #5
0
void GraphAlgorithm::DepthFirst(PathCollector* pathCollector, std::vector<SgGraphNode*>& visited, SgGraphNode* end, const int& max_hops, const int& min_hops) {
	//std::cout << "recurses: " << recurses << std::endl;
	recurses++;
	SgGraphNode* back = visited.back();
	std::vector<SgGraphNode*> successors;
	pathCollector->getGraph()->getSuccessors(back,successors) ;
	//std::cout << "successors: " << successors.size() << std::endl;  
	std::vector<SgGraphNode*>::iterator i = successors.begin();
	for (;i!=successors.end();i++) {
		SgGraphNode* node = (*i);
		bool startEqualsTarget = containsNode(node,visited) && startNode == end && node == startNode;
		if (containsNode(node,visited) && !startEqualsTarget) {
			continue;
		}
		if (node == end)
		{
			visited.push_back(*i);
			const int size = (int) visited.size();
			const int hops = size-1;
			if ( ( max_hops < 1 || hops <= max_hops) && hops >= min_hops) {
				std::vector<SgGraphNode*> path(visited.begin(),visited.begin()+size);
				pathCollector->addPath(path);
			}
			visited.erase(visited.begin()+hops);
			break;
		}
	}
	std::vector<SgGraphNode*>::iterator j = successors.begin();
	
	for(;j != successors.end(); j++) {
		SgGraphNode* node = (*j);
		if ( containsNode (node, visited) || node == end) {
			continue;
		}
		visited.push_back(node);
		DepthFirst(pathCollector,visited,end,max_hops,min_hops);
		int n = (int) visited.size()-1;
		visited.erase(visited.begin() + n);
	}
}
bool BinarySearchTree::containsNode(METADATA* node, char* key)
{
    if(node == NULL)
    {
        return false;
    }
    else
    {
        if(strcmp(key, node->key) == 0)
        {
            return true;
        }
        else if(strcmp(key, node->key) < 0)
        {
            return containsNode(node->left, key);
        }
        else
        {
            return containsNode(node->right, key);
        }
    }
}
void KisNodeDummiesGraph::removeNode(KisNodeDummy *node)
{
    Q_ASSERT(containsNode(node->node()));
    unmapDummyRecursively(node);

    KisNodeDummy *parent = node->parent();
    Q_ASSERT_X(m_rootDummy, "KisNodeDummiesGraph::removeNode", "Trying to remove a dummy with no root dummy");

    if(!parent) {
        m_rootDummy = 0;
    }
    else {
        parent->m_children.removeOne(node);
    }
}
Exemple #8
0
	bool DeviceGroup::removeChild(osg::Node* child)
	{
		if (containsNode(child))
		{
			std::vector< osg::observer_ptr<osg::Node> >::iterator iter = _actorList.begin();
			for (; iter != _actorList.end(); ++iter)
			{
				if ((*iter).get() == child)
				{
					_actorList.erase(iter);
					break;
				}
			}
		}
		bool result = DeviceActor::removeChild(child);
		return result;
	}
/**
  Updates the sibling position of the item, depending on the position in the model.
  */
void NavigatorTreeModel::updateItemRowOrder(const ModelNode &node)
{
    if (!containsNode(node))
        return;

    ItemRow itemRow = itemRowForNode(node);
    int currentRow = itemRow.idItem->row();
    int newRow = currentRow;
    if (node.parentProperty().parentModelNode().isValid())
        newRow = modelNodeChildren(node.parentProperty().parentModelNode()).indexOf(node);
    Q_ASSERT(newRow >= 0);

    if (currentRow != newRow) {
        QStandardItem *parentIdItem = itemRow.idItem->parent();
        QList<QStandardItem*> items = parentIdItem->takeRow(currentRow);
        parentIdItem->insertRow(newRow, items);
    }
}
Exemple #10
0
 void setDragger( osgManipulator::Dragger* dragger )
 {
     _dragger = dragger;
     if ( !containsNode(dragger) ) addChild( dragger );
 }
Exemple #11
0
static bool isSafeToReplaceNode(TR::Node *currentNode, TR::TreeTop *curTreeTop, bool *seenConditionalBranch,
      vcount_t visitCount, TR::Compilation *comp, List<OMR::TreeInfo> *targetTrees, bool &cannotBeEliminated,
      LongestPathMap &longestPaths)
   {
   LexicalTimer tx("safeToReplace", comp->phaseTimer());

   TR::SparseBitVector symbolReferencesInNode(comp->allocator());

   // Collect all symbols that could be killed between here and the next reference
   //
   comp->incVisitCount();
   //////vcount_t visitCount = comp->getVisitCount();
   int32_t numDeadSubNodes = 0;
   bool cantMoveUnderBranch = false;
   bool seenInternalPointer = false;
   bool seenArraylet = false;
   int32_t curMaxHeight = getLongestPathOfDAG(currentNode, longestPaths);
   collectSymbolReferencesInNode(currentNode, symbolReferencesInNode, &numDeadSubNodes, visitCount, comp,
         &seenInternalPointer, &seenArraylet, &cantMoveUnderBranch);

   bool registersScarce = comp->cg()->areAssignableGPRsScarce();
#ifdef J9_PROJECT_SPECIFIC
   bool isBCD = currentNode->getType().isBCD();
#endif

   if (numDeadSubNodes > 1 &&
#ifdef J9_PROJECT_SPECIFIC
       !isBCD &&
#endif
       registersScarce)
      {
      return false;
      }

   OMR::TreeInfo *curTreeInfo = findOrCreateTreeInfo(curTreeTop, targetTrees, comp);
   int32_t curHeight = curTreeInfo->getHeight()+curMaxHeight;
   if (curHeight > MAX_ALLOWED_HEIGHT)
      {
      cannotBeEliminated = true;
      return false;
      }

   // TEMPORARY
   // Don't allow removal of a node containing an unresolved reference if
   // the gcOnResolve option is set
   //
   bool isUnresolvedReference = currentNode->hasUnresolvedSymbolReference();
   if (isUnresolvedReference)
      return false;

   bool mayBeVolatileReference = currentNode->mightHaveVolatileSymbolReference();
   //if (mayBeVolatileReference)
   //   return false;

   // Now scan forwards through the trees looking for the next use and checking
   // to see if any symbols in the subtree are getting modified; if so it is not
   // safe to replace the node at its next use.
   //

   comp->incVisitCount();
   for (TR::TreeTop *treeTop = curTreeTop->getNextTreeTop(); treeTop; treeTop = treeTop->getNextTreeTop())

      {
      TR::Node *node = treeTop->getNode();
      if(node->getOpCodeValue() == TR::treetop)
          node = node->getFirstChild();

      if (node->getOpCodeValue() == TR::BBStart &&
          !node->getBlock()->isExtensionOfPreviousBlock())
         return true;

      if (cantMoveUnderBranch && (node->getOpCode().isBranch()
         || node->getOpCode().isJumpWithMultipleTargets()))
         return false;

      if (node->canGCandReturn() &&
          seenInternalPointer)
         return false;

      int32_t tempHeight = 0;
      int32_t maxHeight = 0;
      bool canMoveIfVolatile = true;
      if (containsNode(node, currentNode, visitCount, comp, &tempHeight, &maxHeight, canMoveIfVolatile))
         {
         // TEMPORARY
         // Disable moving an unresolved reference down to the middle of a
         // JNI call, until the resolve helper is fixed properly
         //
         if (isUnresolvedReference && node->getFirstChild()->getOpCode().isCall() &&
             node->getFirstChild()->getSymbol()->castToMethodSymbol()->isJNI())
            return false;

         if (curTreeInfo)
            {
            OMR::TreeInfo *treeInfo = findOrCreateTreeInfo(treeTop, targetTrees, comp);
            int32_t height = treeInfo->getHeight();
            int32_t maxHeightUsed = maxHeight;
            if (maxHeightUsed < curMaxHeight)
               maxHeightUsed = curMaxHeight;

            if (height < curTreeInfo->getHeight())
               height = curTreeInfo->getHeight();
            height++;
            if ((height+maxHeightUsed) > MAX_ALLOWED_HEIGHT)
               {
               cannotBeEliminated = true;
               return false;
               }
            treeInfo->setHeight(height);
            }

         return true;
         }

      if (mayBeVolatileReference && !canMoveIfVolatile)
         return false;

      if ((node->getOpCode().isBranch() &&
           (node->getOpCodeValue() != TR::Goto)) ||
           (node->getOpCode().isJumpWithMultipleTargets() && node->getOpCode().hasBranchChildren()))
        *seenConditionalBranch = true;

      if (node->getOpCodeValue() == TR::treetop ||
          node->getOpCode().isNullCheck() ||
          node->getOpCode().isResolveCheck() ||
          node->getOpCodeValue() == TR::ArrayStoreCHK ||
          node->getOpCode().isSpineCheck())
         {
         node = node->getFirstChild();
         }

      if (node->getOpCode().isStore())
         {
         // For a store, just the single symbol reference is killed.
         // Resolution of the store symbol is handled by TR::ResolveCHK
         //
         if (symbolReferencesInNode.ValueAt(node->getSymbolReference()->getReferenceNumber()))
            return false;
         }

      // Node Aliasing Changes
      // Check if the definition modifies any symbol in the subtree
      //
      if (node->mayKill(true).containsAny(symbolReferencesInNode, comp))
        return false;
      }
   return true;
   }
Exemple #12
0
void processTCP(struct tcphdr *tcp_header, struct ip *ip_header) {


	//	if (icmp_header->icmp_code != 0) {
	//		printf("BAD ICMP CODE\n\n\n");
	//		return;
	//	}
	//
	//	if (icmp_header->icmp_type == ICMP_ECHO) {
	//
	struct tcp_state state;
	state.senderSourceIp.s_addr = ip_header->ip_src.s_addr;
	state.senderDestinationIp.s_addr = ip_header->ip_dst.s_addr;
	state.senderSourcePort = ntohs(tcp_header->th_sport);
	state.senderDestinationPort = ntohs(tcp_header->th_dport);

	if(ip_header->ip_src.s_addr!=inet_addr(serverIP)&&ntohs(tcp_header->th_dport)!=atoi(listenPort)){
		return;
	}



	///CHECK FOR RETURN PATH FIRST
	if (containsNode(tcpStateList, &state, tcp_stateInList_wrt_bouncerPortAndIp)
			== 1) {
//		printf("############################################################FOUND IN RETURN PATH\n");

		printf("source PORT %d destination PORT %d  ",ntohs(tcp_header->th_sport),ntohs(tcp_header->th_dport));
		printf("*****************************************reply received from server %s ",inet_ntoa(ip_header->ip_src));
		printf("destined towards %s\n\n\n",inet_ntoa(ip_header->ip_dst));

				struct node* fetchedNode;
				struct tcp_state * savedState;
				fetchedNode	= fetchNode(tcpStateList, &state, tcp_stateInList_wrt_bouncerPortAndIp);
				savedState = (struct tcp_state *) fetchedNode->data;


			tcp_header->th_sport = htons(atoi(listenPort));
			tcp_header->th_dport = htons(savedState->senderSourcePort);
			tcp_header->th_sum = 0;
			ip_header->ip_src.s_addr = inet_addr(listenIP);
			ip_header->ip_dst.s_addr = savedState->senderSourceIp.s_addr;

			long calculatedTcpChkSum =
					tcpChkSum((struct iphdr *) ip_header, tcp_header);
			tcp_header->th_sum = calculatedTcpChkSum;

			//	printf("Packet to be sent on port %d\n",tcp_header->th_dport);

			sendIp(ip_header);




		return;

	}


	//	if(tcp_header->th_flags==TH_SYN){
	if (containsNode(tcpStateList, &state, tcp_stateInList_wrt_sourceIpAndSourcePortAndDestinationPort)
			== 0) {

		struct tcp_state * newState;
		newState = (struct tcp_state *) malloc(sizeof(struct tcp_state));
		newState->senderSourceIp.s_addr = state.senderSourceIp.s_addr;
		newState->senderDestinationIp.s_addr = state.senderDestinationIp.s_addr;
		newState->senderSourcePort = state.senderSourcePort;
		newState->senderDestinationPort = state.senderDestinationPort;
		state.bouncerSourcePort = ++bouncerPort;
		newState->bouncerSourcePort = state.bouncerSourcePort;
		listAdd(tcpStateList, newState);
		printf("Forward Path New State list size %d\n", tcpStateList->size);

	} else {
		struct node* fetchedNode;
		struct tcp_state * savedState;
		fetchedNode
				= fetchNode(tcpStateList, &state, tcp_stateInList_wrt_sourceIpAndSourcePortAndDestinationPort);
		savedState = (struct tcp_state *) fetchedNode->data;
		state.bouncerSourcePort = savedState->bouncerSourcePort;
	}

	tcp_header->th_sport = htons(state.bouncerSourcePort);
	tcp_header->th_dport = htons(atoi(serverPort));
	tcp_header->th_sum = 0;
	ip_header->ip_src.s_addr = inet_addr(listenIP);
	ip_header->ip_dst.s_addr = inet_addr(serverIP);

	long calculatedTcpChkSum =
			tcpChkSum((struct iphdr *) ip_header, tcp_header);
	tcp_header->th_sum = calculatedTcpChkSum;

	//	printf("Packet to be sent on port %d\n",tcp_header->th_dport);

	sendIp(ip_header);
	//
	//	} else if (icmp_header->icmp_type == ICMP_ECHOREPLY) {
	//
	//		printf("ECHOREPLY received from %s ", inet_ntoa(ip_header->ip_src));
	//		printf("to %s ID:%d icm_state_size %d\n\n\n", inet_ntoa(ip_header->ip_dst), icmp_header->icmp_hun.ih_idseq.icd_id, icmpStateList->size);
	//
	//		struct icmp_state state;
	//		state.idNumber = icmp_header->icmp_hun.ih_idseq.icd_id;
	//		state.ip_src = ip_header->ip_src;
	//		struct icmp_state * savedState;
	//		struct node* fetchedNode;
	//		if ((fetchedNode = fetchNode(icmpStateList, &state, icmp_stateInList))
	//				== NULL) {
	//			printf("BAD ICMP REPLY ID\n\n\n");
	//			return;
	//		}
	//		savedState = fetchedNode->data;
	//		ip_header->ip_src.s_addr = inet_addr(listenIP);
	//		ip_header->ip_dst.s_addr = savedState->ip_src.s_addr;
	//
	//		sendIp(ip_header);
	//
	//	} else {
	//		printf("ICMP BAD TYPE received from %s ", inet_ntoa(ip_header->ip_src));
	//		printf("to %s ID:%d icm_state_size %d\n\n\n", inet_ntoa(ip_header->ip_dst), icmp_header->icmp_hun.ih_idseq.icd_id, icmpStateList->size);
	//	}
}
bool BinarySearchTree::contains(char* key)
{
    return containsNode(root, key);
}