Skip to content

Commit 9f7dc6e

Browse files
committed
Add Init TLV codecs
1 parent 1b2daaa commit 9f7dc6e

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2019 ACINQ SAS
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package fr.acinq.eclair.wire
18+
19+
import fr.acinq.bitcoin.ByteVector32
20+
import fr.acinq.eclair.UInt64
21+
import fr.acinq.eclair.wire.CommonCodecs._
22+
import scodec.Codec
23+
import scodec.codecs.{discriminated, list, variableSizeBytesLong}
24+
25+
/**
26+
* Created by t-bast on 13/12/2019.
27+
*/
28+
29+
/** Tlv types used inside Init messages. */
30+
sealed trait InitTlv extends Tlv
31+
32+
object InitTlv {
33+
34+
/** The chains the node is interested in. */
35+
case class Networks(chainHashes: List[ByteVector32]) extends InitTlv
36+
37+
}
38+
39+
object InitTlvCodecs {
40+
41+
import InitTlv._
42+
43+
// TODO: wire test-cases:
44+
// * Init not containing any tlv stream
45+
// * Init containing tlv stream without networks (other odd records)
46+
// * Init containing tlv stream without networks (other even records)
47+
// * Init containing tlv stream with networks only
48+
// * Init containing tlv stream with networks and other odd records)
49+
// * Init containing tlv stream with networks and other even records)
50+
51+
// TODO:
52+
// * Add to the Init message after flat features merged
53+
// * Send the chainHash from nodeParams when creating Init
54+
// * Add logic to Peer.scala to fail connections to others that don't offer my chainHash
55+
56+
private val networks: Codec[Networks] = variableSizeBytesLong(varintoverflow, list(bytes32)).as[Networks]
57+
58+
val initTlvCodec = discriminated[InitTlv].by(varint)
59+
.typecase(UInt64(1), networks)
60+
61+
}

0 commit comments

Comments
 (0)