Ignore:
Timestamp:
Apr 22, 2009, 9:07:53 PM (15 years ago)
Author:
Christoph Mayer
Message:

-jede Menge fixes und Umstellungen
-angefangen ariba/interface los zu werden, erste dateien sind weg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sample/pingpong/PingPong.cpp

    r2483 r3037  
    1212use_logging_cpp( PingPong );
    1313
    14 // the service id of the ping pong service
     14// the service that the pingpong wants to use
    1515ServiceID PingPong::PINGPONG_ID = ServiceID( 111 );
    1616
     
    4040
    4141        // get initiator flag
    42         this->isInitiator = Configuration::instance().read<bool> ("node.initiator");
     42        this->isInitiator = Configuration::instance().read<bool>("node.initiator");
    4343
    4444        // get node name
    4545        Name nodeName = Name::UNSPECIFIED;
    46         if (config.exists("node.name")) nodeName
    47                         = config.read<string> ("node.name");
     46        if (config.exists("node.name")) nodeName = config.read<string> ("node.name");
    4847
    4948        // configure ariba module
    5049        if (config.exists("ariba.ip.addr")) ariba->setProperty("ip.addr",
    51                         config.read<string> ("ariba.ip.addr"));
     50                        config.read<string>("ariba.ip.addr"));
    5251        if (config.exists("ariba.tcp.port")) ariba->setProperty("tcp.port",
    53                         config.read<string> ("ariba.tcp.port"));
     52                        config.read<string>("ariba.tcp.port"));
    5453        if (config.exists("ariba.udp.port")) ariba->setProperty("udp.port",
    55                         config.read<string> ("ariba.udp.port"));
     54                        config.read<string>("ariba.udp.port"));
    5655        if (config.exists("ariba.bootstrap.hints")) ariba->setProperty("bootstrap.hints",
    57                         config.read<string> ("ariba.bootstrap.hints"));
     56                        config.read<string>("ariba.bootstrap.hints"));
    5857
    5958        // start ariba module
     
    7170
    7271        // bind communication and node listener
    73         node->bind( this );
    74         node->bind( this, PingPong::PINGPONG_ID);
    75        
     72        node->bind( this );                       /*NodeListener*/
     73        node->bind( this, PingPong::PINGPONG_ID); /*CommunicationListener*/
     74
    7675        // start the ping timer. if we are not
    7776        // the initiator this will happen in onJoinCompleted
     
    7978
    8079        // ping pong started up...
    81         logging_info( "pingpong started up ");
     80        logging_info( "pingpong starting up with"
     81                        << " [spovnetid " << node->getSpoVNetId().toString() << "]"
     82                        << " and [nodeid " << node->getNodeId().toString() << "]" );
    8283}
    8384
     
    9192
    9293        // unbind communication and node listener
    93         node->unbind( this );
    94         node->unbind( this, PingPong::PINGPONG_ID );
     94        node->unbind( this );                        /*NodeListener*/
     95        node->unbind( this, PingPong::PINGPONG_ID ); /*CommunicationListener*/
    9596
    9697        // leave spovnet
     
    110111// node listener interface
    111112void PingPong::onJoinCompleted( const SpoVNetID& vid ) {
    112         logging_info( "pingpong node join completed, spovnetid=" << vid.toString() );
     113        logging_error( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX pingpong node join completed, spovnetid=" << vid.toString() );
    113114
    114115        // start the timer to ping every second
     
    117118
    118119void PingPong::onJoinFailed( const SpoVNetID& vid ) {
    119         logging_error(" pingpong node join failed, spovnetid=" << vid.toString() );
     120        logging_error("pingpong node join failed, spovnetid=" << vid.toString() );
     121}
     122
     123void PingPong::onLeaveCompleted( const SpoVNetID& vid ){
     124        logging_info("pingpong node leave completed, spovnetid=" << vid.toString() );
     125}
     126
     127void PingPong::onLeaveFailed( const SpoVNetID& vid ){
     128        logging_error("pingpong node leave failed, spovnetid=" << vid.toString() );
     129}
     130
     131// timer event
     132void PingPong::eventFunction() {
     133
     134        // we ping all nodes that are known in the overlay structure
     135        // this can be all nodes (OneHop) overlay or just some neighbors
     136        // in case of a Chord or Kademlia structure
     137
     138        logging_info( "pinging overlay neighbors with ping id " << ++pingId );
     139
     140        PingPongMessage pingmsg( pingId );
     141
     142        //-----------------------------------------------------------------------
     143        // Option 1: get all neighboring nodes and send the message to each
     144        //-----------------------------------------------------------------------
     145        vector<NodeID> nodes = node->getNeighborNodes();
     146        BOOST_FOREACH( NodeID nid, nodes ){
     147                node->sendMessage( pingmsg, nid, PingPong::PINGPONG_ID );
     148        }
     149
     150        //-----------------------------------------------------------------------
     151        // Option 2: send a "broadcast message" that actually does the same thing
     152        //           internally, gets all neighboring nodes and sends the message
     153        //-----------------------------------------------------------------------
     154        // node->sendBroadcastMessage( pingmsg, PingPong::PINGPONG_ID );
    120155}
    121156
     
    127162void PingPong::onMessage(const DataMessage& msg, const NodeID& remote, const LinkID& lnk) {
    128163
    129         PingPongMessage* pingmsg = msg.getMessage()->decapsulate<PingPongMessage> ();
     164        PingPongMessage* pingmsg = msg.getMessage()->convert<PingPongMessage> ();
    130165
    131166        logging_info( "received ping message on link " << lnk.toString()
     
    134169}
    135170
    136 // timer event
    137 void PingPong::eventFunction() {
    138        
    139         // we ping all nodes that are known in the overlay structure
    140         // this can be all nodes (OneHop) overlay or just some neighbors
    141         // in case of a Chord or Kademlia structure
    142        
    143         logging_info( "pinging overlay neighbors with ping id " << ++pingId );
    144 
    145         PingPongMessage pingmsg( pingId );
    146         node->sendBroadcastMessage( pingmsg, PingPong::PINGPONG_ID );
     171void PingPong::onLinkUp(const LinkID& lnk, const NodeID& remote){
     172        logging_info( "received link-up event for link " << lnk.toString()
     173                        << " and node " << remote.toString() );
     174}
     175
     176void PingPong::onLinkDown(const LinkID& lnk, const NodeID& remote){
     177        logging_info( "received link-down event for link " << lnk.toString()
     178                        << " and node " << remote.toString() );
     179}
     180
     181void PingPong::onLinkChanged(const LinkID& lnk, const NodeID& remote){
     182        logging_info( "received link-changed event for link " << lnk.toString()
     183                        << " and node " << remote.toString() );
     184}
     185
     186void PingPong::onLinkFail(const LinkID& lnk, const NodeID& remote){
     187        logging_info( "received link-failed event for link " << lnk.toString()
     188                        << " and node " << remote.toString() );
     189}
     190
     191void PingPong::onLinkQoSChanged(const LinkID& lnk, const NodeID& remote, const LinkProperties& prop){
     192        logging_info( "received link-qos-changed event for link " << lnk.toString()
     193                                << " and node " << remote.toString()
     194                                << " with link properties " << prop.toString() );
     195}
     196
     197void PingPong::onMessageSent(seqnum_t seq_num, bool failed, const DataMessage& msg ){
     198        logging_info( "received message sent event for seqnum " << seq_num
     199                        << " with result " << failed );
    147200}
    148201
Note: See TracChangeset for help on using the changeset viewer.