virtual bool handleSetRequest(const JID& from, const JID&, const std::string& id, IBB::ref ibb) {
			if (from == session->from && ibb->getStreamID() == session->id) {
				if (ibb->getAction() == IBB::Data) {
					if (sequenceNumber == ibb->getSequenceNumber()) {
						session->onDataReceived(ibb->getData());
						receivedSize += ibb->getData().size();
						sequenceNumber++;
						sendResponse(from, id, IBB::ref());
						if (receivedSize >= session->size) {
							if (receivedSize > session->size) {
								std::cerr << "Warning: Received more data than expected" << std::endl;
							}
							session->finish(boost::optional<FileTransferError>());
						}
					}
					else {
						SWIFT_LOG(warning) << "Received data out of order" << std::endl;
						sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Cancel);
						session->finish(FileTransferError(FileTransferError::ClosedError));
					}
				}
				else if (ibb->getAction() == IBB::Open) {
					SWIFT_LOG(debug) << "IBB open received" << std::endl;
					sendResponse(from, id, IBB::ref());
				}
				else if (ibb->getAction() == IBB::Close) {
					SWIFT_LOG(debug) << "IBB close received" << std::endl;
					sendResponse(from, id, IBB::ref());
					session->finish(FileTransferError(FileTransferError::ClosedError));
				}
				return true;
			}
			SWIFT_LOG(debug) << "wrong from/sessionID: " << from << " == " << session->from << " / " <<ibb->getStreamID() << " == " << session->id << std::endl;
			return false;
		}
Пример #2
0
void IBBSendSession::handleIBBResponse(IBB::ref, ErrorPayload::ref error) {
    currentRequest.reset();

    if (!error && active) {
        if (!bytestream->isFinished()) {
            sendMoreData();
        }
        else {
            finish(boost::optional<FileTransferError>());
        }
    }
    else {
        finish(FileTransferError(FileTransferError::PeerError));
    }
}
Пример #3
0
void IBBSendSession::sendMoreData() {
    try {
        std::shared_ptr<ByteArray> data = bytestream->read(blockSize);
        if (!data->empty()) {
            waitingForData = false;
            IBBRequest::ref request = IBBRequest::create(from, to, IBB::createIBBData(id, sequenceNumber, *data), router);
            sequenceNumber++;
            request->onResponse.connect(boost::bind(&IBBSendSession::handleIBBResponse, this, _1, _2));
            request->send();
            currentRequest = request;
            onBytesSent(data->size());
        }
        else {
            waitingForData = true;
        }
    }
    catch (const BytestreamException&) {
        finish(FileTransferError(FileTransferError::ReadError));
    }
}