コード例 #1
0
ファイル: STPieceAccess.cpp プロジェクト: Nokia700/SymTorrent
void CSTPieceAccess::OnFileWriteCompleteL(CSTFile& aFile, TInt aPosition)
{
	LWRITE(LOG, _L("Write complete in: "));
	LWRITE(LOG, aFile.Path());
	LWRITE(LOG, _L(" "));
	LWRITELN(LOG, aPosition);
	
	TInt writerIndex = GetWriterIndex(aFile, aPosition);
	if (writerIndex < 0)
		return;
	CPieceWriteEntry* writer = iWriters[writerIndex];
	
	if (writer)
		writer->iWriteCompleteCount++;
	
	if (writer->iFiles.Count() == writer->iWriteCompleteCount)
	{
		writer->iPiece.IncreaseDownloadedSizeL(writer->iLength, writer->iPeer);
		
		TInt begin = writer->iBegin;
		TInt length = writer->iLength;
		CSTPiece& piece = writer->iPiece;
		
		delete writer;
		iWriters.Remove(writerIndex);
		
		writer->iPieceWriteObserver->OnPieceWriteCompleteL(piece, begin, length);		
	}
}
コード例 #2
0
void CSTTrackerConnection::HTTPSessionOpenedL(TBool aResult, RHTTPSession& /*aHTTPSession*/)
{
	if (aResult)
	{
		// starts listening before connecting to the tracker
		// TODO this should be called from the torrent / torrentmanager
		iTorrent.TorrentMgr()->NetworkManager()->StartListeningL(
				0, iTorrent.Preferences()->IncomingPort());
		
		CreateUriL();
		
		// Parse string to URI (as defined in RFC2396)
		TUriParser8 uri;
		uri.Parse(*iUri);

		// Get request method string for HTTP GET
		RStringF method = iSession.StringPool().StringF(HTTP::EGET,
			RHTTPSession::GetTable());
			


		// Open transaction with previous method and parsed uri. This class will
		// receive transaction events in MHFRunL and MHFRunError.
		iTransaction = iSession.OpenTransactionL(uri, *this, method);

		// Set headers for request; user agent and accepted content type
		RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
		SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
		SetHeaderL(hdr, HTTP::EAccept, KAccept);

		// Submit the transaction. After this the framework will give transaction
		// events via MHFRunL and MHFRunError.
		LWRITE(iLog, _L("[Trackerconnection] Starting transaction: GET "));
		LWRITELN(iLog, *iUri);
		iTransaction.SubmitL();

		iRunning = ETrue;
		iConnectionTimeout->Reset(KMaxTrackerAnnounceTime * 1000);
	}
	else
	{
		LWRITE(iLog, _L("[Trackerconnection] Failed "));
		if (iObserver)
			iObserver->TrackerConnectionFailedL();
		
		/*iTorrent.SetFailedL(_L("Failed to establish network connection."));*/
	}
}
コード例 #3
0
void CKiConnectedSocketReader::RunL()
{
    // Active object request complete handler
    switch (iStatus.Int())
    {
        case KErrNone:
            // Character has been read from socket			
			iLongBuffer.AppendL(iBuffer);
			
			//iLog->WriteL(_L8("[Socket] in  ::::"));
			//iLog->WriteLineL(iBuffer);

			
			iBuffer.SetLength(0);			
		    IssueRead(); // Immediately start another read		
			
            iSocketBase.OnReceiveL();
			
            break;
			
        default:
			LWRITE(iLog, _L8("(reader) socket error "));
			LWRITELN(iLog, iStatus.Int());

			// closing connection
			iSocketBase.HandleReadErrorL();
            break;
    }	
}
コード例 #4
0
ファイル: STPieceAccess.cpp プロジェクト: Nokia700/SymTorrent
void CSTPieceAccess::OnFileWriteFailedL(CSTFile& aFile, TInt aPosition)
{
	LWRITE(LOG, _L("Write failed in: "));
	LWRITE(LOG, aFile.Path());
	LWRITE(LOG, _L(" "));
	LWRITELN(LOG, aPosition);
	
	TInt writerIndex = GetWriterIndex(aFile, aPosition);
	if (writerIndex < 0)
		return;
	CPieceWriteEntry* writer = iWriters[writerIndex];
		
	if (writer)
	{
		writer->iPieceWriteObserver->OnPieceWriteFailedL(writer->iPiece, writer->iBegin, writer->iLength);
		delete writer;
		iWriters.Remove(writerIndex);
	}		
}
コード例 #5
0
ファイル: PCADWR.c プロジェクト: nilqed/qepcad
void PCADWR(Word c)
{
    Word M,cb,cp,p,s;
    /* hide p; */

Step1: /* common. */
    LWRITE(LELTI(c,INDX));
    if (LELTI(c,LEVEL) > 0)
    {
        s = LELTI(c,SAMPLE);
        if (ISPRIMIT(s)) CWRITE('p');
        else CWRITE('e');
        GWRITE(CELLDEG(c));
    }
    cb = LELTI(c,CHILD);

Step2: /* c is a leaf. */
    if (cb == NIL)
    {
        SWRITE(" ");
        TRUTHWR(LELTI(c,TRUTH));
        SWRITE("\n");
        goto Return;
    }

Step3: /* c is not a leaf. */
    p = OPOS;
    ADV(cb,&cp,&cb);
    SWRITE("---");
    PCADWR(cp);
    while (cb != NIL)
    {
        TAB(p);
        ADV(cb,&cp,&cb);
        SWRITE("---");
        PCADWR(cp);
    }

Return: /* Prepare for return. */
    return;
}
コード例 #6
0
void CSTTorrentManager::ConstructL()
{
	#ifdef LOG_TO_FILE
	CKiLogManager::InitializeL();
	iLog = LOGMGR->CreateLoggerL(TUid::Uid(SYMTORRENT_ENGINE_UID), KSTLogFile);
	iLog->WriteLineL(_L("****************************************************"));
	iLog->WriteLineL(_L(" [SymTorrent] Engine starting"));
	iLog->WriteLineL(_L("****************************************************"));
	#endif
	
	SetLocalCooperationEnabled(EFalse);
	SetLocalConnectionMSType(EUndefined);

	// seed for random numbers	
	TTime now;
	now.HomeTime();
	iSeed = now.Int64();

	User::LeaveIfError(iFs.Connect());
	
	iDelayedTorrents = new (ELeave) CDesCArrayFlat(3);
	
	// Generatin random key
	iKey = TUint(Math::Rand(iSeed));

	GeneratePeerIdL();

	LWRITELN(iLog, _L("Loading preferences..."));
	iPreferences = new (ELeave) CSTPreferences;
	iPreferences->ConstructL();	
	iPreferences->AddPreferencesObserverL(this);

	iNetworkManager = NETWORKMGR;
	iNetworkManager->SetLog(iLog);
	/*iNetworkManager->Initialize(iPreferences->ProxyConnectionPort(), 
		iPreferences->ProxyServicePort(), 
		iPreferences->ProxyHostName(),
		iPreferences->IncomingPort(),
		iPreferences->AccessPointId());*/		
	iNetworkManager->AddObserverL(this);
	iNetworkManager->AddSocketAccepterL(this);
			
	// local connection, index = 1
	iNetworkManager->CreateNetworkConnectionL(CNetworkConnection::ERConnectionBased);
	
#ifdef USE_DHT
	// DHT LOG	
	#ifdef __WINS__
	iDHTLog = LOGMGR->CreateLoggerL(TUid::Uid(0xA00F20F5), _L("C:\\ST_DHT_LOG.txt"));
	#else
	iDHTLog = LOGMGR->CreateLoggerL(TUid::Uid(0xA00F20F5), _L("E:\\ST_DHT_LOG.txt"));
	#endif
	
	// DHT
	iDHT = new (ELeave) NKademlia::CBitTorrentDHT(iDHTLog, 777);
	iDHT->ConstructL("C:\\SymTorrentDHT.dat");
#endif
	
    iTimer = CPeriodic::NewL(CActive::EPriorityStandard + 1); // higher than standard priority
	// the timer ticks in every second
    iTimer->Start(1000000,1000000,
		TCallBack(StaticOnTimerL, this));

    LWRITE(iLog, _L("Peer ID: "));
    LWRITELN(iLog, iPeerId);	
}
コード例 #7
0
void CSTTorrentManager::OnLocalUDPReceiveL(TInetAddr aSender, const TDesC8& aData)
{
	HLWRITELN(iLog, _L("[TorrentManager] OnLocalUDPReceiveL begin"));
	
	TInetAddr localAddress;
	iNetworkManager->GetLocalAddress(1, localAddress);
	
	if (localAddress.Address() == aSender.Address())
	{
		HLWRITELN(iLog, _L("[TorrentManager] Throwing away own message"));
		return;
	}
	
#ifdef LOG_TO_FILE
	LWRITE(iLog, _L("[TorrentManager] UDP sender: "));
	TBuf<128> addressBuf;
	if (aSender.Address() == 0)
	{
		addressBuf = _L("? (could not get local address)");
	}
	else
	{
		aSender.Output(addressBuf);
		addressBuf.Append(_L(":"));
		TBuf<16> portBuf;
		portBuf.Num(localAddress.Port());
		addressBuf.Append(portBuf);
	}
	HLWRITELN(iLog, addressBuf);
#endif
	
	//HLWRITEL(iLog, _L("[TorrentManager] Data received: "));
	//HLWRITELN(iLog, aData);
	
	// TODO handle multiple torrents
	if (iTorrents.Count() == 0)
		return;
	
	if (aData.Size() >= 4)
	{
		TUint messageLength = NSTUtils::ReadInt32(aData);
		
		LWRITE(iLog, _L("[TorrentManager] Datagram length: "));
		LWRITELN(iLog, aData.Size());
				
		LWRITE(iLog, _L("[TorrentManager] Message length: "));
		LWRITELN(iLog, messageLength);
		
		if ((TUint(aData.Size()) >= (4 + messageLength)) && 
			(aData[4] == KMessageIdPiece))
		{
			TInt index = NSTUtils::ReadInt32(aData.Mid(5));
			TInt begin = NSTUtils::ReadInt32(aData.Mid(9));
			
			TBool pendingRequestFound = EFalse;
			
			// check if the incoming local piece is requested by this peer
			for (TInt i=0; i<iTorrents[0]->PeerCount(); i++)
			{
				if ((iTorrents[0]->Peer(i)->IsLocal()) && (iTorrents[0]->Peer(i)->Connection()) && (iTorrents[0]->Peer(i)->Connection()->State() == EPeerPwConnected))
				{
					pendingRequestFound = iTorrents[0]->Peer(i)->Connection()->HandleIncomingLocalPieceL(index, begin, aData.Mid(13, messageLength - 9));
					if (pendingRequestFound)
						break;
				}
			}
			
			if (!pendingRequestFound)
			{
				if ((iTorrents[0]->PieceCount() > index) && (!iTorrents[0]->Piece(index)->IsDownloaded()))
				{
					HLWRITELN(iLog, _L("[TorrentManager] Received unrequested piece"));
					
					CSTPiece* piece = iTorrents[0]->Piece(index);
					CSTPeer* peer = iTorrents[0]->GetPeer(aSender);
					
					if (piece->InsertBlockL(begin, aData.Mid(13, messageLength - 9), peer) != KErrNone)
					{
						LWRITELN(iLog, _L8("CRITICAL FAULT, Writing to piece failed")); // CRITICAL FAULT								
					}
					else
					{
						HLWRITELN(iLog, _L("[TorrentManager] Writing piece complete"));
						
						if (iTorrents[0]->EndGame())									
							iTorrents[0]->EndGamePieceReceivedL(piece, peer);
					}
					
					iTorrents[0]->iLocalSubPiecesNotRequested++;
					iTorrents[0]->iLocalSubPiecesNotRequestedSize += aData.Size();
					
					
					// TODO remove commented part if the code above is working
					/*if (piece->DownloadedSize() == begin)
					{
						CSTPeer* peer = iTorrents[0]->GetPeer(aSender);
						
						if (piece->AppendBlockL(aData, peer) != KErrNone)
						{
							LWRITELN(iLog, _L8("CRITICAL FAULT, Writing to piece failed")); // CRITICAL FAULT								
						}
						else
						{
							HLWRITELN(iLog, _L("[TorrentManager] Writing piece complete"));
							
							if (iTorrents[0]->EndGame())									
								iTorrents[0]->EndGamePieceReceivedL(piece, peer);
						}
						
						iTorrents[0]->iLocalSubPiecesNotRequested++;
					}
					else
						iTorrents[0]->iLocalSubPiecesReceivedNotMatchPieceBeginning++;*/
				}
				else
				{
					iTorrents[0]->iLocalSubPiecesReceivedAlreadyDownloaded++;
					iTorrents[0]->iLocalSubPiecesReceivedAlreadyDownloadedSize += aData.Size();
				}
			}
		}
	}
	
	HLWRITELN(iLog, _L("[TorrentManager] OnLocalUDPReceiveL end"));
}
コード例 #8
0
ファイル: CELLWR.c プロジェクト: fchapoton/qepcad-1
void QepcadCls::CELLWR(Word c)
{
       Word S,S1,k,t,i,D,M;
       /* hide t; */

Step1: /* Heading. */
       k = LELTI(c,LEVEL);
       SWRITE("---------- Information about the cell "); LWRITE(LELTI(c,INDX));
       SWRITE(" ----------\n\n");

Step2: /* Level. */
       SWRITE("Level                       : ");
       GWRITE(LELTI(c,LEVEL)); SWRITE("\n");

Step3: /* Dimension. */
       if (k == 0) goto Step4;
       SWRITE("Dimension                   : ");
       GWRITE(CELLDIM(c)); SWRITE("\n");

Step4: /* Number of children. */
       SWRITE("Number of children          : ");
       GWRITE(LENGTH(LELTI(c,CHILD))); SWRITE("\n");

Step5: /* Truth value. */
       SWRITE("Truth value                 : ");
       TRUTHWR(LELTI(c,TRUTH)); 
       t = LELTI(c,HOWTV);
       if (t == BYPRP)
         SWRITE("    by propagation.");
       else if (t == BYTEV)
         SWRITE("    by trial evaluation.");
       else if (t == BYEQC)
         SWRITE("    by equational constraint.");
       SWRITE("\n");

Step6: /* Degrees of the substituted polys. */
       SWRITE("Degrees after substitution  : ");
       D = LELTI(c,DEGSUB);
       if (D == NIL) 
         SWRITE("Not known yet or No polynomial.");
       else
         LWRITE(D);
       SWRITE("\n");

Step7: /* Multiplicities of the projection factors. */
       SWRITE("Multiplicities              : ");
       M = LELTI(c,MULSUB);
       LWRITE(M);
       SWRITE("\n");

Step8: /* Signs of Projection Factors. */
       SWRITE("Signs of Projection Factors\n");
       S = LELTI(c,SIGNPF);
       for (i = 1; i <= k; i++)
         {
         S1 = LELTI(S,k-i+1);
         SWRITE("Level "); GWRITE(i); SWRITE("  : ");
         if (S1 == 0)
           SWRITE("Not determined");
         else
           SIGNLWR(S1);
         SWRITE("\n");
         }

Step9: /* Sample point. */
       if (k == 0) goto Step10;
       SWRITE("----------   Sample point  ---------- \n");
       SAMPLEWR(c);

Step10: /* Finish. */
       SWRITE("\n----------------------------------------------------\n");
       goto Return;

Return: /* Prepare for return. */
       return;
}
コード例 #9
0
ファイル: zoltrix.c プロジェクト: jossk/fmio-dos
void
set_freq_zoltrix(u_int16_t frequency) {
	/* tunes the radio to the desired frequency */
	unsigned long long bitmask, f;
	int i;
	float freq = frequency/100;

	f = (unsigned long long)(((float)(freq-88.0))*200.0)+0x4d1c;
	i = 45;
	bitmask = 0xc480402c10080000ull;
	bitmask = (bitmask^((f&0xff)<<47)^((f&0xff00)<<30)^(stereo<<31));

	LWRITE(0x0);
	LWRITE(0x0);
	inb(radioport+3);

	LWRITE(0x40);
	LWRITE(0xc0);
	while (i--) {
		if ((bitmask & 0x8000000000000000ull) != 0) {
			LWRITE(0x80);
			LWRITE(0x00);
			LWRITE(0x80);
		} else {
			LWRITE(0xc0);
			LWRITE(0x40);
			LWRITE(0xc0);
		}
		bitmask *= 2;
	}

	/* Termination sequence */
	LWRITE(0x80);
	LWRITE(0xc0);
	LWRITE(0x40);
	usleep(20000);
	if (vol) { LWRITE(vol); }
	usleep(10000);
	inb(radioport+2);

	return;
}
コード例 #10
0
ファイル: STPieceAccess.cpp プロジェクト: Nokia700/SymTorrent
void CSTPieceAccess::WritePieceAsyncL(CSTPiece& aPiece, TInt aBegin, const TDesC8& aBlock, MPieceWriteObserver* aPieceWriteObserver, CSTPeer* aPeer)
{
	TInt blockPosition = 0;
	TInt piecePosition = aBegin;
	
	LWRITE(LOG, _L("Writing to piece started, piece: "));
	LWRITE(LOG, aPiece.Index());
	LWRITE(LOG, _L(" Position: "));
	LWRITELN(LOG, piecePosition);
	
	CPieceWriteEntry* writer = 
		new (ELeave) CPieceWriteEntry(aPiece, aBegin, aBlock.Length(), aPieceWriteObserver, aPeer);
	CleanupStack::PushL(writer);
	iWriters.AppendL(writer);
	CleanupStack::Pop(); // writer

	while (blockPosition < aBlock.Length())
	{
		CSTFile* file = NULL;
		TInt filePosition = 0;

		aPiece.GetFilePosition(piecePosition, &file, filePosition);

		if (file)
		{
			writer->iFiles.AppendL(CPieceWriteEntry::TSTFilePos(file, filePosition));
			
			//TInt res = KErrNone;
			TInt fileBlockLength = file->Size() - filePosition;

			//LogPieceIndexL();
			LWRITE(LOG, _L("Appending block to "));
			LWRITE(LOG, file->Path());
			LWRITE(LOG, _L(" "));
			LWRITELN(LOG, filePosition);

			if (fileBlockLength <= (aBlock.Length() - blockPosition))	// reached the end of a file
			{
				//LogPieceIndexL();
				LWRITE(LOG, _L("File complete: "));
				LWRITELN(LOG, file->Path());
				
				iFileManager.WriteAsyncL(file, 
					filePosition, aBlock.Mid(blockPosition, fileBlockLength), this);
				
				//FileManager().Close(file);

				blockPosition += fileBlockLength;
				piecePosition += fileBlockLength;				
			}
			else // the file isn't finished yet, the complete block is appended to the file
			{
				iFileManager.WriteAsyncL(file, 
					filePosition, aBlock.Right(aBlock.Length() - blockPosition), this);												

				piecePosition += (aBlock.Length() - blockPosition);
				//blockPosition = aBlock.Length();
				break;
			}
		}
		else
			User::Panic(KSymTorrentEnginePanic, KPanGetFilePositionFailed);
	}
}
コード例 #11
0
void CSTTrackerConnection::MHFRunL(RHTTPTransaction aTransaction, 
						  			const THTTPEvent& aEvent)
{
	switch (aEvent.iStatus)
	{
		case THTTPEvent::EGotResponseHeaders:
		{
			// HTTP response headers have been received. Use
			// aTransaction.Response() to get the response. However, it's not
			// necessary to do anything with the response when this event occurs.

			LWRITELN(iLog, _L("[Trackerconnection] Got HTTP headers"));
			// Get HTTP status code from header (e.g. 200)
			RHTTPResponse resp = aTransaction.Response();
			TInt status = resp.StatusCode();
			
			if (status != 200) // ERROR, hiba esetén mi legyen? 404-et lekezelni!
			{
				LWRITE(iLog, _L("[Trackerconnection] Error, status = "));
				TBuf<20> numBuf;
				numBuf.Num(status);
				LWRITELN(iLog, numBuf);
				Cancel();
				if (iObserver)
					iObserver->TrackerConnectionFailedL();
				break;
			}

			// Get status text (e.g. "OK")
			HLWRITE(iLog, _L("[Trackerconnection] Status text = "));
			TBuf<32> statusText;
			statusText.Copy(resp.StatusText().DesC());
			HLWRITELN(iLog, statusText);
			
			
			#ifdef LOG_TO_FILE
			RHTTPHeaders headers = 
				aTransaction.Response().GetHeaderCollection();		
			THTTPHdrFieldIter i =
				headers.Fields();
			for (i.First(); !(i.AtEnd()); ++i)
			{
				RStringF header = iSession.StringPool().StringF(i());
				
				if ((header.DesC() == _L8("Content-Type")))
				{
					HLWRITE(iLog, header.DesC());
					HLWRITE(iLog, _L(": "));
					THTTPHdrVal	val;
					headers.GetField(header, 0, val);
					RStringF value = val.StrF();
					HLWRITELN(iLog, value.DesC());
				}
				else
					HLWRITELN(iLog, header.DesC());
			}
						
			#endif
		}
		break;

		case THTTPEvent::EGotResponseBodyData:
		{			
			// Part (or all) of response's body data received. Use 
			// aTransaction.Response().Body()->GetNextDataPart() to get the actual
			// body data.						

			// Get the body data supplier
			MHTTPDataSupplier* body = aTransaction.Response().Body();
			TPtrC8 dataChunk;						

			// GetNextDataPart() returns ETrue, if the received part is the last 
			// one.
			TBool isLast = body->GetNextDataPart(dataChunk);
			
			//iDownloadedSize += dataChunk.Size();						
			
			HLWRITELN(iLog, _L8("[TrackerConnection] HTTP response body chunk received: "));
			HLWRITELN(iLog, dataChunk);
			
			if (iReceiveBuffer)
			{
				HBufC8* temp = HBufC8::NewL(
					iReceiveBuffer->Length() + dataChunk.Length());
				TPtr8 tempPtr(temp->Des());
				tempPtr.Copy(*iReceiveBuffer);
				tempPtr.Append(dataChunk);
				
				delete iReceiveBuffer;
				iReceiveBuffer = temp;
			}
			else
				iReceiveBuffer = dataChunk.AllocL();

			// Always remember to release the body data.
			body->ReleaseData();
		
			// NOTE: isLast may not be ETrue even if last data part received.
			// (e.g. multipart response without content length field)
			// Use EResponseComplete to reliably determine when body is completely
			// received.
			if (isLast)
			{
				
				#ifdef LOG_TO_FILE
				_LIT(KBodyReceived,"Body received");
				HLWRITELN(iLog, KBodyReceived);
				#endif
				
				//CSTBencode* bencodedResponse = CSTBencode::ParseL(*iReceiveBuffer);	
				//iLog->WriteLineL(*iReceiveBuffer);
				//
				//if (bencodedResponse)
				//{
				//	CleanupStack::PushL(bencodedResponse);
				//	iTorrent.ProcessTrackerResponseL(bencodedResponse);
				//	CleanupStack::PopAndDestroy(); // bencodedResponse
				//}
			}
		}
		break;

		case THTTPEvent::EResponseComplete:
		{
			// Indicates that header & body of response is completely received.
			// No further action here needed.
			//_LIT(KTransactionComplete, "Transaction Complete");
			//iLog->WriteLineL(KTransactionComplete);
			//iResult = ESucceeded;
		}
		break;

		case THTTPEvent::ESucceeded:
		{
			LWRITELN(iLog, _L("[Trackerconnection] HTTP transaction succeded"));

			CSTBencode* bencodedResponse = CSTBencode::ParseL(*iReceiveBuffer);	
			//iLog->WriteLineL(*iReceiveBuffer);
			
			if (bencodedResponse && iObserver)
			{
				CleanupStack::PushL(bencodedResponse);
				iObserver->TrackerResponseReceivedL(*bencodedResponse);
				CleanupStack::PopAndDestroy(); // bencodedResponse
			}
			
			iRunning = EFalse;
			
			if (iObserver)
				iObserver->TrackerConnectionSucceededL();
		}
		break;

		case THTTPEvent::EFailed:
		{
			LWRITELN(iLog, _L("[Trackerconnection] HTTP transaction failed"));
			iRunning = EFalse;
			if (iObserver)
				iObserver->TrackerConnectionFailedL();
		}
		break;

		default:
			// There are more events in THTTPEvent, but they are not usually 
			// needed. However, event status smaller than zero should be handled 
			// correctly since it's error.
		{
			TBuf<64> text;
			if (aEvent.iStatus < 0)
			{
				LWRITE(iLog, _L("[Trackerconnection] HTTP transaction failed, "));
				_LIT(KErrorStr, "Error: %d");
				text.Format(KErrorStr, aEvent.iStatus);
				LWRITELN(iLog, text);
			
				// Just close the transaction on errors
				aTransaction.Close();
				iRunning = EFalse;
				
				if (iObserver)
					iObserver->TrackerConnectionFailedL();
			}
			else
			{
				// Other events are not errors (e.g. permanent and temporary
				// redirections)
				_LIT(KUnrecognisedEvent, "[Trackerconnection] Unrecognised event: %d");
				text.Format(KUnrecognisedEvent, aEvent.iStatus);
				LWRITELN(iLog, text);
			}		
		}
		break;
	}
}
コード例 #12
0
void CSTTrackerConnection::CreateUriL()
{
	TInetAddr localAddress;
	TInt getAddressRes = KErrGeneral;
	// only send IP if we are connected via proxy
	//if (Preferences()->IncomingConnectionsMode() == EEnabledWithProxy)
	//	getAddressRes = iNetMgr->Address(localAddress);
	
	CBufFlat* uriBuf = CBufFlat::NewL(512);
	CleanupStack::PushL(uriBuf);
	
	//TPtrC8 activeTracker = iTorrent.AnnounceList()->ActiveAddress();
	//LWRITE(iLog, _L("Active tracker: "));
	//LWRITELN(iLog, activeTracker);
	
	uriBuf->InsertL(uriBuf->Size(), *iAddress);
	uriBuf->InsertL(uriBuf->Size(), _L8("?"));
	
	uriBuf->InsertL(uriBuf->Size(), _L8("info_hash="));	
	HBufC8* encoded = EscapeUtils::EscapeEncodeL(iTorrent.InfoHash(), EscapeUtils::EEscapeUrlEncoded);
	CleanupStack::PushL(encoded);
	uriBuf->InsertL(uriBuf->Size(), *encoded);
	CleanupStack::PopAndDestroy(); // encoded
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&peer_id="));
	encoded = EscapeUtils::EscapeEncodeL(TorrentMgr()->PeerId(), EscapeUtils::EEscapeUrlEncoded);
	CleanupStack::PushL(encoded);
	uriBuf->InsertL(uriBuf->Size(), *encoded);
	CleanupStack::PopAndDestroy(); // encoded
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&key="));
	TBuf8<32> keyBuf;
	keyBuf.Num(TorrentMgr()->Key());
	uriBuf->InsertL(uriBuf->Size(), keyBuf);
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&port="));
	TBuf8<32> portBuf;
	if (getAddressRes == KErrNone)
		portBuf.Num(localAddress.Port());
	else
		portBuf.Num(Preferences()->IncomingPort());
	uriBuf->InsertL(uriBuf->Size(), portBuf);
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&uploaded="));
	TBuf8<24> bytesUploaded;
	bytesUploaded.Num(iTorrent.BytesUploaded());
	uriBuf->InsertL(uriBuf->Size(), bytesUploaded);
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&downloaded="));
	TBuf8<24> bytesDownloaded;
	bytesDownloaded.Num(iTorrent.BytesDownloaded());
	uriBuf->InsertL(uriBuf->Size(), bytesDownloaded);
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&left="));
	TBuf8<24> bytesLeft;
	bytesLeft.Num(iTorrent.BytesLeft());
	uriBuf->InsertL(uriBuf->Size(), bytesLeft);

	// it seems that some trackers support only compact responses
	uriBuf->InsertL(uriBuf->Size(), _L8("&compact=1"));

	if (iEvent != ETrackerEventNotSpecified)
	{
		uriBuf->InsertL(uriBuf->Size(), _L8("&event="));
		
		switch (iEvent)
		{
			case ETrackerEventStarted:
				uriBuf->InsertL(uriBuf->Size(), _L8("started"));
			break;
			
			case ETrackerEventStopped:
				uriBuf->InsertL(uriBuf->Size(), _L8("stopped"));
			break;
			
			case ETrackerEventCompleted:
				uriBuf->InsertL(uriBuf->Size(), _L8("completed"));
			break;
			
			default:
			break;
		}
	}
	
	if (getAddressRes == KErrNone)
	{
		TBuf<64> ipBuf;
		localAddress.Output(ipBuf);
		TBuf8<64> ipBuf8;
		ipBuf8.Copy(ipBuf);
		
		uriBuf->InsertL(uriBuf->Size(), _L8("&ip="));
		uriBuf->InsertL(uriBuf->Size(), ipBuf8);
		
		#ifdef LOG_TO_FILE
		// debug info
		LWRITE(iLog, _L("Sent to tracker: "));
		LWRITE(iLog, ipBuf);
		TBuf8<32> portBuf;
		portBuf.Num(localAddress.Port());
		LWRITE(iLog, _L(":"));
		LWRITELN(iLog, portBuf);
		#endif
		//		
	}
	
	iUri = uriBuf->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(); // uriBuf
	
	//iLog->WriteL(_L("[Trackerconnection] GET "));
	//iLog->WriteLineL(*iUri);
}