1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
/*
* Copyright (c) 2011 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <Swiften/FileTransfer/IncomingJingleFileTransfer.h>
#include <boost/bind.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Base/Log.h>
#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/JingleIBBTransportPayload.h>
#include <Swiften/Elements/JingleS5BTransportPayload.h>
#include <Swiften/Elements/JingleFileTransferHash.h>
#include <Swiften/Elements/S5BProxyRequest.h>
#include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h>
#include <Swiften/FileTransfer/JingleIncomingIBBTransport.h>
#include <Swiften/FileTransfer/LocalJingleTransportCandidateGenerator.h>
#include <Swiften/FileTransfer/LocalJingleTransportCandidateGeneratorFactory.h>
#include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelector.h>
#include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamProxy.h>
#include <Swiften/Network/TimerFactory.h>
#include <Swiften/Queries/GenericRequest.h>
namespace Swift {
IncomingJingleFileTransfer::IncomingJingleFileTransfer(
const JID& ourJID,
JingleSession::ref session,
JingleContentPayload::ref content,
RemoteJingleTransportCandidateSelectorFactory* candidateSelectorFactory,
LocalJingleTransportCandidateGeneratorFactory* candidateGeneratorFactory,
IQRouter* router,
SOCKS5BytestreamRegistry* registry,
SOCKS5BytestreamProxy* proxy,
TimerFactory* timerFactory) :
ourJID(ourJID),
session(session),
router(router),
timerFactory(timerFactory),
initialContent(content),
state(Initial),
receivedBytes(0),
s5bRegistry(registry),
s5bProxy(proxy),
remoteTransportCandidateSelectFinished(false),
localTransportCandidateSelectFinished(false),
serverSession(0) {
candidateSelector = candidateSelectorFactory->createCandidateSelector();
candidateSelector->onRemoteTransportCandidateSelectFinished.connect(boost::bind(&IncomingJingleFileTransfer::handleRemoteTransportCandidateSelectFinished, this, _1));
candidateGenerator = candidateGeneratorFactory->createCandidateGenerator();
candidateGenerator->onLocalTransportCandidatesGenerated.connect(boost::bind(&IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated, this, _1));
session->onTransportInfoReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleTransportInfoReceived, this, _1, _2));
session->onTransportReplaceReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleTransportReplaceReceived, this, _1, _2));
session->onSessionTerminateReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleSessionTerminateReceived, this, _1));
session->onSessionInfoReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleSessionInfoReceived, this, _1));
description = initialContent->getDescription<JingleFileTransferDescription>();
assert(description);
assert(description->getOffers().size() == 1);
StreamInitiationFileInfo fileInfo = description->getOffers().front();
fileSizeInBytes = fileInfo.getSize();
filename = fileInfo.getName();
hash = fileInfo.getHash();
algo = fileInfo.getAlgo();
waitOnHashTimer = timerFactory->createTimer(5000);
waitOnHashTimer->onTick.connect(boost::bind(&IncomingJingleFileTransfer::finishOffTransfer, this));
}
IncomingJingleFileTransfer::~IncomingJingleFileTransfer() {
stream->onWrite.disconnect(boost::bind(&IncrementalBytestreamHashCalculator::feedData, hashCalculator, _1));
delete hashCalculator;
session->onSessionTerminateReceived.disconnect(boost::bind(&IncomingJingleFileTransfer::handleSessionTerminateReceived, this));
session->onTransportReplaceReceived.disconnect(boost::bind(&IncomingJingleFileTransfer::handleTransportReplaceReceived, this, _1, _2));
session->onTransportInfoReceived.disconnect(boost::bind(&IncomingJingleFileTransfer::handleTransportInfoReceived, this, _1, _2));
candidateGenerator->onLocalTransportCandidatesGenerated.disconnect(boost::bind(&IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated, this, _1));
delete candidateGenerator;
candidateSelector->onRemoteTransportCandidateSelectFinished.disconnect(boost::bind(&IncomingJingleFileTransfer::handleRemoteTransportCandidateSelectFinished, this, _1));
delete candidateSelector;
}
void IncomingJingleFileTransfer::accept(WriteBytestream::ref stream) {
assert(!this->stream);
this->stream = stream;
hashCalculator = new IncrementalBytestreamHashCalculator( algo == "md5" || hash.empty() , algo == "sha-1" || hash.empty() );
stream->onWrite.connect(boost::bind(&IncrementalBytestreamHashCalculator::feedData, hashCalculator, _1));
stream->onWrite.connect(boost::bind(&IncomingJingleFileTransfer::handleWriteStreamDataReceived, this, _1));
onStateChange(FileTransfer::State(FileTransfer::State::Negotiating));
if (JingleIBBTransportPayload::ref ibbTransport = initialContent->getTransport<JingleIBBTransportPayload>()) {
SWIFT_LOG(debug) << "Got IBB transport payload!" << std::endl;
setActiveTransport(createIBBTransport(ibbTransport));
session->sendAccept(getContentID(), initialContent->getDescriptions()[0], ibbTransport);
}
else if (JingleS5BTransportPayload::ref s5bTransport = initialContent->getTransport<JingleS5BTransportPayload>()) {
SWIFT_LOG(debug) << "Got S5B transport payload!" << std::endl;
state = CreatingInitialTransports;
s5bSessionID = s5bTransport->getSessionID().empty() ? idGenerator.generateID() : s5bTransport->getSessionID();
s5bDestination = SOCKS5BytestreamRegistry::getHostname(s5bSessionID, ourJID, session->getInitiator());
s5bRegistry->addWriteBytestream(s5bDestination, stream);
fillCandidateMap(theirCandidates, s5bTransport);
candidateSelector->addRemoteTransportCandidates(s5bTransport);
candidateSelector->setRequesterTargtet(session->getInitiator(), ourJID);
s5bTransport->setSessionID(s5bSessionID);
candidateGenerator->generateLocalTransportCandidates(s5bTransport);
}
else {
assert(false);
}
}
const JID& IncomingJingleFileTransfer::getSender() const {
return session->getInitiator();
}
const JID& IncomingJingleFileTransfer::getRecipient() const {
return ourJID;
}
void IncomingJingleFileTransfer::cancel() {
session->sendTerminate(JinglePayload::Reason::Cancel);
if (activeTransport) activeTransport->stop();
if (serverSession) serverSession->stop();
if (clientSession) clientSession->stop();
onStateChange(FileTransfer::State(FileTransfer::State::Canceled));
}
void IncomingJingleFileTransfer::handleLocalTransportCandidatesGenerated(JingleTransportPayload::ref candidates) {
if (state == CreatingInitialTransports) {
if (JingleS5BTransportPayload::ref s5bCandidates = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(candidates)) {
//localTransportCandidateSelectFinished = true;
//JingleS5BTransportPayload::ref emptyCandidates = boost::make_shared<JingleS5BTransportPayload>();
//emptyCandidates->setSessionID(s5bCandidates->getSessionID());
fillCandidateMap(ourCandidates, s5bCandidates);
session->sendAccept(getContentID(), initialContent->getDescriptions()[0], s5bCandidates);
state = NegotiatingTransport;
candidateSelector->selectCandidate();
}
}
else {
SWIFT_LOG(debug) << "Unhandled state!" << std::endl;
}
}
void IncomingJingleFileTransfer::handleRemoteTransportCandidateSelectFinished(JingleTransportPayload::ref transport) {
SWIFT_LOG(debug) << std::endl;
if (state == Terminated) {
return;
}
if (JingleS5BTransportPayload::ref s5bPayload = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transport)) {
//remoteTransportCandidateSelectFinished = true;
//selectedRemoteTransportCandidate = transport;
ourCandidate = s5bPayload;
//checkCandidateSelected();
decideOnUsedTransport();
session->sendTransportInfo(getContentID(), s5bPayload);
}
else {
SWIFT_LOG(debug) << "Expected something different here." << std::endl;
}
}
void IncomingJingleFileTransfer::checkCandidateSelected() {
assert(false);
if (localTransportCandidateSelectFinished && remoteTransportCandidateSelectFinished) {
if (candidateGenerator->isActualCandidate(selectedLocalTransportCandidate) && candidateSelector->isActualCandidate(selectedRemoteTransportCandidate)) {
if (candidateGenerator->getPriority(selectedLocalTransportCandidate) > candidateSelector->getPriority(selectedRemoteTransportCandidate)) {
setActiveTransport(candidateGenerator->selectTransport(selectedLocalTransportCandidate));
}
else {
setActiveTransport(candidateSelector->selectTransport(selectedRemoteTransportCandidate));
}
}
else if (candidateSelector->isActualCandidate(selectedRemoteTransportCandidate)) {
setActiveTransport(candidateSelector->selectTransport(selectedRemoteTransportCandidate));
}
else if (candidateGenerator->isActualCandidate(selectedLocalTransportCandidate)) {
setActiveTransport(candidateGenerator->selectTransport(selectedLocalTransportCandidate));
}
else {
state = WaitingForFallbackOrTerminate;
}
}
}
void IncomingJingleFileTransfer::setActiveTransport(JingleTransport::ref transport) {
state = Transferring;
onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
activeTransport = transport;
activeTransport->onDataReceived.connect(boost::bind(&IncomingJingleFileTransfer::handleTransportDataReceived, this, _1));
activeTransport->onFinished.connect(boost::bind(&IncomingJingleFileTransfer::handleTransferFinished, this, _1));
activeTransport->start();
}
bool IncomingJingleFileTransfer::verifyReceviedData() {
if (algo.empty() || hash.empty()) {
SWIFT_LOG(debug) << "no verification possible, skipping" << std::endl;
return true;
} else {
if (algo == "sha-1") {
SWIFT_LOG(debug) << "verify data via SHA-1 hash: " << (hash == hashCalculator->getSHA1String()) << std::endl;
return hash == hashCalculator->getSHA1String();
}
else if (algo == "md5") {
SWIFT_LOG(debug) << "verify data via MD5 hash: " << (hash == hashCalculator->getMD5String()) << std::endl;
return hash == hashCalculator->getMD5String();
}
else {
SWIFT_LOG(debug) << "no verification possible, skipping" << std::endl;
return true;
}
}
}
void IncomingJingleFileTransfer::finishOffTransfer() {
if (verifyReceviedData()) {
onStateChange(FileTransfer::State(FileTransfer::State::Finished));
session->sendTerminate(JinglePayload::Reason::Success);
} else {
onStateChange(FileTransfer::State(FileTransfer::State::Failed, "Verification failed."));
session->sendTerminate(JinglePayload::Reason::MediaError);
}
state = Terminated;
waitOnHashTimer->stop();
}
void IncomingJingleFileTransfer::handleSessionInfoReceived(JinglePayload::ref jinglePayload) {
if (state == Terminated) {
return;
}
JingleFileTransferHash::ref transferHash = jinglePayload->getPayload<JingleFileTransferHash>();
if (transferHash) {
SWIFT_LOG(debug) << "Recevied hash information." << std::endl;
if (transferHash->getHashes().find("sha-1") != transferHash->getHashes().end()) {
algo = "sha-1";
hash = transferHash->getHashes().find("sha-1")->second;
}
else if (transferHash->getHashes().find("md5") != transferHash->getHashes().end()) {
algo = "md5";
hash = transferHash->getHashes().find("md5")->second;
}
checkIfAllDataReceived();
}
}
void IncomingJingleFileTransfer::handleSessionTerminateReceived(boost::optional<JinglePayload::Reason> reason) {
SWIFT_LOG(debug) << "session terminate received" << std::endl;
if (activeTransport) activeTransport->stop();
if (reason && reason.get().type == JinglePayload::Reason::Cancel) {
onStateChange(FileTransfer::State(FileTransfer::State::Canceled, "Other user canceled the transfer."));
}
else if (reason && reason.get().type == JinglePayload::Reason::Success) {
/*if (verifyReceviedData()) {
onStateChange(FileTransfer::State(FileTransfer::State::Finished));
} else {
onStateChange(FileTransfer::State(FileTransfer::State::Failed, "Verification failed."));
}*/
}
state = Terminated;
}
void IncomingJingleFileTransfer::checkIfAllDataReceived() {
if (receivedBytes == fileSizeInBytes) {
SWIFT_LOG(debug) << "All data received." << std::endl;
if (hash.empty()) {
SWIFT_LOG(debug) << "No hash information yet. Waiting 5 seconds on hash info." << std::endl;
waitOnHashTimer->start();
} else {
SWIFT_LOG(debug) << "We already have hash info using " << algo << " algorithm. Finishing off transfer." << std::endl;
finishOffTransfer();
}
}
else if (receivedBytes > fileSizeInBytes) {
SWIFT_LOG(debug) << "We got more than we could handle!" << std::endl;
}
}
void IncomingJingleFileTransfer::handleTransportDataReceived(const std::vector<unsigned char>& data) {
SWIFT_LOG(debug) << data.size() << " bytes received" << std::endl;
onProcessedBytes(data.size());
stream->write(data);
receivedBytes += data.size();
checkIfAllDataReceived();
}
void IncomingJingleFileTransfer::handleWriteStreamDataReceived(const std::vector<unsigned char>& data) {
receivedBytes += data.size();
checkIfAllDataReceived();
}
void IncomingJingleFileTransfer::useOurCandidateChoiceForTransfer(JingleS5BTransportPayload::Candidate candidate) {
SWIFT_LOG(debug) << std::endl;
if (candidate.type == JingleS5BTransportPayload::Candidate::ProxyType) {
// get proxy client session from remoteCandidateSelector
clientSession = candidateSelector->getS5BSession();
// wait on <activated/> transport-info
} else {
// ask s5b client
clientSession = candidateSelector->getS5BSession();
if (clientSession) {
state = Transferring;
SWIFT_LOG(debug) << clientSession->getAddressPort().toString() << std::endl;
clientSession->onBytesReceived.connect(boost::bind(boost::ref(onProcessedBytes), _1));
clientSession->onFinished.connect(boost::bind(&IncomingJingleFileTransfer::handleTransferFinished, this, _1));
clientSession->startReceiving(stream);
} else {
SWIFT_LOG(debug) << "No S5B client session found!!!" << std::endl;
}
}
}
void IncomingJingleFileTransfer::useTheirCandidateChoiceForTransfer(JingleS5BTransportPayload::Candidate candidate) {
SWIFT_LOG(debug) << std::endl;
if (candidate.type == JingleS5BTransportPayload::Candidate::ProxyType) {
// get proxy client session from s5bRegistry
clientSession = s5bProxy->createSOCKS5BytestreamClientSession(candidate.hostPort, SOCKS5BytestreamRegistry::getHostname(s5bSessionID, ourJID, session->getInitiator()));
clientSession->onSessionReady.connect(boost::bind(&IncomingJingleFileTransfer::proxySessionReady, this, candidate.jid, _1));
clientSession->start();
// on reply send activate
} else {
// ask s5b server
serverSession = s5bRegistry->getConnectedSession(s5bDestination);
if (serverSession) {
state = Transferring;
serverSession->onBytesReceived.connect(boost::bind(boost::ref(onProcessedBytes), _1));
serverSession->onFinished.connect(boost::bind(&IncomingJingleFileTransfer::handleTransferFinished, this, _1));
serverSession->startTransfer();
} else {
SWIFT_LOG(debug) << "No S5B server session found!!!" << std::endl;
}
}
}
void IncomingJingleFileTransfer::fillCandidateMap(CandidateMap& map, JingleS5BTransportPayload::ref s5bPayload) {
map.clear();
foreach (JingleS5BTransportPayload::Candidate candidate, s5bPayload->getCandidates()) {
map[candidate.cid] = candidate;
}
}
void IncomingJingleFileTransfer::decideOnUsedTransport() {
if (ourCandidate && theirCandidate) {
if (ourCandidate->hasCandidateError() && theirCandidate->hasCandidateError()) {
state = WaitingForFallbackOrTerminate;
return;
}
std::string our_cid = ourCandidate->getCandidateUsed();
std::string their_cid = theirCandidate->getCandidateUsed();
if (ourCandidate->hasCandidateError() && !their_cid.empty()) {
useTheirCandidateChoiceForTransfer(ourCandidates[their_cid]);
onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
}
else if (theirCandidate->hasCandidateError() && !our_cid.empty()) {
useOurCandidateChoiceForTransfer(theirCandidates[our_cid]);
onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
}
else if (!our_cid.empty() && !their_cid.empty()) {
// compare priorites, if same they win
if (ourCandidates.find(their_cid) == ourCandidates.end() || theirCandidates.find(our_cid) == theirCandidates.end()) {
SWIFT_LOG(debug) << "Didn't recognize candidate IDs!" << std::endl;
session->sendTerminate(JinglePayload::Reason::FailedTransport);
onStateChange(FileTransfer::State(FileTransfer::State::Canceled, "Failed to negotiate candidate."));
onFinished(FileTransferError(FileTransferError::PeerError));
return;
}
JingleS5BTransportPayload::Candidate our_candidate = theirCandidates[our_cid];
JingleS5BTransportPayload::Candidate their_candidate = ourCandidates[their_cid];
if (our_candidate.priority > their_candidate.priority) {
useOurCandidateChoiceForTransfer(our_candidate);
}
else if (our_candidate.priority < their_candidate.priority) {
useTheirCandidateChoiceForTransfer(their_candidate);
}
else {
useTheirCandidateChoiceForTransfer(their_candidate);
}
onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
}
else {
assert(false);
}
} else {
SWIFT_LOG(debug) << "Can't make a transport decision yet." << std::endl;
}
}
void IncomingJingleFileTransfer::proxySessionReady(const JID& proxy, bool error) {
if (error) {
// indicate proxy error
} else {
// activate proxy
activateProxySession(proxy);
}
}
void IncomingJingleFileTransfer::activateProxySession(const JID &proxy) {
S5BProxyRequest::ref proxyRequest = boost::make_shared<S5BProxyRequest>();
proxyRequest->setSID(s5bSessionID);
proxyRequest->setActivate(session->getInitiator());
boost::shared_ptr<GenericRequest<S5BProxyRequest> > request = boost::make_shared<GenericRequest<S5BProxyRequest> >(IQ::Set, proxy, proxyRequest, router);
request->onResponse.connect(boost::bind(&IncomingJingleFileTransfer::handleActivateProxySessionResult, this, _1, _2));
request->send();
}
void IncomingJingleFileTransfer::handleActivateProxySessionResult(boost::shared_ptr<S5BProxyRequest> /*request*/, ErrorPayload::ref error) {
SWIFT_LOG(debug) << std::endl;
if (error) {
SWIFT_LOG(debug) << "ERROR" << std::endl;
} else {
// send activated to other jingle party
JingleS5BTransportPayload::ref proxyActivate = boost::make_shared<JingleS5BTransportPayload>();
proxyActivate->setActivated(theirCandidate->getCandidateUsed());
session->sendTransportInfo(getContentID(), proxyActivate);
// start transferring
clientSession->onBytesReceived.connect(boost::bind(boost::ref(onProcessedBytes), _1));
clientSession->onFinished.connect(boost::bind(&IncomingJingleFileTransfer::handleTransferFinished, this, _1));
clientSession->startReceiving(stream);
onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
}
}
void IncomingJingleFileTransfer::handleTransportInfoReceived(const JingleContentID&, JingleTransportPayload::ref transport) {
SWIFT_LOG(debug) << "transport info received" << std::endl;
if (state == Terminated) {
return;
}
if (JingleS5BTransportPayload::ref s5bPayload = boost::dynamic_pointer_cast<JingleS5BTransportPayload>(transport)) {
if (!s5bPayload->getActivated().empty()) {
if (ourCandidate->getCandidateUsed() == s5bPayload->getActivated()) {
clientSession->onBytesReceived.connect(boost::bind(boost::ref(onProcessedBytes), _1));
clientSession->onFinished.connect(boost::bind(&IncomingJingleFileTransfer::handleTransferFinished, this, _1));
clientSession->startReceiving(stream);
onStateChange(FileTransfer::State(FileTransfer::State::Transferring));
} else {
SWIFT_LOG(debug) << "ourCandidateChoice doesn't match activated proxy candidate!" << std::endl;
JingleS5BTransportPayload::ref proxyError = boost::make_shared<JingleS5BTransportPayload>();
proxyError->setProxyError(true);
proxyError->setSessionID(s5bSessionID);
session->sendTransportInfo(getContentID(), proxyError);
}
} else {
theirCandidate = s5bPayload;
decideOnUsedTransport();
}
}
else {
SWIFT_LOG(debug) << "Expected something different here." << std::endl;
}
/*localTransportCandidateSelectFinished = true;
selectedLocalTransportCandidate = transport;
if (candidateGenerator->isActualCandidate(transport)) {
candidateSelector->setMinimumPriority(candidateGenerator->getPriority(transport));
}*/
//checkCandidateSelected();
}
void IncomingJingleFileTransfer::handleTransportReplaceReceived(const JingleContentID& content, JingleTransportPayload::ref transport) {
if (state == Terminated) {
return;
}
if (JingleIBBTransportPayload::ref ibbTransport = boost::dynamic_pointer_cast<JingleIBBTransportPayload>(transport)) {
SWIFT_LOG(debug) << "transport replaced with IBB" << std::endl;
setActiveTransport(createIBBTransport(ibbTransport));
session->sendTransportAccept(content, ibbTransport);
} else {
SWIFT_LOG(debug) << "transport replaced failed" << std::endl;
session->sendTransportReject(content, transport);
}
}
void IncomingJingleFileTransfer::stopActiveTransport() {
if (activeTransport) {
activeTransport->stop();
activeTransport->onDataReceived.disconnect(boost::bind(&IncomingJingleFileTransfer::handleTransportDataReceived, this, _1));
}
}
JingleIncomingIBBTransport::ref IncomingJingleFileTransfer::createIBBTransport(JingleIBBTransportPayload::ref ibbTransport) {
// TODO: getOffer() -> getOffers correction
return boost::make_shared<JingleIncomingIBBTransport>(session->getInitiator(), ibbTransport->getSessionID(), description->getOffers()[0].getSize(), router);
}
JingleContentID IncomingJingleFileTransfer::getContentID() const {
return JingleContentID(initialContent->getName(), initialContent->getCreator());
}
void IncomingJingleFileTransfer::handleTransferFinished(boost::optional<FileTransferError> error) {
if (state == Terminated) {
return;
}
if (error) {
session->sendTerminate(JinglePayload::Reason::ConnectivityError);
onStateChange(FileTransfer::State(FileTransfer::State::Failed));
onFinished(error);
}
//
}
}
|