gonami

package module
v0.0.0-...-56acec5 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2016 License: MIT Imports: 17 Imported by: 0

README

Golang library for fast file transfers. Not protocol compatible, but heavily inspired by the tsunami protocol:

Usage:

Client

config := gonami.NewConfig()
e := gonami.BsonEncoder{}
client := gonami.NewClient(downloadDir, config, e)

client.GetFile(filename, host)
for p := range progress {
	log.Println(p)
}

GetFile will return a channel that you can use to read the download progress on

Server

  e := gonami.BsonEncoder{}
	s := gonami.NewServer(e, listenPort, uploadDirectory)
	go s.StartListening()

The Server struct contains a channel member that you can use to read the upload progress on

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Number int
	Data   []byte
	Type   BlockType
}

type BlockType

type BlockType int
const (
	ORIGINAL BlockType = iota
	RETRANSMITTED
)

type BsonEncoder

type BsonEncoder struct{}

func (BsonEncoder) Decode

func (b BsonEncoder) Decode(data []byte, numBytes int) (*Packet, error)

func (BsonEncoder) Encode

func (b BsonEncoder) Encode(msg *Packet) ([]byte, error)

type Client

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

func NewClient

func NewClient(localDirectory string, config Config, encoder Encoder) *Client

func (*Client) GetFile

func (c *Client) GetFile(filename string, serverAddr string) <-chan Progress

type Config

type Config struct {
	ListenPort      int
	TransferRate    int //bits per second
	BlockSize       int //in bytes
	ErrorRate       int //threshhold error rate (% x 1000)
	SlowerNum       int //numerator in the slowdown factor
	SlowerDen       int //denominator in the slowdown factor
	FasterNum       int //numerator in the speedup factor
	FasterDen       int //denominator in the speedup factor
	MaxMissedLength int //max number of missed blocks before requesting retransmit
}

func NewConfig

func NewConfig() Config

type Encoder

type Encoder interface {
	Encode(msg *Packet) ([]byte, error)
	Decode(data []byte, numBytes int) (*Packet, error)
}

type GobEncoder

type GobEncoder struct{}

func NewGobEncoder

func NewGobEncoder() GobEncoder

func (GobEncoder) Decode

func (g GobEncoder) Decode(data []byte, numBytes int) (*Packet, error)

func (GobEncoder) Encode

func (g GobEncoder) Encode(msg *Packet) ([]byte, error)

type MessageType

type MessageType int
const (
	AUTH MessageType = iota
	REV
	GET_FILE
	DATA
	RETRANSMIT
	ERROR_RATE
	DONE
)

type Packet

type Packet struct {
	Type    MessageType
	Payload interface{}
}

type Progress

type Progress struct {
	Message    string
	Percentage float64
	Type       ProgressType
}

type ProgressType

type ProgressType int
const (
	HANDSHAKING ProgressType = iota
	TRANSFERRING
	ERROR
	TRANSFER_DONE
)

type Retransmit

type Retransmit struct {
	IsRestart bool
	BlockNums []int
}

type Server

type Server struct {
	TransfersChannel chan chan Progress
	// contains filtered or unexported fields
}

func NewServer

func NewServer(encoder Encoder, port int, localDirectory string) *Server

func (*Server) StartListening

func (s *Server) StartListening()

Jump to

Keyboard shortcuts

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