Skip to content
Snippets Groups Projects
Select Git revision
  • 6cec75481e99a5cbcc1c39ffc7981e19aeaa6e49
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

processor.go

Blame
  • processor.go 2.22 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 (
    	"fmt"
    
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/client/cmix/identity/receptionID"
    	"gitlab.com/elixxir/client/cmix/rounds"
    	"gitlab.com/elixxir/client/fileTransfer/store"
    	"gitlab.com/elixxir/client/fileTransfer/store/cypher"
    	"gitlab.com/elixxir/client/fileTransfer/store/fileMessage"
    	"gitlab.com/elixxir/primitives/format"
    )
    
    // Error messages.
    const (
    	// processor.Process
    	errDecryptPart   = "[FT] Failed to decrypt file part for transfer %s (%q) on round %d: %+v"
    	errUnmarshalPart = "[FT] Failed to unmarshal decrypted file part for transfer %s (%q) on round %d: %+v"
    	errAddPart       = "[FT] Failed to add part #%d to transfer transfer %s (%q): %+v"
    )
    
    // processor manages the reception of file transfer messages. Adheres to the
    // message.Processor interface.
    type processor struct {
    	cypher.Cypher
    	*store.ReceivedTransfer
    	*manager
    }
    
    // Process decrypts and hands off the file part message and adds it to the
    // correct file transfer.
    func (p *processor) Process(msg format.Message,
    	_ receptionID.EphemeralIdentity, round rounds.Round) {
    
    	decryptedPart, err := p.Decrypt(msg)
    	if err != nil {
    		jww.ERROR.Printf(
    			errDecryptPart, p.TransferID(), p.FileName(), round.ID, err)
    		return
    	}
    
    	partMsg, err := fileMessage.UnmarshalPartMessage(decryptedPart)
    	if err != nil {
    		jww.ERROR.Printf(
    			errUnmarshalPart, p.TransferID(), p.FileName(), round.ID, err)
    		return
    	}
    
    	err = p.AddPart(partMsg.GetPart(), int(partMsg.GetPartNum()))
    	if err != nil {
    		jww.WARN.Printf(
    			errAddPart, partMsg.GetPartNum(), p.TransferID(), p.FileName(), err)
    		return
    	}
    
    	// Call callback with updates
    	p.callbacks.Call(p.TransferID(), nil)
    }
    
    func (p *processor) String() string {
    	return fmt.Sprintf("FileTransfer(%s)", p.myID)
    }