void ServerMessageRouter::routeMessages() { ServerConnectDaemon::connectProcess(); Uint16 msg_len; NetMessage* mmessage; while(SERVER->getPacket(&temp_packet) == true) { const NetMessage* message = temp_packet.getNetMessage(); if (message->message_class == _net_message_class_multi) { message_decoder.setDecodeMessage((const MultiMessage *) message, temp_packet.size); NetPacket packet; packet.fromPlayer = temp_packet.fromPlayer; packet.fromClient = temp_packet.fromClient; while ( (msg_len = message_decoder.decodeMessage(&mmessage)) ) { memcpy(packet.data, mmessage, msg_len); routePacket(&packet); } } else { routePacket(&temp_packet); } } }
void Request::handleRouterComplete() { if (router_->receivedData()) { onRequestComplete(); return; } else { /* keep trying to route this packet until it expires */ if (packet_->expired()) { onRequestComplete(); return; } printf("Route failed. Retrying...\n"); routePacket(); } }
void ServerMessageRouter::routeMessages() { ServerConnectDaemon::connectProcess(); while(SERVER->getPacket(&temp_packet) == true) { const NetMessage* message = temp_packet.getNetMessage(); if (message->message_class == _net_message_class_multi) { message_decoder.setDecodeMessage((const MultiMessage *) message); NetPacket packet; packet.toID = temp_packet.toID; packet.fromID = temp_packet.fromID; NetMessage* mmessage; while(message_decoder.decodeMessage(&mmessage)) { memcpy(packet.data, mmessage, mmessage->getSize()); routePacket(&packet); } } else { routePacket(&temp_packet); } } }
// send smth to address 'addr', port 'port' void networkingForwardData(MacInfo_t *macInfo, uint8_t *data, uint16_t len) { // PRINTF("commForwardData, len=%u\n", len); switch (routePacket(macInfo)) { case RD_DROP: // PRINTF("RD_DROP\n"); if (IS_LOCAL(macInfo)){ INC_NETSTAT(NETSTAT_PACKETS_DROPPED_TX, EMPTY_ADDR); } else{ INC_NETSTAT(NETSTAT_PACKETS_DROPPED_RX, EMPTY_ADDR); } break; case RD_LOCAL: // PRINTF("RD_LOCAL\n"); socketInputData(macInfo, data, len); break; case RD_UNICAST: // PRINTF("RD_UNICAST\n"); // force header rebuild macInfo->macHeaderLen = 0; #if PLATFORM_SADMOTE if (!IS_LOCAL(macInfo) && isDuplicate(macInfo, data, len)) { PRINTF("not forwarding, duplicate...\n"); break; } #endif if (IS_LOCAL(macInfo)) { INC_NETSTAT(NETSTAT_PACKETS_SENT, macInfo->originalDst.shortAddr); } macSendEx(macInfo, data, len); break; case RD_BROADCAST: // PRINTF("RD_BROADCAST\n"); if (!IS_LOCAL(macInfo)) { socketInputData(macInfo, data, len); } // and forward to all intToAddr(macInfo->originalDst, OSW_ADDR_BROADCAST); // force header rebuild macInfo->macHeaderLen = 0; INC_NETSTAT(NETSTAT_PACKETS_SENT, EMPTY_ADDR); macSendEx(macInfo, data, len); break; } }
/** * add received packet to receive queue */ boolean Layer3::receive( void* payload ) { packet_t* packet = (packet_t*) payload; #ifdef DEBUG_NETWORK_ENABLE Serial.print(millis()); Serial.println(F(": L3::rcv")); printPacketInformation(packet); #endif //is this a beacon? if(packet->data.type == PACKET_BEACON) { return handleBeacon(packet); } //update the neighbour - this is no beacon. neighbourMgr.updateNeighbour(packet->data.source, packet->data.source, 0); //do we have to route the packet? - no broadcast routing. if(packet->data.destination != localAddress && packet->data.destination != CONFIG_L3_ADDRESS_BROADCAST) { return routePacket(packet); } //is this an ack? (it is for us!) if(packet->data.destination == localAddress && packet->data.type == PACKET_ACK) { return handleAck(packet); } //nope, store it here. boolean success = receiveQueuePush(packet); //is this a numbered packet? - send ACK if required. if(packet->data.type == PACKET_NUMBERED && packet->data.source != localAddress) { success &= sendAck(packet); } if(!success) { return false; } return true; }
Request::State Request::initializeState(boost::shared_ptr<libtorrent::socket_type>& socket) { if (packet_->hopCount) { if (!respond(BinaryBuffer())) { return StateComplete; } printf("Setting up a tunnel.\n"); routePacket(); return StateTunnelling; } if (packet_->command == ArpRequest) { printf("Got an ARP request.\n"); BinaryBuffer response = arpTable_.query(packet_->payload, externalEndpoint_); if (!response.empty()) { return StateArpResolved; } else { broadcastArpRequest(); return StateArpUnresolved; } } if (packet_->command == PingRequest) { printf("Got a ping request.\n"); respond(BinaryBuffer()); return StateComplete; } if (packet_->command == KeyRequest) { printf("Got a key request.\n"); boost::shared_ptr<Persistence::State> state = Persistence::lock(); BinaryBuffer ourDigest = state->rsaSysDigest; Persistence::unlock(false); respond(ourDigest); return StateComplete; } /* unknown type? just shutdown */ return StateComplete; }