tftp

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 17 Imported by: 2

Documentation

Index

Constants

View Source
const (
	RRQ              OpcodeClient = 1
	WRQ              OpcodeClient = 2
	OACKFileTooLarge OpcodeClient = 3
	ACK              OpcodeClient = 4
	ClientError      OpcodeClient = 5
	OACKDeclined     OpcodeClient = 8

	DATA        OpcodeServer = 3
	ServerError OpcodeServer = 5
	OACK        OpcodeServer = 6
)
View Source
const (
	FilepathFieldIndex    int = 0
	ModeFieldIndex        int = 1
	FirstOptionFieldIndex int = 2
)
View Source
const (
	ReadBufferSize = 1024

	OpcodeLength   = 2
	BlocknumLength = 2
	MetaInfoSize   = OpcodeLength + BlocknumLength

	DefaultBlocksize    = 512
	DefaultTransfersize = -1

	// modes
	ModeOctet    = "octet"
	ModeNetAscii = "netascii"
	Octet        = 1
	NetAscii     = 2

	OptionBlksize = "blksize"
	OptionTsize   = "tsize"
)
View Source
const (
	OK ackValue = iota
	Retransmit
	Error
	Failure
)
View Source
const (
	OACKBlockNumber = 0
)

Variables

View Source
var (
	GitTag    = "v0.0.0"
	GitCommit = "local"
	BuildTime = "1970-01-01T00:00:00Z"
)
View Source
var (
	FileErrors = struct {
		ErrNoHandler  error
		ErrInsecure   error
		ErrReadFile   error
		ErrPermission error
		ErrNotFound   error
	}{
		ErrNoHandler:  errors.New("no handler found for file"),
		ErrInsecure:   errors.New("file path was not valid"),
		ErrReadFile:   errors.New("error during read of file"),
		ErrPermission: errors.New("insufficient permission to read file"),
		ErrNotFound:   errors.New("file not found"),
	}
)
View Source
var NullByte = []byte{0}
View Source
var (
	ReceiveError = struct {
		ErrDeclinedByClient error
		ErrFileTooLarge     error
		ErrClient           error
		ErrWeirdBlocknum    error
		ErrWeirdOpcode      error
	}{
		ErrDeclinedByClient: errors.New("oack was declined by the client"),
		ErrFileTooLarge:     errors.New("file was too large for client"),
		ErrClient:           errors.New("received error from client"),
		ErrWeirdBlocknum:    errors.New("received unexpected blocknum from client"),
		ErrWeirdOpcode:      errors.New("client sent unexpected opcode"),
	}
)
View Source
var (
	RequestErrors = struct {
		ErrUnknownOpcode       error
		ErrUnknownMode         error
		ErrUnknownOption       error
		ErrInvalidBlksize      error
		ErrInvalidTransfersize error
		ErrMalformed           error
	}{
		ErrUnknownOpcode:       errors.New("unknown opcode in request"),
		ErrUnknownMode:         errors.New("unknown mode in request"),
		ErrUnknownOption:       errors.New("unknown option in request"),
		ErrInvalidBlksize:      errors.New("invalid blocksize in request"),
		ErrInvalidTransfersize: errors.New("invalid transfersize in request"),
		ErrMalformed:           errors.New("received malformed request"),
	}
)
View Source
var (
	SendErrors = struct {
		ErrAbort  error
		ErrServer error
	}{
		ErrAbort:  errors.New("aborting tranmission after too many retries"),
		ErrServer: errors.New("transmission error in the server"),
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	IP                     string
	Port                   int
	Retransmissions        int
	MaxParallelConnections int

	Metrics metrics.Config
}

type ErrorCode

type ErrorCode uint16
const (
	// Error codes
	// http://tools.ietf.org/html/rfc1350#page-10
	UnknownError     ErrorCode = iota // Not defined, see error message (if any).
	NotFound                          // File not found.
	AccessViolation                   // Access violation.
	DiskFull                          // Disk full or allocation exceeded.
	IllegalOperation                  // Illegal TFTP operation.
	UnknownID                         // Unknown transfer ID.
	AlreadyExists                     // File already exists.
	NoSuchUser                        // No such user.
)

func (ErrorCode) Is

func (ec ErrorCode) Is(other ErrorCode) bool

func (ErrorCode) String

func (e ErrorCode) String() string

func (ErrorCode) Value

func (ec ErrorCode) Value() uint16

type Handler

type Handler interface {
	Matches(file string) bool
	Reader(file string) (io.ReadCloser, int64, error)
}

type OpcodeClient

type OpcodeClient uint16

func (OpcodeClient) Is

func (oc OpcodeClient) Is(other OpcodeClient) bool

func (OpcodeClient) String

func (o OpcodeClient) String() string

func (OpcodeClient) Value

func (o OpcodeClient) Value() uint16

type OpcodeServer

type OpcodeServer uint16

func (OpcodeServer) String

func (o OpcodeServer) String() string

func (OpcodeServer) Value

func (o OpcodeServer) Value() uint16

type RRQParseError

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

func (*RRQParseError) Error

func (e *RRQParseError) Error() string

type Request

type Request struct {
	Opcode        OpcodeClient
	Blocksize     int
	TransferSize  int64
	Mode          int
	Path          string
	ClientAddress *net.UDPAddr
}

func (*Request) SetMode

func (r *Request) SetMode(mode string) error

func (*Request) SetOptions

func (r *Request) SetOptions(option, value string) error

func (*Request) ToString

func (r *Request) ToString() string

type ResponseHandling

type ResponseHandling interface {
	RegisterHandler(handler Handler)
	OpenFile(file string) (io.ReadCloser, int64, error)
}

func NewResponseHandling

func NewResponseHandling() ResponseHandling

type Server

type Server interface {
	ListenAndServe(ctx context.Context) error
}

func NewServer

func NewServer(logger logging.Logger, config Config, udpConnector udp.Connector, responseHandling ResponseHandling) (Server, error)

Jump to

Keyboard shortcuts

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