-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Only read relevant nodes from database in PeerChangedResponse #2509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
af04eb5
67bdd19
619ca9f
c1d57c7
e3d44d3
e0df114
cf70643
03e892c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ package mapper | |
| import ( | ||
| "encoding/binary" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "gorm.io/gorm" | ||
| "io/fs" | ||
| "net/url" | ||
| "os" | ||
|
|
@@ -257,11 +259,6 @@ func (m *Mapper) PeerChangedResponse( | |
| ) ([]byte, error) { | ||
| resp := m.baseMapResponse() | ||
|
|
||
| peers, err := m.ListPeers(node.ID) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree this is not necessary, but instead of listing all, we should just list the one from the change map. It would make more sense to make
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opted against changing
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think modifying both |
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var removedIDs []tailcfg.NodeID | ||
| var changedIDs []types.NodeID | ||
| for nodeID, nodeChanged := range changed { | ||
|
|
@@ -273,13 +270,21 @@ func (m *Mapper) PeerChangedResponse( | |
| } | ||
|
|
||
| changedNodes := make(types.Nodes, 0, len(changedIDs)) | ||
| for _, peer := range peers { | ||
| if slices.Contains(changedIDs, peer.ID) { | ||
| changedNodes = append(changedNodes, peer) | ||
| for _, changedID := range changedIDs { | ||
| if changedID != node.ID { | ||
| changedNode, err := m.GetNode(changedID) | ||
|
||
| if err != nil { | ||
| if errors.Is(err, gorm.ErrRecordNotFound) { | ||
| continue | ||
| } else { | ||
| return nil, err | ||
| } | ||
| } | ||
| changedNodes = append(changedNodes, changedNode) | ||
| } | ||
| } | ||
|
|
||
| err = appendPeerChanges( | ||
| err := appendPeerChanges( | ||
| &resp, | ||
| false, // partial change | ||
| m.polMan, | ||
|
|
@@ -496,6 +501,17 @@ func (m *Mapper) ListPeers(nodeID types.NodeID) (types.Nodes, error) { | |
| return peers, nil | ||
| } | ||
|
|
||
| func (m *Mapper) GetNode(nodeID types.NodeID) (*types.Node, error) { | ||
| node, err := m.db.GetNodeByID(nodeID) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| online := m.notif.IsLikelyConnected(node.ID) | ||
| node.IsOnline = &online | ||
|
|
||
| return node, nil | ||
| } | ||
|
|
||
| func nodeMapToList(nodes map[uint64]*types.Node) types.Nodes { | ||
| ret := make(types.Nodes, 0) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please link the pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done