Remove stale reverse channel links

This commit is contained in:
Brandon McGinty (chatgpt)
2026-08-09 14:22:46 -04:00
committed by Brandon McGinty
parent c99b0f4473
commit cb0951dee8
2 changed files with 35 additions and 3 deletions
@@ -0,0 +1,27 @@
package gumble
import (
"testing"
"git.stormux.org/storm/barnard/gumble/gumble/MumbleProto"
"google.golang.org/protobuf/proto"
)
// Regression: a full channel-link update used to leave the removed peer's
// reverse link behind, making the client report a link that no longer exists.
func TestChannelStateFullLinksRemovesReverseLinks(t *testing.T) {
c := &Client{Config: NewConfig(), Channels: make(Channels)}
a, b, replacement := c.Channels.create(1), c.Channels.create(2), c.Channels.create(3)
a.Links[b.ID], b.Links[a.ID] = b, a
id := a.ID
data, _ := proto.Marshal(&MumbleProto.ChannelState{ChannelId: &id, Links: []uint32{replacement.ID}})
if err := c.handleChannelState(data); err != nil {
t.Fatal(err)
}
if _, ok := b.Links[a.ID]; ok {
t.Fatal("stale reciprocal link remains")
}
if replacement.Links[a.ID] != a {
t.Fatal("replacement reciprocal link missing")
}
}
+8 -3
View File
@@ -463,11 +463,16 @@ func (c *Client) handleChannelState(buffer []byte) error {
channel.Name = *packet.Name
}
if packet.Links != nil {
channel.Links = make(Channels)
// A full replacement must also remove our old reciprocal links.
for oldID, old := range channel.Links {
delete(old.Links, channel.ID)
delete(channel.Links, oldID)
}
event.Type |= ChannelChangeLinks
for _, channelID := range packet.Links {
if c := c.Channels[channelID]; c != nil {
channel.Links[channelID] = c
if linked := c.Channels[channelID]; linked != nil {
channel.Links[channelID] = linked
linked.Links[channel.ID] = channel
}
}
}