bundle

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package bundle provides a library for interaction with Bundles as defined in the Bundle Protocol Version 7 (draft-ietf-dtn-bpbis-17.txt). This includes Bundle creation, modification, serialization and deserialization.

The easiest way to create new Bundles is to use the BundleBuilder.

bndl, err := bundle.Builder().
  CRC(bundle.CRC32).
  Source("dtn://src/").
  Destination("dtn://dest/").
  CreationTimestampNow().
  Lifetime("30m").
  HopCountBlock(64).
  PayloadBlock([]byte("hello world!")).
  Build()

Both serializing and deserializing bundles into the CBOR is supported.

// An existing Bundle bndl1 is serialized. The new bundle bndl2 is created
// from this. A common bytes.Buffer will be used.
buff := new(bytes.Buffer)
err1 := bndl1.WriteBundle(buff)
bndl2, err2 := bundle.ParseBundle(buff)

Index

Constants

View Source
const ExtBlockTypeBundleAgeBlock uint64 = 7
View Source
const ExtBlockTypeHopCountBlock uint64 = 10
View Source
const ExtBlockTypePayloadBlock uint64 = 1
View Source
const ExtBlockTypePreviousNodeBlock uint64 = 6

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockControlFlags

type BlockControlFlags uint64

BlockControlFlags is an uint which represents the Block Processing Control Flags as specified in 4.1.4.

const (
	// ReplicateBlock: block must be replicated in every fragment.
	ReplicateBlock BlockControlFlags = 0x01

	// StatusReportBlock: transmission of a status report is requested if block can't be processed.
	StatusReportBlock BlockControlFlags = 0x02

	// DeleteBundle: bundle must be deleted if block can't be processed.
	DeleteBundle BlockControlFlags = 0x04

	// RemoveBlock: block must be removed from bundle if it can't be processed.
	RemoveBlock BlockControlFlags = 0x10
)

func (BlockControlFlags) CheckValid added in v0.1.1

func (bcf BlockControlFlags) CheckValid() error

func (BlockControlFlags) Has

Has returns true if a given flag or mask of flags is set.

func (BlockControlFlags) String added in v0.1.1

func (bcf BlockControlFlags) String() string

type Bundle

type Bundle struct {
	PrimaryBlock    PrimaryBlock
	CanonicalBlocks []CanonicalBlock
}

Bundle represents a bundle as defined in section 4.2.1. Each Bundle contains one primary block and multiple canonical blocks.

func MustNewBundle

func MustNewBundle(primary PrimaryBlock, canonicals []CanonicalBlock) Bundle

MustNewBundle creates a new Bundle like NewBundle, but skips the validity check. No panic will be called!

func NewBundle

func NewBundle(primary PrimaryBlock, canonicals []CanonicalBlock) (b Bundle, err error)

NewBundle creates a new Bundle. The values and flags of the blocks will be checked and an error might be returned.

func ParseBundle added in v0.1.1

func ParseBundle(r io.Reader) (b Bundle, err error)

ParseBundle reads a new CBOR encoded Bundle from a Reader.

func (*Bundle) AddExtensionBlock

func (b *Bundle) AddExtensionBlock(block CanonicalBlock)

AddExtensionBlock adds a new ExtensionBlock to this Bundle. The block number will be calculated and overwritten within this method.

func (Bundle) CheckValid added in v0.1.1

func (b Bundle) CheckValid() (errs error)

func (*Bundle) ExtensionBlock

func (b *Bundle) ExtensionBlock(blockType uint64) (*CanonicalBlock, error)

ExtensionBlock returns this Bundle's canonical block/extension block matching the requested block type code. If no such block was found, an error will be returned.

func (Bundle) ID

func (b Bundle) ID() BundleID

ID returns a BundleID representing this Bundle.

func (Bundle) IsAdministrativeRecord

func (b Bundle) IsAdministrativeRecord() bool

IsAdministrativeRecord returns if this Bundle's control flags indicate this has an administrative record payload.

func (*Bundle) MarshalCbor added in v0.1.1

func (b *Bundle) MarshalCbor(w io.Writer) error

func (*Bundle) PayloadBlock

func (b *Bundle) PayloadBlock() (*CanonicalBlock, error)

PayloadBlock returns this Bundle's payload block or an error, if it does not exists.

func (*Bundle) SetCRCType

func (b *Bundle) SetCRCType(crcType CRCType)

SetCRCType sets the given CRCType for each block. To also calculate and set the CRC value, one should also call the CalculateCRC method.

func (Bundle) String

func (b Bundle) String() string

func (*Bundle) UnmarshalCbor added in v0.1.1

func (b *Bundle) UnmarshalCbor(r io.Reader) error

func (*Bundle) WriteBundle added in v0.1.1

func (b *Bundle) WriteBundle(w io.Writer) error

WriteBundle writes this Bundle CBOR encoded into a Writer.

type BundleAgeBlock

type BundleAgeBlock uint64

BundleAgeBlock implements the Bundle Protocol's Bundle Age Block.

func NewBundleAgeBlock

func NewBundleAgeBlock(us uint64) *BundleAgeBlock

NewBundleAgeBlock creates a new BundleAgeBlock with the given microseconds.

func (*BundleAgeBlock) Age added in v0.1.1

func (bab *BundleAgeBlock) Age() uint64

Age returns the age in microseconds.

func (*BundleAgeBlock) BlockTypeCode added in v0.1.1

func (bab *BundleAgeBlock) BlockTypeCode() uint64

func (*BundleAgeBlock) CheckValid added in v0.1.1

func (pb *BundleAgeBlock) CheckValid() error

func (*BundleAgeBlock) Increment added in v0.1.1

func (bab *BundleAgeBlock) Increment(offset uint64) uint64

Increment with an offset in microseconds and return the new time.

func (*BundleAgeBlock) MarshalCbor added in v0.1.1

func (bab *BundleAgeBlock) MarshalCbor(w io.Writer) error

func (*BundleAgeBlock) UnmarshalCbor added in v0.1.1

func (bab *BundleAgeBlock) UnmarshalCbor(r io.Reader) error

type BundleBuilder

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

BundleBuilder is a simple framework to create bundles by method chaining.

bndl, err := bundle.Builder().
  CRC(bundle.CRC32).
  Source("dtn://src/").
  Destination("dtn://dest/").
  CreationTimestampNow().
  Lifetime("30m").
  HopCountBlock(64).
  PayloadBlock([]byte("hello world!")).
  Build()

func Builder

func Builder() *BundleBuilder

Builder creates a new BundleBuilder.

func (*BundleBuilder) Build

func (bldr *BundleBuilder) Build() (bndl Bundle, err error)

Build creates a new Bundle and returns an optional error.

func (*BundleBuilder) BundleAgeBlock

func (bldr *BundleBuilder) BundleAgeBlock(args ...interface{}) *BundleBuilder

BundleAgeBlock adds a bundle age block to this bundle. The parameters are:

Age[, BlockControlFlags]

where Age is the age as an uint in microsecond or a format string and
BlockControlFlags are _optional_ block processing control flags

func (*BundleBuilder) BundleCtrlFlags

func (bldr *BundleBuilder) BundleCtrlFlags(bcf BundleControlFlags) *BundleBuilder

BundleBuilder sets the bundle processing control flags in the primary block.

func (*BundleBuilder) CRC

func (bldr *BundleBuilder) CRC(crcType CRCType) *BundleBuilder

CRC sets the bundle's CRC value.

func (*BundleBuilder) Canonical

func (bldr *BundleBuilder) Canonical(args ...interface{}) *BundleBuilder

Canonical adds a canonical block to this bundle. The parameters are:

ExtensionBlock[, BlockControlFlags] or
CanonicalBlock

where ExtensionBlock is a bundle.ExtensionBlock and
BlockControlFlags are _optional_ block processing control flags or
CanonicalBlock is a CanonicalBlock

func (*BundleBuilder) CreationTimestampEpoch

func (bldr *BundleBuilder) CreationTimestampEpoch() *BundleBuilder

CreationTimestampEpoch sets the bundle's creation timestamp to the epoch time, stored in its primary block.

func (*BundleBuilder) CreationTimestampNow

func (bldr *BundleBuilder) CreationTimestampNow() *BundleBuilder

CreationTimestampNow sets the bundle's creation timestamp to the current time, stored in its primary block.

func (*BundleBuilder) CreationTimestampTime

func (bldr *BundleBuilder) CreationTimestampTime(t time.Time) *BundleBuilder

CreationTimestampTime sets the bundle's creation timestamp to a given time, stored in its primary block.

func (*BundleBuilder) Destination

func (bldr *BundleBuilder) Destination(eid interface{}) *BundleBuilder

Destination sets the bundle's destination, stored in its primary block.

func (*BundleBuilder) Error

func (bldr *BundleBuilder) Error() error

Error returns the BundleBuilder's error, if one is present.

func (*BundleBuilder) HopCountBlock

func (bldr *BundleBuilder) HopCountBlock(args ...interface{}) *BundleBuilder

HopCountBlock adds a hop count block to this bundle. The parameters are:

Limit[, BlockControlFlags]

where Limit is the limit of this Hop Count Block and
BlockControlFlags are _optional_ block processing control flags

func (*BundleBuilder) Lifetime

func (bldr *BundleBuilder) Lifetime(duration interface{}) *BundleBuilder

Lifetime sets the bundle's lifetime, stored in its primary block. Possible values are an uint/int, representing the lifetime in microseconds or a format string for the duration. This string is passed to time.ParseDuration.

Lifetime(1000)     // Lifetime of 1000us
Lifetime("1000us") // Lifetime of 1000us
Lifetime("10m")    // Lifetime of 10min

func (*BundleBuilder) PayloadBlock

func (bldr *BundleBuilder) PayloadBlock(args ...interface{}) *BundleBuilder

PayloadBlock adds a payload block to this bundle. The parameters are:

Data[, BlockControlFlags]

where Data is the payload's data and
BlockControlFlags are _optional_ block processing control flags

func (*BundleBuilder) PreviousNodeBlock

func (bldr *BundleBuilder) PreviousNodeBlock(args ...interface{}) *BundleBuilder

PreviousNodeBlock adds a previous node block to this bundle. The parameters are:

PrevNode[, BlockControlFlags]

where PrevNode is an EndpointID or a string describing an endpoint and
BlockControlFlags are _optional_ block processing control flags

func (*BundleBuilder) ReportTo

func (bldr *BundleBuilder) ReportTo(eid interface{}) *BundleBuilder

ReportTo sets the bundle's report-to address, stored in its primary block.

func (*BundleBuilder) Source

func (bldr *BundleBuilder) Source(eid interface{}) *BundleBuilder

Source sets the bundle's source, stored in its primary block.

type BundleControlFlags

type BundleControlFlags uint64

BundleControlFlags is an uint which represents the Bundle Processing Control Flags as specified in section 4.1.3.

const (
	// IsFragment: bundle is a fragment.
	IsFragment BundleControlFlags = 0x000001

	// AdministrativeRecordPayload: payload is an administrative record.
	AdministrativeRecordPayload BundleControlFlags = 0x000002

	// MustNotFragmented: bundle must not be fragmented.
	MustNotFragmented BundleControlFlags = 0x000004

	// RequestUserApplicationAck: user application acknowledgement is requested.
	RequestUserApplicationAck BundleControlFlags = 0x000020

	// RequestStatusTime: status time is requested in all status reports.
	RequestStatusTime BundleControlFlags = 0x000040

	// StatusRequestReception: bundle reception status reports are requested.
	StatusRequestReception BundleControlFlags = 0x004000

	// StatusRequestForward: bundle forwarding status reports are requested.
	StatusRequestForward BundleControlFlags = 0x010000

	// StatusRequestDelivery: bundle delivery status reports are requested.
	StatusRequestDelivery BundleControlFlags = 0x020000

	// StatusRequestDeletion: bundle deletion status reports are requested.
	StatusRequestDeletion BundleControlFlags = 0x040000
)

func (BundleControlFlags) CheckValid added in v0.1.1

func (bcf BundleControlFlags) CheckValid() (errs error)

func (BundleControlFlags) Has

Has returns true if a given flag or mask of flags is set.

func (BundleControlFlags) String

func (bcf BundleControlFlags) String() string

type BundleID added in v0.1.1

type BundleID struct {
	SourceNode EndpointID
	Timestamp  CreationTimestamp

	IsFragment      bool
	FragmentOffset  uint64
	TotalDataLength uint64
}

BundleID identifies a bundle by its source node, creation timestamp and fragmentation offset paired the total data length. The last two fields are only available if and only if the referenced bundle is a fragment.

Furthermore, a BundleID can be serialized and deserialized with the cboring library. Therefore, all required fields will be written in series. For deserialization, the IsFragment field MUST be set beforehand. This will determine if two or four values will be read.

func (BundleID) Len added in v0.1.1

func (bid BundleID) Len() uint64

Len returns the amount of fields, dependent on the fragmentation.

func (*BundleID) MarshalCbor added in v0.1.1

func (bid *BundleID) MarshalCbor(w io.Writer) error

func (BundleID) Scrub added in v0.2.0

func (bid BundleID) Scrub() BundleID

Scrub creates a cleaned BundleID without fragmentation.

func (BundleID) String added in v0.1.1

func (bid BundleID) String() string

func (*BundleID) UnmarshalCbor added in v0.1.1

func (bid *BundleID) UnmarshalCbor(r io.Reader) error

type CRCType

type CRCType uint64

CRCType indicates which CRC type is used. Only the three defined consts CRCNo, CRC16 and CRC32 are valid, as specified in section 4.1.1.

const (
	CRCNo CRCType = 0
	CRC16 CRCType = 1
	CRC32 CRCType = 2
)

func (CRCType) String

func (c CRCType) String() string

type CanonicalBlock

type CanonicalBlock struct {
	BlockNumber       uint64
	BlockControlFlags BlockControlFlags
	CRCType           CRCType
	CRC               []byte
	Value             ExtensionBlock
}

CanonicalBlock represents the canonical bundle block defined in section 4.2.3.

func NewCanonicalBlock

func NewCanonicalBlock(no uint64, bcf BlockControlFlags, value ExtensionBlock) CanonicalBlock

func (CanonicalBlock) CheckValid added in v0.1.1

func (cb CanonicalBlock) CheckValid() (errs error)

func (CanonicalBlock) GetCRCType

func (cb CanonicalBlock) GetCRCType() CRCType

GetCRCType returns the CRCType of this block.

func (CanonicalBlock) HasCRC

func (cb CanonicalBlock) HasCRC() bool

HasCRC returns if the CRCType indicates a CRC is present for this block.

func (*CanonicalBlock) MarshalCbor added in v0.1.1

func (cb *CanonicalBlock) MarshalCbor(w io.Writer) error

func (*CanonicalBlock) SetCRCType

func (cb *CanonicalBlock) SetCRCType(crcType CRCType)

SetCRCType sets the CRC type.

func (CanonicalBlock) String

func (cb CanonicalBlock) String() string

func (CanonicalBlock) TypeCode added in v0.5.1

func (cb CanonicalBlock) TypeCode() uint64

TypeCode returns the block type code.

func (*CanonicalBlock) UnmarshalCbor added in v0.1.1

func (cb *CanonicalBlock) UnmarshalCbor(r io.Reader) error

type CreationTimestamp

type CreationTimestamp [2]uint64

CreationTimestamp is a tuple of a DtnTime and a sequence number (to differ bundles with the same DtnTime (seconds) from the same endpoint). It is specified in section 4.1.7.

func NewCreationTimestamp

func NewCreationTimestamp(time DtnTime, sequence uint64) CreationTimestamp

NewCreationTimestamp creates a new creation timestamp from a given DTN time and a sequence number, resulting in a hopefully unique tuple.

func (CreationTimestamp) DtnTime

func (ct CreationTimestamp) DtnTime() DtnTime

DtnTime returns the creation timestamp's DTN time part.

func (CreationTimestamp) IsZeroTime added in v0.2.0

func (ct CreationTimestamp) IsZeroTime() bool

IsZeroTime returns if the time part is set to zero, indicating the lack of an accurate clock.

func (*CreationTimestamp) MarshalCbor added in v0.1.1

func (ct *CreationTimestamp) MarshalCbor(w io.Writer) error

func (CreationTimestamp) SequenceNumber

func (ct CreationTimestamp) SequenceNumber() uint64

SequenceNumber returns the creation timestamp's sequence number.

func (CreationTimestamp) String

func (ct CreationTimestamp) String() string

func (*CreationTimestamp) UnmarshalCbor added in v0.1.1

func (ct *CreationTimestamp) UnmarshalCbor(r io.Reader) error

type DtnTime

type DtnTime uint64

DtnTime is an integer indicating an interval of Unix epoch time that has elapsed since the start of the year 2000 on the UTC scale. It is specified in section 4.1.6.

const (

	// DtnTimeEpoch represents the zero timestamp/epoch.
	DtnTimeEpoch DtnTime = 0
)

func DtnTimeFromTime

func DtnTimeFromTime(t time.Time) DtnTime

DtnTimeFromTime returns the DtnTime for the time.Time.

func DtnTimeNow

func DtnTimeNow() DtnTime

DtnTimeNow returns the current (UTC) time as DtnTime.

func (DtnTime) String

func (t DtnTime) String() string

String returns this DtnTime's string representation.

func (DtnTime) Time

func (t DtnTime) Time() time.Time

Time returns a UTC-based time.Time for this DtnTime.

func (DtnTime) Unix

func (t DtnTime) Unix() int64

Unix returns the Unix timestamp for this DtnTime.

type EndpointID

type EndpointID struct {
	SchemeName         uint64
	SchemeSpecificPart interface{}
}

EndpointID represents an Endpoint ID as defined in section 4.1.5.1. The "scheme name" is represented by an uint and the "scheme-specific part" (SSP) by an interface{}. Based on the characteristic of the name, the underlying type of the SSP may vary.

func DtnNone

func DtnNone() EndpointID

DtnNone returns the "null endpoint", "dtn:none".

func MustNewEndpointID

func MustNewEndpointID(eid string) EndpointID

MustNewEndpointID returns a new EndpointID like NewEndpointID, but panics in case of an error.

func NewEndpointID

func NewEndpointID(eid string) (e EndpointID, err error)

NewEndpointID creates a new EndpointID by a given "scheme name" and a "scheme-specific part" (SSP). Currently the "dtn" and "ipn"-scheme names are supported.

Example: "dtn:foobar"

func (EndpointID) CheckValid added in v0.1.1

func (eid EndpointID) CheckValid() error

func (*EndpointID) MarshalCbor added in v0.1.1

func (eid *EndpointID) MarshalCbor(w io.Writer) error

func (EndpointID) String

func (eid EndpointID) String() string

func (*EndpointID) UnmarshalCbor added in v0.1.1

func (eid *EndpointID) UnmarshalCbor(r io.Reader) error

type ExtensionBlock added in v0.1.1

type ExtensionBlock interface {
	Valid

	// BlockTypeCode must return a constant integer, indicating the block type code.
	BlockTypeCode() uint64
}

ExtensionBlock describes the block-type specific data of any Canonical Block. Such an ExtensionBlock must implement either the cboring.CborMarshaler interface, if its serializable to / from CBOR, or both encoding.BinaryMarshaler and encoding.BinaryUnmarshaler. The latter allows any kind of serialization, e.g., to a totally custom format.

type ExtensionBlockManager added in v0.1.1

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

ExtensionBlockManager keeps a book on various types of ExtensionBlocks that can be changed at runtime. Thus, new ExtensionBlocks can be created based on their block type code.

A singleton ExtensionBlockManager can be fetched by GetExtensionBlockManager.

func GetExtensionBlockManager added in v0.1.1

func GetExtensionBlockManager() *ExtensionBlockManager

GetExtensionBlockManager returns the singleton ExtensionBlockManager. If none exists, a new ExtensionBlockManager will be generated with a knowledge of the PayloadBlock, PreviousNodeBlock, BundleAgeBlock and HopCountBlock.

func NewExtensionBlockManager added in v0.1.1

func NewExtensionBlockManager() *ExtensionBlockManager

NewExtensionBlockManager creates an empty ExtensionBlockManager. To use a singleton ExtensionBlockManager one can use GetExtensionBlockManager.

func (*ExtensionBlockManager) IsKnown added in v0.1.1

func (ebm *ExtensionBlockManager) IsKnown(typeCode uint64) bool

IsKnown returns true if the ExtensionBlock for this block type code is known.

func (*ExtensionBlockManager) ReadBlock added in v0.5.1

func (ebm *ExtensionBlockManager) ReadBlock(typeCode uint64, r io.Reader) (b ExtensionBlock, err error)

ReadBlock reads an ExtensionBlock from its correct binary format from the io.Reader. Unknown block types are treated as GenericExtensionBlock.

func (*ExtensionBlockManager) Register added in v0.1.1

func (ebm *ExtensionBlockManager) Register(eb ExtensionBlock) error

Register a new ExtensionBlock type through an exemplary instance.

func (*ExtensionBlockManager) Unregister added in v0.1.1

func (ebm *ExtensionBlockManager) Unregister(eb ExtensionBlock)

Register an ExtensionBlock type through an exemplary instance.

func (*ExtensionBlockManager) WriteBlock added in v0.5.1

func (ebm *ExtensionBlockManager) WriteBlock(b ExtensionBlock, w io.Writer) error

WriteBlock writes an ExtensionBlock in its correct binary format into the io.Writer. Unknown block types are treated as GenericExtensionBlock.

type GenericExtensionBlock added in v0.5.1

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

GenericExtensionBlock is a dummy ExtensionBlock to cover for unknown or unregistered ExtensionBlocks.

func NewGenericExtensionBlock added in v0.5.1

func NewGenericExtensionBlock(data []byte, typeCode uint64) *GenericExtensionBlock

NewGenericExtensionBlock creates a new GenericExtensionBlock from some payload and a block type code.

func (*GenericExtensionBlock) BlockTypeCode added in v0.5.1

func (geb *GenericExtensionBlock) BlockTypeCode() uint64

func (*GenericExtensionBlock) CheckValid added in v0.5.1

func (geb *GenericExtensionBlock) CheckValid() error

func (*GenericExtensionBlock) MarshalBinary added in v0.5.1

func (geb *GenericExtensionBlock) MarshalBinary() ([]byte, error)

func (*GenericExtensionBlock) UnmarshalBinary added in v0.5.1

func (geb *GenericExtensionBlock) UnmarshalBinary(data []byte) error

type HopCountBlock

type HopCountBlock struct {
	Limit uint8
	Count uint8
}

HopCountBlock implements the Bundle Protocol's Hop Count Block.

func NewHopCountBlock

func NewHopCountBlock(limit uint8) *HopCountBlock

NewHopCountBlock creates a new HopCountBlock with a given hop limit.

func (*HopCountBlock) BlockTypeCode added in v0.1.1

func (hcb *HopCountBlock) BlockTypeCode() uint64

func (*HopCountBlock) CheckValid added in v0.1.1

func (pb *HopCountBlock) CheckValid() error

func (*HopCountBlock) Decrement added in v0.1.1

func (hcb *HopCountBlock) Decrement()

Decrement the hop counter.

func (*HopCountBlock) Increment added in v0.1.1

func (hcb *HopCountBlock) Increment() bool

Increment the hop counter and returns if the hop limit is exceeded afterwards.

func (HopCountBlock) IsExceeded added in v0.1.1

func (hcb HopCountBlock) IsExceeded() bool

IsExceeded returns true if the hop limit exceeded.

func (*HopCountBlock) MarshalCbor added in v0.1.1

func (hcb *HopCountBlock) MarshalCbor(w io.Writer) error

func (*HopCountBlock) UnmarshalCbor added in v0.1.1

func (hcb *HopCountBlock) UnmarshalCbor(r io.Reader) error

type PayloadBlock

type PayloadBlock []byte

PayloadBlock implements the Bundle Protocol's Payload Block.

func NewPayloadBlock

func NewPayloadBlock(data []byte) *PayloadBlock

NewPayloadBlock creates a new PayloadBlock with the given payload.

func (*PayloadBlock) BlockTypeCode added in v0.1.1

func (pb *PayloadBlock) BlockTypeCode() uint64

func (*PayloadBlock) CheckValid added in v0.1.1

func (pb *PayloadBlock) CheckValid() error

func (*PayloadBlock) Data added in v0.1.1

func (pb *PayloadBlock) Data() []byte

Data returns this PayloadBlock's payload.

func (*PayloadBlock) MarshalBinary added in v0.5.1

func (pb *PayloadBlock) MarshalBinary() ([]byte, error)

func (*PayloadBlock) UnmarshalBinary added in v0.5.1

func (pb *PayloadBlock) UnmarshalBinary(data []byte) error

type PreviousNodeBlock

type PreviousNodeBlock EndpointID

PreviousNodeBlock implements the Bundle Protocol's Previous Node Block.

func NewPreviousNodeBlock

func NewPreviousNodeBlock(prev EndpointID) *PreviousNodeBlock

NewPreviousNodeBlock creates a new Previous Node Block for an Endpoint ID.

func (*PreviousNodeBlock) BlockTypeCode added in v0.1.1

func (pnb *PreviousNodeBlock) BlockTypeCode() uint64

func (*PreviousNodeBlock) CheckValid added in v0.1.1

func (pb *PreviousNodeBlock) CheckValid() error

func (*PreviousNodeBlock) Endpoint added in v0.1.1

func (pnb *PreviousNodeBlock) Endpoint() EndpointID

Endpoint returns this Previous Node Block's Endpoint ID.

func (*PreviousNodeBlock) MarshalCbor added in v0.1.1

func (pnb *PreviousNodeBlock) MarshalCbor(w io.Writer) error

func (*PreviousNodeBlock) UnmarshalCbor added in v0.1.1

func (pnb *PreviousNodeBlock) UnmarshalCbor(r io.Reader) error

type PrimaryBlock

type PrimaryBlock struct {
	Version            uint64
	BundleControlFlags BundleControlFlags
	CRCType            CRCType
	Destination        EndpointID
	SourceNode         EndpointID
	ReportTo           EndpointID
	CreationTimestamp  CreationTimestamp
	Lifetime           uint64
	FragmentOffset     uint64
	TotalDataLength    uint64
	CRC                []byte
}

PrimaryBlock is a representation of the primary bundle block as defined in section 4.2.2.

func NewPrimaryBlock

func NewPrimaryBlock(bundleControlFlags BundleControlFlags,
	destination EndpointID, sourceNode EndpointID,
	creationTimestamp CreationTimestamp, lifetime uint64) PrimaryBlock

NewPrimaryBlock creates a new primary block with the given parameters. All other fields are set to default values. The lifetime is taken in microseconds.

func (PrimaryBlock) CheckValid added in v0.1.1

func (pb PrimaryBlock) CheckValid() (errs error)

func (PrimaryBlock) GetCRCType

func (pb PrimaryBlock) GetCRCType() CRCType

GetCRCType returns the CRCType of this block.

func (PrimaryBlock) HasCRC

func (pb PrimaryBlock) HasCRC() bool

HasCRC returns if the CRCType indicates a CRC is present for this block. This should be always true for the Primary Block.

func (PrimaryBlock) HasFragmentation

func (pb PrimaryBlock) HasFragmentation() bool

HasFragmentation returns true if the bundle processing control flags indicates a fragmented bundle. In this case the FragmentOffset and TotalDataLength fields should become relevant.

func (PrimaryBlock) IsLifetimeExceeded

func (pb PrimaryBlock) IsLifetimeExceeded() bool

IsLifetimeExceeded returns true if this PrimaryBlock's lifetime is exceeded. This method only compares the tuple of the CreationTimestamp and Lifetime against the current time.

If the creatoin timestamp's time value is zero, this method will always return false.

func (*PrimaryBlock) MarshalCbor added in v0.1.1

func (pb *PrimaryBlock) MarshalCbor(w io.Writer) error

func (*PrimaryBlock) SetCRCType

func (pb *PrimaryBlock) SetCRCType(crcType CRCType)

SetCRCType sets the CRC type.

func (PrimaryBlock) String

func (pb PrimaryBlock) String() string

func (*PrimaryBlock) UnmarshalCbor added in v0.1.1

func (pb *PrimaryBlock) UnmarshalCbor(r io.Reader) error

type Valid added in v0.1.1

type Valid interface {
	// CheckValid returns an array of errors for incorrect data.
	CheckValid() error
}

Valid is an interface with the CheckValid function. This function should return an errors for incorrect data. It should be implemented for the different types and sub-types of a Bundle. Each type is able to check its sub-types and by tree-like calls all errors of a whole Bundle can be detected. For non-trivial code, the multierror package might be used.

Directories

Path Synopsis
Package arecord includes an abstration for administrative records, as defined in the Bundle Protocol.
Package arecord includes an abstration for administrative records, as defined in the Bundle Protocol.

Jump to

Keyboard shortcuts

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