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