Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
f9a34f99
Commit
f9a34f99
authored
3 years ago
by
Sébastien Blin
Browse files
Options
Downloads
Patches
Plain Diff
data_transfer: channel can live longer than IncomingFile
Change-Id: Ifbc66d0197949f82826bd743b3a015ae5b540e6f
parent
062111c7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/data_transfer.cpp
+20
-15
20 additions, 15 deletions
src/data_transfer.cpp
src/data_transfer.h
+5
-1
5 additions, 1 deletion
src/data_transfer.h
with
25 additions
and
16 deletions
src/data_transfer.cpp
+
20
−
15
View file @
f9a34f99
...
@@ -832,32 +832,37 @@ IncomingFile::cancel()
...
@@ -832,32 +832,37 @@ IncomingFile::cancel()
void
void
IncomingFile
::
process
()
IncomingFile
::
process
()
{
{
channel_
->
setOnRecv
([
this
](
const
uint8_t
*
buf
,
size_t
len
)
{
channel_
->
setOnRecv
([
w
=
weak
()](
const
uint8_t
*
buf
,
size_t
len
)
{
if
(
stream_
.
is_open
())
if
(
auto
shared
=
w
.
lock
())
{
stream_
<<
std
::
string_view
((
const
char
*
)
buf
,
len
);
if
(
shared
->
stream_
.
is_open
())
info_
.
bytesProgress
=
stream_
.
tellp
();
shared
->
stream_
<<
std
::
string_view
((
const
char
*
)
buf
,
len
);
shared
->
info_
.
bytesProgress
=
shared
->
stream_
.
tellp
();
}
return
len
;
return
len
;
});
});
channel_
->
onShutdown
([
this
]
{
channel_
->
onShutdown
([
w
=
weak
()]
{
auto
correct
=
sha3Sum_
.
empty
();
auto
shared
=
w
.
lock
();
if
(
!
shared
)
return
;
auto
correct
=
shared
->
sha3Sum_
.
empty
();
if
(
!
correct
)
{
if
(
!
correct
)
{
if
(
stream_
&&
stream_
.
is_open
())
if
(
shared
->
stream_
&&
shared
->
stream_
.
is_open
())
stream_
.
close
();
shared
->
stream_
.
close
();
// Verify shaSum
// Verify shaSum
auto
sha3Sum
=
fileutils
::
sha3File
(
info_
.
path
);
auto
sha3Sum
=
fileutils
::
sha3File
(
shared
->
info_
.
path
);
if
(
sha3Sum_
==
sha3Sum
)
{
if
(
shared
->
sha3Sum_
==
sha3Sum
)
{
JAMI_INFO
()
<<
"New file received: "
<<
info_
.
path
;
JAMI_INFO
()
<<
"New file received: "
<<
shared
->
info_
.
path
;
correct
=
true
;
correct
=
true
;
}
else
{
}
else
{
JAMI_WARN
()
<<
"Remove file, invalid sha3sum detected for "
<<
info_
.
path
;
JAMI_WARN
()
<<
"Remove file, invalid sha3sum detected for "
<<
shared
->
info_
.
path
;
fileutils
::
remove
(
info_
.
path
,
true
);
fileutils
::
remove
(
shared
->
info_
.
path
,
true
);
}
}
}
}
if
(
isUserCancelled_
)
if
(
shared
->
isUserCancelled_
)
return
;
return
;
auto
code
=
correct
?
DRing
::
DataTransferEventCode
::
finished
auto
code
=
correct
?
DRing
::
DataTransferEventCode
::
finished
:
DRing
::
DataTransferEventCode
::
closed_by_host
;
:
DRing
::
DataTransferEventCode
::
closed_by_host
;
emit
(
code
);
shared
->
emit
(
code
);
});
});
}
}
...
...
This diff is collapsed.
Click to expand it.
src/data_transfer.h
+
5
−
1
View file @
f9a34f99
...
@@ -79,7 +79,7 @@ protected:
...
@@ -79,7 +79,7 @@ protected:
std
::
function
<
void
(
uint32_t
)
>
finishedCb_
{};
std
::
function
<
void
(
uint32_t
)
>
finishedCb_
{};
};
};
class
IncomingFile
:
public
FileInfo
class
IncomingFile
:
public
FileInfo
,
public
std
::
enable_shared_from_this
<
IncomingFile
>
{
{
public:
public:
IncomingFile
(
const
std
::
shared_ptr
<
ChannelSocket
>&
channel
,
IncomingFile
(
const
std
::
shared_ptr
<
ChannelSocket
>&
channel
,
...
@@ -92,6 +92,10 @@ public:
...
@@ -92,6 +92,10 @@ public:
void
cancel
()
override
;
void
cancel
()
override
;
private:
private:
std
::
weak_ptr
<
IncomingFile
>
weak
()
{
return
std
::
static_pointer_cast
<
IncomingFile
>
(
shared_from_this
());
}
std
::
ofstream
stream_
;
std
::
ofstream
stream_
;
std
::
string
sha3Sum_
{};
std
::
string
sha3Sum_
{};
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment