Classes | |
struct | Client |
Public Member Functions | |
void | initializeApp (int stage) |
App initialization - should be overwritten by application. | |
void | initializeI3 () |
Application I3 initialize - should be overwritten by application. | |
void | deliver (I3Trigger &trigger, I3IdentifierStack &stack, cPacket *msg) |
Delivers packets coming from I3 - should be overwritten by application. | |
void | handleTimerEvent (cMessage *msg) |
Handles timers - should be overwritten by application. | |
void | createMessage () |
Public Attributes | |
int | myIndex |
I3Identifier | myIdentifier |
map< I3Identifier, Client > | clients |
I3Identifier | publicIdentifier |
I3Identifier | privateIdentifier |
cMessage * | handShakeTimer |
cMessage * | sendPacketTimer |
Static Private Attributes | |
static int | index = 0 |
Definition at line 28 of file I3Triggers.cc.
void I3Triggers::createMessage | ( | ) |
void I3Triggers::deliver | ( | I3Trigger & | trigger, | |
I3IdentifierStack & | stack, | |||
cPacket * | msg | |||
) | [virtual] |
Delivers packets coming from I3 - should be overwritten by application.
trigger | Application trigger to which the packet was sent | |
stack | Identifier stack passed from I3 | |
msg | Arriving message |
Reimplemented from I3BaseApp.
Definition at line 117 of file I3Triggers.cc.
{ TriggersHandshakeMsg *hmsg = dynamic_cast<TriggersHandshakeMsg*>(msg); TriggersMsg *tmsg = NULL; if (!hmsg) tmsg = dynamic_cast<TriggersMsg*>(msg); if (myIndex == 0) { // act as server if (hmsg) { getParentModule()->bubble("Got handshake!"); // this is a handshake message TriggersHandshakeMsg *newMsg = new TriggersHandshakeMsg(); // create a new private trigger I3Identifier privateId; privateId.createRandomKey(); // insert it into i3 insertTrigger(privateId); // store the client's value Client client; client.clientId = hmsg->getTriggerId(); client.privateId = privateId; client.sentValue = hmsg->getValue(); clients[privateId] = client; // notify the client back newMsg->setValue(0); newMsg->setTriggerId(privateId); sendPacket(hmsg->getTriggerId(), newMsg); } else if (tmsg) { getParentModule()->bubble("Got normal message!"); // this is a normal message. just reply with sent value TriggersMsg *newMsg = new TriggersMsg(); Client &client = clients[matchingTrigger.getIdentifier()]; newMsg->setValue(client.sentValue); sendPacket(client.clientId, newMsg); } } else { //act as client if (hmsg) { getParentModule()->bubble("Finished handshaking!"); // store the private trigger privateIdentifier = hmsg->getTriggerId(); WATCH(privateIdentifier); } else { // check if the value is valid if (tmsg->getValue() == myIndex) { getParentModule()->bubble("Got packet - Got my id!"); } else { getParentModule()->bubble("Got packet - Got an unknown id"); } } } }
void I3Triggers::handleTimerEvent | ( | cMessage * | msg | ) | [virtual] |
Handles timers - should be overwritten by application.
msg | Timer to be handled |
Reimplemented from I3BaseApp.
Definition at line 87 of file I3Triggers.cc.
{ if (myIndex != 0) { if (msg == handShakeTimer) { // start handshake TriggersHandshakeMsg *msg = new TriggersHandshakeMsg(); msg->setValue(myIndex); msg->setTriggerId(myIdentifier); sendPacket(publicIdentifier, msg); getParentModule()->bubble("Started handshake"); } else if (msg == sendPacketTimer) { //send a packet TriggersMsg *msg = new TriggersMsg(); msg->setValue(0); sendPacket(privateIdentifier, msg); // reset timer sendPacketTimer = new cMessage("packet timer"); scheduleAt(simTime() + 5, sendPacketTimer); getParentModule()->bubble("Sending packet"); } } delete msg; }
void I3Triggers::initializeApp | ( | int | stage | ) | [virtual] |
App initialization - should be overwritten by application.
I3 related commands should go in initializeI3.
stage | Initialization stage passed from initialize() |
Reimplemented from I3BaseApp.
Definition at line 62 of file I3Triggers.cc.
{ myIndex = index++; WATCH(myIndex); WATCH(myIdentifier); }
void I3Triggers::initializeI3 | ( | ) | [virtual] |
Application I3 initialize - should be overwritten by application.
Reimplemented from I3BaseApp.
Definition at line 70 of file I3Triggers.cc.
{ publicIdentifier.createFromHash("Triggers 0"); ostringstream os; os << "Triggers " << myIndex; myIdentifier.createFromHash(os.str()); insertTrigger(myIdentifier); // handshake timer must be set before the packet timer! handShakeTimer = new cMessage("handshake timer"); scheduleAt(simTime() + 5, handShakeTimer); sendPacketTimer = new cMessage("packet timer"); scheduleAt(simTime() + 10, sendPacketTimer); }
Definition at line 44 of file I3Triggers.cc.
Referenced by deliver().
cMessage* I3Triggers::handShakeTimer |
Definition at line 50 of file I3Triggers.cc.
Referenced by handleTimerEvent(), and initializeI3().
int I3Triggers::index = 0 [static, private] |
Definition at line 31 of file I3Triggers.cc.
Referenced by initializeApp().
Definition at line 36 of file I3Triggers.cc.
Referenced by handleTimerEvent(), initializeApp(), and initializeI3().
Definition at line 33 of file I3Triggers.cc.
Referenced by deliver(), handleTimerEvent(), initializeApp(), and initializeI3().
Definition at line 48 of file I3Triggers.cc.
Referenced by deliver(), and handleTimerEvent().
Definition at line 47 of file I3Triggers.cc.
Referenced by handleTimerEvent(), and initializeI3().
cMessage* I3Triggers::sendPacketTimer |
Definition at line 51 of file I3Triggers.cc.
Referenced by handleTimerEvent(), and initializeI3().