iomeshage

package
v2.0.0-...-f0b7fcc Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

iomeshage is a file transfer layer for meshage

Files are stored in a predetermined directory structure. When a particular meshage node needs a file, it polls nodes looking for that file, looking at shortest path nodes first. The node with the file and the fewest hops will transfer the file to the requesting node.

Index

Constants

View Source
const (
	MAX_ATTEMPTS = 3
	QUEUE_LEN    = 3
)
View Source
const (
	PART_SIZE = 10485760 // 10MB
)

Variables

View Source
var (
	// ErrInFlight is the error returned when getting a file that is already being
	// transferred to this node.
	ErrInFlight = errors.New("file already in flight")
)

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	// Path is the absolute path to the file
	Path string

	// Size of the file
	Size int64

	// Modification time of the file
	ModTime time.Time

	// Murmur3 hash of the file
	Hash string

	// embed
	os.FileMode
}

FileInfo is used by the calling API to describe existing files.

type Files

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

Files handles all the logic for whether or not a file needs to be pulled from another node in the mesh. It takes into account if the mesh is running in -headnode mode and has -hashfiles enabled. Having -headnode mode enabled but -hashfiles disabled is equivalent to having -headnode mode disabled.

func NewFiles

func NewFiles(head string, hash bool) *Files

type IOMeshage

type IOMeshage struct {
	Messages chan *meshage.Message // Incoming messages from meshage

	TIDs map[int64]chan *Message // transfer ID -> channel
	// contains filtered or unexported fields
}

IOMeshage object, which must have a base path to serve files on and a meshage node.

func New

func New(base string, node *meshage.Node, head string, hash bool) (*IOMeshage, error)

New returns a new iomeshage object service base directory via meshage

func (*IOMeshage) Delete

func (iom *IOMeshage) Delete(path string) error

Delete a file or directory on the local node. Supports Globs.

func (*IOMeshage) Get

func (iom *IOMeshage) Get(file string) error

Retrieve a file from the shortest path node that has it. Get blocks until the file transfer begins or errors out. If the file specified is a directory, the entire directory will be recursively transferred. If the file already exists on this node, Get will return immediately with no error.

func (*IOMeshage) Info

func (iom *IOMeshage) Info(file string) []string

search the mesh for the file/glob/directory, returning a slice of string matches. The search includes local matches.

func (*IOMeshage) List

func (iom *IOMeshage) List(path string, recurse bool) ([]FileInfo, error)

List files and directories on the local node. List on a file returns the info for that file only. List on a directory returns the contents of that directory. Supports expanding globs. When recursive is true, reports all files and directories below the specified path(s).

func (*IOMeshage) MITM

func (iom *IOMeshage) MITM(m *Message)

Check iom messages that are routing through us in case it's a filepart that we're also looking for. If so, write it out. The message mux for meshage should call this.

func (*IOMeshage) Rel

func (iom *IOMeshage) Rel(info FileInfo) string

func (*IOMeshage) Status

func (iom *IOMeshage) Status() []*Transfer

Status returns a deep copy of the in-flight file transfers

func (*IOMeshage) Stream

func (iom *IOMeshage) Stream(file string) (chan []byte, error)

Stream requests each part of the file in order, returning a channel to read the parts from. This does not store the file locally to avoid filling up the local disk.

type Message

type Message struct {
	// Type of message
	Type MessageType

	From     string
	Filename string
	Perm     os.FileMode
	ModTime  time.Time
	Hash     string
	Glob     []string
	Part     int64
	TID      int64
	ACK      bool
	Data     []byte
}

Message is the only structure sent between iomeshage nodes (including ACKS). It is used as the body of a meshage message.

type MessageType

type MessageType int
const (
	TYPE_INFO MessageType = iota
	TYPE_WHOHAS
	TYPE_XFER
	TYPE_RESPONSE
)

func (MessageType) String

func (m MessageType) String() string

type Transfer

type Transfer struct {
	Dir      string         // temporary directory hold the file parts
	Filename string         // file name
	Parts    map[int64]bool // completed parts
	NumParts int            // total number of parts for this file
	Inflight int64          // currently in-flight part, -1 if none
	Queued   bool
}

Transfer describes an in-flight transfer.

Jump to

Keyboard shortcuts

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