lnd: hook up encrypted onion error scaffolding

In this commit daemon have been changed to set the proper hooks in the
channel link and switch subsystems so that they could send and receive
encrypted onion errors.
This commit is contained in:
Andrey Samokhvalov authored and Olaoluwa Osuntokun committed 2017-07-14 19:08:04 -07:00
1 parent 2d378b3280
commit 6bbb7cbfc3
2 files changed
+62 -10

No files matched your search

+13 -4
View File
@@ -71,7 +71,7 @@ type server struct {
utxoNursery *utxoNursery
sphinx *sphinx.Router
sphinx *htlcswitch.OnionProcessor
connMgr *connmgr.ConnManager
@@ -126,7 +126,8 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
// TODO(roasbeef): derive proper onion key based on rotation
// schedule
sphinx: sphinx.NewRouter(privKey, activeNetParams.Params),
sphinx: htlcswitch.NewOnionProcessor(
sphinx.NewRouter(privKey, activeNetParams.Params)),
lightningID: sha256.Sum256(serializedPubKey),
persistentPeers: make(map[string]struct{}),
@@ -236,11 +237,19 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
Chain: cc.chainIO,
ChainView: cc.chainView,
SendToSwitch: func(firstHop *btcec.PublicKey,
htlcAdd *lnwire.UpdateAddHTLC) ([32]byte, error) {
htlcAdd *lnwire.UpdateAddHTLC,
circuit *sphinx.Circuit) ([32]byte, error) {
// Initialize the data obfuscator in order to be able to decode the
// onion failure and wrap it so that we could process lnwire onion
// failures.
failureDeobfuscator := &htlcswitch.FailureDeobfuscator{
OnionDeobfuscator: sphinx.NewOnionDeobfuscator(circuit),
}
var firstHopPub [33]byte
copy(firstHopPub[:], firstHop.SerializeCompressed())
return s.htlcSwitch.SendHTLC(firstHopPub, htlcAdd)
return s.htlcSwitch.SendHTLC(firstHopPub, htlcAdd, failureDeobfuscator)
},
})
if err != nil {