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, cMessage *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 |
Classes | |
struct | Client |
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.
00060 { 00061 myIndex = index++; 00062 00063 WATCH(myIndex); 00064 WATCH(myIdentifier); 00065 }
void I3Triggers::initializeI3 | ( | ) | [virtual] |
Application I3 initialize - should be overwritten by application.
Reimplemented from I3BaseApp.
00067 { 00068 publicIdentifier.createFromHash("Triggers 0"); 00069 00070 ostringstream os; 00071 os << "Triggers " << myIndex; 00072 00073 myIdentifier.createFromHash(os.str()); 00074 insertTrigger(myIdentifier); 00075 00076 // handshake timer must be set before the packet timer! 00077 handShakeTimer = new cMessage("handshake timer"); 00078 scheduleAt(simulation.simTime() + 5, handShakeTimer); 00079 00080 sendPacketTimer = new cMessage("packet timer"); 00081 scheduleAt(simulation.simTime() + 10, sendPacketTimer); 00082 }
void I3Triggers::deliver | ( | I3Trigger & | trigger, | |
I3IdentifierStack & | stack, | |||
cMessage * | 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.
00115 { 00116 TriggersHandshakeMsg *hmsg = dynamic_cast<TriggersHandshakeMsg*>(msg); 00117 TriggersMsg *tmsg = NULL; 00118 00119 if (!hmsg) tmsg = dynamic_cast<TriggersMsg*>(msg); 00120 00121 if (myIndex == 0) { 00122 // act as server 00123 00124 if (hmsg) { 00125 parentModule()->bubble("Got handshake!"); 00126 00127 // this is a handshake message 00128 TriggersHandshakeMsg *newMsg = new TriggersHandshakeMsg(); 00129 00130 // create a new private trigger 00131 I3Identifier privateId; 00132 privateId.createRandomKey(); 00133 00134 // insert it into i3 00135 insertTrigger(privateId); 00136 00137 // store the client's value 00138 Client client; 00139 client.clientId = hmsg->getTriggerId(); 00140 client.privateId = privateId; 00141 client.sentValue = hmsg->getValue(); 00142 clients[privateId] = client; 00143 00144 // notify the client back 00145 newMsg->setValue(0); 00146 newMsg->setTriggerId(privateId); 00147 sendPacket(hmsg->getTriggerId(), newMsg); 00148 00149 00150 00151 } else if (tmsg) { 00152 00153 parentModule()->bubble("Got normal message!"); 00154 00155 // this is a normal message. just reply with sent value 00156 TriggersMsg *newMsg = new TriggersMsg(); 00157 00158 Client &client = clients[matchingTrigger.getIdentifier()]; 00159 newMsg->setValue(client.sentValue); 00160 sendPacket(client.clientId, newMsg); 00161 } 00162 00163 } else { 00164 //act as client 00165 00166 if (hmsg) { 00167 00168 parentModule()->bubble("Finished handshaking!"); 00169 00170 // store the private trigger 00171 privateIdentifier = hmsg->getTriggerId(); 00172 WATCH(privateIdentifier); 00173 00174 } else { 00175 00176 // check if the value is valid 00177 if (tmsg->getValue() == myIndex) { 00178 parentModule()->bubble("Got packet - Got my id!"); 00179 } else { 00180 parentModule()->bubble("Got packet - Got an unknown id"); 00181 } 00182 00183 } 00184 } 00185 }
void I3Triggers::handleTimerEvent | ( | cMessage * | msg | ) | [virtual] |
Handles timers - should be overwritten by application.
msg | Timer to be handled |
Reimplemented from I3BaseApp.
00085 { 00086 if (myIndex != 0) { 00087 if (msg == handShakeTimer) { 00088 00089 // start handshake 00090 TriggersHandshakeMsg *msg = new TriggersHandshakeMsg(); 00091 00092 msg->setValue(myIndex); 00093 msg->setTriggerId(myIdentifier); 00094 sendPacket(publicIdentifier, msg); 00095 parentModule()->bubble("Started handshake"); 00096 00097 } else if (msg == sendPacketTimer) { 00098 00099 //send a packet 00100 TriggersMsg *msg = new TriggersMsg(); 00101 msg->setValue(0); 00102 sendPacket(privateIdentifier, msg); 00103 00104 // reset timer 00105 sendPacketTimer = new cMessage("packet timer"); 00106 scheduleAt(simulation.simTime() + 5, sendPacketTimer); 00107 00108 parentModule()->bubble("Sending packet"); 00109 } 00110 } 00111 delete msg; 00112 }
void I3Triggers::createMessage | ( | ) |
int I3Triggers::index = 0 [static, private] |
Referenced by initializeApp().
Referenced by deliver(), handleTimerEvent(), initializeApp(), and initializeI3().
Referenced by handleTimerEvent(), initializeApp(), and initializeI3().
Referenced by deliver().
Referenced by handleTimerEvent(), and initializeI3().
Referenced by deliver(), and handleTimerEvent().
cMessage* I3Triggers::handShakeTimer |
Referenced by handleTimerEvent(), and initializeI3().
cMessage* I3Triggers::sendPacketTimer |
Referenced by handleTimerEvent(), and initializeI3().