243 lines
7.8 KiB
C++
243 lines
7.8 KiB
C++
/*
|
|
* File: NFDTestApplication.cc
|
|
* Author: jgaebler
|
|
*
|
|
* Created on April 20, 2011, 11:32 AM
|
|
*/
|
|
|
|
#include "NFDTestApplication.h"
|
|
|
|
#include "Dispatcher.h"
|
|
#include "Moversight.h"
|
|
|
|
#include "common/transport/TransportAddress.h"
|
|
#include "mt/msg/GroupData.h"
|
|
#include "ms/Invitation.h"
|
|
|
|
#include "ms/events/PeerJoinedEvent.h"
|
|
#include "fd/events/PeerReconnectedEvent.h"
|
|
#include "ms/events/LocalPeerUpdatedEvent.h"
|
|
#include "ms/events/JoinRequestEvent.h"
|
|
#include "ms/events/JoinConfirmEvent.h"
|
|
#include "ms/events/JoinRejectedEvent.h"
|
|
#include "ms/events/JoinAbortedEvent.h"
|
|
#include "mt/events/PendingPeersEvent.h"
|
|
|
|
#undef DEBUG
|
|
#define DEBUG(msg) if (module.isPrintDebugAPP()) \
|
|
MOV_DEBUG << "APP@"<<(dis->getLocalState()==DISJOINED?"TA_":"");\
|
|
if(dis->getLocalState()==DISJOINED){MOV_DEBUG << module.getLocalAddress();}\
|
|
else{MOV_DEBUG<< dis->getMembershipService().getLocalID();}MOV_DEBUG<<" "<<msg<<std::endl;
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
/**
|
|
* @brief Constructor
|
|
* @param m The moversight module
|
|
*/
|
|
NFDTestApplication::NFDTestApplication(Moversight & m) : Application(m, "NFDTestApplication") {
|
|
}
|
|
|
|
/**
|
|
* @brief Destructor
|
|
*/
|
|
NFDTestApplication::~NFDTestApplication() {
|
|
}
|
|
|
|
void
|
|
NFDTestApplication::initialise() {
|
|
dis->subscribe<PeerReconnectedEvent>(this);
|
|
dis->subscribe<PendingPeersEvent>(this);
|
|
dis->subscribe<JoinRequestEvent>(this);
|
|
dis->subscribe<JoinConfirmEvent>(this);
|
|
dis->subscribe<JoinRejectedEvent>(this);
|
|
dis->subscribe<PeerJoinedEvent>(this);
|
|
dis->subscribe<JoinAbortedEvent>(this);
|
|
}
|
|
|
|
void
|
|
NFDTestApplication::finalise() {
|
|
}
|
|
|
|
/**
|
|
* @brief Invites a peer to a the moversight group.
|
|
* @param ta The transport address of the peer to invite.
|
|
*/
|
|
void
|
|
NFDTestApplication::invitePeer(TransportAddress & ta) {
|
|
|
|
std::stringstream buf;
|
|
buf << "invitePeer - invite peer at address " << ta;
|
|
DEBUG(buf.str().c_str());
|
|
PeerDescription pDesc;
|
|
dis->invitePeer(ta, pDesc);
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Leaves the current group. The peer leafs the current group be
|
|
* emitting a LeaveAnnounce within the current group.
|
|
*/
|
|
void
|
|
NFDTestApplication::leaveGroup() {
|
|
|
|
DEBUG("leaveGroup - peer leave the group");
|
|
dis->leaveGroup();
|
|
}
|
|
|
|
/**
|
|
* @brief Sends dummy data to the group to simulate application traffic.
|
|
*/
|
|
void
|
|
NFDTestApplication::sendData() {
|
|
|
|
DEBUG("sendData - send 24 byte dummy data to the group");
|
|
GroupData data;
|
|
dis->sendMessage(data);
|
|
|
|
}//End
|
|
|
|
/**
|
|
* @brief Starts the given test case.
|
|
* @param i The number of the test case to start.
|
|
*/
|
|
void
|
|
NFDTestApplication::startTestCase(unsigned int i) {
|
|
|
|
}//End startTestCase
|
|
|
|
/**
|
|
* @brief Callback method. This method is called by moversight to signal that the local peer have receive a group data message.
|
|
* @param dat The received group data.
|
|
* @param sender The sending peer ID.
|
|
*/
|
|
void
|
|
NFDTestApplication::receiveGroupData(GroupData & dat, PeerID sender) {
|
|
|
|
std::stringstream buf;
|
|
buf << "receiveGroupData - receive group data from peer ID " << sender;
|
|
DEBUG(buf.str().c_str());
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Handle an incoming JoinRequestEvent
|
|
* @param e The event.
|
|
*
|
|
* The local instance has received an invitation.
|
|
*/
|
|
void
|
|
NFDTestApplication::handleEvent(const JoinRequestEvent & e) {
|
|
DEBUG("invitationReceived - invitation received");
|
|
std::stringstream buf;
|
|
|
|
buf << "invitationReceived - invitationID: " << e.getInvitation().getInvitationID() << " inviterID: " << e.getInvitation().getInviterID();
|
|
DEBUG(buf.str().c_str());
|
|
|
|
// if(module.localAddress() == 1 || module.localAddress() == 3 ){
|
|
//
|
|
// MOV_DEBUG << "APP_invitationReceived@TA_" << module.localAddress() << " reject invitation" << endl;
|
|
// gc->rejectInvitaion(invitation, "peer placing strategy not supported");
|
|
//
|
|
// }//End if
|
|
// else{
|
|
|
|
DEBUG("invitationReceived - accept invitation");
|
|
PeerDescription pDesc;
|
|
PeerResources resources;
|
|
|
|
dis->acceptInvitation(e.getInvitation(), "accept invitation", pDesc, resources);
|
|
|
|
|
|
// }//End else
|
|
}
|
|
|
|
/**
|
|
* @brief Handle an incoming JoinConfirmEvent
|
|
* @param e The event.
|
|
*
|
|
* The remote peer has accepted the invitation from the local peer.
|
|
*/
|
|
void
|
|
NFDTestApplication::handleEvent(const JoinConfirmEvent & e) {
|
|
|
|
std::stringstream buf;
|
|
buf << "receiveInvitationResponse - peer at TA: " << e.getInvitation().getInviteeAddress() << " accept invitation " << e.getInvitation().getInvitationID();
|
|
buf << " message: " << e.getMessage() << ", peer description: " << e.getDescription().getDescription();
|
|
DEBUG(buf.str().c_str());
|
|
}
|
|
|
|
/**
|
|
* @brief Handle an incoming JoinRejectedEvent.
|
|
* @param e The event.
|
|
*
|
|
* The remote peer has rejected the invitation from the local peer.
|
|
*/
|
|
void
|
|
NFDTestApplication::handleEvent(const JoinRejectedEvent & e) {
|
|
|
|
std::stringstream buf;
|
|
buf << "receiveInvitationResponse - peer at TA: " << e.getInvitation().getInviteeAddress() << " reject invitation " << e.getInvitation().getInvitationID();
|
|
buf << " reason: " << e.getReason();
|
|
DEBUG(buf.str().c_str());
|
|
}
|
|
|
|
/**
|
|
* @brief Handle an incoming JoinAbortedEvent.
|
|
* @param e The event.
|
|
*
|
|
* The invitation process was aborted.
|
|
*/
|
|
void
|
|
NFDTestApplication::handleEvent(const JoinAbortedEvent & e) {
|
|
|
|
std::stringstream buf;
|
|
buf << "invitationAborted - invitation to peer " << e.getTransportAddress() << " aborted";
|
|
buf << " reason: " << e.getReason();
|
|
DEBUG(buf.str().c_str());
|
|
}
|
|
|
|
/**
|
|
* @brief Handle an incoming PeerJoinedEvent.
|
|
* @param e The event.
|
|
*/
|
|
void
|
|
NFDTestApplication::handleEvent(const PeerJoinedEvent & e) {
|
|
std::stringstream buf;
|
|
buf << "peerJoined - peer " << e.getPeerID()
|
|
<< "@TA_" << e.getTransportAddress() << " joined group successfully ("
|
|
<< e.getDescription().getDescription() << ")";
|
|
|
|
DEBUG(buf.str().c_str());
|
|
}
|
|
|
|
/**
|
|
* @brief Handle an incoming PendingPeersEvent.
|
|
* @param e The event.
|
|
*
|
|
* Some peers are pending.
|
|
*/
|
|
void
|
|
NFDTestApplication::handleEvent(const PendingPeersEvent & e) {
|
|
std::stringstream buf;
|
|
buf << "peerIsPending - The following peers are pending: " << e.getPeerIDList();
|
|
DEBUG(buf.str().c_str());
|
|
}
|
|
|
|
/**
|
|
* @brief Handle an incoming PeerReconnectedEvent.
|
|
* @param e The event.
|
|
*
|
|
* A peer has reconnected.
|
|
*/
|
|
void
|
|
NFDTestApplication::handleEvent(const PeerReconnectedEvent & e) {
|
|
|
|
std::stringstream buf;
|
|
buf << "peerReconnected - peer " << e.getPeerID() << " has reconnected";
|
|
DEBUG(buf.str().c_str());
|
|
}
|
|
}
|
|
}
|