| 93 | } |
| 94 | |
| 95 | void Node::NewMsg(ReceivedMsg& message, struct sockaddr_in* from) { |
| 96 | char* msg = message.data(); |
| 97 | size_t len = message.size(); |
| 98 | #ifdef DEBUG_COMM |
| 99 | printf("Node:: got message of length %u at 0x%x\n",len,msg); |
| 100 | printf("from %s:%d\n", inet_ntoa(from->sin_addr), ntohs(from->sin_port)); |
| 101 | phex(msg, 4); |
| 102 | #endif |
| 103 | if(len == strlen(ID_HDR)+sizeof(_id) && 0==strncmp(msg, ID_HDR, strlen(ID_HDR))) { |
| 104 | int *id = (int*)(msg+strlen(ID_HDR)); |
| 105 | printf("Node:: identified as party: %d\n", *id); |
| 106 | assert(*id >=0 && *id <= _numparties && *id !=_id && !_clients_connected[*id]); |
| 107 | _clients_connected[*id] = true; |
| 108 | _clientsmap.insert(std::pair<struct sockaddr_in*,int>( from, *id)); |
| 109 | _ready_nodes[*id] = true; |
| 110 | printf("Node:: _ready_nodes[%d]=%d\n",*id,_ready_nodes[*id]); |
| 111 | return; |
| 112 | } else if (len == strlen(ALL_IDENTIFIED) && 0==strncmp(msg, ALL_IDENTIFIED, strlen(ALL_IDENTIFIED))) { |
| 113 | printf("Node:: received ALL_IDENTIFIED from %d\n",_clientsmap[from]); |
| 114 | _num_parties_identified++; |
| 115 | if(_num_parties_identified == _numparties-1) { |
| 116 | printf("Node:: received ALL_IDENTIFIED from ALL\n"); |
| 117 | _updatable->NodeReady(); |
| 118 | } |
| 119 | return; |
| 120 | } |
| 121 | _updatable->NewMessage(_clientsmap[from], message); |
| 122 | #ifdef DEBUG_COMM |
| 123 | printf("finished with %d bytes at 0x%x\n", len, msg); |
| 124 | phex(msg, 4); |
| 125 | #endif |
| 126 | } |
| 127 | |
| 128 | void Node::ClientsConnected() { |
| 129 | printf("Node:: Clients connected!\n"); |
no test coverage detected