Documentation
¶
Overview ¶
Package bpv7 provides a library for interaction with Bundles as defined in the Bundle Protocol Version 7 (draft-ietf-dtn-bpbis-31.txt). This includes Bundle creation, modification, serialization and deserialization.
The easiest way to create new Bundles is to use the BundleBuilder.
bundle, err := bpv7.Builder(). CRC(bpv7.CRC32). Source("dtn://src/"). Destination("dtn://dest/"). CreationTimestampNow(). Lifetime(time.Hour). HopCountBlock(64). PayloadBlock([]byte("hello world!")). Build()
Both serializing and deserializing bundles into the CBOR is supported.
// An existing Bundle b1 is serialized. The new bundle b2 is created // from this. A common bytes.Buffer will be used. buff := new(bytes.Buffer) err1 := b1.WriteBundle(buff) b2, err2 := bpv7.ParseBundle(buff)
Index ¶
- Constants
- func IsBundleReassemblable(bs []Bundle) bool
- type AdministrativeRecord
- type AdministrativeRecordManager
- func (arm *AdministrativeRecordManager) IsKnown(typeCode uint64) (known bool)
- func (arm *AdministrativeRecordManager) ReadAdministrativeRecord(r io.Reader) (ar AdministrativeRecord, err error)
- func (arm *AdministrativeRecordManager) Register(ar AdministrativeRecord) (err error)
- func (arm *AdministrativeRecordManager) Unregister(ar AdministrativeRecord)
- func (arm *AdministrativeRecordManager) WriteAdministrativeRecord(ar AdministrativeRecord, w io.Writer) (err error)
- type BinarySprayBlock
- func (bsb *BinarySprayBlock) BlockTypeCode() uint64
- func (bsb *BinarySprayBlock) BlockTypeName() string
- func (bsb *BinarySprayBlock) CheckValid() error
- func (bsb *BinarySprayBlock) MarshalCbor(w io.Writer) error
- func (bsb *BinarySprayBlock) RemainingCopies() uint64
- func (bsb *BinarySprayBlock) SetCopies(newValue uint64)
- func (bsb *BinarySprayBlock) UnmarshalCbor(r io.Reader) error
- type BlockControlFlags
- type Bundle
- func BuildFromMap(m map[string]interface{}) (bndl Bundle, err error)
- func MustNewBundle(primary PrimaryBlock, canonicals []CanonicalBlock) (b Bundle)
- func NewBundle(primary PrimaryBlock, canonicals []CanonicalBlock) (b Bundle, err error)
- func ParseBundle(r io.Reader) (b Bundle, err error)
- func ReassembleFragments(bs []Bundle) (b Bundle, err error)
- func (b *Bundle) AddExtensionBlock(block CanonicalBlock) error
- func (b Bundle) AdministrativeRecord() (AdministrativeRecord, error)
- func (b Bundle) CheckValid() (errs error)
- func (b *Bundle) ExtensionBlock(blockType uint64) (*CanonicalBlock, error)
- func (b Bundle) Fragment(mtu int) (bs []Bundle, err error)
- func (b *Bundle) HasExtensionBlock(blockType uint64) bool
- func (b Bundle) ID() BundleID
- func (b Bundle) IsAdministrativeRecord() bool
- func (b Bundle) IsLifetimeExceeded() bool
- func (b *Bundle) MarshalCbor(w io.Writer) error
- func (b Bundle) MarshalJSON() ([]byte, error)
- func (b *Bundle) PayloadBlock() (*CanonicalBlock, error)
- func (b *Bundle) RemoveExtensionBlockByBlockNumber(blockNumber uint64)
- func (b *Bundle) SetCRCType(crcType CRCType)
- func (b Bundle) String() string
- func (b *Bundle) UnmarshalCbor(r io.Reader) error
- func (b *Bundle) WriteBundle(w io.Writer) error
- type BundleAgeBlock
- func (bab *BundleAgeBlock) Age() uint64
- func (bab *BundleAgeBlock) BlockTypeCode() uint64
- func (bab *BundleAgeBlock) BlockTypeName() string
- func (bab *BundleAgeBlock) CheckValid() error
- func (bab *BundleAgeBlock) Increment(offset uint64) uint64
- func (bab *BundleAgeBlock) MarshalCbor(w io.Writer) error
- func (bab *BundleAgeBlock) MarshalJSON() ([]byte, error)
- func (bab *BundleAgeBlock) UnmarshalCbor(r io.Reader) error
- type BundleBuilder
- func (bldr *BundleBuilder) AdministrativeRecord(ar AdministrativeRecord) *BundleBuilder
- func (bldr *BundleBuilder) Build() (bndl Bundle, err error)
- func (bldr *BundleBuilder) BundleAgeBlock(args ...interface{}) *BundleBuilder
- func (bldr *BundleBuilder) BundleCtrlFlags(bcf BundleControlFlags) *BundleBuilder
- func (bldr *BundleBuilder) CRC(crcType CRCType) *BundleBuilder
- func (bldr *BundleBuilder) Canonical(args ...interface{}) *BundleBuilder
- func (bldr *BundleBuilder) CreationTimestampEpoch() *BundleBuilder
- func (bldr *BundleBuilder) CreationTimestampNow() *BundleBuilder
- func (bldr *BundleBuilder) CreationTimestampTime(t time.Time) *BundleBuilder
- func (bldr *BundleBuilder) Destination(eid interface{}) *BundleBuilder
- func (bldr *BundleBuilder) Error() error
- func (bldr *BundleBuilder) HopCountBlock(args ...interface{}) *BundleBuilder
- func (bldr *BundleBuilder) Lifetime(duration interface{}) *BundleBuilder
- func (bldr *BundleBuilder) PayloadBlock(args ...interface{}) *BundleBuilder
- func (bldr *BundleBuilder) PreviousNodeBlock(args ...interface{}) *BundleBuilder
- func (bldr *BundleBuilder) ReportTo(eid interface{}) *BundleBuilder
- func (bldr *BundleBuilder) Source(eid interface{}) *BundleBuilder
- func (bldr *BundleBuilder) StatusReport(args ...interface{}) *BundleBuilder
- type BundleControlFlags
- type BundleID
- type BundleStatusItem
- type CRCType
- type CanonicalBlock
- func (cb CanonicalBlock) CheckValid() (errs error)
- func (cb CanonicalBlock) GetCRCType() CRCType
- func (cb CanonicalBlock) HasCRC() bool
- func (cb *CanonicalBlock) MarshalCbor(w io.Writer) error
- func (cb CanonicalBlock) MarshalJSON() ([]byte, error)
- func (cb *CanonicalBlock) SetCRCType(crcType CRCType)
- func (cb CanonicalBlock) String() string
- func (cb CanonicalBlock) TypeCode() uint64
- func (cb *CanonicalBlock) UnmarshalCbor(r io.Reader) error
- type CreationTimestamp
- func (ct CreationTimestamp) DtnTime() DtnTime
- func (ct CreationTimestamp) IsZeroTime() bool
- func (ct *CreationTimestamp) MarshalCbor(w io.Writer) error
- func (ct CreationTimestamp) MarshalJSON() ([]byte, error)
- func (ct CreationTimestamp) SequenceNumber() uint64
- func (ct CreationTimestamp) String() string
- func (ct *CreationTimestamp) UnmarshalCbor(r io.Reader) error
- type DTLSRBlock
- func (dtlsrb *DTLSRBlock) BlockTypeCode() uint64
- func (dtlsrb *DTLSRBlock) BlockTypeName() string
- func (dtlsrb *DTLSRBlock) CheckValid() error
- func (dtlsrb *DTLSRBlock) GetPeerData() DTLSRPeerData
- func (dtlsrb *DTLSRBlock) MarshalCbor(w io.Writer) error
- func (dtlsrb *DTLSRBlock) UnmarshalCbor(r io.Reader) error
- type DTLSRPeerData
- type DtnEndpoint
- func (e DtnEndpoint) Authority() string
- func (e DtnEndpoint) CheckValid() (err error)
- func (e DtnEndpoint) IsSingleton() bool
- func (e DtnEndpoint) MarshalCbor(w io.Writer) error
- func (e DtnEndpoint) Path() string
- func (_ DtnEndpoint) SchemeName() string
- func (_ DtnEndpoint) SchemeNo() uint64
- func (e DtnEndpoint) String() string
- func (e *DtnEndpoint) UnmarshalCbor(r io.Reader) error
- type DtnTime
- type EndpointID
- func (eid EndpointID) Authority() string
- func (eid EndpointID) CheckValid() error
- func (eid EndpointID) IsSingleton() bool
- func (eid *EndpointID) MarshalCbor(w io.Writer) error
- func (eid EndpointID) MarshalJSON() ([]byte, error)
- func (eid EndpointID) Path() string
- func (eid EndpointID) SameNode(other EndpointID) bool
- func (eid EndpointID) String() string
- func (eid *EndpointID) UnmarshalCbor(r io.Reader) error
- type EndpointType
- type ExtensionBlock
- type ExtensionBlockManager
- func (ebm *ExtensionBlockManager) IsKnown(typeCode uint64) bool
- func (ebm *ExtensionBlockManager) ReadBlock(typeCode uint64, r io.Reader) (b ExtensionBlock, err error)
- func (ebm *ExtensionBlockManager) Register(eb ExtensionBlock) error
- func (ebm *ExtensionBlockManager) Unregister(eb ExtensionBlock)
- func (ebm *ExtensionBlockManager) WriteBlock(b ExtensionBlock, w io.Writer) error
- type GenericExtensionBlock
- func (geb *GenericExtensionBlock) BlockTypeCode() uint64
- func (geb *GenericExtensionBlock) BlockTypeName() string
- func (geb *GenericExtensionBlock) CheckValid() error
- func (geb *GenericExtensionBlock) MarshalBinary() ([]byte, error)
- func (geb *GenericExtensionBlock) UnmarshalBinary(data []byte) error
- type HopCountBlock
- func (hcb *HopCountBlock) BlockTypeCode() uint64
- func (hcb *HopCountBlock) BlockTypeName() string
- func (hcb *HopCountBlock) CheckValid() error
- func (hcb *HopCountBlock) Decrement()
- func (hcb *HopCountBlock) Increment() bool
- func (hcb HopCountBlock) IsExceeded() bool
- func (hcb *HopCountBlock) MarshalCbor(w io.Writer) error
- func (hcb *HopCountBlock) MarshalJSON() ([]byte, error)
- func (hcb *HopCountBlock) UnmarshalCbor(r io.Reader) error
- type IpnEndpoint
- func (e IpnEndpoint) Authority() string
- func (e IpnEndpoint) CheckValid() error
- func (_ IpnEndpoint) IsSingleton() bool
- func (e IpnEndpoint) MarshalCbor(w io.Writer) error
- func (e IpnEndpoint) Path() string
- func (e IpnEndpoint) SchemeName() string
- func (e IpnEndpoint) SchemeNo() uint64
- func (e IpnEndpoint) String() string
- func (e *IpnEndpoint) UnmarshalCbor(r io.Reader) error
- type PayloadBlock
- func (pb *PayloadBlock) BlockTypeCode() uint64
- func (pb *PayloadBlock) BlockTypeName() string
- func (pb *PayloadBlock) CheckValid() error
- func (pb *PayloadBlock) Data() []byte
- func (pb *PayloadBlock) MarshalBinary() ([]byte, error)
- func (pb *PayloadBlock) MarshalJSON() ([]byte, error)
- func (pb *PayloadBlock) UnmarshalBinary(data []byte) error
- type PreviousNodeBlock
- func (pnb *PreviousNodeBlock) BlockTypeCode() uint64
- func (pnb *PreviousNodeBlock) BlockTypeName() string
- func (pnb *PreviousNodeBlock) CheckValid() error
- func (pnb *PreviousNodeBlock) Endpoint() EndpointID
- func (pnb *PreviousNodeBlock) MarshalCbor(w io.Writer) error
- func (pnb *PreviousNodeBlock) MarshalJSON() ([]byte, error)
- func (pnb *PreviousNodeBlock) UnmarshalCbor(r io.Reader) error
- type PrimaryBlock
- func (pb PrimaryBlock) CheckValid() (errs error)
- func (pb PrimaryBlock) GetCRCType() CRCType
- func (pb PrimaryBlock) HasCRC() bool
- func (pb PrimaryBlock) HasFragmentation() bool
- func (pb *PrimaryBlock) MarshalCbor(w io.Writer) error
- func (pb PrimaryBlock) MarshalJSON() ([]byte, error)
- func (pb *PrimaryBlock) SetCRCType(crcType CRCType)
- func (pb PrimaryBlock) String() string
- func (pb *PrimaryBlock) UnmarshalCbor(r io.Reader) error
- type ProphetBlock
- func (pBlock *ProphetBlock) BlockTypeCode() uint64
- func (pBlock *ProphetBlock) BlockTypeName() string
- func (pBlock ProphetBlock) CheckValid() error
- func (pBlock *ProphetBlock) GetPredictabilities() map[EndpointID]float64
- func (pBlock *ProphetBlock) MarshalCbor(w io.Writer) error
- func (pBlock *ProphetBlock) UnmarshalCbor(r io.Reader) error
- type SignatureBlock
- func (s *SignatureBlock) BlockTypeCode() uint64
- func (s *SignatureBlock) BlockTypeName() string
- func (s *SignatureBlock) CheckValid() (err error)
- func (s *SignatureBlock) MarshalCbor(w io.Writer) error
- func (s *SignatureBlock) UnmarshalCbor(r io.Reader) error
- func (s *SignatureBlock) Verify(b Bundle) (valid bool)
- type StatusInformationPos
- type StatusReport
- type StatusReportReason
- type Valid
Constants ¶
const ( // ExtBlockTypePayloadBlock is the block type code for a Payload Block, bpv7/extension_block_payload.go ExtBlockTypePayloadBlock uint64 = 1 // ExtBlockTypePreviousNodeBlock is the block type code for a Previous Node Block, bpv7/extension_block_previous_node.go ExtBlockTypePreviousNodeBlock uint64 = 6 // ExtBlockTypeBundleAgeBlock is the block type code for a Bundle Age Block, bpv7/extension_block_bundle_age.go ExtBlockTypeBundleAgeBlock uint64 = 7 // ExtBlockTypeHopCountBlock is the block type code for a Hop Count Block, bpv7/extension_block_hop_count.go ExtBlockTypeHopCountBlock uint64 = 10 // ExtBlockTypeBinarySprayBlock is the custom block type code for a BinarySprayBlock, bpv7/extension_block_spray.go ExtBlockTypeBinarySprayBlock uint64 = 192 // ExtBlockTypeDTLSRBlock is the custom block type code for a DTLSRBlock, bpv7/extension_block_dtlsr.go ExtBlockTypeDTLSRBlock uint64 = 193 // ExtBlockTypeProphetBlock is the custom block type code for a ProphetBlock, bpv7/extension_block_prophet.go ExtBlockTypeProphetBlock uint64 = 194 // ExtBlockTypeSignatureBlock is the custom block type code for a SignatureBlock, bpv7/extension_block_signature.go ExtBlockTypeSignatureBlock uint64 = 195 )
Sorted list of all known block type codes to prevent double usage.
const ( // AdminRecordTypeStatusReport is the administrative record type code for a status report. AdminRecordTypeStatusReport uint64 = 1 )
Sorted list of all known administrative record type codes to prevent double usage.
Variables ¶
This section is empty.
Functions ¶
func IsBundleReassemblable ¶
IsBundleReassemblable checks if a Bundle can be reassembled from the given fragments. This method might sort the given array as a side effect.
Types ¶
type AdministrativeRecord ¶
type AdministrativeRecord interface { cboring.CborMarshaler // RecordTypeCode returns this AdministrativeRecord's type code. RecordTypeCode() uint64 }
AdministrativeRecord describes an administrative record, e.g., a status report.
func NewAdministrativeRecordFromCbor ¶
func NewAdministrativeRecordFromCbor(data []byte) (ar AdministrativeRecord, err error)
NewAdministrativeRecordFromCbor creates a new AdministrativeRecord from a given byte array. TODO: remove this function; replace by AdministrativeRecordManager
type AdministrativeRecordManager ¶
type AdministrativeRecordManager struct {
// contains filtered or unexported fields
}
AdministrativeRecordManager keeps a book on various types of AdministrativeRecords that can be changed at runtime. Thus, new AdministrativeRecords can be created based on their block type code.
A singleton AdministrativeRecordManager can be fetched by GetAdministrativeRecordManager.
func GetAdministrativeRecordManager ¶
func GetAdministrativeRecordManager() *AdministrativeRecordManager
GetAdministrativeRecordManager returns the singleton AdministrativeRecordManager. If none exists, a new one will be generated with "sane defaults".
func NewAdministrativeRecordManager ¶
func NewAdministrativeRecordManager() *AdministrativeRecordManager
NewAdministrativeRecordManager creates an empty AdministrativeRecordManager. To use a singleton AdministrativeRecordManager one can use GetAdministrativeRecordManager.
func (*AdministrativeRecordManager) IsKnown ¶
func (arm *AdministrativeRecordManager) IsKnown(typeCode uint64) (known bool)
IsKnown returns true if the AdministrativeRecord for this record type code is known.
func (*AdministrativeRecordManager) ReadAdministrativeRecord ¶
func (arm *AdministrativeRecordManager) ReadAdministrativeRecord(r io.Reader) (ar AdministrativeRecord, err error)
ReadAdministrativeRecord from a Reader within its CBOR array and returns the wrapped data type.
func (*AdministrativeRecordManager) Register ¶
func (arm *AdministrativeRecordManager) Register(ar AdministrativeRecord) (err error)
Register a new AdministrativeRecord type through an exemplary instance.
func (*AdministrativeRecordManager) Unregister ¶
func (arm *AdministrativeRecordManager) Unregister(ar AdministrativeRecord)
Unregister an AdministrativeRecord type through an exemplary instance.
func (*AdministrativeRecordManager) WriteAdministrativeRecord ¶
func (arm *AdministrativeRecordManager) WriteAdministrativeRecord(ar AdministrativeRecord, w io.Writer) (err error)
WriteAdministrativeRecord to a Writer wrapped in an CBOR array with both its record type code and its representation.
type BinarySprayBlock ¶
type BinarySprayBlock uint64
BinarySprayBlock contains metadata used by the "Binary Spray & Wait" routing algorithm.
It is attached to a bundle to let the receiving peers know of the bundle's remaining "multiplicity, that is the number of times this bundle may be forwarded to non-recipient nodes. Each node in the forwarding chain is expected to update the the block upon a successful forward and halve the remaining multiplicity.
NOTE: This is a custom extension block, and not part of the original bpv7 specification. It is currently assigned the block type code 192, which the specification sets aside for "private and/or experimental use"
func NewBinarySprayBlock ¶
func NewBinarySprayBlock(copies uint64) *BinarySprayBlock
func (*BinarySprayBlock) BlockTypeCode ¶
func (bsb *BinarySprayBlock) BlockTypeCode() uint64
func (*BinarySprayBlock) BlockTypeName ¶
func (bsb *BinarySprayBlock) BlockTypeName() string
func (*BinarySprayBlock) CheckValid ¶
func (bsb *BinarySprayBlock) CheckValid() error
func (*BinarySprayBlock) MarshalCbor ¶
func (bsb *BinarySprayBlock) MarshalCbor(w io.Writer) error
func (*BinarySprayBlock) RemainingCopies ¶
func (bsb *BinarySprayBlock) RemainingCopies() uint64
func (*BinarySprayBlock) SetCopies ¶
func (bsb *BinarySprayBlock) SetCopies(newValue uint64)
func (*BinarySprayBlock) UnmarshalCbor ¶
func (bsb *BinarySprayBlock) UnmarshalCbor(r io.Reader) error
type BlockControlFlags ¶
type BlockControlFlags uint64
BlockControlFlags is an uint which represents the Block Processing Control Flags as specified in 4.1.4.
const ( // ReplicateBlock requires this block to be replicated in every fragment. ReplicateBlock BlockControlFlags = 0x01 // StatusReportBlock requires transmission of a status report if this block cannot be processed. StatusReportBlock BlockControlFlags = 0x02 // DeleteBundle requires bundle deletion if this block cannot be processed. DeleteBundle BlockControlFlags = 0x04 // RemoveBlock requires the block to be removed from the bundle if it cannot be processed. RemoveBlock BlockControlFlags = 0x10 )
func (BlockControlFlags) CheckValid ¶
func (bcf BlockControlFlags) CheckValid() error
CheckValid returns an array of errors for incorrect data.
func (BlockControlFlags) Has ¶
func (bcf BlockControlFlags) Has(flag BlockControlFlags) bool
Has returns true if a given flag or mask of flags is set.
func (BlockControlFlags) MarshalJSON ¶
func (bcf BlockControlFlags) MarshalJSON() ([]byte, error)
MarshalJSON returns a JSON array of control flags.
func (BlockControlFlags) String ¶
func (bcf BlockControlFlags) String() string
func (BlockControlFlags) Strings ¶
func (bcf BlockControlFlags) Strings() (fields []string)
Strings returns an array of all flags as a string representation.
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 BuildFromMap ¶
BuildFromMap creates a Bundle from a map which "calls" the BundleBuilder's methods.
This function does not use reflection or other dark magic. So it is safe to be called by unchecked data.
args := map[string]interface{}{ "destination": "dtn://dst/", "source": "dtn://src/", "creation_timestamp_now": true, "lifetime": "24h", "payload_block": "hello world", } b, err := BuildFromMap(args)
func MustNewBundle ¶
func MustNewBundle(primary PrimaryBlock, canonicals []CanonicalBlock) (b 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 ¶
ParseBundle reads a new CBOR encoded Bundle from a Reader.
func ReassembleFragments ¶
ReassembleFragments merges a slice of Bundle fragments into the reassembled Bundle.
func (*Bundle) AddExtensionBlock ¶
func (b *Bundle) AddExtensionBlock(block CanonicalBlock) error
AddExtensionBlock adds a new ExtensionBlock to this Bundle.
The block number will be calculated and overwritten within this method. Will return an error if the Bundle already has an ExtensionBlock with the same type code.
func (Bundle) AdministrativeRecord ¶
func (b Bundle) AdministrativeRecord() (AdministrativeRecord, error)
AdministrativeRecord stored within this Bundle.
An error arises if this Bundle is not an AdministrativeRecord, compare IsAdministrativeRecord.
func (Bundle) CheckValid ¶
CheckValid returns an array of errors for incorrect data.
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) Fragment ¶
Fragment a Bundle into multiple Bundles, with each serialized Bundle limited to mtu bytes.
func (*Bundle) HasExtensionBlock ¶
HasExtensionBlock checks if a CanonicalBlock / ExtensionBlock for some block type number is present.
func (Bundle) IsAdministrativeRecord ¶
IsAdministrativeRecord returns if this Bundle's control flags indicate this has an administrative record payload.
func (Bundle) IsLifetimeExceeded ¶
IsLifetimeExceeded of this Bundle by checking an optional Bundle Age Block and the PrimaryBlock's Lifetime.
func (*Bundle) MarshalCbor ¶
MarshalCbor writes this Bundle's CBOR representation.
func (Bundle) MarshalJSON ¶
MarshalJSON creates a JSON object for this Bundle.
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) RemoveExtensionBlockByBlockNumber ¶
RemoveExtensionBlockByBlockNumber searches and removes a CanonicalBlock / ExtensionBlock with the given block number.
If no such block exists, the method will do nothing. Sorting will not be performed, as we assume that the blocks are already in their correct order.
func (*Bundle) SetCRCType ¶
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) UnmarshalCbor ¶
UnmarshalCbor creates this Bundle based on a CBOR representation.
type BundleAgeBlock ¶
type BundleAgeBlock uint64
BundleAgeBlock implements the Bundle Protocol's Bundle Age Block.
func NewBundleAgeBlock ¶
func NewBundleAgeBlock(ms uint64) *BundleAgeBlock
NewBundleAgeBlock creates a new BundleAgeBlock for the given milliseconds.
func (*BundleAgeBlock) Age ¶
func (bab *BundleAgeBlock) Age() uint64
Age returns the age in milliseconds.
func (*BundleAgeBlock) BlockTypeCode ¶
func (bab *BundleAgeBlock) BlockTypeCode() uint64
BlockTypeCode must return a constant integer, indicating the block type code.
func (*BundleAgeBlock) BlockTypeName ¶
func (bab *BundleAgeBlock) BlockTypeName() string
BlockTypeName must return a constant string, this block's name.
func (*BundleAgeBlock) CheckValid ¶
func (bab *BundleAgeBlock) CheckValid() error
CheckValid returns an array of errors for incorrect data.
func (*BundleAgeBlock) Increment ¶
func (bab *BundleAgeBlock) Increment(offset uint64) uint64
Increment with an offset in milliseconds and return the new time.
func (*BundleAgeBlock) MarshalCbor ¶
func (bab *BundleAgeBlock) MarshalCbor(w io.Writer) error
MarshalCbor writes a CBOR representation for a Bundle Age Block.
func (*BundleAgeBlock) MarshalJSON ¶
func (bab *BundleAgeBlock) MarshalJSON() ([]byte, error)
MarshalJSON writes a JSON representation for a Bundle Age Block, e.g., "23 ms".
func (*BundleAgeBlock) UnmarshalCbor ¶
func (bab *BundleAgeBlock) UnmarshalCbor(r io.Reader) error
UnmarshalCbor reads the CBOR representation for a Bundle Age Block.
type BundleBuilder ¶
type BundleBuilder struct {
// contains filtered or unexported fields
}
BundleBuilder is a simple framework to create bundles by method chaining.
bndl, err := bpv7.Builder(). CRC(bpv7.CRC32). Source("dtn://src/"). Destination("dtn://dest/"). CreationTimestampNow(). Lifetime("30m"). HopCountBlock(64). PayloadBlock([]byte("hello world!")). Build()
func (*BundleBuilder) AdministrativeRecord ¶
func (bldr *BundleBuilder) AdministrativeRecord(ar AdministrativeRecord) *BundleBuilder
AdministrativeRecord configures an AdministrativeRecord as the Payload. Furthermore, the AdministrativeRecordPayload BundleControlFlags is set.
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 milliseconds, a format string or a time.Duration and BlockControlFlags are _optional_ block processing control flags
func (*BundleBuilder) BundleCtrlFlags ¶
func (bldr *BundleBuilder) BundleCtrlFlags(bcf BundleControlFlags) *BundleBuilder
BundleCtrlFlags 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 bpv7.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 milliseconds, a format string (compare time.ParseDuration) for the duration or a time.Duration.
Lifetime(1000) // Lifetime of 1000ms Lifetime("1000ms") // Lifetime of 1000ms Lifetime("10m") // Lifetime of 10min Lifetime(10 * time.Minute) // 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.
func (*BundleBuilder) StatusReport ¶
func (bldr *BundleBuilder) StatusReport(args ...interface{}) *BundleBuilder
StatusReport configures this BundleBuilder's Bundle to be an AdministrativeRecord, delivering a StatusReport.
Bundle, StatusInformationPos, StatusReportReason[, DtnTime] Where Bundle is the reference Bundle, StatusInformationPos describes the kind of StatusInformation, and StatusReportReason is the reason. An optional DtnTime for the record can also be passed. Otherwise the current time will be used.
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 indicates this bundle is a fragment. IsFragment BundleControlFlags = 0x000001 // AdministrativeRecordPayload indicates the payload is an administrative record. AdministrativeRecordPayload BundleControlFlags = 0x000002 // MustNotFragmented forbids bundle fragmentation. MustNotFragmented BundleControlFlags = 0x000004 // RequestUserApplicationAck requests an acknowledgement from the application agent. RequestUserApplicationAck BundleControlFlags = 0x000020 // RequestStatusTime requests a status time in all status reports. RequestStatusTime BundleControlFlags = 0x000040 // StatusRequestReception requests a bundle reception status report. StatusRequestReception BundleControlFlags = 0x004000 // StatusRequestForward requests a bundle forwarding status report. StatusRequestForward BundleControlFlags = 0x010000 // StatusRequestDelivery requests a bundle delivery status report. StatusRequestDelivery BundleControlFlags = 0x020000 // StatusRequestDeletion requests a bundle deletion status report. StatusRequestDeletion BundleControlFlags = 0x040000 )
func (BundleControlFlags) CheckValid ¶
func (bcf BundleControlFlags) CheckValid() (errs error)
CheckValid returns an array of errors for incorrect data.
func (BundleControlFlags) Has ¶
func (bcf BundleControlFlags) Has(flag BundleControlFlags) bool
Has returns true if a given flag or mask of flags is set.
func (BundleControlFlags) MarshalJSON ¶
func (bcf BundleControlFlags) MarshalJSON() ([]byte, error)
MarshalJSON creates a JSON array of control flags.
func (BundleControlFlags) String ¶
func (bcf BundleControlFlags) String() string
func (BundleControlFlags) Strings ¶
func (bcf BundleControlFlags) Strings() (fields []string)
Strings returns an array of all flags as a string representation.
type BundleID ¶
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) MarshalCbor ¶
MarshalCbor writes the Bundle ID's CBOR representation.
type BundleStatusItem ¶
BundleStatusItem represents the a bundle status item, as used as an element in the bundle status information array of each Bundle Status Report.
func NewBundleStatusItem ¶
func NewBundleStatusItem(asserted bool) BundleStatusItem
NewBundleStatusItem returns a new BundleStatusItem, indicating an optional assertion - givenas asserted -, but no status time request.
func NewTimeReportingBundleStatusItem ¶
func NewTimeReportingBundleStatusItem(time DtnTime) BundleStatusItem
NewTimeReportingBundleStatusItem returns a new BundleStatusItem, indicating both a positive assertion and a requested status time report.
func (*BundleStatusItem) MarshalCbor ¶
func (bsi *BundleStatusItem) MarshalCbor(w io.Writer) error
func (BundleStatusItem) String ¶
func (bsi BundleStatusItem) String() string
func (*BundleStatusItem) UnmarshalCbor ¶
func (bsi *BundleStatusItem) 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.
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 AdministrativeRecordToCbor ¶
func AdministrativeRecordToCbor(ar AdministrativeRecord) (blk CanonicalBlock, err error)
AdministrativeRecordToCbor creates a canonical block, containing this administrative record. The surrounding bundle _must_ have a set AdministrativeRecordPayload bundle processing control flag. TODO: remove this function; replace by AdministrativeRecordManager
func NewCanonicalBlock ¶
func NewCanonicalBlock(no uint64, bcf BlockControlFlags, value ExtensionBlock) CanonicalBlock
NewCanonicalBlock based on its number, some control flags and an Extension Block.
func (CanonicalBlock) CheckValid ¶
func (cb CanonicalBlock) CheckValid() (errs error)
CheckValid returns an array of errors for incorrect data.
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 ¶
func (cb *CanonicalBlock) MarshalCbor(w io.Writer) error
MarshalCbor writes this Canonical Block's CBOR representation.
func (CanonicalBlock) MarshalJSON ¶
func (cb CanonicalBlock) MarshalJSON() ([]byte, error)
MarshalJSON writes a JSON object for this Canonical Block.
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 ¶
func (cb CanonicalBlock) TypeCode() uint64
TypeCode returns the block type code.
func (*CanonicalBlock) UnmarshalCbor ¶
func (cb *CanonicalBlock) UnmarshalCbor(r io.Reader) error
UnmarshalCbor creates this Canonical Block based on a CBOR representation.
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 ¶
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 ¶
func (ct *CreationTimestamp) MarshalCbor(w io.Writer) error
MarshalCbor writes a CBOR representation for this CreationTimestamp.
func (CreationTimestamp) MarshalJSON ¶
func (ct CreationTimestamp) MarshalJSON() ([]byte, error)
MarshalJSON creates a JSON object representing this CreationTimestamp.
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 ¶
func (ct *CreationTimestamp) UnmarshalCbor(r io.Reader) error
UnmarshalCbor reads a CBOR representation of a CreationTimestamp.
type DTLSRBlock ¶
type DTLSRBlock DTLSRPeerData
DTLSRBlock contains metadata used by the "Delay-Tolerant Link State Routing"-algorithm. It is a basic transmission-encapsulation of the DTLSRPeerData type,.
NOTE: This is a custom extension block, and not part of the original bpv7 specification. It is currently assigned the block type code 193, which the specification sets aside for "private and/or experimental use"
TODO: Turn this into an administrative record
func NewDTLSRBlock ¶
func NewDTLSRBlock(data DTLSRPeerData) *DTLSRBlock
func (*DTLSRBlock) BlockTypeCode ¶
func (dtlsrb *DTLSRBlock) BlockTypeCode() uint64
func (*DTLSRBlock) BlockTypeName ¶
func (dtlsrb *DTLSRBlock) BlockTypeName() string
func (*DTLSRBlock) CheckValid ¶
func (dtlsrb *DTLSRBlock) CheckValid() error
func (*DTLSRBlock) GetPeerData ¶
func (dtlsrb *DTLSRBlock) GetPeerData() DTLSRPeerData
func (*DTLSRBlock) MarshalCbor ¶
func (dtlsrb *DTLSRBlock) MarshalCbor(w io.Writer) error
func (*DTLSRBlock) UnmarshalCbor ¶
func (dtlsrb *DTLSRBlock) UnmarshalCbor(r io.Reader) error
type DTLSRPeerData ¶
type DTLSRPeerData struct { // ID is the sending node's endpoint ID ID EndpointID // Timestamp is the time of the last update of the sending node's connection data. // When a node receives another's connection data, it should only update its view of the network // if this data is newer than the present one. Timestamp DtnTime // Peers is a representation of the node's connections. // Keys are the EndpointIDs of node which are or were connected to the sending node. // If the peer was currently connected when this block was sent, then the value will be 0. // If the connection to the peer was lost, the value will be the timestamp of the connection loss. Peers map[EndpointID]DtnTime }
DTLSRPeerData contains a peer's connection data This struct is placed in this location to avoid an import-loop with the routing package.
func (DTLSRPeerData) ShouldReplace ¶
func (pd DTLSRPeerData) ShouldReplace(other DTLSRPeerData) bool
ShouldReplace checks if one set of connection data should replace a different one. Currently only checks the timestamps.
type DtnEndpoint ¶
DtnEndpoint describes the dtn URI for EndpointIDs, as defined in ietf-dtn-bpbis.
Format of a "normal" dtn URI: "dtn:" "//" NodeName "/" Demux ^------^ 1*(ALPHA/DIGIT/"-"/"."/"_") ^---^ *VCHAR Format of the null endpoint: "dtn:none"
func (DtnEndpoint) Authority ¶
func (e DtnEndpoint) Authority() string
Authority is the authority part of the Endpoint URI, e.g., "foo" for "dtn://foo/bar" or "none" for "dtn:none".
func (DtnEndpoint) CheckValid ¶
func (e DtnEndpoint) CheckValid() (err error)
CheckValid returns an error for incorrect data.
func (DtnEndpoint) IsSingleton ¶
func (e DtnEndpoint) IsSingleton() bool
IsSingleton checks if this Endpoint represents a singleton.
- If a "dtn" URI's demux start with "~", this Endpoint is not a singleton. - "dtn:none" cannot be a singleton.
func (DtnEndpoint) MarshalCbor ¶
func (e DtnEndpoint) MarshalCbor(w io.Writer) error
MarshalCbor writes this DtnEndpoint's CBOR representation.
func (DtnEndpoint) Path ¶
func (e DtnEndpoint) Path() string
Path is the path part of the Endpoint URI, e.g., "/bar" for "dtn://foo/bar" or "/" for "dtn:none".
func (DtnEndpoint) SchemeName ¶
func (_ DtnEndpoint) SchemeName() string
SchemeName is "dtn" for DtnEndpoints.
func (DtnEndpoint) SchemeNo ¶
func (_ DtnEndpoint) SchemeNo() uint64
SchemeNo is 1 for DtnEndpoints.
func (DtnEndpoint) String ¶
func (e DtnEndpoint) String() string
func (*DtnEndpoint) UnmarshalCbor ¶
func (e *DtnEndpoint) UnmarshalCbor(r io.Reader) error
UnmarshalCbor reads a CBOR representation.
type DtnTime ¶
type DtnTime uint64
DtnTime is an integer representation of milliseconds since the start of the year 2000 (UTC).
const ( // DtnTimeEpoch represents the zero timestamp/epoch. DtnTimeEpoch DtnTime = 0 )
func DtnTimeFromTime ¶
DtnTimeFromTime returns the DtnTime for the time.Time.
type EndpointID ¶
type EndpointID struct {
EndpointType EndpointType
}
EndpointID represents an Endpoint ID as defined in section 4.1.5.1. Its form is specified in an EndpointType, e.g., DtnEndpoint.
func DtnNone ¶
func DtnNone() EndpointID
DtnNone returns a new instance of the null endpoint "dtn:none".
func MustNewEndpointID ¶
func MustNewEndpointID(uri string) EndpointID
MustNewEndpointID based on an URI like NewEndpointID, but panics on an error.
func NewEndpointID ¶
func NewEndpointID(uri string) (e EndpointID, err error)
NewEndpointID based on an URI, e.g., "dtn://seven/".
func (EndpointID) Authority ¶
func (eid EndpointID) Authority() string
Authority is the authority part of the Endpoint URI, e.g., "foo" for "dtn://foo/bar".
func (EndpointID) CheckValid ¶
func (eid EndpointID) CheckValid() error
CheckValid returns an array of errors for incorrect data.
func (EndpointID) IsSingleton ¶
func (eid EndpointID) IsSingleton() bool
IsSingleton checks if this Endpoint represents a singleton.
func (*EndpointID) MarshalCbor ¶
func (eid *EndpointID) MarshalCbor(w io.Writer) error
MarshalCbor writes the CBOR representation of this Endpoint ID.
func (EndpointID) MarshalJSON ¶
func (eid EndpointID) MarshalJSON() ([]byte, error)
MarshalJSON writes the JSON representation of an EndpointID, which is the String representation.
func (EndpointID) Path ¶
func (eid EndpointID) Path() string
Path is the path part of the Endpoint URI, e.g., "/bar" for "dtn://foo/bar".
func (EndpointID) SameNode ¶
func (eid EndpointID) SameNode(other EndpointID) bool
SameNode checks if two Endpoints contain to the same Node, based on the scheme and authority part.
func (EndpointID) String ¶
func (eid EndpointID) String() string
func (*EndpointID) UnmarshalCbor ¶
func (eid *EndpointID) UnmarshalCbor(r io.Reader) error
UnmarshalCbor creates this Endpoint ID based on a CBOR representation.
type EndpointType ¶
type EndpointType interface { // SchemeName must return the static URI scheme type for this endpoint, e.g., "dtn" or "ipn". SchemeName() string // SchemeNo must return the static URI scheme type number for this endpoint, e.g., 1 for "dtn". SchemeNo() uint64 // Authority is the authority part of the Endpoint URI, e.g., "foo" for "dtn://foo/bar". Authority() string // Path is the path part of the Endpoint URI, e.g., "/bar" for "dtn://foo/bar". Path() string // IsSingleton checks if this Endpoint represents a singleton. IsSingleton() bool // MarshalCbor is the marshalling CBOR function from the cboring library. MarshalCbor(io.Writer) error Valid fmt.Stringer }
EndpointType describes a discrete EndpointID. Because of Go's type system, the MarshalCbor function from the cboring library must be implemented as a value receiver in this interface. In addition, the UnmarshalCbor function MUST be implemented as a pointer receiver. Afaik, this is not possible to describe with a Golang interface..
func NewDtnEndpoint ¶
func NewDtnEndpoint(uri string) (e EndpointType, err error)
NewDtnEndpoint from an URI with the dtn scheme.
func NewIpnEndpoint ¶
func NewIpnEndpoint(uri string) (e EndpointType, err error)
NewIpnEndpoint from an URI with the ipn scheme.
type ExtensionBlock ¶
type ExtensionBlock interface { Valid // BlockTypeCode must return a constant integer, indicating the block type code. BlockTypeCode() uint64 // BlockTypeName must return a constant string, this block's name. BlockTypeName() string }
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.
Furthermore, an ExtensionBlock can implement the json.Marshaler for a more human-readable representation.
type ExtensionBlockManager ¶
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 ¶
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 ¶
func NewExtensionBlockManager() *ExtensionBlockManager
NewExtensionBlockManager creates an empty ExtensionBlockManager. To use a singleton ExtensionBlockManager one can use GetExtensionBlockManager.
func (*ExtensionBlockManager) IsKnown ¶
func (ebm *ExtensionBlockManager) IsKnown(typeCode uint64) bool
IsKnown returns true if the ExtensionBlock for this block type code is known.
func (*ExtensionBlockManager) ReadBlock ¶
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 ¶
func (ebm *ExtensionBlockManager) Register(eb ExtensionBlock) error
Register a new ExtensionBlock type through an exemplary instance.
func (*ExtensionBlockManager) Unregister ¶
func (ebm *ExtensionBlockManager) Unregister(eb ExtensionBlock)
Unregister an ExtensionBlock type through an exemplary instance.
func (*ExtensionBlockManager) WriteBlock ¶
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 ¶
type GenericExtensionBlock struct {
// contains filtered or unexported fields
}
GenericExtensionBlock is a dummy ExtensionBlock to cover for unknown or unregistered ExtensionBlocks.
func NewGenericExtensionBlock ¶
func NewGenericExtensionBlock(data []byte, typeCode uint64) *GenericExtensionBlock
NewGenericExtensionBlock creates a new GenericExtensionBlock from some payload and a block type code.
func (*GenericExtensionBlock) BlockTypeCode ¶
func (geb *GenericExtensionBlock) BlockTypeCode() uint64
BlockTypeCode must return a constant integer, indicating the block type code.
func (*GenericExtensionBlock) BlockTypeName ¶
func (geb *GenericExtensionBlock) BlockTypeName() string
BlockTypeName must return a constant string, this block's name.
func (*GenericExtensionBlock) CheckValid ¶
func (geb *GenericExtensionBlock) CheckValid() error
CheckValid returns an array of errors for incorrect data.
func (*GenericExtensionBlock) MarshalBinary ¶
func (geb *GenericExtensionBlock) MarshalBinary() ([]byte, error)
MarshalBinary writes a binary representation of this block.
func (*GenericExtensionBlock) UnmarshalBinary ¶
func (geb *GenericExtensionBlock) UnmarshalBinary(data []byte) error
UnmarshalBinary reads a binary representation of a generic block.
type HopCountBlock ¶
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 ¶
func (hcb *HopCountBlock) BlockTypeCode() uint64
BlockTypeCode must return a constant integer, indicating the block type code.
func (*HopCountBlock) BlockTypeName ¶
func (hcb *HopCountBlock) BlockTypeName() string
BlockTypeName must return a constant string, this block's name.
func (*HopCountBlock) CheckValid ¶
func (hcb *HopCountBlock) CheckValid() error
CheckValid returns an array of errors for incorrect data.
func (*HopCountBlock) Increment ¶
func (hcb *HopCountBlock) Increment() bool
Increment the hop counter and returns if the hop limit is exceeded afterwards.
func (HopCountBlock) IsExceeded ¶
func (hcb HopCountBlock) IsExceeded() bool
IsExceeded returns true if the hop limit exceeded.
func (*HopCountBlock) MarshalCbor ¶
func (hcb *HopCountBlock) MarshalCbor(w io.Writer) error
MarshalCbor writes a CBOR representation of this Hop Count Block.
func (*HopCountBlock) MarshalJSON ¶
func (hcb *HopCountBlock) MarshalJSON() ([]byte, error)
MarshalJSON writes a JSON representation of this Hop Count Block.
func (*HopCountBlock) UnmarshalCbor ¶
func (hcb *HopCountBlock) UnmarshalCbor(r io.Reader) error
UnmarshalCbor reads a CBOR representation of a Hop Count Block.
type IpnEndpoint ¶
IpnEndpoint describes the ipn URI for EndpointIDs, as defined in RFC 6260.
func (IpnEndpoint) Authority ¶
func (e IpnEndpoint) Authority() string
Authority is the authority part of the Endpoint URI, e.g., "23" for "ipn:23.42".
func (IpnEndpoint) CheckValid ¶
func (e IpnEndpoint) CheckValid() error
CheckValid returns an array of errors for incorrect data.
func (IpnEndpoint) IsSingleton ¶
func (_ IpnEndpoint) IsSingleton() bool
IsSingleton checks if this Endpoint represents a singleton.
All IPN Endpoints are singletons by definition.
func (IpnEndpoint) MarshalCbor ¶
func (e IpnEndpoint) MarshalCbor(w io.Writer) error
MarshalCbor writes this IpnEndpoint's CBOR representation.
func (IpnEndpoint) Path ¶
func (e IpnEndpoint) Path() string
Path is the path part of the Endpoint URI, e.g., "42" for "ipn:23.42".
func (IpnEndpoint) SchemeName ¶
func (e IpnEndpoint) SchemeName() string
SchemeName is "ipn" for IpnEndpoints.
func (IpnEndpoint) SchemeNo ¶
func (e IpnEndpoint) SchemeNo() uint64
SchemeNo is 2 for IpnEndpoints.
func (IpnEndpoint) String ¶
func (e IpnEndpoint) String() string
func (*IpnEndpoint) UnmarshalCbor ¶
func (e *IpnEndpoint) UnmarshalCbor(r io.Reader) error
UnmarshalCbor reads a CBOR representation for an IpnEndpoint.
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 ¶
func (pb *PayloadBlock) BlockTypeCode() uint64
BlockTypeCode must return a constant integer, indicating the block type code.
func (*PayloadBlock) BlockTypeName ¶
func (pb *PayloadBlock) BlockTypeName() string
BlockTypeName must return a constant string, this block's name.
func (*PayloadBlock) CheckValid ¶
func (pb *PayloadBlock) CheckValid() error
CheckValid returns an array of errors for incorrect data.
func (*PayloadBlock) Data ¶
func (pb *PayloadBlock) Data() []byte
Data returns this PayloadBlock's payload.
func (*PayloadBlock) MarshalBinary ¶
func (pb *PayloadBlock) MarshalBinary() ([]byte, error)
MarshalBinary writes the binary representation of a PayloadBlock.
func (*PayloadBlock) MarshalJSON ¶
func (pb *PayloadBlock) MarshalJSON() ([]byte, error)
MarshalJSON writes the binary representation of a PayloadBlock.
If this type does not implement the json.Marshaler, the CBOR encoding would be returned which might be misleading.
func (*PayloadBlock) UnmarshalBinary ¶
func (pb *PayloadBlock) UnmarshalBinary(data []byte) error
UnmarshalBinary reads a binary PayloadBlock.
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 ¶
func (pnb *PreviousNodeBlock) BlockTypeCode() uint64
BlockTypeCode must return a constant integer, indicating the block type code.
func (*PreviousNodeBlock) BlockTypeName ¶
func (pnb *PreviousNodeBlock) BlockTypeName() string
BlockTypeName must return a constant string, this block's name.
func (*PreviousNodeBlock) CheckValid ¶
func (pnb *PreviousNodeBlock) CheckValid() error
CheckValid returns an array of errors for incorrect data.
func (*PreviousNodeBlock) Endpoint ¶
func (pnb *PreviousNodeBlock) Endpoint() EndpointID
Endpoint returns this Previous Node Block's Endpoint ID.
func (*PreviousNodeBlock) MarshalCbor ¶
func (pnb *PreviousNodeBlock) MarshalCbor(w io.Writer) error
MarshalCbor writes the CBOR representation of a PreviousNodeBlock.
func (*PreviousNodeBlock) MarshalJSON ¶
func (pnb *PreviousNodeBlock) MarshalJSON() ([]byte, error)
MarshalJSON writes the JSON representation of a PreviousNodeBlock.
func (*PreviousNodeBlock) UnmarshalCbor ¶
func (pnb *PreviousNodeBlock) UnmarshalCbor(r io.Reader) error
UnmarshalCbor reads a CBOR representation of a PreviousNodeBlock.
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.3.1.
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 passed in milliseconds.
func (PrimaryBlock) CheckValid ¶
func (pb PrimaryBlock) CheckValid() (errs error)
CheckValid returns an array of errors for incorrect data.
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.
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) MarshalCbor ¶
func (pb *PrimaryBlock) MarshalCbor(w io.Writer) error
MarshalCbor writes the CBOR representation of a PrimaryBlock.
func (PrimaryBlock) MarshalJSON ¶
func (pb PrimaryBlock) MarshalJSON() ([]byte, error)
MarshalJSON writes a JSON object representing this PrimaryBlock.
func (*PrimaryBlock) SetCRCType ¶
func (pb *PrimaryBlock) SetCRCType(crcType CRCType)
SetCRCType sets the CRC type.
While a primary block without a CRC might get parsed, created primary blocks MUST have a CRC value attached. Due to draft-bpbis-15 (and newer), all primary blocks require a CRC unless a block integrity block addressing the primary block is present. Thus, until BPsec is available in dtn7-go, all created primary blocks will have a mandatory CRC value.
func (PrimaryBlock) String ¶
func (pb PrimaryBlock) String() string
func (*PrimaryBlock) UnmarshalCbor ¶
func (pb *PrimaryBlock) UnmarshalCbor(r io.Reader) error
UnmarshalCbor reads the CBOR representation of a PrimaryBlock.
type ProphetBlock ¶
type ProphetBlock map[EndpointID]float64
ProphetBlock contains metadata used by the "PRoPHET" routing algorithm.
Each key-value pair represents the encounter probability between the sending node and other nodes in the network.
NOTE: This is a custom extension block, and not part of the original bpv7 specification. It is currently assigned the block type code 194, which the specification sets aside for "private and/or experimental use"
TODO: Turn this into an administrative record
func NewProphetBlock ¶
func NewProphetBlock(data map[EndpointID]float64) *ProphetBlock
func (*ProphetBlock) BlockTypeCode ¶
func (pBlock *ProphetBlock) BlockTypeCode() uint64
func (*ProphetBlock) BlockTypeName ¶
func (pBlock *ProphetBlock) BlockTypeName() string
func (ProphetBlock) CheckValid ¶
func (pBlock ProphetBlock) CheckValid() error
func (*ProphetBlock) GetPredictabilities ¶
func (pBlock *ProphetBlock) GetPredictabilities() map[EndpointID]float64
func (*ProphetBlock) MarshalCbor ¶
func (pBlock *ProphetBlock) MarshalCbor(w io.Writer) error
func (*ProphetBlock) UnmarshalCbor ¶
func (pBlock *ProphetBlock) UnmarshalCbor(r io.Reader) error
type SignatureBlock ¶
SignatureBlock is a custom block to sign a Bundle's Primary Block and Payload Block via ed25519.
The signature will be created for the concatenated CBOR representation of the Bundle's Primary Block and Payload Block using ed25519. Other blocks, like the Hop Count or Previous Node Block, might be altered on the way to the Bundle's destination. Therefore this signature is limited to these two blocks. It also follows that fragmented Bundles can neither be signed nor verified because the fragmentation offset is altered.
To create a SignatureBlock, a Bundle with a PayloadBlock needs to exist first. Afterwards, one needs to create a SignatureBlock for this Bundle and attach it to the Bundle.
b, bErr := bpv7.Builder()./* ... */.Build() sb, sbErr := bpv7.NewSignatureBlock(b, priv) b.AddExtensionBlock(bpv7.NewCanonicalBlock(0, bpv7.ReplicateBlock|bpv7.DeleteBundle, sb))
The block-type-specific data in a SignatureBlock MUST be represented as a CBOR array comprising two elements. These elements are firstly the PublicKey and secondly the Signature, both represented as a CBOR byte string. Both the array and the byte strings MUST be of a defined length, NOT indefinite-length items.
Although this block is present in the bpv7 package, it is NOT specified in ietf-dtn-bpbis. It might be removed once ietf-dtn-bpsec is implemented.
func NewSignatureBlock ¶
func NewSignatureBlock(b Bundle, priv ed25519.PrivateKey) (s *SignatureBlock, err error)
NewSignatureBlock for a Bundle from a private key.
func (*SignatureBlock) BlockTypeCode ¶
func (s *SignatureBlock) BlockTypeCode() uint64
BlockTypeCode must return a constant integer, indicating the block type code.
func (*SignatureBlock) BlockTypeName ¶
func (s *SignatureBlock) BlockTypeName() string
BlockTypeName must return a constant string, this block's name.
func (*SignatureBlock) CheckValid ¶
func (s *SignatureBlock) CheckValid() (err error)
CheckValid checks the field lengths for errors.
This DOES NOT verify the signature. Therefore please use the Verify method.
func (*SignatureBlock) MarshalCbor ¶
func (s *SignatureBlock) MarshalCbor(w io.Writer) error
MarshalCbor writes the CBOR representation of a SignatureBlock.
func (*SignatureBlock) UnmarshalCbor ¶
func (s *SignatureBlock) UnmarshalCbor(r io.Reader) error
UnmarshalCbor reads a CBOR representation of a SignatureBlock.
func (*SignatureBlock) Verify ¶
func (s *SignatureBlock) Verify(b Bundle) (valid bool)
Verify the signature against a Bundle.
type StatusInformationPos ¶
type StatusInformationPos int
StatusInformationPos describes the different bundle status information entries. Each bundle status report must contain at least the following bundle status items.
const ( // ReceivedBundle is the first bundle status information entry, indicating // the reporting node received this bundle. ReceivedBundle StatusInformationPos = 0 // ForwardedBundle is the second bundle status information entry, indicating // the reporting node forwarded this bundle. ForwardedBundle StatusInformationPos = 1 // DeliveredBundle is the third bundle status information entry, indicating // the reporting node delivered this bundle. DeliveredBundle StatusInformationPos = 2 // DeletedBundle is the fourth bundle status information entry, indicating // the reporting node deleted this bundle. DeletedBundle StatusInformationPos = 3 )
func (StatusInformationPos) String ¶
func (sip StatusInformationPos) String() string
type StatusReport ¶
type StatusReport struct { StatusInformation []BundleStatusItem ReportReason StatusReportReason RefBundle BundleID }
StatusReport is the bundle status report, used in an administrative record.
func NewStatusReport ¶
func NewStatusReport(bndl Bundle, statusItem StatusInformationPos, reason StatusReportReason, time DtnTime) (report *StatusReport)
NewStatusReport creates a bundle status report for the given bundle and StatusInformationPos, which creates the right bundle status item. The bundle status report reason code will be used and the bundle status item gets the given timestamp.
func (*StatusReport) MarshalCbor ¶
func (sr *StatusReport) MarshalCbor(w io.Writer) error
func (*StatusReport) RecordTypeCode ¶
func (sr *StatusReport) RecordTypeCode() uint64
func (StatusReport) StatusInformations ¶
func (sr StatusReport) StatusInformations() (sips []StatusInformationPos)
StatusInformations returns an array of available StatusInformationPos.
func (StatusReport) String ¶
func (sr StatusReport) String() string
func (*StatusReport) UnmarshalCbor ¶
func (sr *StatusReport) UnmarshalCbor(r io.Reader) error
type StatusReportReason ¶
type StatusReportReason uint64
StatusReportReason is the bundle status report reason code, which is used as the second element of the bundle status report array.
const ( // NoInformation is the "No additional information" bundle status report // reason code. NoInformation StatusReportReason = 0 // LifetimeExpired is the "Lifetime expired" bundle status report reason code. LifetimeExpired StatusReportReason = 1 // ForwardUnidirectionalLink is the "Forwarded over unidirectional link" // bundle status report reason code. ForwardUnidirectionalLink StatusReportReason = 2 // TransmissionCanceled is the "Transmission canceled" bundle status report // reason code. TransmissionCanceled StatusReportReason = 3 // DepletedStorage is the "Depleted storage" bundle status report reason code. DepletedStorage StatusReportReason = 4 // DestEndpointUnintelligible is the "Destination endpoint ID unintelligible" // bundle status report reason code. DestEndpointUnintelligible StatusReportReason = 5 // NoRouteToDestination is the "No known route to destination from here" // bundle status report reason code. NoRouteToDestination StatusReportReason = 6 // NoNextNodeContact is the "No timely contact with next node on route" bundle // status report reason code. NoNextNodeContact StatusReportReason = 7 // BlockUnintelligible is the "Block unintelligible" bundle status report // reason code. BlockUnintelligible StatusReportReason = 8 // HopLimitExceeded is the "Hop limit exceeded" bundle status report reason // code. HopLimitExceeded StatusReportReason = 9 // TrafficPared is the "Traffic pared (e.g., status reports)" bundle status // report reason code. TrafficPared StatusReportReason = 10 // BlockUnsupported is the "Block unsupported" bundle status report reason // code. BlockUnsupported StatusReportReason = 11 )
func (StatusReportReason) String ¶
func (srr StatusReportReason) String() string
type Valid ¶
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.
Source Files
¶
- 0doc.go
- administrative_record.go
- administrative_record_status_report.go
- block.go
- block_control_flags.go
- bundle.go
- bundle_builder.go
- bundle_control_flags.go
- bundle_id.go
- canonical_block.go
- canonical_block_sort.go
- crc.go
- endpoint.go
- endpoint_dtn.go
- endpoint_ipn.go
- extension_block.go
- extension_block_bundle_age.go
- extension_block_dtlsr.go
- extension_block_generic.go
- extension_block_hop_count.go
- extension_block_payload.go
- extension_block_previous_node.go
- extension_block_prophet.go
- extension_block_signature.go
- extension_block_spray.go
- fragmentation.go
- primary_block.go
- time.go
- valid.go