/******************************************************************* * Function Name: internalFunction ********************************************************************/ Model &Dispatcher::internalFunction( const InternalMessage & ){ passivate(); // we just passivate immediately return *this; }
/******************************************************************* * Function Name: internalFunction ********************************************************************/ Model <SNetwork::internalFunction( const InternalMessage & msg){ if(VERBOSE) cout<<"Internal Transition :"<<endl<<"time: "<<msg.time().asMsecs()<<endl; currenttimefloat = msg.time().asMsecs();//currenttimefloat + lastChange().asMsecs(); //hack - test //lastChange(msg.time()); //if(VERBOSE) cout<<"currenttime now:"<<currenttimefloat<<endl; if (!EvQ.empty()){ //|| !DisconnectionQueue.empty() || !ConnectionQueue.empty()) { // if any of the queues are not empty //advance my internal time //calculate time until next scheduled change : float remainingdelay = EvQ.top().time - currenttimefloat; //EvQ.top() is the next NetworkEvent to be output // hold until then holdIn(active, Time(remainingdelay/1000)); // time remaining until next scheduled change } else { passivate(); // we just passivate immediately } return *this; }
/******************************************************************* * Function Name: internalFunction ********************************************************************/ Model &Gnutella::internalFunction( const InternalMessage & ){ //set these back routing = false; hitting = false; passivate(); // we just passivate immediately return *this; }
/******************************************************************* * Function Name: internalFunction ********************************************************************/ Model &Server::internalFunction( const InternalMessage & ){ //Any responses to output ? if (!QueryhitQ.empty()) { // if we were or now are in the process of routing messages holdIn( active, Time(0,0,0,2)); // we wait 2ms to dequeue } else { passivate(); // we just passivate immediately } return *this; }
/******************************************************************* * Function Name: internalFunction ********************************************************************/ Model <SNetwork::internalFunction( const InternalMessage & ){ if (!EvQ.empty() || !DisconnectionQueue.empty() || !ConnectionQueue.empty()) { // if any of the queues are not empty holdIn( active, Time(0,0,0,10)); // we wait 10ms to dequeue // that is, we only have a useless fixed timing between two messages getting through the network } else { passivate(); // we just passivate immediately } return *this; }
/******************************************************************* * Function Name: internalFunction ********************************************************************/ Model <SNetwork::internalFunction( const InternalMessage & ){ if (!EvQ.empty()) { // if we were or now are in the process of routing messages holdIn( active, Time(0.01f)); // we wait 0.01s to dequeue // that is, we only have a useless fixed timing between two messages getting through the network } else { passivate(); // we just passivate immediately } return *this; }
/******************************************************************* * Function Name: externalFunction * Description: the Network gets input from outside ********************************************************************/ Model <SNetwork::externalFunction( const ExternalMessage &msg ){ //advance my internal time if(VERBOSE) cout<<"External Transition :"<<endl<<"time: "<<msg.time().asMsecs()<<endl; currenttimefloat = msg.time().asMsecs(); if (msg.port() == peer_online) { thegraph->online(msg.value()); //adds a node to the graph with the given value if(VERBOSE) cout<<"node "<<msg.value()<<" inserted\n"; } else if (msg.port() == peer_offline){ int inpeer = msg.value(); //get all the connected nodes a disconnect them, plus let them know they've been disconnected set<int> connected = thegraph->getConnectedNodes(inpeer); set<int>::iterator sit; int count = 0; for ( sit=connected.begin() ; sit != connected.end(); sit++ ){ count++; thegraph->disconnect(inpeer, *sit); //disconnect them EvQ.push(makeDisConnectEvent(inpeer, *sit,currenttimefloat+count)); // enqueue messages to be output with just 1 millisecond delay //DisconnectionQueue.push(buildMessage(*sit, inpeer)); //enqueue a message saying peer "inpeer" disconnects from "*sit" } thegraph->offline(inpeer); if(VERBOSE) cout<<"node "<<msg.value()<<" removed\n"; //holdIn( active, Time(0.00f)); } else if (msg.port() == peer_connect){ int twonumbers, from, to; twonumbers = msg.value(); from = getPeerId(twonumbers); //first and second field encoding of the peers to = getMessageId(twonumbers); if(VERBOSE) cout<<"connecting "<<from<<" to "<< to<<"\n"; if(thegraph->connect(from,to)) EvQ.push(makeConnectEvent(from, to,currenttimefloat+1)); // enqueue message to be output with just 1 millisecond delay //ConnectionQueue.push(buildMessage(to, from, 1)); // enqueue a connection message : adding the TTL makes it different from a disconnect message, further down the road //holdIn( active, Time(0.00f)); } else if (msg.port() == peer_disconnect){ int twonumbers, from, to; twonumbers = msg.value(); from = getPeerId(twonumbers); //first and second field encoding of the peers to = getMessageId(twonumbers); if(VERBOSE) cout<<"disconnecting "<<from<<" and "<< to<<"\n"; if(thegraph->disconnect(from, to)) EvQ.push(makeDisConnectEvent(from, to,currenttimefloat+1));//DisconnectionQueue.push(twonumbers); // enqueue the original message to be re-output as confirmation that connection took place //holdIn( active, Time(0.00f)); } else if (msg.port() == inroute){ //routing=true; int inpeer, TTL, messageId; inpeer = getPeerId(msg.value()); TTL= getTTL(msg.value()); messageId = getMessageId(msg.value()); if(VERBOSE) cout<<"about to route a message from"<<inpeer<<"\n"; //get all the connected nodes and enqueue the "arrival of the message" event for all these new nodes //find the nodes connected to this one set<int> connected = thegraph->getConnectedNodes(inpeer); //if(VERBOSE) cout<<"loop for enqueuing nodes :"<<connected.size()<<" nodes to enqueue"; set<int>::iterator sit; //if(VERBOSE) cout << "connected nodes contains:"; for ( sit=connected.begin() ; sit != connected.end(); sit++ ){ //generate a random network delay: float delay = static_cast<float>(distribution().get()); if(VERBOSE) cout<<"enqueueing event for time = "<<currenttimefloat +delay*1000<<"\n"; //delay in milliseconds ! EvQ.push(makeNetworkEvent(messageId, *sit, TTL, currenttimefloat + (delay*1000))); //enqueue a network event with the "*sit" peer (the other parts are not used for now) //holdIn( active, Time(0.01f)); } } if (EvQ.empty()){ // this transition didn't enqueue anything if(VERBOSE) cout<<"LTS:Event queue is empty. Passivating."<<endl; passivate(); } else { //calculate time until next scheduled change : float remainingdelay = EvQ.top().time - currenttimefloat; //EvQ.top() is the next NetworkEvent to be output if(VERBOSE) cout<<"next change at (ms):"<<EvQ.top().time<<"time until next change (s):"<<remainingdelay/1000<<endl; // hold until then holdIn(active, Time(remainingdelay/1000)); // time remaining until next scheduled change //then it will be time for an internal transition... } /*/ TEST : no external transition unless we're passive if (this->state()==passive){ holdIn( active, Time(0,0,0,120)); //wait 120ms before doing something }*/ return *this ; }
Model <SNetwork::initFunction() { passivate(); // a first change just to make sure that we start the clock right. return *this; }
void acceptor::stop_reading() { CAF_LOG_TRACE(CAF_ARG2("fd", fd())); close_read_channel(); passivate(); }
/******************************************************************* * Function Name: internalFunction ********************************************************************/ Model &Logger::internalFunction( const InternalMessage & ) { passivate(); return *this; }