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

Remove recipient from connection file transfer send and instead use partner in connection

parent 66462228
No related branches found
No related tags found
1 merge request!510Release
......@@ -15,6 +15,7 @@ import (
"gitlab.com/elixxir/client/cmix/message"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/ratchet/partner"
"gitlab.com/elixxir/client/e2e/receive"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic"
......@@ -28,6 +29,7 @@ import (
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime"
"sync"
"testing"
"time"
)
......@@ -167,21 +169,30 @@ func newMockConnectionHandler() *mockConnectionHandler {
var _ Connection = (*mockConnection)(nil)
type mockConnection struct {
myID *id.ID
handler *mockConnectionHandler
myID *id.ID
recipient *id.ID
handler *mockConnectionHandler
t *testing.T
}
type mockListener struct {
hearChan chan receive.Message
}
func newMockConnection(myID *id.ID, handler *mockConnectionHandler) *mockConnection {
func newMockConnection(myID, recipient *id.ID, handler *mockConnectionHandler,
t *testing.T) *mockConnection {
return &mockConnection{
myID: myID,
handler: handler,
myID: myID,
recipient: recipient,
handler: handler,
t: t,
}
}
func (m *mockConnection) GetPartner() partner.Manager {
return partner.NewTestManager(m.recipient, nil, nil, m.t)
}
// SendE2E adds the message to the e2e handler map.
func (m *mockConnection) SendE2E(mt catalog.MessageType, payload []byte,
_ e2e.Params) ([]id.Round, e2eCrypto.MessageID, time.Time, error) {
......
......@@ -10,6 +10,7 @@ package connect
import (
"gitlab.com/elixxir/client/catalog"
"gitlab.com/elixxir/client/e2e"
"gitlab.com/elixxir/client/e2e/ratchet/partner"
"gitlab.com/elixxir/client/e2e/receive"
ft "gitlab.com/elixxir/client/fileTransfer"
e2eCrypto "gitlab.com/elixxir/crypto/e2e"
......@@ -38,6 +39,7 @@ type Wrapper struct {
// Connection interface matches a subset of the connect.Connection methods used
// by the Wrapper for easier testing.
type Connection interface {
GetPartner() partner.Manager
SendE2E(mt catalog.MessageType, payload []byte, params e2e.Params) (
[]id.Round, e2eCrypto.MessageID, time.Time, error)
RegisterListener(messageType catalog.MessageType,
......@@ -84,10 +86,10 @@ func (w *Wrapper) MaxPreviewSize() int {
return w.ft.MaxPreviewSize()
}
// Send initiates the sending of a file to a recipient and returns a transfer ID
// that uniquely identifies this file transfer. The initial and final messages
// are sent via Connection E2E.
func (w *Wrapper) Send(recipient *id.ID, fileName, fileType string,
// Send initiates the sending of a file to the connection partner and returns a
// transfer ID that uniquely identifies this file transfer. The initial and
// final messages are sent via Connection E2E.
func (w *Wrapper) Send(fileName, fileType string,
fileData []byte, retry float32, preview []byte,
progressCB ft.SentProgressCallback, period time.Duration) (
*ftCrypto.TransferID, error) {
......@@ -98,6 +100,8 @@ func (w *Wrapper) Send(recipient *id.ID, fileName, fileType string,
modifiedProgressCB := w.addEndMessageToCallback(progressCB)
recipient := w.conn.GetPartner().PartnerId()
return w.ft.Send(recipient, fileName, fileType, fileData, retry, preview,
modifiedProgressCB, period, sendNew)
}
......
......@@ -56,10 +56,11 @@ func Test_FileTransfer_Smoke(t *testing.T) {
tid, fileName, fileType, sender, size, preview}
}
myID1 := id.NewIdFromString("myID1", id.User, t)
myID2 := id.NewIdFromString("myID2", id.User, t)
storage1 := newMockStorage()
endE2eChan1 := make(chan receive.Message, 3)
conn1 := newMockConnection(myID1, e2eHandler)
conn1.RegisterListener(catalog.EndFileTransfer, newMockListener(endE2eChan1))
conn1 := newMockConnection(myID1, myID2, e2eHandler, t)
_, _ = conn1.RegisterListener(catalog.EndFileTransfer, newMockListener(endE2eChan1))
cmix1 := newMockCmix(myID1, cMixHandler, storage1)
ftManager1, err := ft.NewManager(ftParams, myID1, cmix1, storage1, rngGen)
if err != nil {
......@@ -81,11 +82,10 @@ func Test_FileTransfer_Smoke(t *testing.T) {
receiveCbChan2 <- receiveCbValues{
tid, fileName, fileType, sender, size, preview}
}
myID2 := id.NewIdFromString("myID2", id.User, t)
storage2 := newMockStorage()
endE2eChan2 := make(chan receive.Message, 3)
conn2 := newMockConnection(myID2, e2eHandler)
conn2.RegisterListener(catalog.EndFileTransfer, newMockListener(endE2eChan2))
conn2 := newMockConnection(myID2, myID1, e2eHandler, t)
_, _ = conn2.RegisterListener(catalog.EndFileTransfer, newMockListener(endE2eChan2))
cmix2 := newMockCmix(myID1, cMixHandler, storage2)
ftManager2, err := ft.NewManager(ftParams, myID2, cmix2, storage2, rngGen)
if err != nil {
......@@ -160,7 +160,7 @@ func Test_FileTransfer_Smoke(t *testing.T) {
// Send file
sendStart := netTime.Now()
tid1, err := m1.Send(
myID2, fileName, fileType, fileData, retry, preview, sentProgressCb1, 0)
fileName, fileType, fileData, retry, preview, sentProgressCb1, 0)
if err != nil {
t.Errorf("Failed to send file: %+v", err)
}
......
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