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

Make FileTransfer in bindings a pointer

parent c062a271
Branches
Tags
1 merge request!117Release
...@@ -48,7 +48,7 @@ type FileTransferReceiveFunc interface { ...@@ -48,7 +48,7 @@ type FileTransferReceiveFunc interface {
// fileTransfer.Params object. If it is left empty, then defaults are used. It // fileTransfer.Params object. If it is left empty, then defaults are used. It
// must match the following format: {"MaxThroughput":150000} // must match the following format: {"MaxThroughput":150000}
func NewFileTransferManager(client *Client, receiveFunc FileTransferReceiveFunc, func NewFileTransferManager(client *Client, receiveFunc FileTransferReceiveFunc,
parameters string) (FileTransfer, error) { parameters string) (*FileTransfer, error) {
receiveCB := func(tid ftCrypto.TransferID, fileName, fileType string, receiveCB := func(tid ftCrypto.TransferID, fileName, fileType string,
sender *id.ID, size uint32, preview []byte) { sender *id.ID, size uint32, preview []byte) {
...@@ -61,23 +61,23 @@ func NewFileTransferManager(client *Client, receiveFunc FileTransferReceiveFunc, ...@@ -61,23 +61,23 @@ func NewFileTransferManager(client *Client, receiveFunc FileTransferReceiveFunc,
if parameters != "" { if parameters != "" {
err := json.Unmarshal([]byte(parameters), &p) err := json.Unmarshal([]byte(parameters), &p)
if err != nil { if err != nil {
return FileTransfer{}, err return nil, err
} }
} }
// Create new file transfer manager // Create new file transfer manager
m, err := ft.NewManager(&client.api, receiveCB, p) m, err := ft.NewManager(&client.api, receiveCB, p)
if err != nil { if err != nil {
return FileTransfer{}, err return nil, err
} }
// Start sending and receiving threads // Start sending and receiving threads
err = client.api.AddService(m.StartProcesses) err = client.api.AddService(m.StartProcesses)
if err != nil { if err != nil {
return FileTransfer{}, err return nil, err
} }
return FileTransfer{m}, nil return &FileTransfer{m}, nil
} }
// Send sends a file to the recipient. The sender must have an E2E relationship // Send sends a file to the recipient. The sender must have an E2E relationship
...@@ -95,7 +95,7 @@ func NewFileTransferManager(client *Client, receiveFunc FileTransferReceiveFunc, ...@@ -95,7 +95,7 @@ func NewFileTransferManager(client *Client, receiveFunc FileTransferReceiveFunc,
// Returns a unique transfer ID used to identify the transfer. // Returns a unique transfer ID used to identify the transfer.
// PeriodMS is the duration, in milliseconds, to wait between progress callback // PeriodMS is the duration, in milliseconds, to wait between progress callback
// calls. Set this large enough to prevent spamming. // calls. Set this large enough to prevent spamming.
func (f FileTransfer) Send(fileName, fileType string, fileData []byte, func (f *FileTransfer) Send(fileName, fileType string, fileData []byte,
recipientID []byte, retry float32, preview []byte, recipientID []byte, retry float32, preview []byte,
progressFunc FileTransferSentProgressFunc, periodMS int) ([]byte, error) { progressFunc FileTransferSentProgressFunc, periodMS int) ([]byte, error) {
...@@ -134,7 +134,7 @@ func (f FileTransfer) Send(fileName, fileType string, fileData []byte, ...@@ -134,7 +134,7 @@ func (f FileTransfer) Send(fileName, fileType string, fileData []byte,
// not be reported and instead, the progress will be reported once at the end of // not be reported and instead, the progress will be reported once at the end of
// the period. // the period.
// The period is specified in milliseconds. // The period is specified in milliseconds.
func (f FileTransfer) RegisterSendProgressCallback(transferID []byte, func (f *FileTransfer) RegisterSendProgressCallback(transferID []byte,
progressFunc FileTransferSentProgressFunc, periodMS int) error { progressFunc FileTransferSentProgressFunc, periodMS int) error {
// Unmarshal transfer ID // Unmarshal transfer ID
...@@ -154,7 +154,7 @@ func (f FileTransfer) RegisterSendProgressCallback(transferID []byte, ...@@ -154,7 +154,7 @@ func (f FileTransfer) RegisterSendProgressCallback(transferID []byte,
// Resend resends a file if sending fails. This function should only be called // Resend resends a file if sending fails. This function should only be called
//if the interfaces.SentProgressCallback returns an error. //if the interfaces.SentProgressCallback returns an error.
func (f FileTransfer) Resend(transferID []byte) error { func (f *FileTransfer) Resend(transferID []byte) error {
// Unmarshal transfer ID // Unmarshal transfer ID
tid := ftCrypto.UnmarshalTransferID(transferID) tid := ftCrypto.UnmarshalTransferID(transferID)
...@@ -164,7 +164,7 @@ func (f FileTransfer) Resend(transferID []byte) error { ...@@ -164,7 +164,7 @@ func (f FileTransfer) Resend(transferID []byte) error {
// CloseSend deletes a sent file transfer from the sent transfer map and from // CloseSend deletes a sent file transfer from the sent transfer map and from
// storage once a transfer has completed or reached the retry limit. Returns an // storage once a transfer has completed or reached the retry limit. Returns an
// error if the transfer has not run out of retries. // error if the transfer has not run out of retries.
func (f FileTransfer) CloseSend(transferID []byte) error { func (f *FileTransfer) CloseSend(transferID []byte) error {
// Unmarshal transfer ID // Unmarshal transfer ID
tid := ftCrypto.UnmarshalTransferID(transferID) tid := ftCrypto.UnmarshalTransferID(transferID)
...@@ -181,7 +181,7 @@ func (f FileTransfer) CloseSend(transferID []byte) error { ...@@ -181,7 +181,7 @@ func (f FileTransfer) CloseSend(transferID []byte) error {
// Once the callback reports that the transfer has completed, the recipient // Once the callback reports that the transfer has completed, the recipient
// can get the full file by calling Receive. // can get the full file by calling Receive.
// The period is specified in milliseconds. // The period is specified in milliseconds.
func (f FileTransfer) RegisterReceiveProgressCallback(transferID []byte, func (f *FileTransfer) RegisterReceiveProgressCallback(transferID []byte,
progressFunc FileTransferReceivedProgressFunc, periodMS int) error { progressFunc FileTransferReceivedProgressFunc, periodMS int) error {
// Unmarshal transfer ID // Unmarshal transfer ID
tid := ftCrypto.UnmarshalTransferID(transferID) tid := ftCrypto.UnmarshalTransferID(transferID)
...@@ -202,7 +202,7 @@ func (f FileTransfer) RegisterReceiveProgressCallback(transferID []byte, ...@@ -202,7 +202,7 @@ func (f FileTransfer) RegisterReceiveProgressCallback(transferID []byte,
// It deletes the transfer from the received transfer map and from storage. // It deletes the transfer from the received transfer map and from storage.
// Returns an error if the transfer is not complete, the full file cannot be // Returns an error if the transfer is not complete, the full file cannot be
// verified, or if the transfer cannot be found. // verified, or if the transfer cannot be found.
func (f FileTransfer) Receive(transferID []byte) ([]byte, error) { func (f *FileTransfer) Receive(transferID []byte) ([]byte, error) {
// Unmarshal transfer ID // Unmarshal transfer ID
tid := ftCrypto.UnmarshalTransferID(transferID) tid := ftCrypto.UnmarshalTransferID(transferID)
...@@ -214,24 +214,24 @@ func (f FileTransfer) Receive(transferID []byte) ([]byte, error) { ...@@ -214,24 +214,24 @@ func (f FileTransfer) Receive(transferID []byte) ([]byte, error) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// GetMaxFilePreviewSize returns the maximum file preview size, in bytes. // GetMaxFilePreviewSize returns the maximum file preview size, in bytes.
func (f FileTransfer) GetMaxFilePreviewSize() int { func (f *FileTransfer) GetMaxFilePreviewSize() int {
return ft.PreviewMaxSize return ft.PreviewMaxSize
} }
// GetMaxFileNameByteLength returns the maximum length, in bytes, allowed for a // GetMaxFileNameByteLength returns the maximum length, in bytes, allowed for a
// file name. // file name.
func (f FileTransfer) GetMaxFileNameByteLength() int { func (f *FileTransfer) GetMaxFileNameByteLength() int {
return ft.FileNameMaxLen return ft.FileNameMaxLen
} }
// GetMaxFileTypeByteLength returns the maximum length, in bytes, allowed for a // GetMaxFileTypeByteLength returns the maximum length, in bytes, allowed for a
// file type. // file type.
func (f FileTransfer) GetMaxFileTypeByteLength() int { func (f *FileTransfer) GetMaxFileTypeByteLength() int {
return ft.FileTypeMaxLen return ft.FileTypeMaxLen
} }
// GetMaxFileSize returns the maximum file size, in bytes, allowed to be // GetMaxFileSize returns the maximum file size, in bytes, allowed to be
// transferred. // transferred.
func (f FileTransfer) GetMaxFileSize() int { func (f *FileTransfer) GetMaxFileSize() int {
return ft.FileMaxSize return ft.FileMaxSize
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment