Documentation ¶
Index ¶
- Constants
- Variables
- type ExpTimeType
- type HopField
- func (h *HopField) CalcMac(mac hash.Hash, tsInt uint32, prev common.RawBytes) common.RawBytes
- func (h *HopField) Equal(o *HopField) bool
- func (h *HopField) Pack() common.RawBytes
- func (h *HopField) String() string
- func (h *HopField) Verify(macH hash.Hash, tsInt uint32, prev common.RawBytes) error
- func (h *HopField) Write(b common.RawBytes)
- func (h *HopField) WriteTo(w io.Writer) (int64, error)
- type InfoField
- type Path
Constants ¶
const ( HopFieldLength = common.LineLen DefaultHopFExpiry = ExpTimeType(63) MacLen = 3 XoverMask = 0x01 VerifyOnlyMask = 0x02 MaxTTL = 24 * 60 * 60 // One day in seconds ExpTimeUnit = MaxTTL / 256 // ~5m38s MaxTTLField = ExpTimeType(math.MaxUint8) )
const ErrInfoFTooShort common.ErrMsg = "InfoF too short"
ErrInfoFTooShort indicates that the info field is to short to be parsed.
const InfoFieldLength = common.LineLen
InfoFieldLength is the length of the info field.
const (
MaxTimestamp = math.MaxUint32
)
Variables ¶
var ( ErrorHopFTooShort = serrors.New("HopF too short") ErrorHopFBadMac = serrors.New("Bad HopF MAC") )
var ( // MaxExpirationTime is the maximum absolute expiration time of SCION hop // fields. MaxExpirationTime = time.Unix(MaxTimestamp, 0).Add(MaxTTLField.ToDuration()) )
Functions ¶
This section is empty.
Types ¶
type ExpTimeType ¶ added in v0.2.0
type ExpTimeType uint8
ExpTimeType describes the relative expiration time of the hop field.
func ExpTimeFromDuration ¶ added in v0.4.0
func ExpTimeFromDuration(duration time.Duration, roundUp bool) (ExpTimeType, error)
ExpTimeFromDuration converts a time duration to the relative expiration time.
Round Up Mode:
The round up mode guarantees that the resulting relative expiration time is more than the provided duration. The duration is rounded up to the next unit, and then 1 is subtracted from the result, e.g. 1.3 is rounded to 1. In case the requested duration exceeds the maximum value for the expiration time (256*Unit) in this mode, an error is returned.
Round Down Mode:
The round down mode guarantees that the resulting relative expiration time is less than the provided duration. The duration is rounded down to the next unit, and then 1 is subtracted from the result, e.g. 1.3 is rounded to 0. In case the requested duration is below the unit for the expiration time in this mode, an error is returned.
func (ExpTimeType) ToDuration ¶ added in v0.2.0
func (e ExpTimeType) ToDuration() time.Duration
ToDuration calculates the relative expiration time in seconds. Note that for a 0 value ExpTime, the minimal duration is ExpTimeUnit.
type HopField ¶
type HopField struct { Xover bool VerifyOnly bool // ExpTime defines for how long this HopField is valid, expressed as the number // of ExpTimeUnits relative to the PathSegments's InfoField.Timestamp(). // A 0 value means the minimum expiration time of ExpTimeUnit. // See ToDuration() for how to convert from ExpTimeUnits to Seconds. ExpTime ExpTimeType // ConsIngress is the interface the PCB entered the AS during path construction. ConsIngress common.IFIDType // ConsEgress is the interface the PCB exited the AS during path construction. ConsEgress common.IFIDType // Mac is the message authentication code of this HF, // see CalcMac() to see how it should be calculated. Mac common.RawBytes }
Hop Field format:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |r r r r r r V X| ExpTime | ConsIngress | ... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ...ConsEgress | MAC | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The absolute expiration time in seconds of a Hop Field is calculated as:
TS + ( (1 + ExpTime) * ExpTimeUnit ), where TS is the Info Field Timestamp.
func HopFFromRaw ¶
HopFFromRaw returns a HopField object from the raw content in b.
func (*HopField) CalcMac ¶
CalcMac calculates the MAC of a HopField and its preceding HopField, if any. prev does not contain flags byte. This implies that the length of prev can either be 0 or k*8+7, where k >=0. WARN: If prev is of different length, this function panics.
MAC input block format:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Timestamp | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 0 | ExpTime | ConsIngress | ... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ...ConsEgress | | +-+-+-+-+-+-+-+-+ | | PrevHopF | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
type InfoField ¶
type InfoField struct { // Previously Up, ConsDir = !Up ConsDir bool Shortcut bool Peer bool // TsInt is the timestamp that denotes when the propagation of a path segment started. // Use Timestamp() to get a time.Time value. TsInt uint32 // ISD denotes the origin ISD of a path segment. ISD uint16 Hops uint8 }
InfoField hast the following format:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |r r r r r P S C| Timestamp ... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ... | ISD | Hops | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
func InfoFFromRaw ¶
type Path ¶
type Path struct { Raw common.RawBytes InfOff int // Offset of current Info Field HopOff int // Offset of current Hop Field }
func NewOneHop ¶ added in v0.4.0
func NewOneHop(isd addr.ISD, ifid common.IFIDType, ts time.Time, exp ExpTimeType, hfmac hash.Hash) *Path
NewOneHop creates a new one hop path with. If necessary, the caller has to initialize the offsets.
func (*Path) IncOffsets ¶
IncOffsets updates the info and hop indices to the next routing field, while skipping verify only fields.
func (*Path) InitOffsets ¶
InitOffsets computes the initial Hop Field offset (in bytes) for a newly created packet.