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