store

package
v4.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2023 License: BSD-2-Clause, BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOrLoadReceived

func NewOrLoadReceived(kv *versioned.KV) (*Received, []*ReceivedTransfer, error)

NewOrLoadReceived attempts to load a Received from storage. Or if none exist, then a new Received is returned. Also returns a list of all transfers that have unreceived file parts so their fingerprints can be re-added.

func NewOrLoadSent

func NewOrLoadSent(kv *versioned.KV) (*Sent, []Part, error)

NewOrLoadSent attempts to load Sent from storage. Or if none exist, then a new Sent is returned. If running transfers were loaded from storage, a list of unsent parts is returned.

Types

type Part

type Part struct {
	// contains filtered or unexported fields
}

Part contains information about a single file part and its parent transfer. Also contains cryptographic information needed to encrypt the part data.

func (*Part) FileName

func (p *Part) FileName() string

FileName returns the name of the file.

func (*Part) GetEncryptedPart

func (p *Part) GetEncryptedPart(contentsSize int) (
	encryptedPart, mac []byte, fp format.Fingerprint, err error)

GetEncryptedPart gets the specified part, encrypts it, and returns the encrypted part along with its MAC and fingerprint. An error is returned if no fingerprints are available.

func (*Part) MarkArrived

func (p *Part) MarkArrived()

MarkArrived marks the part as arrived. This should be called after the round the part is sent on succeeds.

func (*Part) Recipient

func (p *Part) Recipient() *id.ID

Recipient returns the recipient of the file transfer.

func (*Part) TransferID

func (p *Part) TransferID() *ftCrypto.TransferID

TransferID returns the ID of the file transfer.

type Received

type Received struct {
	// contains filtered or unexported fields
}

Received contains a list of all received transfers.

func (*Received) AddTransfer

func (r *Received) AddTransfer(key *ftCrypto.TransferKey,
	tid *ftCrypto.TransferID, fileName string, transferMAC []byte,
	fileSize uint32, numParts, numFps uint16) (*ReceivedTransfer, error)

AddTransfer adds the ReceivedTransfer to the map keyed on its transfer ID.

func (*Received) GetTransfer

func (r *Received) GetTransfer(tid *ftCrypto.TransferID) (*ReceivedTransfer, bool)

GetTransfer returns the ReceivedTransfer with the desiccated transfer ID or false if none exists.

func (*Received) RemoveTransfer

func (r *Received) RemoveTransfer(tid *ftCrypto.TransferID) error

RemoveTransfer removes the transfer from the map. If no transfer exists, returns nil. Only errors due to saving to storage are returned.

type ReceivedTransfer

type ReceivedTransfer struct {
	// contains filtered or unexported fields
}

ReceivedTransfer contains information and progress data for a receiving or received file transfer.

func (*ReceivedTransfer) AddPart

func (rt *ReceivedTransfer) AddPart(part []byte, partNum int) error

AddPart adds the file part to the list of file parts at the index of partNum.

func (*ReceivedTransfer) CompareAndSwapCallbackFps

func (rt *ReceivedTransfer) CompareAndSwapCallbackFps(
	completed bool, received, total uint16, err error) bool

CompareAndSwapCallbackFps compares the fingerprint to the previous callback call's fingerprint. If they are different, the new one is stored, and it returns true. Returns fall if they are the same.

func (*ReceivedTransfer) CopyPartStatusVector

func (rt *ReceivedTransfer) CopyPartStatusVector() *utility.StateVector

CopyPartStatusVector returns a copy of the part status vector that can be used to look up the current status of parts. Note that the statuses are from when this function is called and not realtime.

func (*ReceivedTransfer) Delete

func (rt *ReceivedTransfer) Delete() error

Delete deletes all data in the ReceivedTransfer from storage.

func (*ReceivedTransfer) FileName

func (rt *ReceivedTransfer) FileName() string

FileName returns the transfer's file name.

func (*ReceivedTransfer) FileSize

func (rt *ReceivedTransfer) FileSize() uint32

FileSize returns the size of the entire file transfer.

func (*ReceivedTransfer) GetFile

func (rt *ReceivedTransfer) GetFile() []byte

GetFile concatenates all file parts and returns it as a single complete file. Note that this function does not care for the completeness of the file and returns all parts it has.

func (*ReceivedTransfer) GetUnusedCyphers

func (rt *ReceivedTransfer) GetUnusedCyphers() []cypher.Cypher

GetUnusedCyphers returns a list of cyphers with unused fingerprint numbers.

func (*ReceivedTransfer) NumParts

func (rt *ReceivedTransfer) NumParts() uint16

NumParts returns the total number of file parts in the transfer.

func (*ReceivedTransfer) NumReceived

func (rt *ReceivedTransfer) NumReceived() uint16

NumReceived returns the number of parts that have been received.

func (*ReceivedTransfer) TransferID

func (rt *ReceivedTransfer) TransferID() *ftCrypto.TransferID

TransferID returns the transfer's ID.

type Sent

type Sent struct {
	// contains filtered or unexported fields
}

Sent contains a list of all sent transfers.

func (*Sent) AddTransfer

func (s *Sent) AddTransfer(recipient *id.ID, key *ftCrypto.TransferKey,
	tid *ftCrypto.TransferID, fileName string, fileSize uint32, parts [][]byte,
	numFps uint16) (*SentTransfer, error)

AddTransfer creates a SentTransfer and adds it to the map keyed on its transfer ID.

func (*Sent) GetTransfer

func (s *Sent) GetTransfer(tid *ftCrypto.TransferID) (*SentTransfer, bool)

GetTransfer returns the SentTransfer with the desiccated transfer ID or false if none exists.

func (*Sent) RemoveTransfer

func (s *Sent) RemoveTransfer(tid *ftCrypto.TransferID) error

RemoveTransfer removes the transfer from the map. If no transfer exists, returns nil. Only errors due to saving to storage are returned.

type SentTransfer

type SentTransfer struct {
	// contains filtered or unexported fields
}

SentTransfer contains information and progress data for sending or sent file transfer.

func (*SentTransfer) CompareAndSwapCallbackFps

func (st *SentTransfer) CompareAndSwapCallbackFps(
	completed bool, arrived, total uint16, err error) bool

CompareAndSwapCallbackFps compares the fingerprint to the previous callback call's fingerprint. If they are different, the new one is stored, and it returns true. Returns fall if they are the same.

func (*SentTransfer) CopyPartStatusVector

func (st *SentTransfer) CopyPartStatusVector() *utility.StateVector

CopyPartStatusVector returns a copy of the part status vector that can be used to look up the current status of parts. Note that the statuses are from when this function is called and not realtime.

func (*SentTransfer) Delete

func (st *SentTransfer) Delete() error

Delete deletes all data in the SentTransfer from storage.

func (*SentTransfer) FileName

func (st *SentTransfer) FileName() string

FileName returns the transfer's file name.

func (*SentTransfer) FileSize

func (st *SentTransfer) FileSize() uint32

FileSize returns the size of the entire file transfer.

func (*SentTransfer) GetUnsentParts

func (st *SentTransfer) GetUnsentParts() []Part

GetUnsentParts builds a list of all unsent parts, each in a Part object.

func (*SentTransfer) NumArrived

func (st *SentTransfer) NumArrived() uint16

NumArrived returns the number of parts that have arrived.

func (*SentTransfer) NumParts

func (st *SentTransfer) NumParts() uint16

NumParts returns the total number of file parts in the transfer.

func (*SentTransfer) Recipient

func (st *SentTransfer) Recipient() *id.ID

Recipient returns the transfer's recipient ID.

func (*SentTransfer) Status

func (st *SentTransfer) Status() TransferStatus

Status returns the status of the transfer.

func (*SentTransfer) TransferID

func (st *SentTransfer) TransferID() *ftCrypto.TransferID

TransferID returns the transfer's ID.

type TransferStatus

type TransferStatus int

TransferStatus indicates the state of the transfer.

const (
	// Running indicates that the transfer is in the processes of sending
	Running TransferStatus = iota

	// Completed indicates that all file parts have been sent and arrived
	Completed

	// Failed indicates that the transfer has run out of sending retries
	Failed
)

func UnmarshalTransferStatus

func UnmarshalTransferStatus(b []byte) TransferStatus

UnmarshalTransferStatus unmarshalls the 8-byte byte slice into a TransferStatus.

func (TransferStatus) Marshal

func (ts TransferStatus) Marshal() []byte

Marshal returns the byte representation of the TransferStatus.

func (TransferStatus) String

func (ts TransferStatus) String() string

String prints the string representation of the TransferStatus. This function satisfies the fmt.Stringer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL