common

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LineLen is the number of bytes that all SCION headers are padded to a multiple of.
	LineLen = 8
	MinMTU  = 1280
	MaxMTU  = (1 << 16) - 1
	TimeFmt = "2006-01-02 15:04:05.000000-0700"
)
View Source
const (
	BR = "BR"
	BS = "BS"
	PS = "PS"
	CS = "CS"
	SB = "SB"
	RS = "RS"
	DS = "DS"
)
View Source
const (
	// Maximum allowed hop-by-hop extensions, excluding a potential leading SCMP extension.
	ExtnMaxHBH       = 3
	ExtnSubHdrLen    = 3
	ExtnFirstLineLen = LineLen - ExtnSubHdrLen
)
View Source
const IFIDBytes = 8

Variables

View Source
var (
	Order       ByteOrderN = newBigEndianN()
	NativeOrder ByteOrderN
	IsBigEndian bool
)
View Source
var (
	ExtnSCMPType                = ExtnType{HopByHopClass, 0}
	ExtnOneHopPathType          = ExtnType{HopByHopClass, 1}
	ExtnSIBRAType               = ExtnType{HopByHopClass, 2}
	ExtnPathTransType           = ExtnType{End2EndClass, 0}
	ExtnPathProbeType           = ExtnType{End2EndClass, 1}
	ExtnSCIONPacketSecurityType = ExtnType{End2EndClass, 2}
)
View Source
var L4Protocols = map[L4ProtocolType]bool{
	L4SCMP: true, L4TCP: true, L4UDP: true,
}

Functions

func FmtError

func FmtError(e error) string

FmtError formats e for logging. It walks through all nested errors, putting each on a new line, and indenting multi-line errors.

func GetErrorMsg

func GetErrorMsg(e error) string

GetErrorMsg extracts the message from e, if e implements the ErrorMsger interface. As a fall-back, if e implements ErrorNester, GetErrorMsg recurses on the nested error. Otherwise returns an empty string.

func GetNestedError

func GetNestedError(e error) error

GetNestedError returns the nested error, if any. Returns nil otherwise.

func IsTemporaryErr

func IsTemporaryErr(e error) bool

IsTemporaryErr determins if e is a temporary Error. As a fall-back, if e implements ErrorNester, IsTemporaryErr recurses on the nested error. Otherwise returns false.

func IsTimeoutErr

func IsTimeoutErr(e error) bool

IsTimeoutErr determins if e is a temporary Error. As a fall-back, if e implements ErrorNester, IsTimeoutErr recurses on the nested error. Otherwise returns false.

func NewBasicError

func NewBasicError(msg string, e error, logCtx ...interface{}) error

NewBasicError creates a new BasicError, with e as the embedded error (can be nil), with logCtx being a list of string/val pairs.

func TypeOf

func TypeOf(v interface{}) string

Types

type BasicError

type BasicError struct {
	// Error message
	Msg string

	// Nested error, if any.
	Err error
	// contains filtered or unexported fields
}

BasicError is a simple error type that implements ErrorMsger and ErrorNester, and can contain context (slice of [string, val, string, val...]) for logging purposes.

func (BasicError) Error

func (be BasicError) Error() string

func (BasicError) GetErr

func (be BasicError) GetErr() error

func (BasicError) GetMsg

func (be BasicError) GetMsg() string

func (BasicError) TopError

func (be BasicError) TopError() string

type ByteOrderN

type ByteOrderN interface {
	binary.ByteOrder
	// Width is the size of the unsigned int value in bytes.
	UintN(b []byte, width int) uint64
	// Width is the size of the unsigned int value in bytes.
	PutUintN(b []byte, v uint64, width int)
}

type ErrorMsger

type ErrorMsger interface {
	error
	GetMsg() string
}

ErrorMsger allows extracting the message from an error. This means a caller can determine the type of error by comparing the returned message with a const error string. E.g.:

if GetErrorMsg(err) == addr.ErrorBadHostAddrType {
   // Handle bad host addr error
}

type ErrorNester

type ErrorNester interface {
	error
	TopError() string // should not include the nested error
	GetErr() error
}

ErrorNester allows recursing into nested errors.

type Extension

type Extension interface {
	ExtnBase
	// Allocate buffer, write extn into it, and return it.
	Pack() (RawBytes, error)
	// Write extn into supplied buffer
	Write(b RawBytes) error
	Copy() Extension
	// bool is true if extn is reversed, and false if it should be dropped.
	Reverse() (bool, error)
}

type ExtnBase

type ExtnBase interface {
	// Length in bytes, excluding 3B subheader
	Len() int
	Class() L4ProtocolType
	Type() ExtnType
	fmt.Stringer
}

type ExtnType

type ExtnType struct {
	Class L4ProtocolType
	Type  uint8
}

func (ExtnType) String

func (e ExtnType) String() string

type IFIDType

type IFIDType uint64

Interface ID

func (IFIDType) String

func (ifid IFIDType) String() string

type L4ProtocolType

type L4ProtocolType uint8
const (
	L4None L4ProtocolType = 0
	L4SCMP L4ProtocolType = 1
	L4TCP  L4ProtocolType = 6
	L4UDP  L4ProtocolType = 17

	HopByHopClass L4ProtocolType = 0
	End2EndClass  L4ProtocolType = 222
)

func (L4ProtocolType) String

func (p L4ProtocolType) String() string

type Payload

type Payload interface {
	fmt.Stringer
	Len() int
	Copy() (Payload, error)
	// Writes payload to buffer
	WritePld(RawBytes) (int, error)
}

type RawBytes

type RawBytes []byte

func (RawBytes) Copy

func (r RawBytes) Copy() (Payload, error)

func (RawBytes) Len

func (r RawBytes) Len() int

func (RawBytes) String

func (r RawBytes) String() string

func (RawBytes) WritePld

func (r RawBytes) WritePld(b RawBytes) (int, error)

func (RawBytes) Zero

func (r RawBytes) Zero()

type Temporary

type Temporary interface {
	error
	Temporary() bool
}

Temporary allows signalling of a temporary error. Based on https://golang.org/pkg/net/#Error

type Timeout

type Timeout interface {
	error
	Timeout() bool
}

Temporary allows signalling of a timeout error. Based on https://golang.org/pkg/net/#Error

Jump to

Keyboard shortcuts

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