Complete the transaction
| 353 | |
| 354 | // Complete the transaction |
| 355 | bool SiteToSiteClient::complete(const utils::Identifier& transactionID) { |
| 356 | int ret; |
| 357 | std::shared_ptr<Transaction> transaction = NULL; |
| 358 | |
| 359 | if (peer_state_ != READY) { |
| 360 | bootstrap(); |
| 361 | } |
| 362 | |
| 363 | if (peer_state_ != READY) { |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | auto it = this->known_transactions_.find(transactionID); |
| 368 | |
| 369 | if (it == known_transactions_.end()) { |
| 370 | return false; |
| 371 | } else { |
| 372 | transaction = it->second; |
| 373 | } |
| 374 | |
| 375 | if (transaction->total_transfers_ > 0 && transaction->getState() != TRANSACTION_CONFIRMED) { |
| 376 | return false; |
| 377 | } |
| 378 | if (transaction->getDirection() == RECEIVE) { |
| 379 | if (transaction->current_transfers_ == 0) { |
| 380 | transaction->_state = TRANSACTION_COMPLETED; |
| 381 | return true; |
| 382 | } else { |
| 383 | logger_->log_debug("Site2Site transaction %s receive finished", transactionID.to_string()); |
| 384 | ret = this->writeResponse(transaction, TRANSACTION_FINISHED, "Finished"); |
| 385 | if (ret <= 0) { |
| 386 | return false; |
| 387 | } else { |
| 388 | transaction->_state = TRANSACTION_COMPLETED; |
| 389 | return true; |
| 390 | } |
| 391 | } |
| 392 | } else { |
| 393 | RespondCode code; |
| 394 | std::string message; |
| 395 | int ret; |
| 396 | |
| 397 | ret = readResponse(transaction, code, message); |
| 398 | |
| 399 | if (ret <= 0) |
| 400 | return false; |
| 401 | |
| 402 | if (code == TRANSACTION_FINISHED) { |
| 403 | logger_->log_info("Site2Site transaction %s peer finished transaction", transactionID.to_string()); |
| 404 | transaction->_state = TRANSACTION_COMPLETED; |
| 405 | return true; |
| 406 | } else { |
| 407 | logger_->log_warn("Site2Site transaction %s peer unknown respond code %d", transactionID.to_string(), code); |
| 408 | return false; |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 |
nothing calls this directly
no test coverage detected