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