Skip to content
Snippets Groups Projects
Commit eb166d55 authored by Jono Wenger's avatar Jono Wenger
Browse files

Add transfer ID to Progress struct

parent 00e04d4d
No related branches found
No related tags found
1 merge request!430XX-4277 / Fix file transfer crashes
......@@ -34,29 +34,29 @@ type FileTransfer struct {
//
// Example JSON:
// {
// "TransferID":"B4Z9cwU18beRoGbk5xBjbcd5Ryi9ZUFA2UBvi8FOHWo=",
// "SenderID":"emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD",
// "Preview":"aXQncyBtZSBhIHByZXZpZXc=",
// "Name":"testfile.txt",
// "Type":"text file",
// "Size":2048
// "TransferID": "0U+QY1nMOUzQGxGpqZyxDw8Cd6+qm8t870CzLtVoUM8=",
// "SenderID": "UL3+S8XdJHAfUtCUm7iZMxW8orR8Nd5JM9Ky7/5jds8D",
// "Preview": "aXQNcyBtZSBhIHByZXZpZXc=",
// "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":"aXQncyBtZSBhIHByZXZpZXc=",
// "Contents":"VGhpcyBpcyB0aGUgZnVsbCBjb250ZW50cyBvZiB0aGUgZmlsZSBpbiBieXRlcw=="
// "Name": "testfile.txt",
// "Type": "text file",
// "Preview": "aXQnCyBtZSBhIHByZXZpZXc=",
// "Contents": "VGhpCyBpCyB0aGUgZnVsbCBjb250ZW50cyBvZiB0aGUgZm6lsZSBPbiBieXRl2w=="
// }
type FileSend struct {
Name string // Name of the file
......@@ -70,16 +70,16 @@ type FileSend struct {
//
// Example JSON:
// {
// "Completed":false,
// "Transmitted":128,
// "Total":2048,
// "Err":null
// "TransferID": "RyJcMqtI3IIM1+YMxRwCcFiOX6AGuIzS+vQaPnqXVT8=",
// "Completed": false,
// "Transmitted": 128,
// "Total": 2048
// }
type Progress struct {
Completed bool // Status of transfer (true if done)
Transmitted int // Number of file parts sent/received
Total int // Total number of file parts
Err error // Error status (if any)
TransferID *ftCrypto.TransferID // Transfer ID
Completed bool // Status of transfer (true if done)
Transmitted int // Number 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(progress)
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(progress)
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(progress)
callback.Callback(pm, &FilePartTracker{t}, err)
}
p := time.Millisecond * time.Duration(period)
......
......@@ -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.NewIdFromString("zezima", id.User, t)
sid, _ := id.NewRandomID(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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment