Ejemplo n.º 1
0
/**
 * Sends an ACK packet, from given port, to given port and mip
 * @param src    Port to send ACK from
 * @param port   Port to send ACK to
 * @param srcmip MIP to send ACK to
 */
void sendAck(struct applist *src, uint16_t port, uint8_t srcmip) {
	//if(debug) fprintf(stderr, "MIPTP: sendAck(%p, %d, %d)\n", src, port, srcmip);
	struct tp_packet *tpp;
	tpCreatepacket(0, port, src->recvinfo->nextRecvSeqno, 0, NULL, &tpp);

	if(debug || seqnodb) fprintf(stderr, "MIPTP: Sent ACK, requesting SN %d to port %d\n", tpp->seqno, tpp->port);

	addPacket(tpp, srcmip, sizeof(struct tp_packet), src->recvinfo->ackQueue);
}
ARTPAssembler::AssemblyStatus AMPEG4ElementaryAssembler::assembleMore(
        const sp<ARTPSource> &source) {
    AssemblyStatus status = addPacket(source);
    if (status == MALFORMED_PACKET) {
        ALOGI("access unit is damaged");
        mAccessUnitDamaged = true;
    }
    return status;
}
Ejemplo n.º 3
0
void EWAHttpPocketsCollection::cloneSettings( const EWAHttpPocketsCollection *pOther )
{
    clear();
    delete m_pRoute;

    m_pRoute = new QList<EWASiteRoutePoint*>();
    for( int i = 0; i < pOther->packetsCollectionCount(); i++ )
    {
        addPacket( pOther->getPacketAt( i ) );
    }
}
Ejemplo n.º 4
0
/// Attempts to parse a packet from the given Socket::Buffer.
/// Returns true if successful, removing the parsed part from the buffer.
/// Returns false if invalid or not enough data is in the buffer.
/// \arg buffer The Socket::Buffer to attempt to parse.
bool DTSC::Stream::parsePacket(Socket::Buffer & buffer) {
  uint32_t len;
  static bool syncing = false;
  if (buffer.available(8)) {
    std::string header_bytes = buffer.copy(8);
    if (memcmp(header_bytes.c_str(), DTSC::Magic_Header, 4) == 0) {
      len = ntohl(((uint32_t *)header_bytes.c_str())[1]);
      if (!buffer.available(len + 8)) {
        return false;
      }
      unsigned int i = 0;
      std::string wholepacket = buffer.remove(len + 8);
      JSON::Value meta;
      JSON::fromDTMI((unsigned char *)wholepacket.c_str() + 8, len, i, meta);
      addMeta(meta);
      //recursively calls itself until failure or data packet instead of header
      return parsePacket(buffer);
    }
    int version = 0;
    if (memcmp(header_bytes.c_str(), DTSC::Magic_Packet, 4) == 0) {
      version = 1;
    }
    if (memcmp(header_bytes.c_str(), DTSC::Magic_Packet2, 4) == 0) {
      version = 2;
    }
    if (version) {
      len = ntohl(((uint32_t *)header_bytes.c_str())[1]);
      if (!buffer.available(len + 8)) {
        return false;
      }
      JSON::Value newPack;
      unsigned int i = 0;
      std::string wholepacket = buffer.remove(len + 8);
      if (version == 1) {
        JSON::fromDTMI((unsigned char *)wholepacket.c_str() + 8, len, i, newPack);
      }
      if (version == 2) {
        JSON::fromDTMI2((unsigned char *)wholepacket.c_str() + 8, len, i, newPack);
      }
      addPacket(newPack);
      syncing = false;
      return true;
    }
#if DEBUG >= DLVL_WARN
    if (!syncing) {
      DEBUG_MSG(DLVL_WARN, "Invalid DTMI data detected - syncing");
      syncing = true;
    }
#endif
    buffer.get().clear();
  }
  return false;
}
Ejemplo n.º 5
0
/// Adds a keyframe packet to all tracks, so the stream can be fully played.
void DTSC::Stream::endStream() {
  if (!metadata.tracks.size()) {
    return;
  }
  for (std::map<unsigned int, Track>::iterator it = metadata.tracks.begin(); it != metadata.tracks.end(); it++) {
    JSON::Value newPack;
    newPack["time"] = (long long)it->second.lastms;
    newPack["trackid"] = it->first;
    newPack["keyframe"] = 1ll;
    newPack["data"] = "";
    addPacket(newPack);
  }
}
Ejemplo n.º 6
0
bool Graph::stop() {
  
  if(!is_running) {
    printf("error: cannot stop as we're not running.\n");
    return false;
  }

  GraphPacket* gp = new GraphPacket();
  gp->putU8(PKT_TYPE_STOP);
  addPacket(gp);

  return true;
}
Ejemplo n.º 7
0
void* makePackets(void * data) {
   int fragment = 1;

   char* s = malloc(PACKET_SIZE);

   for(;;){
      if (!isFull(ph)) {
         s = fgets(s, PACKET_SIZE, file);

         if (s == NULL) {
            getLock(ph);
            addPacket(ph, initPacket(NULL, DUMMY_FRAG_NUM));
            unlock(ph);
            pthread_exit(0);
         } else {
            getLock(ph);
            addPacket(ph, initPacket(s, fragment++));
            unlock(ph);
         }	         
      }
   }  
}
Ejemplo n.º 8
0
void Graph::addGraph(const GraphConfig& gc) {
  GraphPacket* gp = new GraphPacket();
  gp->putU8(PKT_TYPE_CONFIG);
  gp->putU16(gc.width);
  gp->putU16(gc.height);
  gp->putU16(gc.x);
  gp->putU16(gc.y);
  gp->putU8(gc.xtics);
  gp->putU8(gc.ytics);
  gp->putS32(gc.yrange[0]);
  gp->putS32(gc.yrange[1]);
  gp->putU8(gc.id);
  addPacket(gp);
}
Ejemplo n.º 9
0
void
PacketsScene::addPackets ()
{
  bool foundNodes = setUpNodeLines ();
  if (!foundNodes)
    return;
  Table * table = PacketsMode::getInstance ()->getTable ();
  table->removeAllRows ();
  uint32_t count = 0;
  uint32_t maxPackets = 10000;

  if (m_packetPathItem)
    {
      removeItem (m_packetPathItem);
    }
  m_packetPathItem = new QGraphicsPathItem;
  addItem (m_packetPathItem);
  m_packetPath = QPainterPath ();
  TimeValue <AnimEvent*> *events = AnimatorMode::getInstance ()->getEvents ();
  for (TimeValue<AnimEvent *>::TimeValue_t::const_iterator i = events->Begin ();
      i != events->End ();
      ++i)
    {
      AnimEvent * ev = i->second;
      if (ev->m_type == AnimEvent::PACKET_FBTX_EVENT)
        {
          AnimPacketEvent * packetEvent = static_cast<AnimPacketEvent *> (ev);
          if (!isAllowedNode (packetEvent->m_fromId))
            continue;
          if (!isAllowedNode (packetEvent->m_toId))
            continue;
          if (packetEvent->m_fbRx > m_toTime)
              continue;
          if (packetEvent->m_fbTx < m_fromTime)
              continue;

          if ((count == maxPackets) && m_showGraph)
            AnimatorMode::getInstance ()->showPopup ("Currently only the first " + QString::number (maxPackets) + " packets will be shown. Table will be fully populated");
          addPacket (packetEvent->m_fbTx, packetEvent->m_fbRx, packetEvent->m_fromId, packetEvent->m_toId, packetEvent->m_metaInfo, count < maxPackets );
          AnimatorMode::getInstance ()->keepAppResponsive ();
          ++count;

        }
    }
  table->adjust ();
  m_infoWidget->setVisible (false);

}
Ejemplo n.º 10
0
/**
 * Recieves and parses a packet from a connected application
 * @param recvd Recieved packet
 * @param src   Port packet was recieved from
 */
void recvApp(struct miptp_packet *recvd, struct applist *src) {
	//if(debug) fprintf(stderr, "MIPTP: recvApp(%p, %p)\n", recvd, src);
	uint16_t msglen = recvd->content_len;

	struct tp_packet *tpp;
	uint8_t pl = 4-(msglen%4);
	if(pl == 4) pl = 0;

	if(src->sendinfo->nextAddSeqno == 0) src->sendinfo->lastAckTime = time(NULL);

	tpCreatepacket(pl, recvd->dst_port, src->sendinfo->nextAddSeqno++, msglen, recvd->content, &tpp);
	uint16_t totlen = sizeof(struct tp_packet)+msglen+pl;
	if(debug || seqnodb) fprintf(stderr, "MIPTP: Packet recieved with len %d, assigned SN %d. TPP len: %d\n", recvd->content_len, src->sendinfo->nextAddSeqno, totlen);

	addPacket(tpp, recvd->dst_mip, totlen, src->sendinfo->sendQueue);
}
Ejemplo n.º 11
0
void EWAHttpPocketsCollection::load( QSettings *pSettings )
{
    clear();
    
    if( pSettings )
    {
        int requestCount = pSettings->beginReadArray( "requests" );
        for( int requestCounter = 0; requestCounter < requestCount; ++requestCounter )
        {
            pSettings->setArrayIndex( requestCounter );

            QNetworkRequest req;
            EWASiteRoutePoint *pStore = addPacket();
            pStore->load( pSettings );
        }
        pSettings->endArray();
    }
}
Ejemplo n.º 12
0
void Packets::addGraduate(QString packname, QString id, QString fio, QString dateBirth, QString dateOFfile)
{
    if(dateOFfile.isEmpty())
        dateOFfile = QString("01.04.2015");

    if (packindexBYheader.contains(packname))
    {
        int i = packindexBYheader[packname];
        packet* tmppack = Packets::packets.at(i);
        tmppack->addGraduate(id,fio,dateBirth);
    }
    else
    {
        packet* addpack = new packet();
        addpack->setHeader(packname);
        addpack->addGraduate(id,fio,dateBirth);
        addPacket(addpack);
    }

    return;
}
Ejemplo n.º 13
0
	void PacketSocket::clearPieces(bool reject)
	{
		QMutexLocker locker(&mutex);
		
		auto i = data_packets.begin();
		while (i != data_packets.end())
		{
			Packet::Ptr p = *i;
			if (p->getType() == bt::PIECE && !p->sending() && curr_packet != p)
			{
				if (reject)
					addPacket(Packet::Ptr(p->makeRejectOfPiece()));
				
				i = data_packets.erase(i);
			}
			else
			{
				i++;
			}
		}
	}
Ejemplo n.º 14
0
	void PacketSocket::doNotSendPiece(const bt::Request& req, bool reject)
	{
		QMutexLocker locker(&mutex);
		auto i = data_packets.begin();
		while (i != data_packets.end())
		{
			Packet::Ptr p = *i;
			if (p->isPiece(req) && !p->sending() && p != curr_packet)
			{
				i = data_packets.erase(i);
				if (reject)
				{
					// queue a reject packet
					addPacket(Packet::Ptr(p->makeRejectOfPiece()));
				}
			}
			else
			{
				i++;
			}
		}
	}
Ejemplo n.º 15
0
np::TransferSuccess np::BufferComponent::appendPacket( np::ResourcePacket* packet )
{
	if ( types.contains( packet->resourceType))
	{
		double spaceLeft = getSpaceLeft( packet->resourceType);
		
		std::list<np::ResourcePacket*>::iterator i = buffer.begin();
		while ( i != buffer.end())
		{
			if ( packet->resourceType == (*i)->resourceType && packet->signature == (*i)->signature)
			{
				double amount = std::min( packet->amount, spaceLeft);

				(*i)->amount += amount;
				packet->amount -= amount;

				if ( packet->amount == 0.0)
				{
					delete packet;
					return FULL;
				}
				else
				{
					return PARTIAL;
				}
			}
			i++;
		}

		return addPacket( packet);
	}
	else
	{
		return TYPE_CONFLICT;
	}
}
Ejemplo n.º 16
0
ARTPAssembler::AssemblyStatus AAMRAssembler::assembleMore(
    const sp<ARTPSource> &source) {
    return addPacket(source);
}
Ejemplo n.º 17
0
/// Attempts to parse a packet from the given std::string buffer.
/// Returns true if successful, removing the parsed part from the buffer string.
/// Returns false if invalid or not enough data is in the buffer.
/// \arg buffer The std::string buffer to attempt to parse.
bool DTSC::Stream::parsePacket(std::string & buffer) {
  uint32_t len;
  static bool syncing = false;
  if (buffer.length() > 8) {
    if (memcmp(buffer.c_str(), DTSC::Magic_Header, 4) == 0) {
      len = ntohl(((uint32_t *)buffer.c_str())[1]);
      if (buffer.length() < len + 8) {
        return false;
      }
      unsigned int i = 0;
      JSON::Value meta;
      JSON::fromDTMI((unsigned char *)buffer.c_str() + 8, len, i, meta);
      metadata = Meta(meta);
      buffer.erase(0, len + 8);
      if (buffer.length() <= 8) {
        return false;
      }
    }
    int version = 0;
    if (memcmp(buffer.c_str(), DTSC::Magic_Packet, 4) == 0) {
      version = 1;
    }
    if (memcmp(buffer.c_str(), DTSC::Magic_Packet2, 4) == 0) {
      version = 2;
    }
    if (version) {
      len = ntohl(((uint32_t *)buffer.c_str())[1]);
      if (buffer.length() < len + 8) {
        return false;
      }
      JSON::Value newPack;
      unsigned int i = 0;
      if (version == 1) {
        JSON::fromDTMI((unsigned char *)buffer.c_str() + 8, len, i, newPack);
      }
      if (version == 2) {
        JSON::fromDTMI2((unsigned char *)buffer.c_str() + 8, len, i, newPack);
      }
      buffer.erase(0, len + 8);
      addPacket(newPack);
      syncing = false;
      return true;
    }
#if DEBUG >= DLVL_WARN
    if (!syncing) {
      DEBUG_MSG(DLVL_WARN, "Invalid DTMI data detected - re-syncing");
      syncing = true;
    }
#endif
    size_t magic_search = buffer.find(Magic_Packet);
    size_t magic_search2 = buffer.find(Magic_Packet2);
    if (magic_search2 == std::string::npos) {
      if (magic_search == std::string::npos) {
        buffer.clear();
      } else {
        buffer.erase(0, magic_search);
      }
    } else {
      buffer.erase(0, magic_search2);
    }
  }
  return false;
}
Ejemplo n.º 18
0
void PacketHandler::readRaw(ConstBuffer buffer) {
  PacketReader packet(buffer);
  std::int32_t type = packet.readVarInt();
  PacketUniquePtr ptr;

  switch (mSession.getConnectionState()) {
  case ConnectionState::Handshake: {
    switch (type) {
    case 0x00: {
      packets::Handshake handshake(packet);
      handleHandshake(handshake);
      return;
    } break;

    default:
      break;
    }
  }
    break;

  case ConnectionState::Login: {
    switch (type) {
    case 0x00: {
      packets::LoginStart ls(packet);
      handleLoginStart(ls);
      return;
    }

    default:
      break;
    }
  } break;

  case ConnectionState::Status: {
    switch (type) {
    case 0x00:
      ptr = std::make_unique<packets::Request>(packet);
      break;

    case 0x01:
      ptr = std::make_unique<packets::Ping>(packet);
      break;

    default:
      break;
    }
  } break;

  case ConnectionState::Play: {
    switch (type) {
    case 0x02:
      ptr = std::make_unique<packets::ChatMessage>(packet);
      break;

    case 0x0D:
      ptr = std::make_unique<packets::PlayerPositionAndLook>(packet);
      break;

    case 0x0C:
      ptr = std::make_unique<packets::PlayerPosition>(packet);
      break;

    case 0x0E:
      ptr = std::make_unique<packets::PlayerLook>(packet);
      break;

    default:
      break;
    }
  } break;
  }

  addPacket(std::move(ptr));
}
Ejemplo n.º 19
0
Stack iteration (int sockfd, char* buffer, Stack stack) {  
  bzero(buffer, PACKET_SIZE_MAX);
  
  struct sockaddr_in serv_addr;
  socklen_t servlen = sizeof(serv_addr);
  
  int n = recvfrom(sockfd, buffer, PACKET_SIZE_MAX, 0, (struct sockaddr *)&serv_addr ,&servlen);  
  if (n < 0)exception("ERROR reading from socket");
  //printf("READ %d bytes fom a reply\n", n);
  
  Packet p = readFromBuffer(buffer, n);
  ppacket(p, "RECV");
  // only possible exit
  if (p.pt == EOT) {
    if (p.sn != checkStackWindow(stack)) {
      failure("Packet SN out of order on EOT");
      
      return iteration(sockfd, buffer, stack);
    }
    ppacket(p, "SEND");
    writeToBuffer(buffer, PACKET_SIZE_MAX, p);
    int n = sendto(sockfd, buffer, p.pl, 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr));    
    if (n < 0)exception("ERROR writing to socket");
    stack = addPacket(stack, p);
    
    return stack;
  }
  
  if (p.pt != DAT) {
    failure("Packet Type other than EOT and DAT aren't supportted");
    
    return iteration(sockfd, buffer, stack);
  }
  if (p.sn < stack.window_low || p.sn > stack.window_high) {
    failure("Packet SN out of order");
    
    return iteration(sockfd, buffer, stack);
  }
  
  
  p.pt = ACK;
  stack = addPacket(stack, p);
  // dummy window size management for now
  stack.window_high = stack.size;
  //stack = updateStackWindow(stack, p);
  
  p.pl = PACKET_SIZE_MIN;
#ifdef GBN
  p.sn = checkStackWindow(stack) - 1;
#endif
#ifdef SR
  // don't need to do anything
#endif
  ppacket(p, "SEND");
  if (p.sn >= 0){
    writeToBuffer(buffer, PACKET_SIZE_MAX, p);
    int n = sendto(sockfd, buffer, p.pl, 0, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
    if (n < 0)exception("ERROR writing to socket");
  }
  
  return iteration(sockfd, buffer, stack);
}
Ejemplo n.º 20
0
/**
* Handle a single packet for this channel
*
* Description:\n
*	Given an input packet, checks to make sure that the packet belongs
*	to this channel (fatal error if not).  If the packet is late (i.e.,
*	the current sequence number is greater than the packet sequence
*	number, the packet is discarded and the "out of sequence" counter
*	is bumped.  If the packet is not late, it is processed.\n
*	Processing consists of converting the linear (X & Y) input
*	polarization to circular (LCP & RCP), buffering the resulting
*	data until there is enough data to perform the DFB, then
*	queuing the channel to a worker thread for DFB processing.\n\n
* Notes:\n
*	Handles startup of the activity.
* 	There are two ways to handle single polarization: (1) clone the
* 	active polarization packets to make the inactive polarization
* 	packets, which results in two identical data streams, for which
* 	all processing is done except reporting signals.  (2) Create
* 	a single data stream and eliminate downstream processing of the
* 	inactive polarization.  Either method requires that the number
* 	of polarizations be checked at certain points during the
* 	processing.\n
* 	This version clones the active polarization into the inactive
* 	polarization to create a dual-pol stream.
*
* @param	pkt the input data packet.
*
* @see		addPacket
*/
Error
Channel::handlePacket_(ChannelPacket *pkt)
{
	// if we're not in an observation, discard the data without even
	// looking at it
	switch (getState()) {
	case DX_ACT_PEND_BASE_ACCUM:
	case DX_ACT_RUN_BASE_ACCUM:
	case DX_ACT_PEND_DC:
	case DX_ACT_RUN_DC:
		break;
	default:
		pktList->free(pkt);
		return (0);
	}

	// if the collection has been aborted internally, just throw away
	// all packets.  This can occur when the two polarizations are not
	// synchronized, and will eventually stop data collection.
	if (abortCollection) {
		pktList->free(pkt);
		return (0);
	}
	++stats.netStats.total;
	// validate the packet.  It must be our packet (correct src and pol)
	// and have the data valid bit set.
	ATADataPacketHeader& hdr = pkt->getHeader();
	if (hdr.src != channelSpec.src || hdr.chan != (uint32_t) channelSpec.chan) {
		++stats.netStats.wrong;
		pktList->free(pkt);
		return (0);
	}
	if (!(hdr.flags & ATADataPacketHeader::DATA_VALID)) {
		++stats.netStats.invalid;
		stats.inputStats.reset();
		pktList->free(pkt);
		curSeq = 0;
		return (0);
	}

	// reject all packets which don't match the correct polarization(s)
	if (hdr.polCode != rPol && hdr.polCode != lPol) {
		++stats.netStats.wrong;
		pktList->free(pkt);
		return (0);
	}

	// handle data collection startup
	Error err = 0;
	if (getState() == DX_ACT_PEND_BASE_ACCUM
			|| getState() == DX_ACT_PEND_DC) {
		// check for correct version number
		if (hdr.version != ATADataPacketHeader::CURRENT_VERSION) {
//			setState(DX_ACT_NONE);
			pktList->free(pkt);
			return (ERR_IPV);
		}

		int32_t t = hdr.absTime >> 32;
		NssDate start = activity->getStartTime();
#if (LOG_PACKET_TIMES)
		// send a message to the SSE logging activity start time and
		// packet time of first packtet received
		if (!armed) {
			timeval tv;
			gettimeofday(&tv, NULL);
			LogWarning(ERR_NE, activity->getActivityId(),
					"t = %u, Start time = %u, first pkt time = %u",
					tv.tv_sec, start.tv_sec, t);
		}
#endif
		if (!armed || t < start.tv_sec) {
			armed = true;
			if (t >= start.tv_sec)
				err = ERR_STAP;
			pktList->free(pkt);
			return (err);
		}
		else {
#if (LOG_PACKET_TIMES)
			// send a message to the SSE logging activity start time and
			// packet time of start packet
			timeval tv;
			gettimeofday(&tv, NULL);
			LogWarning(ERR_NE, activity->getActivityId(),
					"t = %u, Start time = %u, start pkt time = %u",
					tv.tv_sec, start.tv_sec, t);
#endif
			// start the data collection, recording the actual start time
			// and setting the packet sequence number
			if (getState() == DX_ACT_PEND_BASE_ACCUM)
				setState(DX_ACT_RUN_BASE_ACCUM);
			else
				setState(DX_ACT_RUN_DC);
			startSeq = curSeq = hdr.seq;
			// register the actual start time
			timeval s = ATADataPacketHeader::absTimeToTimeval(hdr.absTime);
			start.tv_sec = s.tv_sec;
			start.tv_usec = s.tv_usec;
			activity->setActualStartTime(start);
			// set the channel frequency from the packet header
			channelSpec.freq = hdr.freq;
			activity->setSkyFreq(hdr.freq);
		}
	}

	// test for out-of-sync between packet streams (this would normally
	// be one stream received, other not due to channelizer crash).  This
	// will stop data collection and send a message to the SSE.
	int32_t e = r.size() - l.size();
	if (!singlePol && abs(e) >= MAX_PACKET_ERROR) {
		pktList->free(pkt);
		abortCollection = true;
		return (ERR_PSU);
	}
	if (abs(e) > abs(data.err))
		data.err = e;

	// all late packets can be immediately discarded
	if (getState() != DX_ACT_RUN_BASE_ACCUM
			&& getState() != DX_ACT_RUN_DC) {
		pktList->free(pkt);
	}
	else if (hdr.seq < curSeq) {
		++stats.netStats.late;
		pktList->free(pkt);
	}
	else {
		// insert the packet
		addPacket(pkt);
		// if this is a single polarization, clone the packet for the
		// other polarization
		if (singlePol) {
			ChannelPacket *tmp = static_cast<ChannelPacket *> (pktList->alloc());
			memcpy(tmp, pkt, sizeof(ChannelPacket));
			ATADataPacketHeader& hdr = tmp->getHeader();
			hdr.polCode = inactivePol;
			addPacket(tmp);
		}
	}
	return (0);
}