common

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Examples

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"
	TimeFmtSecs = "2006-01-02 15:04:05-0700"
)
View Source
const (
	BR  = "BR"
	CS  = "CS"
	SB  = "SB"
	RS  = "RS"
	SIG = "SIG"

	CPService = "Control Plane Service"
)
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}
	// ExtnE2EDebugType can be used to trace specific packets through the
	// network. This is intended only for local use, and is not a recognized
	// SCION extension.
	ExtnE2EDebugType = ExtnType{End2EndClass, 254}
)
View Source
var L4Protocols = map[L4ProtocolType]bool{
	L4SCMP: true, L4TCP: true, L4UDP: true,
}

Functions

func CloneByteSlice added in v0.4.0

func CloneByteSlice(x []byte) []byte

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 FmtErrors added in v0.4.0

func FmtErrors(es []error) string

FmtErrors formats a slice of errors for logging.

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 determines 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 determines 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 ErrMsg, 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. These key/value pairs should contain all context-dependent information: 'msg' argument itself should be a constant string.

func TypeOf

func TypeOf(v interface{}) string

Types

type BasicError

type BasicError struct {
	// Error message
	Msg ErrMsg

	// 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) Is added in v0.4.0

func (be BasicError) Is(err error) bool

Is returns whether this error is the same error as err, or in case err is a ErrMsg whether the message is equal.

func (BasicError) TopError

func (be BasicError) TopError() string

func (BasicError) Unwrap added in v0.4.0

func (be BasicError) Unwrap() error

Unwrap returns the next error in the error chain, or nil if there is none.

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 ErrMsg added in v0.4.0

type ErrMsg string

ErrMsg should be used for error string constants. The constant can then be used for Is checking in the calling code.

Example
var SomeErr ErrMsg = "this is the error msg"

fmt.Println(errors.Is(NewBasicError(SomeErr, nil, "ctx", 1), SomeErr))
Output:

true

func (ErrMsg) Error added in v0.4.0

func (e ErrMsg) Error() string

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

IFIDType is the type for interface IDs.

func (IFIDType) String

func (ifid IFIDType) String() string

func (*IFIDType) UnmarshalJSON added in v0.5.0

func (ifid *IFIDType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the JSON data into the IfID.

func (*IFIDType) UnmarshalText added in v0.4.0

func (ifid *IFIDType) UnmarshalText(text []byte) error

UnmarshalText unmarshals the text into the IfID.

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 MultiError added in v0.4.0

type MultiError []error

MultiError is a slice of errors

func (MultiError) ToError added in v0.4.0

func (be MultiError) ToError() error

ToError returns the object as error interface implementation.

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
}

Timeout 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