Rename Channel.Id to Channel.ID per Golang code standards

This commit is contained in:
Ola Bini 2019-12-21 17:30:05 +00:00
parent e7589e706e
commit c7c9cedd38
No known key found for this signature in database
GPG key ID: 6786A150F6A2B28F
7 changed files with 49 additions and 49 deletions

View file

@ -12,7 +12,7 @@ import (
// Channel represents a Mumble channel // Channel represents a Mumble channel
type Channel struct { type Channel struct {
Id int ID int
Name string Name string
Position int Position int
@ -34,7 +34,7 @@ type Channel struct {
// NewChannel creates a new Mumble channel // NewChannel creates a new Mumble channel
func NewChannel(id int, name string) (channel *Channel) { func NewChannel(id int, name string) (channel *Channel) {
channel = new(Channel) channel = new(Channel)
channel.Id = id channel.ID = id
channel.Name = name channel.Name = name
channel.clients = make(map[uint32]*Client) channel.clients = make(map[uint32]*Client)
channel.children = make(map[int]*Channel) channel.children = make(map[int]*Channel)
@ -47,14 +47,14 @@ func NewChannel(id int, name string) (channel *Channel) {
func (channel *Channel) AddChild(child *Channel) { func (channel *Channel) AddChild(child *Channel) {
child.parent = channel child.parent = channel
child.ACL.Parent = &channel.ACL child.ACL.Parent = &channel.ACL
channel.children[child.Id] = child channel.children[child.ID] = child
} }
// RemoveChild removes a child channel from a parent // RemoveChild removes a child channel from a parent
func (channel *Channel) RemoveChild(child *Channel) { func (channel *Channel) RemoveChild(child *Channel) {
child.parent = nil child.parent = nil
child.ACL.Parent = nil child.ACL.Parent = nil
delete(channel.children, child.Id) delete(channel.children, child.ID)
} }
// AddClient adds client // AddClient adds client
@ -93,8 +93,8 @@ func (channel *Channel) AllLinks() (seen map[int]*Channel) {
current := walk[len(walk)-1] current := walk[len(walk)-1]
walk = walk[0 : len(walk)-1] walk = walk[0 : len(walk)-1]
for _, linked := range current.Links { for _, linked := range current.Links {
if _, alreadySeen := seen[linked.Id]; !alreadySeen { if _, alreadySeen := seen[linked.ID]; !alreadySeen {
seen[linked.Id] = linked seen[linked.ID] = linked
walk = append(walk, linked) walk = append(walk, linked)
} }
} }
@ -112,8 +112,8 @@ func (channel *Channel) AllSubChannels() (seen map[int]*Channel) {
current := walk[len(walk)-1] current := walk[len(walk)-1]
walk = walk[0 : len(walk)-1] walk = walk[0 : len(walk)-1]
for _, child := range current.children { for _, child := range current.children {
if _, alreadySeen := seen[child.Id]; !alreadySeen { if _, alreadySeen := seen[child.ID]; !alreadySeen {
seen[child.Id] = child seen[child.ID] = child
walk = append(walk, child) walk = append(walk, child)
} }
} }

View file

@ -292,7 +292,7 @@ func (c *Client) sendPermissionDeniedTypeUser(denyType mumbleproto.PermissionDen
func (c *Client) sendPermissionDenied(who *Client, where *Channel, what acl.Permission) { func (c *Client) sendPermissionDenied(who *Client, where *Channel, what acl.Permission) {
pd := &mumbleproto.PermissionDenied{ pd := &mumbleproto.PermissionDenied{
Permission: proto.Uint32(uint32(what)), Permission: proto.Uint32(uint32(what)),
ChannelId: proto.Uint32(uint32(where.Id)), ChannelId: proto.Uint32(uint32(where.ID)),
Session: proto.Uint32(who.Session()), Session: proto.Uint32(who.Session()),
Type: mumbleproto.PermissionDenied_Permission.Enum(), Type: mumbleproto.PermissionDenied_Permission.Enum(),
} }
@ -593,11 +593,11 @@ func (client *Client) sendChannelList() {
func (client *Client) sendChannelTree(channel *Channel) { func (client *Client) sendChannelTree(channel *Channel) {
chanstate := &mumbleproto.ChannelState{ chanstate := &mumbleproto.ChannelState{
ChannelId: proto.Uint32(uint32(channel.Id)), ChannelId: proto.Uint32(uint32(channel.ID)),
Name: proto.String(channel.Name), Name: proto.String(channel.Name),
} }
if channel.parent != nil { if channel.parent != nil {
chanstate.Parent = proto.Uint32(uint32(channel.parent.Id)) chanstate.Parent = proto.Uint32(uint32(channel.parent.ID))
} }
if channel.HasDescription() { if channel.HasDescription() {

View file

@ -167,10 +167,10 @@ func FreezeBan(ban ban.Ban) (fb *freezer.Ban) {
func (channel *Channel) Freeze() (fc *freezer.Channel, err error) { func (channel *Channel) Freeze() (fc *freezer.Channel, err error) {
fc = new(freezer.Channel) fc = new(freezer.Channel)
fc.Id = proto.Uint32(uint32(channel.Id)) fc.Id = proto.Uint32(uint32(channel.ID))
fc.Name = proto.String(channel.Name) fc.Name = proto.String(channel.Name)
if channel.parent != nil { if channel.parent != nil {
fc.ParentId = proto.Uint32(uint32(channel.parent.Id)) fc.ParentId = proto.Uint32(uint32(channel.parent.ID))
} }
fc.Position = proto.Int64(int64(channel.Position)) fc.Position = proto.Int64(int64(channel.Position))
fc.InheritAcl = proto.Bool(channel.ACL.InheritACL) fc.InheritAcl = proto.Bool(channel.ACL.InheritACL)
@ -445,15 +445,15 @@ func NewServerFromFrozen(name string) (s *Server, err error) {
// Update the server's nextChanId field if it needs to be, // Update the server's nextChanId field if it needs to be,
// to make sure the server doesn't re-use channel id's. // to make sure the server doesn't re-use channel id's.
c := NewChannel(int(*fc.Id), *fc.Name) c := NewChannel(int(*fc.Id), *fc.Name)
if c.Id >= s.nextChanId { if c.ID >= s.nextChanId {
s.nextChanId = c.Id + 1 s.nextChanId = c.ID + 1
} }
// Update the channel with the contents of the freezer.Channel. // Update the channel with the contents of the freezer.Channel.
c.Unfreeze(fc) c.Unfreeze(fc)
// Add the channel's id to the server's channel-id-map. // Add the channel's id to the server's channel-id-map.
s.Channels[c.Id] = c s.Channels[c.ID] = c
// Mark the channel's parent // Mark the channel's parent
if fc.ParentId != nil { if fc.ParentId != nil {
@ -602,8 +602,8 @@ func NewServerFromFrozen(name string) (s *Server, err error) {
// Add the channel and increment the server's // Add the channel and increment the server's
// nextChanId field to a consistent state. // nextChanId field to a consistent state.
channel = NewChannel(channelId, *fc.Name) channel = NewChannel(channelId, *fc.Name)
if channel.Id >= s.nextChanId { if channel.ID >= s.nextChanId {
s.nextChanId = channel.Id + 1 s.nextChanId = channel.ID + 1
} }
} }
@ -701,7 +701,7 @@ func (server *Server) UpdateFrozenUser(client *Client, state *mumbleproto.UserSt
fu := &freezer.User{} fu := &freezer.User{}
fu.Id = proto.Uint32(user.Id) fu.Id = proto.Uint32(user.Id)
if state.ChannelId != nil { if state.ChannelId != nil {
fu.LastChannelId = proto.Uint32(uint32(client.Channel.Id)) fu.LastChannelId = proto.Uint32(uint32(client.Channel.ID))
} }
if state.TextureHash != nil { if state.TextureHash != nil {
fu.TextureBlob = proto.String(user.TextureBlob) fu.TextureBlob = proto.String(user.TextureBlob)
@ -725,7 +725,7 @@ func (server *Server) UpdateFrozenUserLastChannel(client *Client) {
fu := &freezer.User{} fu := &freezer.User{}
fu.Id = proto.Uint32(user.Id) fu.Id = proto.Uint32(user.Id)
fu.LastChannelId = proto.Uint32(uint32(client.Channel.Id)) fu.LastChannelId = proto.Uint32(uint32(client.Channel.ID))
fu.LastActive = proto.Uint64(uint64(time.Now().Unix())) fu.LastActive = proto.Uint64(uint64(time.Now().Unix()))
err := server.freezelog.Put(fu) err := server.freezelog.Put(fu)
@ -751,7 +751,7 @@ func (server *Server) DeleteFrozenUser(user *User) {
// frozen.Channel to the datastore. // frozen.Channel to the datastore.
func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.ChannelState) { func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.ChannelState) {
fc := &freezer.Channel{} fc := &freezer.Channel{}
fc.Id = proto.Uint32(uint32(channel.Id)) fc.Id = proto.Uint32(uint32(channel.ID))
if state.Name != nil { if state.Name != nil {
fc.Name = state.Name fc.Name = state.Name
} }
@ -784,7 +784,7 @@ func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.C
func (server *Server) UpdateFrozenChannelACLs(channel *Channel) { func (server *Server) UpdateFrozenChannelACLs(channel *Channel) {
fc := &freezer.Channel{} fc := &freezer.Channel{}
fc.Id = proto.Uint32(uint32(channel.Id)) fc.Id = proto.Uint32(uint32(channel.ID))
fc.InheritAcl = proto.Bool(channel.ACL.InheritACL) fc.InheritAcl = proto.Bool(channel.ACL.InheritACL)
acls := []*freezer.ACL{} acls := []*freezer.ACL{}
@ -816,7 +816,7 @@ func (server *Server) UpdateFrozenChannelACLs(channel *Channel) {
// DeleteFrozenChannel will mark a channel as deleted in the datastore. // DeleteFrozenChannel will mark a channel as deleted in the datastore.
func (server *Server) DeleteFrozenChannel(channel *Channel) { func (server *Server) DeleteFrozenChannel(channel *Channel) {
err := server.freezelog.Put(&freezer.ChannelRemove{Id: proto.Uint32(uint32(channel.Id))}) err := server.freezelog.Put(&freezer.ChannelRemove{Id: proto.Uint32(uint32(channel.ID))})
if err != nil { if err != nil {
server.Fatal(err) server.Fatal(err)
} }

View file

@ -204,7 +204,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
name = *chanstate.Name name = *chanstate.Name
// We don't allow renames for the root channel. // We don't allow renames for the root channel.
if channel != nil && channel.Id != 0 { if channel != nil && channel.ID != 0 {
// Pick a parent. If the name change is part of a re-parent (a channel move), // Pick a parent. If the name change is part of a re-parent (a channel move),
// we must evaluate the parent variable. Since we're explicitly exlcuding the root // we must evaluate the parent variable. Since we're explicitly exlcuding the root
// channel from renames, channels that are the target of renames are guaranteed to have // channel from renames, channels that are the target of renames are guaranteed to have
@ -293,7 +293,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
server.ClearCaches() server.ClearCaches()
} }
chanstate.ChannelId = proto.Uint32(uint32(channel.Id)) chanstate.ChannelId = proto.Uint32(uint32(channel.ID))
// Broadcast channel add // Broadcast channel add
server.broadcastProtoMessageWithPredicate(chanstate, func(client *Client) bool { server.broadcastProtoMessageWithPredicate(chanstate, func(client *Client) bool {
@ -313,7 +313,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
if channel.IsTemporary() { if channel.IsTemporary() {
userstate := &mumbleproto.UserState{} userstate := &mumbleproto.UserState{}
userstate.Session = proto.Uint32(client.Session()) userstate.Session = proto.Uint32(client.Session())
userstate.ChannelId = proto.Uint32(uint32(channel.Id)) userstate.ChannelId = proto.Uint32(uint32(channel.ID))
server.userEnterChannel(client, channel, userstate) server.userEnterChannel(client, channel, userstate)
server.broadcastProtoMessage(userstate) server.broadcastProtoMessage(userstate)
} }
@ -325,7 +325,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
if chanstate.Name != nil { if chanstate.Name != nil {
// The client can only rename the channel if it has WritePermission in the channel. // The client can only rename the channel if it has WritePermission in the channel.
// Also, clients cannot change the name of the root channel. // Also, clients cannot change the name of the root channel.
if !acl.HasPermission(&channel.ACL, client, acl.WritePermission) || channel.Id == 0 { if !acl.HasPermission(&channel.ACL, client, acl.WritePermission) || channel.ID == 0 {
client.sendPermissionDenied(client, channel, acl.WritePermission) client.sendPermissionDenied(client, channel, acl.WritePermission)
return return
} }
@ -1049,7 +1049,7 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) {
} }
reply := &mumbleproto.ACL{} reply := &mumbleproto.ACL{}
reply.ChannelId = proto.Uint32(uint32(channel.Id)) reply.ChannelId = proto.Uint32(uint32(channel.ID))
channels := []*Channel{} channels := []*Channel{}
users := map[int]bool{} users := map[int]bool{}
@ -1533,7 +1533,7 @@ func (server *Server) handleRequestBlob(client *Client, msg *Message) {
server.Panicf("Blobstore error: %v", err) server.Panicf("Blobstore error: %v", err)
return return
} }
chanstate.ChannelId = proto.Uint32(uint32(channel.Id)) chanstate.ChannelId = proto.Uint32(uint32(channel.ID))
chanstate.Description = proto.String(string(buf)) chanstate.Description = proto.String(string(buf))
if err := client.sendMessage(chanstate); err != nil { if err := client.sendMessage(chanstate); err != nil {
client.Panic(err) client.Panic(err)

View file

@ -146,7 +146,7 @@ func populateChannelInfoFromDatabase(server *Server, c *Channel, db *sql.DB) err
} }
// Fetch description // Fetch description
rows, err := stmt.Query(server.Id, c.Id, ChannelInfoDescription) rows, err := stmt.Query(server.Id, c.ID, ChannelInfoDescription)
if err != nil { if err != nil {
return err return err
} }
@ -167,7 +167,7 @@ func populateChannelInfoFromDatabase(server *Server, c *Channel, db *sql.DB) err
} }
// Fetch position // Fetch position
rows, err = stmt.Query(server.Id, c.Id, ChannelInfoPosition) rows, err = stmt.Query(server.Id, c.ID, ChannelInfoPosition)
if err != nil { if err != nil {
return err return err
} }
@ -190,7 +190,7 @@ func populateChannelACLFromDatabase(server *Server, c *Channel, db *sql.DB) erro
return err return err
} }
rows, err := stmt.Query(server.Id, c.Id) rows, err := stmt.Query(server.Id, c.ID)
if err != nil { if err != nil {
return err return err
} }
@ -237,7 +237,7 @@ func populateChannelGroupsFromDatabase(server *Server, c *Channel, db *sql.DB) e
return err return err
} }
rows, err := stmt.Query(server.Id, c.Id) rows, err := stmt.Query(server.Id, c.ID)
if err != nil { if err != nil {
return err return err
} }
@ -324,7 +324,7 @@ func populateChannelsFromDatabase(server *Server, db *sql.DB, parentId int) erro
} }
c := NewChannel(chanid, name) c := NewChannel(chanid, name)
server.Channels[c.Id] = c server.Channels[c.ID] = c
c.ACL.InheritACL = inherit c.ACL.InheritACL = inherit
parent.AddChild(c) parent.AddChild(c)
} }

View file

@ -351,7 +351,7 @@ func (server *Server) RemoveClient(client *Client, kicked bool) {
// AddChannel adds a new channel to the server. Automatically assign it a channel ID. // AddChannel adds a new channel to the server. Automatically assign it a channel ID.
func (server *Server) AddChannel(name string) (channel *Channel) { func (server *Server) AddChannel(name string) (channel *Channel) {
channel = NewChannel(server.nextChanId, name) channel = NewChannel(server.nextChanId, name)
server.Channels[channel.Id] = channel server.Channels[channel.ID] = channel
server.nextChanId += 1 server.nextChanId += 1
return return
@ -359,24 +359,24 @@ func (server *Server) AddChannel(name string) (channel *Channel) {
// RemoveChanel removes a channel from the server. // RemoveChanel removes a channel from the server.
func (server *Server) RemoveChanel(channel *Channel) { func (server *Server) RemoveChanel(channel *Channel) {
if channel.Id == 0 { if channel.ID == 0 {
server.Printf("Attempted to remove root channel.") server.Printf("Attempted to remove root channel.")
return return
} }
delete(server.Channels, channel.Id) delete(server.Channels, channel.ID)
} }
// LinkChannels will link two channels // LinkChannels will link two channels
func (server *Server) LinkChannels(channel *Channel, other *Channel) { func (server *Server) LinkChannels(channel *Channel, other *Channel) {
channel.Links[other.Id] = other channel.Links[other.ID] = other
other.Links[channel.Id] = channel other.Links[channel.ID] = channel
} }
// UnlinkChannels will unlink two channels // UnlinkChannels will unlink two channels
func (server *Server) UnlinkChannels(channel *Channel, other *Channel) { func (server *Server) UnlinkChannels(channel *Channel, other *Channel) {
delete(channel.Links, other.Id) delete(channel.Links, other.ID)
delete(other.Links, channel.Id) delete(other.Links, channel.ID)
} }
// This is the synchronous handler goroutine. // This is the synchronous handler goroutine.
@ -618,7 +618,7 @@ func (server *Server) finishAuthenticate(client *Client) {
userstate := &mumbleproto.UserState{ userstate := &mumbleproto.UserState{
Session: proto.Uint32(client.Session()), Session: proto.Uint32(client.Session()),
Name: proto.String(client.ShownName()), Name: proto.String(client.ShownName()),
ChannelId: proto.Uint32(uint32(channel.Id)), ChannelId: proto.Uint32(uint32(channel.ID)),
} }
if client.HasCertificate() { if client.HasCertificate() {
@ -802,7 +802,7 @@ func (server *Server) sendUserList(client *Client) {
userstate := &mumbleproto.UserState{ userstate := &mumbleproto.UserState{
Session: proto.Uint32(connectedClient.Session()), Session: proto.Uint32(connectedClient.Session()),
Name: proto.String(connectedClient.ShownName()), Name: proto.String(connectedClient.ShownName()),
ChannelId: proto.Uint32(uint32(connectedClient.Channel.Id)), ChannelId: proto.Uint32(uint32(connectedClient.Channel.ID)),
} }
if connectedClient.HasCertificate() { if connectedClient.HasCertificate() {
@ -1183,7 +1183,7 @@ func (server *Server) RemoveChannel(channel *Channel) {
// Remove all links // Remove all links
for _, linkedChannel := range channel.Links { for _, linkedChannel := range channel.Links {
delete(linkedChannel.Links, channel.Id) delete(linkedChannel.Links, channel.ID)
} }
// Remove all subchannels // Remove all subchannels
@ -1200,7 +1200,7 @@ func (server *Server) RemoveChannel(channel *Channel) {
userstate := &mumbleproto.UserState{} userstate := &mumbleproto.UserState{}
userstate.Session = proto.Uint32(client.Session()) userstate.Session = proto.Uint32(client.Session())
userstate.ChannelId = proto.Uint32(uint32(target.Id)) userstate.ChannelId = proto.Uint32(uint32(target.ID))
server.userEnterChannel(client, target, userstate) server.userEnterChannel(client, target, userstate)
if err := server.broadcastProtoMessage(userstate); err != nil { if err := server.broadcastProtoMessage(userstate); err != nil {
server.Panicf("%v", err) server.Panicf("%v", err)
@ -1209,10 +1209,10 @@ func (server *Server) RemoveChannel(channel *Channel) {
// Remove the channel itself // Remove the channel itself
parent := channel.parent parent := channel.parent
delete(parent.children, channel.Id) delete(parent.children, channel.ID)
delete(server.Channels, channel.Id) delete(server.Channels, channel.ID)
chanremove := &mumbleproto.ChannelRemove{ chanremove := &mumbleproto.ChannelRemove{
ChannelId: proto.Uint32(uint32(channel.Id)), ChannelId: proto.Uint32(uint32(channel.ID)),
} }
if err := server.broadcastProtoMessage(chanremove); err != nil { if err := server.broadcastProtoMessage(chanremove); err != nil {
server.Panicf("%v", err) server.Panicf("%v", err)

View file

@ -85,7 +85,7 @@ func (vt *VoiceTarget) SendVoiceBroadcast(vb *VoiceBroadcast) {
if vtc.links { if vtc.links {
newchans = channel.AllLinks() newchans = channel.AllLinks()
} else { } else {
newchans[channel.Id] = channel newchans[channel.ID] = channel
} }
if vtc.subChannels { if vtc.subChannels {
subchans := channel.AllSubChannels() subchans := channel.AllSubChannels()