mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 14:45:23 +01:00
peer: add localFeatures as parameter to newPeer
In this commit we add the set of local features advertised as a parameter to the newPeer function. With this change, the server will be able to programmatically determine _which_ bits should be set on a connection basis, rather than re-using the same global set of bits for each peer.
This commit is contained in:
parent
f6f983a13b
commit
56d4c15914
10
peer.go
10
peer.go
@ -147,6 +147,9 @@ type peer struct {
|
||||
|
||||
server *server
|
||||
|
||||
// localFeatures is the set of local features that we advertised to the
|
||||
// remote node.
|
||||
localFeatures *lnwire.RawFeatureVector
|
||||
|
||||
// remoteLocalFeatures is the local feature vector received from the
|
||||
// peer during the connection handshake.
|
||||
@ -164,7 +167,8 @@ type peer struct {
|
||||
// newPeer creates a new peer from an establish connection object, and a
|
||||
// pointer to the main server.
|
||||
func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
|
||||
addr *lnwire.NetAddress, inbound bool) (*peer, error) {
|
||||
addr *lnwire.NetAddress, inbound bool,
|
||||
localFeatures *lnwire.RawFeatureVector) (*peer, error) {
|
||||
|
||||
nodePub := addr.IdentityKey
|
||||
|
||||
@ -178,6 +182,8 @@ func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
|
||||
|
||||
server: server,
|
||||
|
||||
localFeatures: localFeatures,
|
||||
|
||||
sendQueue: make(chan outgoinMsg),
|
||||
sendQueueSync: make(chan struct{}),
|
||||
outgoingQueue: make(chan outgoinMsg),
|
||||
@ -1967,7 +1973,7 @@ func (p *peer) handleInitMsg(msg *lnwire.Init) error {
|
||||
func (p *peer) sendInitMsg() error {
|
||||
msg := lnwire.NewInitMessage(
|
||||
p.server.globalFeatures.RawFeatureVector,
|
||||
p.server.localFeatures.RawFeatureVector,
|
||||
p.localFeatures,
|
||||
)
|
||||
|
||||
return p.writeMessage(msg)
|
||||
|
31
server.go
31
server.go
@ -102,10 +102,6 @@ type server struct {
|
||||
// advertised to other nodes.
|
||||
globalFeatures *lnwire.FeatureVector
|
||||
|
||||
// localFeatures is an feature vector which represent the features
|
||||
// which only affect the protocol between these two nodes.
|
||||
localFeatures *lnwire.FeatureVector
|
||||
|
||||
// currentNodeAnn is the node announcement that has been broadcast to
|
||||
// the network upon startup, if the attributes of the node (us) has
|
||||
// changed since last start.
|
||||
@ -132,7 +128,6 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
}
|
||||
|
||||
globalFeatures := lnwire.NewRawFeatureVector()
|
||||
localFeatures := lnwire.NewRawFeatureVector(lnwire.InitialRoutingSync)
|
||||
|
||||
serializedPubKey := privKey.PubKey().SerializeCompressed()
|
||||
s := &server{
|
||||
@ -164,9 +159,6 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
||||
|
||||
globalFeatures: lnwire.NewFeatureVector(globalFeatures,
|
||||
lnwire.GlobalFeatures),
|
||||
localFeatures: lnwire.NewFeatureVector(localFeatures,
|
||||
lnwire.LocalFeatures),
|
||||
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
|
||||
@ -1100,9 +1092,12 @@ func (s *server) peerConnected(conn net.Conn, connReq *connmgr.ConnReq,
|
||||
ChainNet: activeNetParams.Net,
|
||||
}
|
||||
|
||||
// Now that we've established a connection, create a peer, and
|
||||
// it to the set of currently active peers.
|
||||
p, err := newPeer(conn, connReq, s, peerAddr, inbound)
|
||||
// With the brontide connection established, we'll now craft the local
|
||||
// feature vector to advertise to the remote node.
|
||||
localFeatures := lnwire.NewRawFeatureVector()
|
||||
// Now that we've established a connection, create a peer, and it to
|
||||
// the set of currently active peers.
|
||||
p, err := newPeer(conn, connReq, s, peerAddr, inbound, localFeatures)
|
||||
if err != nil {
|
||||
srvrLog.Errorf("unable to create peer %v", err)
|
||||
return
|
||||
@ -1335,16 +1330,16 @@ func (s *server) addPeer(p *peer) {
|
||||
// Launch a goroutine to watch for the unexpected termination of this
|
||||
// peer, which will ensure all resources are properly cleaned up, and
|
||||
// re-establish persistent connections when necessary. The peer
|
||||
// termination watcher will be short circuited if the peer is ever added
|
||||
// to the ignorePeerTermination map, indicating that the server has
|
||||
// already handled the removal of this peer.
|
||||
// termination watcher will be short circuited if the peer is ever
|
||||
// added to the ignorePeerTermination map, indicating that the server
|
||||
// has already handled the removal of this peer.
|
||||
s.wg.Add(1)
|
||||
go s.peerTerminationWatcher(p)
|
||||
|
||||
if p.theirLocalFeatures.HasFeature(lnwire.InitialRoutingSync) {
|
||||
// Once the peer has been added to our indexes, send a message to the
|
||||
// channel router so we can synchronize our view of the channel graph
|
||||
// with this new peer.
|
||||
// If the remote peer has the initial sync feature bit set, then we'll
|
||||
// being the synchronization protocol to exchange authenticated channel
|
||||
// graph edges/vertexes
|
||||
if p.remoteLocalFeatures.HasFeature(lnwire.InitialRoutingSync) {
|
||||
go s.authGossiper.SynchronizeNode(p.addr.IdentityKey)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user