server: initialize server with persistent sphinx router

This commit is contained in:
Conner Fromknecht 2018-02-23 17:33:05 -08:00
parent c2ec3a6ef5
commit a4d8b30367
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF

@ -9,6 +9,7 @@ import (
"image/color" "image/color"
"math/big" "math/big"
"net" "net"
"path/filepath"
"strconv" "strconv"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -151,6 +152,15 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
globalFeatures := lnwire.NewRawFeatureVector() globalFeatures := lnwire.NewRawFeatureVector()
serializedPubKey := privKey.PubKey().SerializeCompressed() serializedPubKey := privKey.PubKey().SerializeCompressed()
// Initialize the sphinx router, placing it's persistent replay log in
// the same directory as the channel graph database.
graphDir := filepath.Dir(chanDB.Path())
sharedSecretPath := filepath.Join(graphDir, "sphinxreplay.db")
sphinxRouter := sphinx.NewRouter(
sharedSecretPath, privKey, activeNetParams.Params, cc.chainNotifier,
)
s := &server{ s := &server{
chanDB: chanDB, chanDB: chanDB,
cc: cc, cc: cc,
@ -162,8 +172,7 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
// TODO(roasbeef): derive proper onion key based on rotation // TODO(roasbeef): derive proper onion key based on rotation
// schedule // schedule
sphinx: htlcswitch.NewOnionProcessor( sphinx: htlcswitch.NewOnionProcessor(sphinxRouter),
sphinx.NewRouter(privKey, activeNetParams.Params)),
lightningID: sha256.Sum256(serializedPubKey), lightningID: sha256.Sum256(serializedPubKey),
persistentPeers: make(map[string]struct{}), persistentPeers: make(map[string]struct{}),
@ -491,7 +500,9 @@ func (s *server) Start() error {
if err := s.cc.chainNotifier.Start(); err != nil { if err := s.cc.chainNotifier.Start(); err != nil {
return err return err
} }
if err := s.sphinx.Start(); err != nil {
return err
}
if err := s.htlcSwitch.Start(); err != nil { if err := s.htlcSwitch.Start(); err != nil {
return err return err
} }
@ -554,6 +565,7 @@ func (s *server) Stop() error {
s.cc.chainNotifier.Stop() s.cc.chainNotifier.Stop()
s.chanRouter.Stop() s.chanRouter.Stop()
s.htlcSwitch.Stop() s.htlcSwitch.Stop()
s.sphinx.Stop()
s.utxoNursery.Stop() s.utxoNursery.Stop()
s.breachArbiter.Stop() s.breachArbiter.Stop()
s.authGossiper.Stop() s.authGossiper.Stop()