Skip to content
Snippets Groups Projects
Select Git revision
  • 03fe45d2dfcd50a495039f4c66d4f49fbf723f89
  • release default
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • master protected
  • XX-4688/DbEncoding
  • hotfix/update
  • @XX-4682/Files
  • hotfix/XX-4655
  • dev protected
  • project/HavenNotifications
  • XX-4602/SilentMessageType
  • jono/npmTest
  • wasmTest2
  • XX-4461/FileUpload
  • XX-4505/blockuser
  • XX-4441
  • Jakub/Emoji-CI-Test
  • testing/websockets
  • fastReg
  • fast-registration
  • NewHostPool
  • v0.3.22
  • v0.3.21
  • v0.3.20
  • v0.3.18
  • v0.3.17
  • v0.3.16
  • v0.3.15
  • v0.3.14
  • v0.3.13
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • 812b395df518ce096d01d5292596ca26f8fe92d9c4487ddfa515e190a51aa1a1
  • 76ba08e2dfa1798412a265404fa271840b52c035869111fce8e8cdb23a036a5a
41 results

restlike.go

Blame
  • sendE2e.go 3.06 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                           //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file                                                               //
    ////////////////////////////////////////////////////////////////////////////////
    
    package fileTransfer
    
    import (
    	"github.com/golang/protobuf/proto"
    	"github.com/pkg/errors"
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/client/catalog"
    	"gitlab.com/elixxir/client/e2e"
    	ftCrypto "gitlab.com/elixxir/crypto/fileTransfer"
    	"gitlab.com/xx_network/primitives/id"
    )
    
    // Error messages.
    const (
    	// manager.sendNewFileTransferMessage
    	errProtoMarshal = "failed to proto marshal NewFileTransfer: %+v"
    	errNewFtSendE2e = "failed to send initial file transfer message via E2E: %+v"
    
    	// manager.sendEndFileTransferMessage
    	errEndFtSendE2e = "[FT] Failed to send ending file transfer message via E2E: %+v"
    )
    
    const (
    	// Tag that is used for log printing in SendE2E when sending the initial
    	// message
    	initialMessageDebugTag = "FT.New"
    
    	// Tag that is used for log printing in SendE2E when sending the ending
    	// message
    	lastMessageDebugTag = "FT.End"
    )
    
    // sendNewFileTransferMessage sends an E2E message to the recipient informing
    // them of the incoming file transfer.
    func (m *manager) sendNewFileTransferMessage(recipient *id.ID, fileName,
    	fileType string, key *ftCrypto.TransferKey, mac []byte, numParts uint16,
    	fileSize uint32, retry float32, preview []byte) error {
    
    	// Construct NewFileTransfer message
    	protoMsg := &NewFileTransfer{
    		FileName:    fileName,
    		FileType:    fileType,
    		TransferKey: key.Bytes(),
    		TransferMac: mac,
    		NumParts:    uint32(numParts),
    		Size:        fileSize,
    		Retry:       retry,
    		Preview:     preview,
    	}
    
    	// Marshal the message
    	payload, err := proto.Marshal(protoMsg)
    	if err != nil {
    		return errors.Errorf(errProtoMarshal, err)
    	}
    
    	// Get E2E parameters
    	params := e2e.GetDefaultParams()
    	params.ServiceTag = catalog.Silent
    	params.LastServiceTag = catalog.Silent
    	params.DebugTag = initialMessageDebugTag
    
    	_, _, _, err = m.e2e.SendE2E(
    		catalog.NewFileTransfer, recipient, payload, params)
    	if err != nil {
    		return errors.Errorf(errNewFtSendE2e, err)
    	}
    
    	return nil
    }
    
    // sendEndFileTransferMessage sends an E2E message to the recipient informing
    // them that all file parts have arrived once the network is healthy.
    func (m *manager) sendEndFileTransferMessage(recipient *id.ID) {
    	callbackID := make(chan uint64, 1)
    	callbackID <- m.cmix.AddHealthCallback(
    		func(healthy bool) {
    			if healthy {
    				params := e2e.GetDefaultParams()
    				params.LastServiceTag = catalog.EndFT
    				params.DebugTag = lastMessageDebugTag
    
    				_, _, _, err := m.e2e.SendE2E(
    					catalog.EndFileTransfer, recipient, nil, params)
    				if err != nil {
    					jww.ERROR.Printf(errEndFtSendE2e, err)
    				}
    
    				cbID := <-callbackID
    				m.cmix.RemoveHealthCallback(cbID)
    			}
    		},
    	)
    }