// NewHopPayload creates a new hop payload given an optional set of forwarding
// instructions for a hop, and a set of optional opaque extra onion bytes to
// drop off at the target hop. If both values are not specified, then an error
// is returned.
NewHopPayload creates a new hop payload given an optional set of forwarding
instructions for a hop, and a set of optional opaque extra onion bytes to
drop off at the target hop. If both values are not specified, then an error
is returned.
// NewHopPayload creates a new hop payload given an optional set of forwarding // instructions for a hop and a set of optional opaque extra onion bytes to // drop off at the target hop . If both values are not specified then an error // is returned .
func NewHopPayload(hopData *HopData, eob []byte) (HopPayload, error) {
	var (
		h HopPayload
		b bytes.Buffer
	)
	switch {
	case hopData == nil && len(eob) == 0:
		return h, fmt.Errorf("either hop data or eob must " +
			"be specified")
	case hopData != nil && len(eob) > 0:
		return h, fmt.Errorf("cannot provide both hop data AND an eob")
	}
	if hopData != nil {
		if err := hopData.Encode(&b); err != nil {
			return h, nil
		}
		h.Type = PayloadLegacy
	} else {
		if _, err := b.Write(eob); err != nil {
			return h, nil
		}
		h.Type = PayloadTLV
	}
	h.Payload = b.Bytes()
	return h, nil
}
func NewHopPayload ( hopData * HopData , eob [ ] byte ) ( HopPayload , error ) { var ( h HopPayload b bytes . Buffer ) switch { case hopData == nil && len ( eob ) == 0 : return h , fmt . Errorf ( " " + " " ) case hopData != nil && len ( eob ) > 0 : return h , fmt . Errorf ( " " ) } if hopData != nil { if err := hopData . Encode ( & b ) ; err != nil { return h , nil } h . Type = PayloadLegacy } else { if _ , err := b . Write ( eob ) ; err != nil { return h , nil } h . Type = PayloadTLV } h . Payload = b . Bytes ( ) return h , nil }
NewHopPayload creates a new hop payload given an optional set of forwarding
instructions for a hop, and a set of optional opaque extra onion bytes to
drop off at the target hop.
NewHopPayload creates a new hop payload given an optional set of forwarding instructions for a hop and a set of optional opaque extra onion bytes to drop off at the target hop .
// We can't proceed if neither the hop data or the EOB has been // specified by the caller. // If the hop data is specified, then we'll write that now, as it // should proceed the EOB portion of the payload. // We'll also mark that this particular hop will be using the // legacy format as the modern format packs the existing hop // data information into the EOB space as a TLV stream. // Otherwise, we'll write out the raw EOB which contains a set // of opaque bytes that the recipient can decode to make a // forwarding decision.