void DownloadBase::Clear() { m_cookie = 1; m_runcookie = 1; m_savecookie = 1; m_size = SIZE_UNKNOWN; m_bBTH = FALSE; m_uploaded = 0; m_downloaded = 0; m_file = OP_NEW(P2PBlockFile, ()); m_received = op_time(NULL); m_transferfirst = NULL; m_transferlast = NULL; m_transfercount = 0; m_transferstart = 0; m_paused = FALSE; m_boosted = FALSE; m_complete = FALSE; m_completedTime = 0; m_saved = 0; m_began = 0; // m_sourcefirst = NULL; // m_sourcelast = NULL; m_verify = TS_UNKNOWN; m_sourcecount = 0; m_transfer_id = -1; m_seeding = FALSE; m_need_more_sources = FALSE; m_transfer_item = NULL; m_is_transfer_manager_listener = FALSE; m_lastProgressUpdate = op_time(NULL); m_last_uploaded = 0; m_last_downloaded = 0; m_delete_files_when_removed = FALSE; }
void P2PConnection::OnSocketConnected(OpSocket* socket) { ENTER_METHOD; AddRef(); if(m_closing) { // we are closing, do nothing // m_observer = &m_nullobserver; if(m_socket.Get() != NULL) { // m_socket.Get()->SetObserver(&m_nullobserver); } Release(); return; } DEBUGTRACE_CONNECT(UNI_L("CONNECTED TO: %s, "), (uni_char *)m_address); DEBUGTRACE8_CONNECT(UNI_L("this: 0x%08x, socket: "), this); DEBUGTRACE8_CONNECT(UNI_L("0x%08x\n"), socket); m_initiated = TRUE; m_connectedTime = op_time(NULL); m_connected = TRUE; Observer().AddRef(); Observer().OnP2PConnected(this); Observer().Release(); Release(); LEAVE_METHOD; }
void DownloadBase::FileDownloadSharing(BOOL& transfer_failed) { transfer_failed = FALSE; OpTransferItem* item = GetTransferItem(); if(item != 0) { TransferItem* transfer_item = (TransferItem *)(item); OP_ASSERT(transfer_item != 0); transfer_item->SetCalculateKbps(TRUE); transfer_item->Get_P2P_URL()->ForceStatus(P2P_URL::P2P_SHARING_FILES); transfer_item->SetCurrentSize(GetVolumeComplete()); transfer_item->SetCompleteSize(m_torrent.GetImpl()->GetTotalSize()); transfer_item->SetUploaded(GetVolumeUploaded()); if(GetVolumeComplete() == m_torrent.GetImpl()->GetTotalSize()) { transfer_item->SetCompleted(TRUE); } g_Transfers->UpdateTransferSpeed((UINTPTR)this, transfer_item->GetKbps(), transfer_item->GetKbpsUpload()); // OpVector<UploadTransferBT> *uploads = ((BTDownload *)this)->GetUploads(); // UINT32 idx; UINT32 activeuploads = 0; if(m_lastProgressUpdate != 0) { time_t now = op_time(NULL); if(now < m_lastProgressUpdate + BT_PROGRESS_DELAY) { return; } m_lastProgressUpdate = now; activeuploads = m_Uploads.GetTransferCount(upsRequestAndUpload); UINT32 seeds = GetTransferCount(dtsCountAllWithCompleteFile); UINT32 all_peers = GetTransferCount(dtsCountAll); UINT32 downloading = GetTransferCount(dtsDownloading); all_peers -= seeds; transfer_item->SetConnectionsWithCompleteFile(seeds); transfer_item->SetConnectionsWithIncompleteFile(all_peers); transfer_item->SetDownloadConnections(downloading); transfer_item->SetUploadConnections(activeuploads); transfer_item->SetTotalWithCompleteFile(max(((BTDownload *)this)->m_totalSeeders, seeds)); transfer_item->SetTotalDownloaders(max(((BTDownload *)this)->m_totalPeers, all_peers)); } } else transfer_failed = TRUE; }
void P2PConnection::AcceptFrom(P2PSocket *socket, OpString& address) { ENTER_METHOD; m_address.Set(address); m_socket.Attach(socket->Detach()); m_input = OP_NEW(OpByteBuffer, ()); m_initiated = FALSE; m_connected = TRUE; m_connectedTime = op_time(NULL); m_upload = TRUE; DEBUGTRACE_CONNECT(UNI_L("ACCEPT: %s, socket: "), (uni_char *)m_address); DEBUGTRACE_CONNECT(UNI_L("0x%08x\n"), m_socket.Get()); LEAVE_METHOD; }
HX_DATETIME HX_GET_DATETIME(void) { op_tm tm; time_t t = op_time(); HX_DATETIME dt; // XXXSAB - localtime? op_gmtime(t, &tm); dt.second = tm.tm_sec; dt.minute = tm.tm_min; dt.hour = tm.tm_hour; dt.dayofweek = tm.tm_wday; dt.dayofmonth = tm.tm_mday; dt.dayofyear = tm.tm_yday; dt.month = tm.tm_mon + 1; // 0 based (11 = December) dt.year = tm.tm_year; dt.gmtDelta = 0; // or something return dt; }
void GadgetsTreeModel::RefreshModel() { // Refreshing the model involves deleting all existing items. We can't do // that if any item is in use (DSK-292233). for (INT32 i = 0; i < GetItemCount(); ++i) { if (GetItemByIndex(i)->IsLocked()) { return; } } // Refresh all gadget sources. for (UINT32 i = 0; i < m_sources.GetCount(); ++i) { const OP_STATUS status = m_sources.Get(i)->Refresh(); OP_ASSERT(OpStatus::IsSuccess(status) || !"Failed to refresh gadget source"); } m_platform_timestamp = op_time(NULL); // (Re)build the model. ModelLock model_lock(this); DeleteAll(); for (UINT32 i = 0; i < m_sources.GetCount(); ++i) { const Source& source = *m_sources.Get(i); for (UINT32 j = 0; j < source.GetItemCount(); ++j) { GadgetsTreeModelItemImpl* item_impl = source.CreateItemImpl(j); if (NULL != item_impl) { AddLast(OP_NEW(GadgetsTreeModelItem, (item_impl))); } } } }
void Transfers::OnTimeOut(OpTimer* timer) { ENTER_METHOD; OnRun(); time_t now = op_time(NULL); if(now > m_last_resource_check + 5) { // do resource cleanup every 5 seconds Clear(); m_last_resource_check = now; } CalculateTransferRates(); BT_RESOURCE_CHECKPOINT(FALSE); m_check_timer.Start(CHECK_INTERVAL_BT); LEAVE_METHOD; }
void DownloadBase::FileProgress(BOOL& transfer_failed) { transfer_failed = FALSE; OpTransferItem* item = GetTransferItem(); if(item != 0) { UINT64 downloaded = GetVolumeComplete(); TransferItem* transfer_item = (TransferItem *)(item); OP_ASSERT(transfer_item != 0); transfer_item->SetCalculateKbps(TRUE); // If the user have pressed stop, the status won't be loading anymore. // if(transfer_item->Get_P2P_URL()->Status() == URL_LOADING) if(downloaded != m_torrent.GetImpl()->GetTotalSize()) { transfer_item->Get_P2P_URL()->ForceStatus(URL_LOADING); if(downloaded >= m_last_downloaded) { transfer_item->SetCurrentSize(downloaded); } transfer_item->SetCompleteSize(m_torrent.GetImpl()->GetTotalSize()); transfer_item->SetCompleted(FALSE); } UINT64 uploaded = GetVolumeUploaded(); if(uploaded > m_last_uploaded) { transfer_item->SetUploaded(uploaded); // g_Transfers->SetUploaded(uploaded - m_last_uploaded); } m_last_uploaded = uploaded; UINT32 activeuploads = 0; if(m_lastProgressUpdate != 0) { time_t now = op_time(NULL); if(now < m_lastProgressUpdate + BT_PROGRESS_DELAY) { return; } m_lastProgressUpdate = now; activeuploads = m_Uploads.GetTransferCount(upsRequestAndUpload); UINT32 seeds = GetTransferCount(dtsCountAllWithCompleteFile); UINT32 all_peers = GetTransferCount(dtsCountAll); UINT32 downloading = GetTransferCount(dtsDownloading); all_peers -= seeds; transfer_item->SetConnectionsWithCompleteFile(seeds); transfer_item->SetConnectionsWithIncompleteFile(all_peers); transfer_item->SetDownloadConnections(downloading); transfer_item->SetUploadConnections(activeuploads); transfer_item->SetTotalWithCompleteFile(max(((BTDownload *)this)->m_totalSeeders, seeds)); transfer_item->SetTotalDownloaders(max(((BTDownload *)this)->m_totalPeers, all_peers)); } if(downloaded > m_last_downloaded) { m_last_downloaded = downloaded; } } else transfer_failed = TRUE; }
static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom) { unsigned char *buf=NULL; int ret=0,bit,bytes,mask; time_t tim; if (bits == 0) { BN_zero(rnd); return 1; } bytes=(bits+7)/8; bit=(bits-1)%8; mask=0xff<<(bit+1); buf=(unsigned char *)OPENSSL_malloc(bytes); if (buf == NULL) { BNerr(BN_F_BNRAND,ERR_R_MALLOC_FAILURE); goto err; } #ifdef VALGRIND op_memset(&tim,0,sizeof(tim)); op_memset(buf,0,bytes); #endif /* make a random number and set the top and bottom bits */ op_time(&tim); RAND_add(&tim,sizeof(tim),0.0); #ifdef LIBOPEAY_ASYNCHRONOUS_KEYGENERATION if (pseudorand) { if (RAND_pseudo_bytes(buf, bytes) == -1) goto err; } else #endif { if (RAND_bytes(buf, bytes) <= 0) goto err; } #if 1 #ifndef OPERA_SMALL_VERSION if (pseudorand == 2) { /* generate patterns that are more likely to trigger BN library bugs */ int i; unsigned char c; for (i = 0; i < bytes; i++) { RAND_pseudo_bytes(&c, 1); if (c >= 128 && i > 0) buf[i] = buf[i-1]; else if (c < 42) buf[i] = 0; else if (c < 84) buf[i] = 255; } } #endif #endif if (top != -1) { if (top) { if (bit == 0) { buf[0]=1; buf[1]|=0x80; } else { buf[0]|=(3<<(bit-1)); } } else { buf[0]|=(1<<bit); } } buf[0] &= ~mask; if (bottom) /* set bottom bit if requested */ buf[bytes-1]|=1; if (!BN_bin2bn(buf,bytes,rnd)) goto err; ret=1; err: if (buf != NULL) { OPENSSL_cleanse(buf,bytes); OPENSSL_free(buf); } bn_check_top(rnd); return(ret); }