peer: don't use global cfg

This commit is contained in:
Oliver Gugger 2020-05-14 14:26:07 +02:00
parent 4343f9e9a6
commit 7c1304b31c
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 10 additions and 6 deletions

14
peer.go

@ -114,6 +114,8 @@ type peer struct {
started int32 started int32
disconnect int32 disconnect int32
cfg *Config
// The following fields are only meant to be used *atomically* // The following fields are only meant to be used *atomically*
bytesReceived uint64 bytesReceived uint64
bytesSent uint64 bytesSent uint64
@ -263,7 +265,7 @@ var _ lnpeer.Peer = (*peer)(nil)
// pointer to the main server. It takes an error buffer which may contain errors // pointer to the main server. It takes an error buffer which may contain errors
// from a previous connection with the peer if we have been connected to them // from a previous connection with the peer if we have been connected to them
// before. // before.
func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server, func newPeer(cfg *Config, conn net.Conn, connReq *connmgr.ConnReq, server *server,
addr *lnwire.NetAddress, inbound bool, addr *lnwire.NetAddress, inbound bool,
features, legacyFeatures *lnwire.FeatureVector, features, legacyFeatures *lnwire.FeatureVector,
chanActiveTimeout time.Duration, chanActiveTimeout time.Duration,
@ -277,6 +279,8 @@ func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
conn: conn, conn: conn,
addr: addr, addr: addr,
cfg: cfg,
activeSignal: make(chan struct{}), activeSignal: make(chan struct{}),
inbound: inbound, inbound: inbound,
@ -651,7 +655,7 @@ func (p *peer) addLink(chanPoint *wire.OutPoint,
DecodeHopIterators: p.server.sphinx.DecodeHopIterators, DecodeHopIterators: p.server.sphinx.DecodeHopIterators,
ExtractErrorEncrypter: p.server.sphinx.ExtractErrorEncrypter, ExtractErrorEncrypter: p.server.sphinx.ExtractErrorEncrypter,
FetchLastChannelUpdate: p.server.fetchLastChanUpdate(), FetchLastChannelUpdate: p.server.fetchLastChanUpdate(),
HodlMask: cfg.Hodl.Mask(), HodlMask: p.cfg.Hodl.Mask(),
Registry: p.server.invoices, Registry: p.server.invoices,
Switch: p.server.htlcSwitch, Switch: p.server.htlcSwitch,
Circuits: p.server.htlcSwitch.CircuitModifier(), Circuits: p.server.htlcSwitch.CircuitModifier(),
@ -671,13 +675,13 @@ func (p *peer) addLink(chanPoint *wire.OutPoint,
FwdPkgGCTicker: ticker.New(time.Minute), FwdPkgGCTicker: ticker.New(time.Minute),
PendingCommitTicker: ticker.New(time.Minute), PendingCommitTicker: ticker.New(time.Minute),
BatchSize: 10, BatchSize: 10,
UnsafeReplay: cfg.UnsafeReplay, UnsafeReplay: p.cfg.UnsafeReplay,
MinFeeUpdateTimeout: htlcswitch.DefaultMinLinkFeeUpdateTimeout, MinFeeUpdateTimeout: htlcswitch.DefaultMinLinkFeeUpdateTimeout,
MaxFeeUpdateTimeout: htlcswitch.DefaultMaxLinkFeeUpdateTimeout, MaxFeeUpdateTimeout: htlcswitch.DefaultMaxLinkFeeUpdateTimeout,
OutgoingCltvRejectDelta: p.outgoingCltvRejectDelta, OutgoingCltvRejectDelta: p.outgoingCltvRejectDelta,
TowerClient: p.server.towerClient, TowerClient: p.server.towerClient,
MaxOutgoingCltvExpiry: cfg.MaxOutgoingCltvExpiry, MaxOutgoingCltvExpiry: p.cfg.MaxOutgoingCltvExpiry,
MaxFeeAllocation: cfg.MaxChannelFeeAllocation, MaxFeeAllocation: p.cfg.MaxChannelFeeAllocation,
NotifyActiveLink: p.server.channelNotifier.NotifyActiveLinkEvent, NotifyActiveLink: p.server.channelNotifier.NotifyActiveLinkEvent,
NotifyActiveChannel: p.server.channelNotifier.NotifyActiveChannelEvent, NotifyActiveChannel: p.server.channelNotifier.NotifyActiveChannelEvent,
NotifyInactiveChannel: p.server.channelNotifier.NotifyInactiveChannelEvent, NotifyInactiveChannel: p.server.channelNotifier.NotifyInactiveChannelEvent,

@ -2788,7 +2788,7 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
// htlcs, an extra block is added to prevent the channel from being // htlcs, an extra block is added to prevent the channel from being
// closed when the htlc is outstanding and a new block comes in. // closed when the htlc is outstanding and a new block comes in.
p, err := newPeer( p, err := newPeer(
conn, connReq, s, peerAddr, inbound, initFeatures, s.cfg, conn, connReq, s, peerAddr, inbound, initFeatures,
legacyFeatures, s.cfg.ChanEnableTimeout, legacyFeatures, s.cfg.ChanEnableTimeout,
lncfg.DefaultOutgoingCltvRejectDelta, errBuffer, lncfg.DefaultOutgoingCltvRejectDelta, errBuffer,
) )