From 5fdc90f99a88c95323c4b99aa52b41b1d4c656ac Mon Sep 17 00:00:00 2001 From: Jono Wenger <jono@elixxir.io> Date: Thu, 21 Jul 2022 11:25:16 -0700 Subject: [PATCH] Remove recipient from connection file transfer send and instead use partner in connection --- fileTransfer/connect/utils_test.go | 21 ++++++++++++++++----- fileTransfer/connect/wrapper.go | 12 ++++++++---- fileTransfer/connect/wrapper_test.go | 12 ++++++------ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/fileTransfer/connect/utils_test.go b/fileTransfer/connect/utils_test.go index e5c5c6d90..20adcb6eb 100644 --- a/fileTransfer/connect/utils_test.go +++ b/fileTransfer/connect/utils_test.go @@ -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) { diff --git a/fileTransfer/connect/wrapper.go b/fileTransfer/connect/wrapper.go index 0bfde770e..9f4c3a99a 100644 --- a/fileTransfer/connect/wrapper.go +++ b/fileTransfer/connect/wrapper.go @@ -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) } diff --git a/fileTransfer/connect/wrapper_test.go b/fileTransfer/connect/wrapper_test.go index c02ac5d78..0b7bd0b9f 100644 --- a/fileTransfer/connect/wrapper_test.go +++ b/fileTransfer/connect/wrapper_test.go @@ -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) } -- GitLab