Skip to content
Snippets Groups Projects
Select Git revision
  • ef8e90f4d32e22c090a37ae45a7285f11bbe6d8f
  • 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

params.go

Blame
  • info.go 2.31 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2022 xx foundation                                             //
    //                                                                            //
    // 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"
    	ftCrypto "gitlab.com/elixxir/crypto/fileTransfer"
    )
    
    // TransferInfo contains all the information for a new transfer. This is the
    // information sent in the initial file transfer so the recipient can prepare
    // for the incoming file transfer parts.
    type TransferInfo struct {
    	FileName string               // Name of the file
    	FileType string               // String that indicates type of file
    	Key      ftCrypto.TransferKey // 256-bit encryption key
    	Mac      []byte               // 256-bit MAC of the entire file
    	NumParts uint16               // Number of file parts
    	Size     uint32               // The size of the file, in bytes
    	Retry    float32              // Determines how many times to retry sending
    	Preview  []byte               // A preview of the file
    }
    
    // Marshal serialises the TransferInfo for sending over the network.
    func (ti *TransferInfo) Marshal() ([]byte, error) {
    	// Construct NewFileTransfer message
    	protoMsg := &NewFileTransfer{
    		FileName:    ti.FileName,
    		FileType:    ti.FileType,
    		TransferKey: ti.Key.Bytes(),
    		TransferMac: ti.Mac,
    		NumParts:    uint32(ti.NumParts),
    		Size:        ti.Size,
    		Retry:       ti.Retry,
    		Preview:     ti.Preview,
    	}
    
    	return proto.Marshal(protoMsg)
    }
    
    // UnmarshalTransferInfo deserializes the TransferInfo.
    func UnmarshalTransferInfo(data []byte) (*TransferInfo, error) {
    	// Unmarshal the request message
    	var newFT NewFileTransfer
    	err := proto.Unmarshal(data, &newFT)
    	if err != nil {
    		return nil, err
    	}
    	transferKey := ftCrypto.UnmarshalTransferKey(newFT.GetTransferKey())
    
    	return &TransferInfo{
    		FileName: newFT.FileName,
    		FileType: newFT.FileType,
    		Key:      transferKey,
    		Mac:      newFT.TransferMac,
    		NumParts: uint16(newFT.NumParts),
    		Size:     newFT.Size,
    		Retry:    newFT.Retry,
    		Preview:  newFT.Preview,
    	}, nil
    }