Commit Graph

19 Commits

Author SHA1 Message Date
Conner Fromknecht
1b2c9a02b5
record+tlv/onion_types: move type constants to route/hop 2019-09-04 12:05:10 -07:00
Olaoluwa Osuntokun
5b4c8ac232
routing/route+tlv: add new TLV-EOB awareness to Hop+Route
In this commit, we extend the Hop struct to carry an arbitrary set of
TLV values, and add a new field that allows us to distinguish between
the modern and legacy TLV payload.

We add a new `PackPayload` method that will be used to encode the
combined required routing TLV fields along any set of TLV fields that
were specified as part of path finding.

Finally, the `ToSphinxPath` has been extended to be able to recognize if
a hop needs the modern, or legacy payload.
2019-08-22 18:53:00 -07:00
Olaoluwa Osuntokun
e60b36751c
tlv: display the unknown primitive type in MakePrimitiveRecord error message 2019-08-22 18:52:59 -07:00
Olaoluwa Osuntokun
aea529d9f6
tlv: add new Type() and Encode() methods to Record
In this commit, we add two new method so the `Record` struct: Type() and
Encode(). These are useful when a caller is handling a record and may
not know its underlying type and may need to encode a record in
isolation.
2019-08-22 18:52:58 -07:00
Conner Fromknecht
1cc48ceaf5
tlv/stream: create MaxRecordSize, remove lnwire import, add test 2019-08-21 18:12:57 -07:00
nsa
dfd1b38648
tlv: fix panic with large length
This commit fixes a panic where a large length in a record could
cause the DVarBytes function to fail to allocate a byte slice.
2019-08-21 16:48:23 -07:00
Conner Fromknecht
da7cb2d42a
tlv/primitive: use constructor for encoding/decoding type err 2019-08-08 15:57:48 -07:00
Conner Fromknecht
474ddc98ed
tlv/primitive_test: add basic encode/decode tests for primitives 2019-08-08 15:57:48 -07:00
Conner Fromknecht
e6fdfbb1cb
tlv/truncated: fix decoding bug in DTUint16 and DTUint32
This commit fixes a bug in DTUint16 and DTUint32, which would cause them
to read too many bytes from the reader. This is due to the fact that
ReadFull was being called on a slice that could be greater than the
underlying type. This is not an issue for DTUint64, since the 8-byte
buffer corresponds to the maximum possible size of a uint64. The
solution is to clamp the buffer to 2 and 4 bytes respectively.

A series of tests are also added to exercise these cases.
2019-08-07 19:42:15 -07:00
Conner Fromknecht
32bb9917f9
tlv/truncated_test: add tests for SizeTuintXX methods 2019-08-07 19:38:57 -07:00
Conner Fromknecht
3690999511
tlv/tlv_test: add BOLT1 test vectors 2019-08-07 15:04:45 -07:00
Conner Fromknecht
7c94bbb4a2
tlv/truncated: add truncated integer encodings
This commit adds the truncated integer encodings used in the
variable-size onion payloads. The amount and cltv delta both use the
truncated encoding to shave bytes in the overall size, and will likely
be used in the future for additional extensions where size is a
constraint.
2019-08-07 15:04:33 -07:00
Conner Fromknecht
abdcd47dcc
tlv/bench_test: add basic benchmark 2019-08-07 15:04:20 -07:00
Conner Fromknecht
a0ebaeaa6c
tlv: zero alloc encoding for extended types
This commit adds concrete encoding methods for primitive integral types.
When external libs need to create custom encoders, this allows them to
do so without incurring an extra allocation on the heap. Previously, the
need to pass a pointer to the integer using an interface{} would cause
the argument to escape, which we avoid by having them copied directly.
2019-08-07 15:04:08 -07:00
Conner Fromknecht
bc1f23d98a
tlv/stream: adds tlv stream encoding/decoding 2019-08-07 15:03:56 -07:00
Conner Fromknecht
96e0bb1411
tlv/record: adds various tlv record constructors 2019-08-07 15:03:43 -07:00
Conner Fromknecht
6773d4770a
tlv/primitive: add primitive encodings 2019-08-07 15:03:30 -07:00
Conner Fromknecht
75fcf1cee1
tlv/varint_test: add tests vectors for custom Read/WriteVarInt 2019-08-07 15:03:18 -07:00
Conner Fromknecht
3afcb1f224
tlv/varint: add modified bitcoin varint
This varint has the same serialization as the varint in btcd and
bitcoind, but has different behavior wrt returned errors. In order to
ensure the inner loop properly detects cleanly written records,
ReadVarInt will not only return EOF if it can't read the first byte, as
that means the reader has zero bytes left.

It also modifies the API to allow the caller to provided a static byte
array, which can be reused across all encoding and decoding and
increases performance.
2019-08-07 15:03:05 -07:00