Remove stale reverse channel links
This commit is contained in:
committed by
Brandon McGinty
parent
c99b0f4473
commit
cb0951dee8
@@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -463,11 +463,16 @@ func (c *Client) handleChannelState(buffer []byte) error {
|
|||||||
channel.Name = *packet.Name
|
channel.Name = *packet.Name
|
||||||
}
|
}
|
||||||
if packet.Links != nil {
|
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
|
event.Type |= ChannelChangeLinks
|
||||||
for _, channelID := range packet.Links {
|
for _, channelID := range packet.Links {
|
||||||
if c := c.Channels[channelID]; c != nil {
|
if linked := c.Channels[channelID]; linked != nil {
|
||||||
channel.Links[channelID] = c
|
channel.Links[channelID] = linked
|
||||||
|
linked.Links[channel.ID] = channel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user