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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
a802e2b8
Commit
a802e2b8
authored
Dec 14, 2021
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Fix file transfer partStore and minor integration test fixes
parent
45bf3665
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!117
Release
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/fileTransfer.go
+17
-18
17 additions, 18 deletions
cmd/fileTransfer.go
storage/fileTransfer/partStore.go
+8
-3
8 additions, 3 deletions
storage/fileTransfer/partStore.go
with
25 additions
and
21 deletions
cmd/fileTransfer.go
+
17
−
18
View file @
a802e2b8
...
...
@@ -18,10 +18,8 @@ import (
"gitlab.com/elixxir/crypto/contact"
ftCrypto
"gitlab.com/elixxir/crypto/fileTransfer"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/netTime"
"gitlab.com/xx_network/primitives/utils"
"io/ioutil"
"strconv"
"time"
)
...
...
@@ -186,23 +184,29 @@ func sendFile(filePath, fileType, filePreviewPath, filePreviewString,
}
}
// Truncate file path if it is too long to be a file name
fileName
:=
filePath
if
len
(
fileName
)
>
ft
.
FileNameMaxLen
{
fileName
=
fileName
[
:
ft
.
FileNameMaxLen
]
}
// Get recipient contact from file
recipient
:=
getContactFromFile
(
recipientContactPath
)
jww
.
DEBUG
.
Printf
(
"Sending file %q of size %d to recipient %s."
,
file
Path
,
len
(
fileData
),
recipient
.
ID
)
file
Name
,
len
(
fileData
),
recipient
.
ID
)
// Create sent progress callback that prints the results
progressCB
:=
func
(
completed
bool
,
sent
,
arrived
,
total
uint16
,
t
interfaces
.
FilePartTracker
,
err
error
)
{
jww
.
DEBUG
.
Printf
(
"Sent progress callback for %q "
+
"{completed: %t, sent: %d, arrived: %d, total: %d, err: %v}
\n
"
,
file
Path
,
completed
,
sent
,
arrived
,
total
,
err
)
file
Name
,
completed
,
sent
,
arrived
,
total
,
err
)
if
(
sent
==
0
&&
arrived
==
0
)
||
(
arrived
==
total
)
||
completed
||
err
!=
nil
{
fmt
.
Printf
(
"Sent progress callback for %q "
+
"{completed: %t, sent: %d, arrived: %d, total: %d, err: %v}
\n
"
,
file
Path
,
completed
,
sent
,
arrived
,
total
,
err
)
file
Name
,
completed
,
sent
,
arrived
,
total
,
err
)
}
if
completed
{
...
...
@@ -215,11 +219,11 @@ func sendFile(filePath, fileType, filePreviewPath, filePreviewString,
}
// Send the file
_
,
err
=
m
.
Send
(
file
Path
,
fileType
,
fileData
,
recipient
.
ID
,
retry
,
_
,
err
=
m
.
Send
(
file
Name
,
fileType
,
fileData
,
recipient
.
ID
,
retry
,
filePreviewData
,
progressCB
,
callbackPeriod
)
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to send file %q to %s: %+v"
,
file
Path
,
recipient
.
ID
,
err
)
file
Name
,
recipient
.
ID
,
err
)
}
}
...
...
@@ -236,9 +240,9 @@ func receiveNewFileTransfers(receive chan receivedFtResults, done,
"message."
)
return
case
r
:=
<-
receive
:
jww
.
DEBUG
.
Printf
(
"Received new file %q transfer %s
from %s of siz
e %
d
"
+
"bytes with preview: %q"
,
r
.
fileName
,
r
.
tid
,
r
.
sender
,
r
.
size
,
r
.
preview
)
jww
.
DEBUG
.
Printf
(
"Received new file %q transfer %s
of typ
e %
q
"
+
"
from %s of size %d
bytes with preview: %q"
,
r
.
fileName
,
r
.
tid
,
r
.
fileType
,
r
.
sender
,
r
.
size
,
r
.
preview
)
fmt
.
Printf
(
"Received new file transfer %q of size %d "
+
"bytes with preview: %q
\n
"
,
r
.
fileName
,
r
.
size
,
r
.
preview
)
...
...
@@ -305,16 +309,16 @@ func getContactFromFile(path string) contact.Contact {
// init initializes commands and flags for Cobra.
func
init
()
{
ftCmd
.
Flags
()
.
String
(
"sendFile"
,
""
,
"Sends a file to a recipient with with the contact at this path."
)
"Sends a file to a recipient with with the contact
file
at this path."
)
bindPFlagCheckErr
(
"sendFile"
)
ftCmd
.
Flags
()
.
String
(
"filePath"
,
"
testFile-"
+
timeNanoString
()
+
".txt
"
,
ftCmd
.
Flags
()
.
String
(
"filePath"
,
""
,
"The path to the file to send. Also used as the file name."
)
bindPFlagCheckErr
(
"filePath"
)
ftCmd
.
Flags
()
.
String
(
"fileType"
,
"txt"
,
"8-byte file type."
)
bindPFlagCheckErr
(
"file
Path
"
)
bindPFlagCheckErr
(
"file
Type
"
)
ftCmd
.
Flags
()
.
String
(
"filePreviewPath"
,
""
,
"The path to the file preview to send. Set either this flag or "
+
...
...
@@ -336,11 +340,6 @@ func init() {
rootCmd
.
AddCommand
(
ftCmd
)
}
// timeNanoString returns the current UNIX time in nanoseconds as a string.
func
timeNanoString
()
string
{
return
strconv
.
Itoa
(
int
(
netTime
.
Now
()
.
UnixNano
()))
}
// bindPFlagCheckErr binds the key to a pflag.Flag used by Cobra and prints an
// error if one occurs.
func
bindPFlagCheckErr
(
key
string
)
{
...
...
This diff is collapsed.
Click to expand it.
storage/fileTransfer/partStore.go
+
8
−
3
View file @
a802e2b8
...
...
@@ -74,7 +74,8 @@ func (ps *partStore) addPart(part []byte, partNum uint16) error {
ps
.
mux
.
Lock
()
defer
ps
.
mux
.
Unlock
()
ps
.
parts
[
partNum
]
=
part
ps
.
parts
[
partNum
]
=
make
([]
byte
,
len
(
part
))
copy
(
ps
.
parts
[
partNum
],
part
)
err
:=
ps
.
savePart
(
partNum
)
if
err
!=
nil
{
...
...
@@ -90,7 +91,10 @@ func (ps *partStore) getPart(partNum uint16) ([]byte, bool) {
defer
ps
.
mux
.
Unlock
()
part
,
exists
:=
ps
.
parts
[
partNum
]
return
part
,
exists
newPart
:=
make
([]
byte
,
len
(
part
))
copy
(
newPart
,
part
)
return
newPart
,
exists
}
// getFile returns all file parts concatenated into a single file. Returns the
...
...
@@ -268,7 +272,8 @@ func partSliceToMap(parts ...[]byte) map[uint16][]byte {
// Add each file part to the map
for
partNum
,
part
:=
range
parts
{
partMap
[
uint16
(
partNum
)]
=
part
partMap
[
uint16
(
partNum
)]
=
make
([]
byte
,
len
(
part
))
copy
(
partMap
[
uint16
(
partNum
)],
part
)
}
return
partMap
...
...
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