Beispiel #1
0
RtpPacket * AsfReader::ReadNextRtpPacket()					//读取下一个Packet ,并将其转化为RtpPacket
{
	while(1)
	{
		BYTE* buf = ReadNextPacket();
		if( buf == NULL ) return NULL;
		AsfPacket* asfPack = AsfPacket::CreatePacket( buf, pHeadObj->PacketSize );
		if( asfPack == NULL ) continue;
		RtpPacket * pa = Packet2Rtp( asfPack );

		delete  asfPack;
		delete[] buf;
		return pa;
	}

}
Beispiel #2
0
	Core::CBlock* Miner::GetBlock(int nTimeout)
	{
		Packet* packet = new Packet();
		packet->SetHeader(GET_BLOCK);
		this->WritePacket(packet);
		delete(packet);	


		Packet RESPONSE = ReadNextPacket(nTimeout);
			
		if(RESPONSE.IsNull())
			return NULL;
		Core::CBlock* BLOCK = DeserializeBlock(RESPONSE.GetData());
		ResetPacket();
			
		return BLOCK;
	}
Beispiel #3
0
	unsigned int Miner::GetHeight(int nTimeout)
	{
		Packet* packet = new Packet();
		packet->SetHeader((unsigned char)GET_HEIGHT);
		this->WritePacket(packet);
		delete(packet);
			
		Packet RESPONSE = ReadNextPacket(nTimeout);
			
		if(RESPONSE.IsNull())
			return 0;
				
		if(RESPONSE.GetData().size() == 0)
		{
			return 0;
		}

		unsigned int nHeight = bytes2uint(RESPONSE.GetData());
		ResetPacket();
			
		return nHeight;
	}
Beispiel #4
0
	unsigned char Miner::SubmitBlock(uint512 hashMerkleRoot, unsigned long long nNonce, int nTimeout)
	{
		Packet* PACKET = new Packet();
		PACKET->SetHeader(SUBMIT_BLOCK);
			
		PACKET->SetData(hashMerkleRoot.GetBytes());
		std::vector<unsigned char> NONCE  = uint2bytes64(nNonce);
			
		std::vector<unsigned char> pckt = PACKET->GetData();
		pckt.insert(pckt.end(), NONCE.begin(), NONCE.end());
		PACKET->SetData(pckt);
		PACKET->SetLength(72);
			
		this->WritePacket(PACKET);
		delete(PACKET);

		Packet RESPONSE = ReadNextPacket(nTimeout);
		if(RESPONSE.IsNull())
			return 0;
			
		ResetPacket();
			
		return RESPONSE.GetHeader();
	}
void RecoverState(QHLP_PAR *qhlp)
{
ISI_DL snapshot;
ISI_DL_SYS sys;
QDPLUS_PKT pkt;
struct { ISI_SEQNO seqno; UINT32 index; } beg, end;
static char *fid = "RecoverState";

/* Get the current state of the disk loop */

    if (!isidlSnapshot(qhlp->input.dl, &snapshot, &sys)) {
        LogMsg("%s: isidlSnapshot failed: %s", fid, strerror(errno));
        Exit(MY_MOD_ID + 3);
    }

/* If there isn't any preserved state, then configure to dump the entire QDP disk loop */

    if (qhlp->qdplus->state != QDPLUS_STATE_OK) {
        LogMsg("no valid HLP state data found, default to oldest QDP data available");
        history.nxtndx = snapshot.sys->index.oldest;
        history.endndx = snapshot.sys->index.yngest;
        if (!VerifyIndicies(&snapshot)) Exit(MY_MOD_ID + 4);
        qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_PRODUCTION);
        LogMsg("going into production mode with nxtndx=0x%08x, endndx=0x%08x\n", history.nxtndx, history.endndx);
        return;
    }

/* We have state... find the range of packets to preload */

    if (!qdplusStateSeqnoLimits(qhlp->qdplus, &beg.seqno, &end.seqno)) {
        LogMsg("%s: qdplusStateSeqnoLimits: %s", fid, strerror(errno));
        Exit(MY_MOD_ID + 5);
    }

    if (isiIsUndefinedSeqno(&beg.seqno) || isiIsUndefinedSeqno(&end.seqno)) {
        LogMsg("empty HLP state data found, default to oldest QDP data available");
        history.nxtndx = snapshot.sys->index.oldest;
        history.endndx = snapshot.sys->index.yngest;
        if (!VerifyIndicies(&snapshot)) Exit(MY_MOD_ID + 6);
        qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_PRODUCTION);
        LogMsg("going into production mode with nxtndx=0x%08x, endndx=0x%08x\n", history.nxtndx, history.endndx);
        return;
    }

    if (!isiIsAbsoluteSeqno(&beg.seqno) || !isiIsAbsoluteSeqno(&end.seqno)) {
        LogMsg("%s: unexpected non-absolute sequence numbers", fid);
        Exit(MY_MOD_ID + 7);
    }

    beg.index = isidlSearchDiskLoopForSeqno(&snapshot, &beg.seqno, ISI_UNDEFINED_INDEX, ISI_UNDEFINED_INDEX);
    LogMsg("beg.seqno = %s, beg.index = 0x%08x\n", isiSeqnoString(&beg.seqno, NULL), beg.index);
    end.index = isidlSearchDiskLoopForSeqno(&snapshot, &end.seqno, ISI_UNDEFINED_INDEX, ISI_UNDEFINED_INDEX);
    LogMsg("end.seqno = %s, end.index = 0x%08x\n", isiSeqnoString(&end.seqno, NULL), end.index);

/* If we can't find the desired packets (disk loop overwritten?) then start with current data */

    if (!isiIsValidIndex(beg.index) || !isiIsValidIndex(end.index)) {
        LogMsg("unable to locate dl indices for HLP state data, default to start with current QDP data");
        history.nxtndx = snapshot.sys->index.yngest;
        history.endndx = snapshot.sys->index.yngest;
        if (!VerifyIndicies(&snapshot)) Exit(MY_MOD_ID + 8);
        qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_PRODUCTION);
        LogMsg("going into production mode with nxtndx=0x%08x, endndx=0x%08x\n", history.nxtndx, history.endndx);
        return;
    }

/* We know where to find the data to backfill, set up reader accordingly */

    history.nxtndx = beg.index;
    history.endndx = end.index;
    if (!VerifyIndicies(&snapshot)) Exit(MY_MOD_ID + 9);

/* Backfill the LCQ */

    qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_INITIALIZE);
    LogMsg("recovering state with data from indicies 0x%08x through 0x%08x", history.nxtndx, history.endndx);

    do {
        QuitOnShutdown(MY_MOD_ID + 9);
        ReadNextPacket(qhlp, &pkt);
        if (qdplusProcessPacket(qhlp->qdplus, &pkt) == NULL) {
            LogMsg("%s: qdplusProcessPacket failed: %s", fid, strerror(errno));
            Exit(MY_MOD_ID + 10);
        }
    } while (history.status == DATA_AVAILABLE);

    qdplusSetLcqStateFlag(qhlp->qdplus, QDP_LCQ_STATE_PRODUCTION);
    LogMsg("state recovery complete");
}