Network::Network(QObject* parent) : QObject(parent), _options(NULL), _handShakingStep(0), _port(3128), _retries(0) { this->_ns = dynamic_cast<QNetsoul*>(parent); if (this->_ns) { this->_reconnectionTimer.setSingleShot(true); QObject::connect(&this->_reconnectionTimer, SIGNAL(timeout()), this->_ns, SLOT(reconnect())); QObject::connect(&this->_socket, SIGNAL(readyRead()), SLOT(processPackets())); QObject::connect(&this->_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this->_ns, SLOT(updateWidgets(QAbstractSocket::SocketState))); QObject::connect(&this->_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(handleSocketState(QAbstractSocket::SocketState))); QObject::connect(&this->_socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(handleSocketError(QAbstractSocket::SocketError))); } else qFatal("Network constructor: parent must be a QNetsoul instance !"); this->_socket.setProxy(QNetworkProxy::NoProxy); }
// // void step() // Last modified: 27Aug2006 // // Processes packets received and updates the state of the cell, // which is then broadcast within the neighborhood of the cell. // // Returns: <none> // Parameters: <none> // void Cell::step() { if (processPackets()) { updateState(); sendStateToNbrs(); } Robot::step(); } // step()
int main(int argc, char *argv[]) { MLENV env; MLINK link; int ierr; ierr = PetscInitialize(&argc, &argv, NULL, help);if (ierr) return(ierr); ierr = setupConnection(&env, &link, "192.168.119.1", MATHEMATICA_LINK_CONNECT);CHKERRQ(ierr); ierr = processPackets(link);CHKERRQ(ierr); ierr = cleanupConnection(env, link);CHKERRQ(ierr); ierr = PetscFinalize(); return(ierr); }
void DataBus::Server::processReceivedPacket(Client *client) { // Check client if (client == 0) { // Error, null pointer return; } // Find client in the list int index = m_clients.indexOf(client); if (index < 0) { // Error, client was not found return; } // Process received packet from a client processPackets(client); }
Robot* Robot::auctioningStep() { Robot* answer = NULL; processPackets(); updateDistanceTraveled(); if(auctionStepCount>0) { auctionStepCount++; }else{ if(AUTONOMOUS_INIT) { if(auctionStepCount==0) { answer = this; //cout << "Robot["<<ID<<"] is going to hold an auction."<<endl; } } } return answer; }
//////////////////////////////////////////////////// // Constructor EQPacket::EQPacket(const QString& worldopcodesxml, const QString& zoneopcodesxml, uint16_t arqSeqGiveUp, QString device, QString ip, QString mac_address, bool realtime, bool sessionTrackingFlag, bool recordPackets, int playbackPackets, int8_t playbackSpeed, QObject * parent, const char *name) : QObject (parent, name), m_packetCapture(NULL), m_vPacket(NULL), m_timer(NULL), m_busy_decoding(false), m_arqSeqGiveUp(arqSeqGiveUp), m_device(device), m_ip(ip), m_mac(mac_address), m_realtime(realtime), m_session_tracking(sessionTrackingFlag), m_recordPackets(recordPackets), m_playbackPackets(playbackPackets), m_playbackSpeed(playbackSpeed) { // create the packet type db m_packetTypeDB = new EQPacketTypeDB(); #ifdef PACKET_OPCODEDB_DIAG m_packetTypeDB->list(); #endif // create the world opcode db (with hash size of 29) m_worldOPCodeDB = new EQPacketOPCodeDB(29); // load the world opcode db if (!m_worldOPCodeDB->load(*m_packetTypeDB, worldopcodesxml)) seqFatal("Error loading '%s'!", (const char*)worldopcodesxml); #ifdef PACKET_OPCODEDB_DIAG m_worldOPCodeDB->list(); #endif //m_worldOPCodeDB->save("/tmp/worldopcodes.xml"); // create the zone opcode db (with hash size of 211) m_zoneOPCodeDB = new EQPacketOPCodeDB(211); // load the zone opcode db if (!m_zoneOPCodeDB->load(*m_packetTypeDB, zoneopcodesxml)) seqFatal("Error loading '%s'!", (const char*)zoneopcodesxml); #ifdef PACKET_OPCODEDB_DIAG m_zoneOPCodeDB->list(); #endif //m_zoneOPCodeDB->save("/tmp/zoneopcodes.xml"); // Setup the data streams // Setup client -> world stream m_client2WorldStream = new EQPacketStream(client2world, DIR_Client, m_arqSeqGiveUp, *m_worldOPCodeDB, this, "client2world"); connectStream(m_client2WorldStream); // Setup world -> client stream m_world2ClientStream = new EQPacketStream(world2client, DIR_Server, m_arqSeqGiveUp, *m_worldOPCodeDB, this, "world2client"); connectStream(m_world2ClientStream); // Setup client -> zone stream m_client2ZoneStream = new EQPacketStream(client2zone, DIR_Client, m_arqSeqGiveUp, *m_zoneOPCodeDB, this, "client2zone"); connectStream(m_client2ZoneStream); // Setup zone -> client stream m_zone2ClientStream = new EQPacketStream(zone2client, DIR_Server, m_arqSeqGiveUp, *m_zoneOPCodeDB, this, "zone2client"); connectStream(m_zone2ClientStream); // Initialize convenient streams array m_streams[client2world] = m_client2WorldStream; m_streams[world2client] = m_world2ClientStream; m_streams[client2zone] = m_client2ZoneStream; m_streams[zone2client] = m_zone2ClientStream; // no client/server ports yet m_clientPort = 0; m_serverPort = 0; struct hostent *he; struct in_addr ia; if (m_ip.isEmpty() && m_mac.isEmpty()) seqFatal("No address specified"); if (!m_ip.isEmpty()) { /* Substitute "special" IP which is interpreted to set up a different filter for picking up new sessions */ if (m_ip == "auto") inet_aton (AUTOMATIC_CLIENT_IP, &ia); else if (inet_aton (m_ip, &ia) == 0) { he = gethostbyname(m_ip); if (!he) seqFatal("Invalid address; %s", (const char*)m_ip); memcpy (&ia, he->h_addr_list[0], he->h_length); } m_client_addr = ia.s_addr; m_ip = inet_ntoa(ia); if (m_ip == AUTOMATIC_CLIENT_IP) { m_detectingClient = true; seqInfo("Listening for first client seen."); } else { m_detectingClient = false; seqInfo("Listening for client: %s", (const char*)m_ip); } } if (m_playbackPackets == PLAYBACK_OFF) { // create the pcap object and initialize, either with MAC or IP m_packetCapture = new PacketCaptureThread(); if (m_mac.length() == 17) m_packetCapture->start(m_device, m_mac, m_realtime, MAC_ADDRESS_TYPE ); else m_packetCapture->start(m_device, m_ip, m_realtime, IP_ADDRESS_TYPE ); emit filterChanged(); } else if (m_playbackPackets == PLAYBACK_FORMAT_TCPDUMP) { // Create the pcap object and initialize with the file input given m_packetCapture = new PacketCaptureThread(); const char* filename = pSEQPrefs->getPrefString("Filename", "VPacket"); m_packetCapture->startOffline(filename, m_playbackSpeed); seqInfo("Playing back packets from '%s' at speed '%d'", filename, m_playbackSpeed); } // Flag session tracking properly on streams session_tracking(sessionTrackingFlag); // if running setuid root, then give up root access, since the PacketCapture // is the only thing that needed it. if ((geteuid() == 0) && (getuid() != geteuid())) setuid(getuid()); /* Create timer object */ m_timer = new QTimer (this); if (m_playbackPackets == PLAYBACK_OFF || m_playbackPackets == PLAYBACK_FORMAT_TCPDUMP) { // Normal pcap packet handler connect (m_timer, SIGNAL (timeout ()), this, SLOT (processPackets ())); } else { // Special internal playback handler connect (m_timer, SIGNAL (timeout ()), this, SLOT (processPlaybackPackets ())); } /* setup VPacket */ m_vPacket = NULL; QString section = "VPacket"; // First param to VPacket is the filename // Second param is playback speed: 0 = fast as poss, 1 = 1X, 2 = 2X etc if (pSEQPrefs->isPreference("Filename", section)) { const char *filename = pSEQPrefs->getPrefString("Filename", section); if (m_recordPackets) { m_vPacket = new VPacket(filename, 1, true); // Must appear befire next call to getPrefString, which uses a static string seqInfo("Recording packets to '%s' for future playback", filename); if (pSEQPrefs->getPrefBool("FlushPackets", section)) m_vPacket->setFlushPacket(true); } else if (m_playbackPackets == PLAYBACK_FORMAT_SEQ) { m_vPacket = new VPacket(filename, 1, false); m_vPacket->setCompressTime(pSEQPrefs->getPrefInt("CompressTime", section, 0)); m_vPacket->setPlaybackSpeed(m_playbackSpeed); seqInfo("Playing back packets from '%s' at speed '%d'", filename, m_playbackSpeed); } } else { m_recordPackets = 0; m_playbackPackets = PLAYBACK_OFF; } }
//////////////////////////////////////////////////// // Constructor EQPacket::EQPacket (QObject * parent, const char *name) : QObject (parent, name), m_packetCapture(NULL), m_vPacket(NULL), m_timer(NULL), m_busy_decoding(false) { // Setup the data streams // Setup client -> world stream m_client2WorldStream = new EQPacketStream(client2world, DIR_CLIENT, showeq_params->arqSeqGiveUp, this, "client2world"); connect(m_client2WorldStream, SIGNAL(rawPacket(const uint8_t*, size_t, uint8_t, uint16_t)), this, SIGNAL(rawWorldPacket(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_client2WorldStream, SIGNAL(decodedPacket(const uint8_t*, size_t, uint8_t, uint16_t)), this, SIGNAL(decodedWorldPacket(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_client2WorldStream, SIGNAL(dispatchData(const uint8_t*, size_t, uint8_t, uint16_t)), this, SLOT(dispatchWorldData(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_client2WorldStream, SIGNAL(cacheSize(int, int)), this, SIGNAL(cacheSize(int, int))); connect(m_client2WorldStream, SIGNAL(seqReceive(int, int)), this, SIGNAL(seqReceive(int, int))); connect(m_client2WorldStream, SIGNAL(seqExpect(int, int)), this, SIGNAL(seqExpect(int, int))); connect(m_client2WorldStream, SIGNAL(numPacket(int, int)), this, SIGNAL(numPacket(int, int))); // Setup world -> client stream m_world2ClientStream = new EQPacketStream(world2client, DIR_SERVER, showeq_params->arqSeqGiveUp, this, "world2client"); connect(m_world2ClientStream, SIGNAL(rawPacket(const uint8_t*, size_t, uint8_t, uint16_t)), this, SIGNAL(rawWorldPacket(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_world2ClientStream, SIGNAL(decodedPacket(const uint8_t*, size_t, uint8_t, uint16_t)), this, SIGNAL(decodedWorldPacket(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_world2ClientStream, SIGNAL(dispatchData(const uint8_t*, size_t, uint8_t, uint16_t)), this, SLOT(dispatchWorldData(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_world2ClientStream, SIGNAL(cacheSize(int, int)), this, SIGNAL(cacheSize(int, int))); connect(m_world2ClientStream, SIGNAL(seqReceive(int, int)), this, SIGNAL(seqReceive(int, int))); connect(m_world2ClientStream, SIGNAL(seqExpect(int, int)), this, SIGNAL(seqExpect(int, int))); connect(m_world2ClientStream, SIGNAL(numPacket(int, int)), this, SIGNAL(numPacket(int, int))); // Setup client -> zone stream m_client2ZoneStream = new EQPacketStream(client2zone, DIR_CLIENT, showeq_params->arqSeqGiveUp, this, "client2zone"); connect(m_client2ZoneStream, SIGNAL(rawPacket(const uint8_t*, size_t, uint8_t, uint16_t)), this, SIGNAL(rawZonePacket(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_client2ZoneStream, SIGNAL(decodedPacket(const uint8_t*, size_t, uint8_t, uint16_t)), this, SIGNAL(decodedZonePacket(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_client2ZoneStream, SIGNAL(dispatchData(const uint8_t*, size_t, uint8_t, uint16_t)), this, SLOT(dispatchZoneData(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_client2ZoneStream, SIGNAL(cacheSize(int, int)), this, SIGNAL(cacheSize(int, int))); connect(m_client2ZoneStream, SIGNAL(seqReceive(int, int)), this, SIGNAL(seqReceive(int, int))); connect(m_client2ZoneStream, SIGNAL(seqExpect(int, int)), this, SIGNAL(seqExpect(int, int))); connect(m_client2ZoneStream, SIGNAL(numPacket(int, int)), this, SIGNAL(numPacket(int, int))); // Setup zone -> client stream m_zone2ClientStream = new EQPacketStream(zone2client, DIR_SERVER, showeq_params->arqSeqGiveUp, this, "zone2client"); connect(m_zone2ClientStream, SIGNAL(rawPacket(const uint8_t*, size_t, uint8_t, uint16_t)), this, SIGNAL(rawZonePacket(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_zone2ClientStream, SIGNAL(decodedPacket(const uint8_t*, size_t, uint8_t, uint16_t)), this, SIGNAL(decodedZonePacket(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_zone2ClientStream, SIGNAL(dispatchData(const uint8_t*, size_t, uint8_t, uint16_t)), this, SLOT(dispatchZoneData(const uint8_t*, size_t, uint8_t, uint16_t))); connect(m_zone2ClientStream, SIGNAL(cacheSize(int, int)), this, SIGNAL(cacheSize(int, int))); connect(m_zone2ClientStream, SIGNAL(seqReceive(int, int)), this, SIGNAL(seqReceive(int, int))); connect(m_zone2ClientStream, SIGNAL(seqExpect(int, int)), this, SIGNAL(seqExpect(int, int))); connect(m_zone2ClientStream, SIGNAL(numPacket(int, int)), this, SIGNAL(numPacket(int, int))); // Zone to client stream specific signals (session tracking non-sense) connect(m_zone2ClientStream, SIGNAL(sessionTrackingChanged(uint8_t)), this, SIGNAL(sessionTrackingChanged(uint8_t))); connect(m_zone2ClientStream, SIGNAL(lockOnClient(in_port_t, in_port_t)), this, SLOT(lockOnClient(in_port_t, in_port_t))); connect(m_zone2ClientStream, SIGNAL(closing()), this, SLOT(closeStream())); // Initialize convenient streams array m_streams[client2world] = m_client2WorldStream; m_streams[world2client] = m_world2ClientStream; m_streams[client2zone] = m_client2ZoneStream; m_streams[zone2client] = m_zone2ClientStream; // no client/server ports yet m_clientPort = 0; m_serverPort = 0; struct hostent *he; struct in_addr ia; if (showeq_params->ip.isEmpty() && showeq_params->mac_address.isEmpty()) { printf ("No address specified\n"); exit(0); } if (!showeq_params->ip.isEmpty()) { /* Substitute "special" IP which is interpreted to set up a different filter for picking up new sessions */ if (showeq_params->ip == "auto") inet_aton (AUTOMATIC_CLIENT_IP, &ia); else if (inet_aton (showeq_params->ip, &ia) == 0) { he = gethostbyname(showeq_params->ip); if (!he) { printf ("Invalid address; %s\n", (const char*)showeq_params->ip); exit (0); } memcpy (&ia, he->h_addr_list[0], he->h_length); } m_client_addr = ia.s_addr; showeq_params->ip = inet_ntoa(ia); if (showeq_params->ip == AUTOMATIC_CLIENT_IP) { m_detectingClient = true; printf("Listening for first client seen.\n"); } else { m_detectingClient = false; printf("Listening for client: %s\n", (const char*)showeq_params->ip); } } if (!showeq_params->playbackpackets) { // create the pcap object and initialize, either with MAC or IP m_packetCapture = new PacketCaptureThread(); if (showeq_params->mac_address.length() == 17) m_packetCapture->start(showeq_params->device, showeq_params->mac_address, showeq_params->realtime, MAC_ADDRESS_TYPE ); else m_packetCapture->start(showeq_params->device, showeq_params->ip, showeq_params->realtime, IP_ADDRESS_TYPE ); emit filterChanged(); } /* Create timer object */ m_timer = new QTimer (this); if (!showeq_params->playbackpackets) connect (m_timer, SIGNAL (timeout ()), this, SLOT (processPackets ())); else connect (m_timer, SIGNAL (timeout ()), this, SLOT (processPlaybackPackets ())); /* setup VPacket */ m_vPacket = NULL; QString section = "VPacket"; // First param to VPacket is the filename // Second param is playback speed: 0 = fast as poss, 1 = 1X, 2 = 2X etc if (pSEQPrefs->isPreference("Filename", section)) { const char *filename = pSEQPrefs->getPrefString("Filename", section); if (showeq_params->recordpackets) { m_vPacket = new VPacket(filename, 1, true); // Must appear befire next call to getPrefString, which uses a static string printf("Recording packets to '%s' for future playback\n", filename); if (pSEQPrefs->getPrefString("FlushPackets", section)) m_vPacket->setFlushPacket(true); } else if (showeq_params->playbackpackets) { m_vPacket = new VPacket(filename, 1, false); m_vPacket->setCompressTime(pSEQPrefs->getPrefInt("CompressTime", section, 0)); m_vPacket->setPlaybackSpeed(showeq_params->playbackspeed); printf("Playing back packets from '%s' at speed '%d'\n", filename, showeq_params->playbackspeed); } } else { showeq_params->recordpackets = 0; showeq_params->playbackpackets = 0; } }
/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { GOTO_REAL(); /* * Initialization */ parseArgs(argc, (char** const)argv); long numThread = global_params[PARAM_THREAD]; SIM_GET_NUM_CPU(numThread); TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); long percentAttack = global_params[PARAM_ATTACK]; long maxDataLength = global_params[PARAM_LENGTH]; long numFlow = global_params[PARAM_NUM]; long randomSeed = global_params[PARAM_SEED]; printf("Percent attack = %li\n", percentAttack); printf("Max data length = %li\n", maxDataLength); printf("Num flow = %li\n", numFlow); printf("Random seed = %li\n", randomSeed); dictionary_t* dictionaryPtr = dictionary_alloc(); assert(dictionaryPtr); stream_t* streamPtr = stream_alloc(percentAttack); assert(streamPtr); long numAttack = stream_generate(streamPtr, dictionaryPtr, numFlow, randomSeed, maxDataLength); printf("Num attack = %li\n", numAttack); decoder_t* decoderPtr = decoder_alloc(); assert(decoderPtr); vector_t** errorVectors = (vector_t**)malloc(numThread * sizeof(vector_t*)); assert(errorVectors); long i; for (i = 0; i < numThread; i++) { vector_t* errorVectorPtr = vector_alloc(numFlow); assert(errorVectorPtr); errorVectors[i] = errorVectorPtr; } arg_t arg; arg.streamPtr = streamPtr; arg.decoderPtr = decoderPtr; arg.errorVectors = errorVectors; /* * Run transactions */ TIMER_T startTime; TIMER_READ(startTime); GOTO_SIM(); #ifdef OTM #pragma omp parallel { processPackets((void*)&arg); } #else thread_start(processPackets, (void*)&arg); #endif GOTO_REAL(); TIMER_T stopTime; TIMER_READ(stopTime); printf("\nTime = %lf\n", TIMER_DIFF_SECONDS(startTime, stopTime)); /* * Check solution */ /*long numFound = 0; for (i = 0; i < numThread; i++) { vector_t* errorVectorPtr = errorVectors[i]; long e; long numError = vector_getSize(errorVectorPtr); numFound += numError; for (e = 0; e < numError; e++) { long flowId = (long)vector_at(errorVectorPtr, e); bool_t status = stream_isAttack(streamPtr, flowId); assert(status); } }*/ /*printf("Num found = %li\n", numFound); assert(numFound == numAttack);*/ /* * Clean up */ for (i = 0; i < numThread; i++) { vector_free(errorVectors[i]); } free(errorVectors); decoder_free(decoderPtr); stream_free(streamPtr); dictionary_free(dictionaryPtr); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); GOTO_SIM(); thread_shutdown(); MAIN_RETURN(0); }
void Lobby::timepass() { processPackets(); }