Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
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
elixxir
client
Commits
eb166d55
Commit
eb166d55
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Add transfer ID to Progress struct
parent
00e04d4d
No related branches found
No related tags found
1 merge request
!430
XX-4277 / Fix file transfer crashes
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bindings/fileTransfer.go
+36
-36
36 additions, 36 deletions
bindings/fileTransfer.go
bindings/fileTransfer_test.go
+17
-20
17 additions, 20 deletions
bindings/fileTransfer_test.go
with
53 additions
and
56 deletions
bindings/fileTransfer.go
+
36
−
36
View file @
eb166d55
...
...
@@ -34,29 +34,29 @@ type FileTransfer struct {
//
// Example JSON:
// {
// "TransferID":
"B4Z9cwU18beRoGbk5xBjbcd5Ryi9ZUFA2UBvi8FOHWo
=",
// "SenderID":
"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
D",
// "Preview":"aXQ
n
cyBtZSBhIHByZXZpZXc=",
// "Name":"testfile.txt",
// "Type":"text file",
// "Size":2048
// "TransferID":
"0U+QY1nMOUzQGxGpqZyxDw8Cd6+qm8t870CzLtVoUM8
=",
// "SenderID":
"UL3+S8XdJHAfUtCUm7iZMxW8orR8Nd5JM9Ky7/5jds8
D",
// "Preview":
"aXQ
N
cyBtZSBhIHByZXZpZXc=",
// "Name":
"testfile.txt",
// "Type":
"text file",
// "Size":
2048
// }
type
ReceivedFile
struct
{
TransferID
[]
byte
// ID of the file transfer
SenderID
[]
byte
// ID of the file sender
Preview
[]
byte
// A preview of the file
Name
string
// Name of the file
Type
string
// String that indicates type of file
Size
int
// The size of the file, in bytes
TransferID
*
ftCrypto
.
TransferID
// ID of the file transfer
SenderID
*
id
.
ID
// ID of the file sender
Preview
[]
byte
// A preview of the file
Name
string
// Name of the file
Type
string
// String that indicates type of file
Size
int
// The size of the file, in bytes
}
// FileSend is a public struct that contains the file contents and its name,
// type, and preview.
// {
// "Name":"testfile.txt",
// "Type":"text file",
// "Preview":"aXQn
c
yBtZSBhIHByZXZpZXc=",
// "Contents":"VGhp
c
yBp
c
yB0aGUgZnVsbCBjb250ZW50cyBvZiB0aGUgZmlsZSB
p
biBieXRl
c
w=="
// "Name":
"testfile.txt",
// "Type":
"text file",
// "Preview":
"aXQn
C
yBtZSBhIHByZXZpZXc=",
// "Contents":
"VGhp
C
yBp
C
yB0aGUgZnVsbCBjb250ZW50cyBvZiB0aGUgZm
6
lsZSB
P
biBieXRl
2
w=="
// }
type
FileSend
struct
{
Name
string
// Name of the file
...
...
@@ -70,16 +70,16 @@ type FileSend struct {
//
// Example JSON:
// {
// "
Completed":false
,
// "
Transmitted":128
,
// "T
otal":204
8,
// "
Err":null
// "
TransferID": "RyJcMqtI3IIM1+YMxRwCcFiOX6AGuIzS+vQaPnqXVT8="
,
// "
Completed": false
,
// "T
ransmitted": 12
8,
// "
Total": 2048
// }
type
Progress
struct
{
Completed
bool
// Status of transfer (true if done)
Transmitted
int
// Number of file parts sent/received
T
otal
int
// Total n
umber of file parts
Err
error
// Error status (if any)
TransferID
*
ftCrypto
.
TransferID
// Transfer ID
Completed
bool
// Status of transfer (true if done)
T
ransmitted
int
// N
umber of file parts
sent/received
Total
int
// Total number of file parts
}
// ReceiveFileCallback is a bindings-layer interface that contains a callback
...
...
@@ -130,7 +130,7 @@ type FileTransferReceiveProgressCallback interface {
func
InitFileTransfer
(
e2eID
int
,
receiveFileCallback
ReceiveFileCallback
,
e2eFileTransferParamsJson
,
fileTransferParamsJson
[]
byte
)
(
*
FileTransfer
,
error
)
{
jww
.
INFO
.
Printf
(
"[FT] Calling InitFileTransfer(e2eID:%d params:%s)"
,
fileTransferParamsJson
)
e2eID
,
fileTransferParamsJson
)
// Get user from singleton
user
,
err
:=
e2eTrackerSingleton
.
get
(
e2eID
)
if
err
!=
nil
{
...
...
@@ -153,8 +153,8 @@ func InitFileTransfer(e2eID int, receiveFileCallback ReceiveFileCallback,
rcb
:=
func
(
tid
*
ftCrypto
.
TransferID
,
fileName
,
fileType
string
,
sender
*
id
.
ID
,
size
uint32
,
preview
[]
byte
)
{
receiveFileCallback
.
Callback
(
json
.
Marshal
(
ReceivedFile
{
TransferID
:
tid
.
Bytes
()
,
SenderID
:
sender
.
Marshal
()
,
TransferID
:
tid
,
SenderID
:
sender
,
Preview
:
preview
,
Name
:
fileName
,
Type
:
fileType
,
...
...
@@ -206,13 +206,13 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32,
// Wrap transfer progress callback to be passed to fileTransfer layer
cb
:=
func
(
completed
bool
,
arrived
,
total
uint16
,
st
fileTransfer
.
SentTransfer
,
t
fileTransfer
.
FilePartTracker
,
err
error
)
{
prog
:=
&
Progress
{
progress
:=
&
Progress
{
TransferID
:
st
.
TransferID
(),
Completed
:
completed
,
Transmitted
:
int
(
arrived
),
Total
:
int
(
total
),
Err
:
err
,
}
pm
,
err
:=
json
.
Marshal
(
prog
)
pm
,
err
:=
json
.
Marshal
(
prog
ress
)
callback
.
Callback
(
pm
,
&
FilePartTracker
{
t
},
err
)
}
...
...
@@ -282,13 +282,13 @@ func (f *FileTransfer) RegisterSentProgressCallback(tidBytes []byte,
callback
FileTransferSentProgressCallback
,
period
int
)
error
{
cb
:=
func
(
completed
bool
,
arrived
,
total
uint16
,
st
fileTransfer
.
SentTransfer
,
t
fileTransfer
.
FilePartTracker
,
err
error
)
{
prog
:=
&
Progress
{
progress
:=
&
Progress
{
TransferID
:
st
.
TransferID
(),
Completed
:
completed
,
Transmitted
:
int
(
arrived
),
Total
:
int
(
total
),
Err
:
err
,
}
pm
,
err
:=
json
.
Marshal
(
prog
)
pm
,
err
:=
json
.
Marshal
(
prog
ress
)
callback
.
Callback
(
pm
,
&
FilePartTracker
{
t
},
err
)
}
p
:=
time
.
Millisecond
*
time
.
Duration
(
period
)
...
...
@@ -312,13 +312,13 @@ func (f *FileTransfer) RegisterReceivedProgressCallback(tidBytes []byte,
callback
FileTransferReceiveProgressCallback
,
period
int
)
error
{
cb
:=
func
(
completed
bool
,
received
,
total
uint16
,
rt
fileTransfer
.
ReceivedTransfer
,
t
fileTransfer
.
FilePartTracker
,
err
error
)
{
prog
:=
&
Progress
{
progress
:=
&
Progress
{
TransferID
:
rt
.
TransferID
(),
Completed
:
completed
,
Transmitted
:
int
(
received
),
Total
:
int
(
total
),
Err
:
err
,
}
pm
,
err
:=
json
.
Marshal
(
prog
)
pm
,
err
:=
json
.
Marshal
(
prog
ress
)
callback
.
Callback
(
pm
,
&
FilePartTracker
{
t
},
err
)
}
p
:=
time
.
Millisecond
*
time
.
Duration
(
period
)
...
...
This diff is collapsed.
Click to expand it.
bindings/fileTransfer_test.go
+
17
−
20
View file @
eb166d55
...
...
@@ -9,6 +9,7 @@ package bindings
import
(
"encoding/json"
"fmt"
"testing"
"gitlab.com/elixxir/crypto/fileTransfer"
...
...
@@ -23,36 +24,33 @@ func TestFileTransfer_inputs(t *testing.T) {
Preview
:
[]
byte
(
"it's me a preview"
),
Contents
:
[]
byte
(
"This is the full contents of the file in bytes"
),
}
fsm
,
_
:=
json
.
Marshal
(
fs
)
t
.
Log
(
"FileSend example json:"
)
t
.
Log
(
string
(
fsm
))
t
.
Log
(
"
\n
"
)
fsm
,
_
:=
json
.
MarshalIndent
(
fs
,
""
,
" "
)
t
.
Log
(
"FileSend example JSON:"
)
fmt
.
Printf
(
"%s
\n\n
"
,
fsm
)
tid
,
_
:=
fileTransfer
.
NewTransferID
(
csprng
.
NewSystemRNG
())
sid
:=
id
.
New
IdFromString
(
"zezima"
,
id
.
User
,
t
)
sid
,
_
:=
id
.
New
RandomID
(
csprng
.
NewSystemRNG
()
,
id
.
User
)
rf
:=
&
ReceivedFile
{
TransferID
:
tid
.
Bytes
()
,
SenderID
:
sid
.
Marshal
()
,
TransferID
:
&
tid
,
SenderID
:
sid
,
Preview
:
[]
byte
(
"it's me a preview"
),
Name
:
"testfile.txt"
,
Type
:
"text file"
,
Size
:
2048
,
}
rfm
,
_
:=
json
.
Marshal
(
rf
)
t
.
Log
(
"ReceivedFile example json:"
)
t
.
Log
(
string
(
rfm
))
t
.
Log
(
"
\n
"
)
rfm
,
_
:=
json
.
MarshalIndent
(
rf
,
""
,
" "
)
t
.
Log
(
"ReceivedFile example JSON:"
)
fmt
.
Printf
(
"%s
\n\n
"
,
rfm
)
p
:=
&
Progress
{
TransferID
:
&
tid
,
Completed
:
false
,
Transmitted
:
128
,
Total
:
2048
,
Err
:
nil
,
}
pm
,
_
:=
json
.
Marshal
(
p
)
t
.
Log
(
"Progress example json:"
)
t
.
Log
(
string
(
pm
))
t
.
Log
(
"
\n
"
)
pm
,
_
:=
json
.
MarshalIndent
(
p
,
""
,
" "
)
t
.
Log
(
"Progress example JSON:"
)
fmt
.
Printf
(
"%s
\n\n
"
,
pm
)
er
:=
&
EventReport
{
Priority
:
1
,
...
...
@@ -60,8 +58,7 @@ func TestFileTransfer_inputs(t *testing.T) {
EventType
:
"Ping"
,
Details
:
"This is an example of an event report"
,
}
erm
,
_
:=
json
.
Marshal
(
er
)
t
.
Log
(
"EventReport example json:"
)
t
.
Log
(
string
(
erm
))
t
.
Log
(
"
\n
"
)
erm
,
_
:=
json
.
MarshalIndent
(
er
,
""
,
" "
)
t
.
Log
(
"EventReport example JSON:"
)
fmt
.
Printf
(
"%s
\n\n
"
,
erm
)
}
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