Skip to content

Commit

Permalink
rpcserver: Remove unneeded AddedNodeInfo method.
Browse files Browse the repository at this point in the history
The RPC server was refactored some time ago to decouple it from the
internals of the main server and part of that refactoring modified the
RPC server to make use of a local peer interface to obtain all necessary
information about peers which is then used to create RPC server results.
Due to that, the AddedNodeInfo and PersistentPeers methods now do the
exact same thing.

This modifies the rpcserver.ConnManager interface to remove the now
unnecessary AddedNodeInfo method in favor of the PersistentPeers method
and updates all relevant code accordingly.
  • Loading branch information
davecgh committed Apr 30, 2024
1 parent 63d36dd commit 29e11bd
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 52 deletions.
8 changes: 2 additions & 6 deletions internal/rpcserver/interface.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2023 The Decred developers
// Copyright (c) 2019-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -113,8 +113,7 @@ type ConnManager interface {
// ConnectedPeers returns an array consisting of all connected peers.
ConnectedPeers() []Peer

// PersistentPeers returns an array consisting of all the persistent
// peers.
// PersistentPeers returns an array consisting of all the persistent peers.
PersistentPeers() []Peer

// BroadcastMessage sends the provided message to all currently
Expand All @@ -130,9 +129,6 @@ type ConnManager interface {
// the passed transactions to all connected peers.
RelayTransactions(txns []*dcrutil.Tx)

// AddedNodeInfo returns information describing persistent (added) nodes.
AddedNodeInfo() []Peer

// Lookup defines the DNS lookup function to be used.
Lookup(host string) ([]net.IP, error)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/rpcserver/rpcserver.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2013-2016 The btcsuite developers
// Copyright (c) 2015-2023 The Decred developers
// Copyright (c) 2015-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -1795,7 +1795,7 @@ func handleGetAddedNodeInfo(_ context.Context, s *Server, cmd interface{}) (inte

// Retrieve a list of persistent (added) peers from the Decred server
// and filter the list of peers per the specified address (if any).
peers := s.cfg.ConnMgr.AddedNodeInfo()
peers := s.cfg.ConnMgr.PersistentPeers()
if c.Node != nil {
found := false
for i, peer := range peers {
Expand Down
14 changes: 1 addition & 13 deletions internal/rpcserver/rpcserverhandlers_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 The Decred developers
// Copyright (c) 2020-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -802,7 +802,6 @@ type testConnManager struct {
netTotalSent uint64
connectedPeers []Peer
persistentPeers []Peer
addedNodeInfo []Peer
lookup func(host string) ([]net.IP, error)
}

Expand Down Expand Up @@ -870,11 +869,6 @@ func (c *testConnManager) AddRebroadcastInventory(iv *wire.InvVect, data interfa
// inventory vectors for all of the passed transactions to all connected peers.
func (c *testConnManager) RelayTransactions(txns []*dcrutil.Tx) {}

// AddedNodeInfo returns a mocked slice of persistent (added) peers.
func (c *testConnManager) AddedNodeInfo() []Peer {
return c.addedNodeInfo
}

// Lookup defines a mocked DNS lookup function to be used.
func (c *testConnManager) Lookup(host string) ([]net.IP, error) {
return c.lookup(host)
Expand Down Expand Up @@ -1704,12 +1698,6 @@ func defaultMockConnManager() *testConnManager {
testPeer3,
testPeer4,
},
addedNodeInfo: []Peer{
testPeer1,
testPeer2,
testPeer3,
testPeer4,
},
lookup: func(host string) ([]net.IP, error) {
if host == "mydomain.org" {
return []net.IP{net.ParseIP("127.0.0.211")}, nil
Expand Down
20 changes: 2 additions & 18 deletions rpcadaptors.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2017 The btcsuite developers
// Copyright (c) 2015-2022 The Decred developers
// Copyright (c) 2015-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -247,7 +247,7 @@ func (cm *rpcConnManager) PersistentPeers() []rpcserver.Peer {
cm.server.query <- getAddedNodesMsg{reply: replyChan}
serverPeers := <-replyChan

// Convert to generic peers.
// Convert to RPC server peers.
peers := make([]rpcserver.Peer, 0, len(serverPeers))
for _, sp := range serverPeers {
peers = append(peers, (*rpcPeer)(sp))
Expand Down Expand Up @@ -282,22 +282,6 @@ func (cm *rpcConnManager) RelayTransactions(txns []*dcrutil.Tx) {
cm.server.relayTransactions(txns)
}

// AddedNodeInfo returns information describing persistent (added) nodes.
//
// This function is safe for concurrent access and is part of the
// rpcserver.ConnManager interface implementation.
func (cm *rpcConnManager) AddedNodeInfo() []rpcserver.Peer {
serverPeers := cm.server.AddedNodeInfo()

// Convert to RPC server peers.
peers := make([]rpcserver.Peer, 0, len(serverPeers))
for _, sp := range serverPeers {
peers = append(peers, (*rpcPeer)(sp))
}

return peers
}

// Lookup defines the DNS lookup function to be used.
//
// This function is safe for concurrent access and is part of the
Expand Down
14 changes: 1 addition & 13 deletions server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2013-2016 The btcsuite developers
// Copyright (c) 2015-2023 The Decred developers
// Copyright (c) 2015-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -2550,18 +2550,6 @@ func (s *server) OutboundGroupCount(key string) int {
}
}

// AddedNodeInfo returns an array of dcrjson.GetAddedNodeInfoResult structures
// describing the persistent (added) nodes.
func (s *server) AddedNodeInfo() []*serverPeer {
replyChan := make(chan []*serverPeer)
select {
case <-s.quit:
return nil
case s.query <- getAddedNodesMsg{reply: replyChan}:
return <-replyChan
}
}

// AddBytesSent adds the passed number of bytes to the total bytes sent counter
// for the server. It is safe for concurrent access.
func (s *server) AddBytesSent(bytesSent uint64) {
Expand Down

0 comments on commit 29e11bd

Please sign in to comment.