From d9b6cbb89fb165a26b42d5afc7655b1dff30f529 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 16:06:26 +0000 Subject: [PATCH 01/14] Remove unreachable code reported by go vet --- cmd/grumble/client.go | 5 ++-- cmd/grumble/server.go | 11 ++++---- pkg/acl/acl.go | 4 +-- pkg/acl/group.go | 58 +++++++++++++++++++++---------------------- 4 files changed, 36 insertions(+), 42 deletions(-) diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index 8fb1650..3272414 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -392,10 +392,9 @@ func (client *Client) SendUDP(buf []byte) error { crypted := make([]byte, len(buf)+client.crypt.Overhead()) client.crypt.Encrypt(crypted, buf) return client.server.SendUDP(crypted, client.udpaddr) - } else { - return client.sendMessage(buf) } - panic("unreachable") + + return client.sendMessage(buf) } // Send a Message to the client. The Message in msg to the client's diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index 8dc0f21..3638616 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -869,13 +869,12 @@ func (server *Server) sendClientPermissions(client *Client, channel *Channel) { } // fixme(mkrautz): re-add when we have ACL caching - return - perm := acl.Permission(acl.NonePermission) - client.sendMessage(&mumbleproto.PermissionQuery{ - ChannelId: proto.Uint32(uint32(channel.Id)), - Permissions: proto.Uint32(uint32(perm)), - }) + // perm := acl.Permission(acl.NonePermission) + // client.sendMessage(&mumbleproto.PermissionQuery{ + // ChannelId: proto.Uint32(uint32(channel.Id)), + // Permissions: proto.Uint32(uint32(perm)), + // }) } type ClientPredicate func(client *Client) bool diff --git a/pkg/acl/acl.go b/pkg/acl/acl.go index 68e0601..867a304 100644 --- a/pkg/acl/acl.go +++ b/pkg/acl/acl.go @@ -161,9 +161,7 @@ func HasPermission(ctx *Context, user User, perm Permission) bool { // permissions exccept SpeakPermission and WhisperPermission. if perm != SpeakPermission && perm != WhisperPermission { return (granted & (perm | WritePermission)) != NonePermission - } else { - return (granted & perm) != NonePermission } - return false + return (granted & perm) != NonePermission } diff --git a/pkg/acl/group.go b/pkg/acl/group.go index c533668..55d5050 100644 --- a/pkg/acl/group.go +++ b/pkg/acl/group.go @@ -298,42 +298,40 @@ func GroupMemberCheck(current *Context, acl *Context, name string, user User) (o pdepth := len(userChain) - 1 return pdepth >= mindepth && pdepth <= maxdepth - } else { - // Non-magic groups - groups := []Group{} - - iter := channel - for iter != nil { - if group, ok := iter.Groups[name]; ok { - // Skip non-inheritable groups if we're in parents - // of our evaluated context. - if iter != channel && !group.Inheritable { - break - } - // Prepend group - groups = append([]Group{group}, groups...) - // If this group does not inherit from groups in its ancestors, stop looking - // for more ancestor groups. - if !group.Inherit { - break - } - } - iter = iter.Parent - } + } + + // Non-magic groups + groups := []Group{} - isMember := false - for _, group := range groups { - if group.AddContains(user.UserId()) || group.TemporaryContains(user.UserId()) || group.TemporaryContains(-int(user.Session())) { - isMember = true + iter := channel + for iter != nil { + if group, ok := iter.Groups[name]; ok { + // Skip non-inheritable groups if we're in parents + // of our evaluated context. + if iter != channel && !group.Inheritable { + break } - if group.RemoveContains(user.UserId()) { - isMember = false + // Prepend group + groups = append([]Group{group}, groups...) + // If this group does not inherit from groups in its ancestors, stop looking + // for more ancestor groups. + if !group.Inherit { + break } } - return isMember + iter = iter.Parent } - return false + isMember := false + for _, group := range groups { + if group.AddContains(user.UserId()) || group.TemporaryContains(user.UserId()) || group.TemporaryContains(-int(user.Session())) { + isMember = true + } + if group.RemoveContains(user.UserId()) { + isMember = false + } + } + return isMember } // GroupNames gets the list of group names for the given ACL context. From 72c4f0a7e68216de985cca06f7491c0be4349c2a Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 16:08:04 +0000 Subject: [PATCH 02/14] Add missing ... for forwarding to Print, reported by go vet --- cmd/grumble/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index 3272414..d6bf9cd 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -161,7 +161,7 @@ func (client *Client) IsVerified() bool { // Log a panic and disconnect the client. func (client *Client) Panic(v ...interface{}) { - client.Print(v) + client.Print(v...) client.Disconnect() } From 65d43576a0d19cd2cb41d88843001df3696879cd Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 17:00:19 +0000 Subject: [PATCH 03/14] Fix all lint comments about comments in the cmd/grumble package --- cmd/grumble/args.go | 4 ++++ cmd/grumble/channel.go | 3 ++- cmd/grumble/client.go | 16 ++++++++++------ cmd/grumble/freeze.go | 24 ++++++++++++------------ cmd/grumble/gencert.go | 2 +- cmd/grumble/message.go | 2 ++ cmd/grumble/murmurdb.go | 13 +++++++++++-- cmd/grumble/register.go | 5 +++-- cmd/grumble/server.go | 30 +++++++++++++++++++++--------- cmd/grumble/signal_unix.go | 1 + cmd/grumble/user.go | 5 +++-- cmd/grumble/voicetarget.go | 6 +++--- 12 files changed, 73 insertions(+), 38 deletions(-) diff --git a/cmd/grumble/args.go b/cmd/grumble/args.go index 4b2331c..a00a4b4 100644 --- a/cmd/grumble/args.go +++ b/cmd/grumble/args.go @@ -8,6 +8,8 @@ import ( "text/template" ) +// UsageArgs contains usage information that can be +// templated for the final usage display type UsageArgs struct { Version string BuildDate string @@ -67,6 +69,7 @@ func defaultLogPath() string { return filepath.Join(defaultDataDir(), "grumble.log") } +// Usage will print usage information about the command func Usage() { t, err := template.New("usage").Parse(usageTmpl) if err != nil { @@ -85,6 +88,7 @@ func Usage() { } } +// Args contains all the possible arguments to the Grumble command var Args args func init() { diff --git a/cmd/grumble/channel.go b/cmd/grumble/channel.go index 672c439..f9eaabd 100644 --- a/cmd/grumble/channel.go +++ b/cmd/grumble/channel.go @@ -10,7 +10,7 @@ import ( "mumble.info/grumble/pkg/acl" ) -// A Mumble channel +// Channel represents a Mumble channel type Channel struct { Id int Name string @@ -31,6 +31,7 @@ type Channel struct { DescriptionBlob string } +// NewChannel creates a new Mumble channel func NewChannel(id int, name string) (channel *Channel) { channel = new(Channel) channel.Id = id diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index d6bf9cd..233958b 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -23,7 +23,7 @@ import ( "mumble.info/grumble/pkg/packetdata" ) -// A client connection +// Client contains all information about a client connection type Client struct { // Logging *log.Logger @@ -115,18 +115,22 @@ func (client *Client) IsSuperUser() bool { return client.user.Id == 0 } +// ACLContext returns the access control list context for this client func (client *Client) ACLContext() *acl.Context { return &client.Channel.ACL } +// CertHash returns the certificate hash for this client func (client *Client) CertHash() string { return client.certHash } +// Session returns the session ID for this client func (client *Client) Session() uint32 { return client.session } +// Tokens return all tokens for this client func (client *Client) Tokens() []string { return client.tokens } @@ -159,13 +163,13 @@ func (client *Client) IsVerified() bool { return len(state.VerifiedChains) > 0 } -// Log a panic and disconnect the client. +// Panic will log a panic and disconnect the client. func (client *Client) Panic(v ...interface{}) { client.Print(v...) client.Disconnect() } -// Log a formatted panic and disconnect the client. +// Panicf will log a formatted panic and disconnect the client. func (client *Client) Panicf(format string, v ...interface{}) { client.Printf(format, v...) client.Disconnect() @@ -203,7 +207,7 @@ func (client *Client) Disconnect() { client.disconnect(false) } -// Disconnect a client (kick/ban) +// ForceDisconnect will disconnect a client (kick/ban) func (client *Client) ForceDisconnect() { client.disconnect(true) } @@ -215,7 +219,7 @@ func (client *Client) ClearCaches() { } } -// Reject an authentication attempt +// RejectAuth will reject an authentication attempt func (client *Client) RejectAuth(rejectType mumbleproto.Reject_RejectType, reason string) { var reasonString *string = nil if len(reason) > 0 { @@ -384,7 +388,7 @@ func (client *Client) udpRecvLoop() { } } -// Send buf as a UDP message. If the client does not have +// SendUDP will send buf as a UDP message. If the client does not have // an established UDP connection, the datagram will be tunelled // through the client's control channel (TCP). func (client *Client) SendUDP(buf []byte) error { diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index a8dbcfe..4b289dd 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -22,7 +22,7 @@ import ( "mumble.info/grumble/pkg/serverconf" ) -// Freeze a server to disk and closes the log file. +// FreezeToFile will freeze a server to disk and closes the log file. // This must be called from within the Server's synchronous handler. func (server *Server) FreezeToFile() error { // See freeeze_{windows,unix}.go for real implementations. @@ -116,7 +116,7 @@ func (server *Server) Freeze() (fs *freezer.Server, err error) { return fs, nil } -// Merge the contents of a freezer.BanList into the server's +// UnfreezeBanList will merge the contents of a freezer.BanList into the server's // ban list. func (s *Server) UnfreezeBanList(fblist *freezer.BanList) { s.Bans = nil @@ -147,7 +147,7 @@ func (s *Server) UnfreezeBanList(fblist *freezer.BanList) { } } -// Freeze a ban into a flattened protobuf-based struct +// FreezeBan will freeze a ban into a flattened protobuf-based struct // ready to be persisted to disk. func FreezeBan(ban ban.Ban) (fb *freezer.Ban) { fb = new(freezer.Ban) @@ -307,7 +307,7 @@ func (user *User) Freeze() (fu *freezer.User, err error) { return } -// Merge the contents of a frozen User into an existing user struct. +// Unfreeze will merge the contents of a frozen User into an existing user struct. func (u *User) Unfreeze(fu *freezer.User) { if fu.Name != nil { u.Name = *fu.Name @@ -332,7 +332,7 @@ func (u *User) Unfreeze(fu *freezer.User) { } } -// Freeze a ChannelACL into it a flattened protobuf-based structure +// FreezeACL will freeze a ChannelACL into it a flattened protobuf-based structure // ready to be persisted to disk. func FreezeACL(aclEntry acl.ACL) (*freezer.ACL, error) { frozenAcl := &freezer.ACL{} @@ -348,7 +348,7 @@ func FreezeACL(aclEntry acl.ACL) (*freezer.ACL, error) { return frozenAcl, nil } -// Freeze a Group into a flattened protobuf-based structure +// FreezeGroup will freeze a Group into a flattened protobuf-based structure // ready to be persisted to disk. func FreezeGroup(group acl.Group) (*freezer.Group, error) { frozenGroup := &freezer.Group{} @@ -364,7 +364,7 @@ func FreezeGroup(group acl.Group) (*freezer.Group, error) { return frozenGroup, nil } -// Create a new server from its on-disk representation. +// NewServerFromFrozen will create a new server from its on-disk representation. // // This will read a full serialized server (typically stored in // a file called 'main.fz') from disk. It will also check for @@ -681,7 +681,7 @@ func NewServerFromFrozen(name string) (s *Server, err error) { return s, nil } -// Update the datastore with the user's current state. +// UpdateFrozenUser will update the datastore with the user's current state. func (server *Server) UpdateFrozenUser(client *Client, state *mumbleproto.UserState) { // Full sync If there's no userstate messgae provided, or if there is one, and // it includes a registration operation. @@ -718,7 +718,7 @@ func (server *Server) UpdateFrozenUser(client *Client, state *mumbleproto.UserSt server.numLogOps += 1 } -// Update a user's last active channel +// UpdateFrozenUserLastChannel will update a user's last active channel func (server *Server) UpdateFrozenUserLastChannel(client *Client) { if client.IsRegistered() { user := client.user @@ -737,7 +737,7 @@ func (server *Server) UpdateFrozenUserLastChannel(client *Client) { } } -// Mark a user as deleted in the datstore. +// DeleteFrozenUser will mark a user as deleted in the datstore. func (server *Server) DeleteFrozenUser(user *User) { err := server.freezelog.Put(&freezer.UserRemove{Id: proto.Uint32(user.Id)}) if err != nil { @@ -746,7 +746,7 @@ func (server *Server) DeleteFrozenUser(user *User) { server.numLogOps += 1 } -// Given a target channel and a ChannelState protocol message, create a freezer.Channel that +// UpdateFrozenChannel will, given a target channel and a ChannelState protocol message, create a freezer.Channel that // only includes the values changed by the given ChannelState message. When done, write that // frozen.Channel to the datastore. func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.ChannelState) { @@ -814,7 +814,7 @@ func (server *Server) UpdateFrozenChannelACLs(channel *Channel) { server.numLogOps += 1 } -// Mark a channel as deleted in the datastore. +// DeleteFrozenChannel will mark a channel as deleted in the datastore. func (server *Server) DeleteFrozenChannel(channel *Channel) { err := server.freezelog.Put(&freezer.ChannelRemove{Id: proto.Uint32(uint32(channel.Id))}) if err != nil { diff --git a/cmd/grumble/gencert.go b/cmd/grumble/gencert.go index 4c2bb30..904caa8 100644 --- a/cmd/grumble/gencert.go +++ b/cmd/grumble/gencert.go @@ -17,7 +17,7 @@ import ( "time" ) -// Generate a 4096-bit RSA keypair and a Grumble auto-generated X509 +// GenerateSelfSignedCert will generate a 4096-bit RSA keypair and a Grumble auto-generated X509 // certificate. Output PEM-encoded DER representations of the resulting // certificate and private key to certpath and keypath. func GenerateSelfSignedCert(certpath, keypath string) (err error) { diff --git a/cmd/grumble/message.go b/cmd/grumble/message.go index 417faba..b9e9780 100644 --- a/cmd/grumble/message.go +++ b/cmd/grumble/message.go @@ -18,12 +18,14 @@ import ( "mumble.info/grumble/pkg/mumbleproto" ) +// Message contains a specific message for a client type Message struct { buf []byte kind uint16 client *Client } +// VoiceBroadcast contains a voice broadcast for a specific client type VoiceBroadcast struct { // The client who is performing the broadcast client *Client diff --git a/cmd/grumble/murmurdb.go b/cmd/grumble/murmurdb.go index 83cd2c9..55792e2 100644 --- a/cmd/grumble/murmurdb.go +++ b/cmd/grumble/murmurdb.go @@ -23,22 +23,31 @@ import ( ) const ( + // ChannelInfoDescription represents the description of a channel info ChannelInfoDescription int = iota + // ChannelInfoPosition represents the position of a channel info ChannelInfoPosition ) const ( + // UserInfoName points to the name field of user information UserInfoName int = iota + // UserInfoEmail points to the email field of user information UserInfoEmail + // UserInfoComment points to the comment field of user information UserInfoComment + // UserInfoHash points to the hash field of user information UserInfoHash + // UserInfoPassword points to the password field of user information UserInfoPassword + // UserInfoLastActive points to the last active field of user information UserInfoLastActive ) +// SQLiteSupport marks whether SQLite is supported or not const SQLiteSupport = true -// Import the structure of an existing Murmur SQLite database. +// MurmurImport will import the structure of an existing Murmur SQLite database. func MurmurImport(filename string) (err error) { db, err := sql.Open("sqlite", filename) if err != nil { @@ -84,7 +93,7 @@ func MurmurImport(filename string) (err error) { return } -// Create a new Server from a Murmur SQLite database +// NewServerFromSQLite will create a new Server from a Murmur SQLite database func NewServerFromSQLite(id int64, db *sql.DB) (s *Server, err error) { s, err = NewServer(id) if err != nil { diff --git a/cmd/grumble/register.go b/cmd/grumble/register.go index 50015a8..76d318f 100644 --- a/cmd/grumble/register.go +++ b/cmd/grumble/register.go @@ -16,6 +16,7 @@ import ( "net/http" ) +// Register contains the information necessary to register a server type Register struct { XMLName xml.Name `xml:"server"` Version string `xml:"version"` @@ -33,7 +34,7 @@ type Register struct { const registerUrl = "https://mumble.info/register.cgi" -// Determines whether a server is public by checking whether the +// IsPublic Determines whether a server is public by checking whether the // config values required for public registration are set. // // This function is used to determine whether or not to periodically @@ -54,7 +55,7 @@ func (server *Server) IsPublic() bool { return true } -// Perform a public server registration update. +// RegisterPublicServer will perform a public server registration update. // // When a Mumble server connects to the master server // for registration, it connects using its server certificate diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index 3638616..03ed4ac 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -36,13 +36,23 @@ import ( "mumble.info/grumble/pkg/web" ) -// The default port a Murmur server listens on +// DefaultPort is the default port a Murmur server listens on const DefaultPort = 64738 + +// DefaultWebPort is the default web port a Grumble server listens on const DefaultWebPort = 443 + +// UDPPacketSize is the size of each UDP packet const UDPPacketSize = 1024 +// LogOpsBeforeSync is the amount of logging operations that can be done +// before syncing const LogOpsBeforeSync = 100 + +// CeltCompatBitstream specifies the codec for celt compatibility const CeltCompatBitstream = -2147483637 + +// These constants keep track of the different states the server can be in const ( StateClientConnected = iota StateServerSentVersion @@ -52,13 +62,14 @@ const ( StateClientDead ) +// KeyValuePair contains a key value pair and a reset flag type KeyValuePair struct { Key string Value string Reset bool } -// A Murmur server instance +// Server is a Grumble server instance type Server struct { Id int64 @@ -137,7 +148,7 @@ func (lf clientLogForwarder) Write(incoming []byte) (int, error) { return len(incoming), nil } -// Allocate a new Murmur instance +// NewServer will allocate a new Grumble instance func NewServer(id int64) (s *Server, err error) { s = new(Server) @@ -175,7 +186,7 @@ func (server *Server) RootChannel() *Channel { return root } -// Set password as the new SuperUser password +// SetSuperUserPassword will set password as the new SuperUser password func (server *Server) SetSuperUserPassword(password string) { saltBytes := make([]byte, 24) _, err := rand.Read(saltBytes) @@ -356,13 +367,13 @@ func (server *Server) RemoveChanel(channel *Channel) { delete(server.Channels, channel.Id) } -// Link two channels +// LinkChannels will link two channels func (server *Server) LinkChannels(channel *Channel, other *Channel) { channel.Links[other.Id] = other other.Links[channel.Id] = channel } -// Unlink two channels +// UnlinkChannels will unlink two channels func (server *Server) UnlinkChannels(channel *Channel, other *Channel) { delete(channel.Links, other.Id) delete(other.Links, channel.Id) @@ -877,6 +888,7 @@ func (server *Server) sendClientPermissions(client *Client, channel *Channel) { // }) } +// ClientPredicate takes a client and returns a boolean type ClientPredicate func(client *Client) bool func (server *Server) broadcastProtoMessageWithPredicate(msg interface{}, clientcheck ClientPredicate) error { @@ -940,7 +952,7 @@ func (server *Server) handleIncomingMessage(client *Client, msg *Message) { } } -// Send the content of buf as a UDP packet to addr. +// SendUDP will send the content of buf as a UDP packet to addr. func (s *Server) SendUDP(buf []byte, addr *net.UDPAddr) (err error) { _, err = s.udpconn.WriteTo(buf, addr) return @@ -1085,7 +1097,7 @@ func (server *Server) userEnterChannel(client *Client, channel *Channel, usersta } } -// Register a client on the server. +// RegisterClient will register a client on the server. func (s *Server) RegisterClient(client *Client) (uid uint32, err error) { // Increment nextUserId only if registration succeeded. defer func() { @@ -1257,7 +1269,7 @@ func (server *Server) IsCertHashBanned(hash string) bool { return false } -// Filter incoming text according to the server's current rules. +// FilterText filters incoming text according to the server's current rules. func (server *Server) FilterText(text string) (filtered string, err error) { options := &htmlfilter.Options{ StripHTML: !server.cfg.BoolValue("AllowHTML"), diff --git a/cmd/grumble/signal_unix.go b/cmd/grumble/signal_unix.go index 7127f24..c46cf9e 100644 --- a/cmd/grumble/signal_unix.go +++ b/cmd/grumble/signal_unix.go @@ -15,6 +15,7 @@ import ( "mumble.info/grumble/pkg/logtarget" ) +// SignalHandler manages signals on Unix like systems func SignalHandler() { sigchan := make(chan os.Signal, 10) signal.Notify(sigchan, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT) diff --git a/cmd/grumble/user.go b/cmd/grumble/user.go index 8346514..47ab09b 100644 --- a/cmd/grumble/user.go +++ b/cmd/grumble/user.go @@ -13,6 +13,7 @@ import ( // // Users are registered clients on the server. +// User contains all user information type User struct { Id uint32 Name string @@ -25,7 +26,7 @@ type User struct { LastActive uint64 } -// Create a new User +// NewUser will create a new User func NewUser(id uint32, name string) (user *User, err error) { if id < 0 { return nil, errors.New("Invalid user id") @@ -40,7 +41,7 @@ func NewUser(id uint32, name string) (user *User, err error) { }, nil } -// HasComment Does the channel have comment? +// HasComment checks whether the channel have comment? func (user *User) HasComment() bool { return len(user.CommentBlob) > 0 } diff --git a/cmd/grumble/voicetarget.go b/cmd/grumble/voicetarget.go index 4c8453e..74d3175 100644 --- a/cmd/grumble/voicetarget.go +++ b/cmd/grumble/voicetarget.go @@ -6,7 +6,7 @@ package main import "mumble.info/grumble/pkg/acl" -// A VoiceTarget holds information about a single +// VoiceTarget holds information about a single // VoiceTarget entry of a Client. type VoiceTarget struct { sessions []uint32 @@ -23,7 +23,7 @@ type voiceTargetChannel struct { onlyGroup string } -// Add's a client's session to the VoiceTarget +// AddSession adds a client's session to the VoiceTarget func (vt *VoiceTarget) AddSession(session uint32) { vt.sessions = append(vt.sessions, session) } @@ -53,7 +53,7 @@ func (vt *VoiceTarget) ClearCache() { vt.fromChannelsCache = nil } -// Send the contents of the VoiceBroadcast to all targets specified in the +// SendVoiceBroadcast will send the contents of the VoiceBroadcast to all targets specified in the // VoiceTarget. func (vt *VoiceTarget) SendVoiceBroadcast(vb *VoiceBroadcast) { buf := vb.buf From e7589e706ebb6e2ac4f373382fbace37faf37a09 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 17:19:26 +0000 Subject: [PATCH 04/14] Fix all golint comment related problems in the pkg packages --- pkg/acl/acl.go | 2 +- pkg/acl/group.go | 1 + pkg/ban/ban.go | 6 ++++-- pkg/blobstore/blobstore.go | 2 +- pkg/cryptstate/cryptstate.go | 6 ++++++ pkg/freezer/types.go | 1 + pkg/freezer/walker.go | 6 +++--- pkg/freezer/writer.go | 10 +++++----- pkg/htmlfilter/htmlfilter.go | 2 ++ pkg/logtarget/logtarget.go | 1 + pkg/mumbleproto/types.go | 2 ++ pkg/packetdata/packetdata.go | 8 ++++++-- pkg/replacefile/flags.go | 2 ++ pkg/replacefile/replacefile_stub.go | 2 ++ pkg/serverconf/config.go | 3 ++- pkg/sessionpool/sessionpool.go | 6 +++--- pkg/web/wslisten.go | 5 +++++ 17 files changed, 47 insertions(+), 18 deletions(-) diff --git a/pkg/acl/acl.go b/pkg/acl/acl.go index 867a304..08fc761 100644 --- a/pkg/acl/acl.go +++ b/pkg/acl/acl.go @@ -4,8 +4,8 @@ package acl +// Per-channel permissions const ( - // Per-channel permissions NonePermission = 0x0 WritePermission = 0x1 TraversePermission = 0x2 diff --git a/pkg/acl/group.go b/pkg/acl/group.go index 55d5050..b2b282f 100644 --- a/pkg/acl/group.go +++ b/pkg/acl/group.go @@ -1,6 +1,7 @@ // Copyright (c) 2010-2013 The Grumble Authors // The use of this source code is goverened by a BSD-style // license that can be found in the LICENSE-file. + package acl import ( diff --git a/pkg/ban/ban.go b/pkg/ban/ban.go index 6bd9dcf..c3cb8a8 100644 --- a/pkg/ban/ban.go +++ b/pkg/ban/ban.go @@ -10,9 +10,11 @@ import ( ) const ( + // ISODate represents ISO 8601 formatting ISODate = "2006-01-02T15:04:05" ) +// Ban contains information about a specific ban type Ban struct { IP net.IP Mask int @@ -23,7 +25,7 @@ type Ban struct { Duration uint32 } -// Create a net.IPMask from a specified amount of mask bits +// IPMask creates a net.IPMask from a specified amount of mask bits func (ban Ban) IPMask() (mask net.IPMask) { allbits := ban.Mask for i := 0; i < 16; i++ { @@ -48,7 +50,7 @@ func (ban Ban) Match(ip net.IP) bool { return banned.Equal(masked) } -// Set Start date from an ISO 8601 date (in UTC) +// SetISOStartDate sets Start date from an ISO 8601 date (in UTC) func (ban *Ban) SetISOStartDate(isodate string) { startTime, err := time.Parse(ISODate, isodate) if err != nil { diff --git a/pkg/blobstore/blobstore.go b/pkg/blobstore/blobstore.go index 97cd582..5b94ae6 100644 --- a/pkg/blobstore/blobstore.go +++ b/pkg/blobstore/blobstore.go @@ -2,7 +2,7 @@ // The use of this source code is goverened by a BSD-style // license that can be found in the LICENSE-file. -// This package implements a simple disk-persisted content-addressed blobstore. +// Package blobstore implements a simple disk-persisted content-addressed blobstore. package blobstore import ( diff --git a/pkg/cryptstate/cryptstate.go b/pkg/cryptstate/cryptstate.go index 3ce84a0..74e61d6 100644 --- a/pkg/cryptstate/cryptstate.go +++ b/pkg/cryptstate/cryptstate.go @@ -13,6 +13,7 @@ import ( const decryptHistorySize = 0x100 +// CryptoMode represents a specific cryptographic mode type CryptoMode interface { NonceSize() int KeySize() int @@ -23,6 +24,7 @@ type CryptoMode interface { Decrypt(dst []byte, src []byte, nonce []byte) bool } +// CryptState represents the current state of a cryptographic operation type CryptState struct { Key []byte EncryptIV []byte @@ -62,6 +64,7 @@ func createMode(mode string) (CryptoMode, error) { return nil, errors.New("cryptstate: no such CryptoMode") } +// GenerateKey will generate a key for the specific mode func (cs *CryptState) GenerateKey(mode string) error { cm, err := createMode(mode) if err != nil { @@ -93,6 +96,7 @@ func (cs *CryptState) GenerateKey(mode string) error { return nil } +// SetKey will set the cryptographic key for a specific mode func (cs *CryptState) SetKey(mode string, key []byte, eiv []byte, div []byte) error { cm, err := createMode(mode) if err != nil { @@ -115,6 +119,7 @@ func (cs *CryptState) Overhead() int { return 1 + cs.mode.Overhead() } +// Decrypt decrypts the source into the destination func (cs *CryptState) Decrypt(dst, src []byte) error { if len(src) < cs.Overhead() { return errors.New("cryptstate: crypted length too short to decrypt") @@ -228,6 +233,7 @@ func (cs *CryptState) Decrypt(dst, src []byte) error { return nil } +// Encrypt will encrypt the source into the destination func (cs *CryptState) Encrypt(dst, src []byte) { // First, increase our IV for i := range cs.EncryptIV { diff --git a/pkg/freezer/types.go b/pkg/freezer/types.go index 1342f69..bf02e40 100644 --- a/pkg/freezer/types.go +++ b/pkg/freezer/types.go @@ -6,6 +6,7 @@ package freezer type typeKind uint32 +// The different types of data that can be frozen const ( ServerType typeKind = iota ConfigKeyValuePairType diff --git a/pkg/freezer/walker.go b/pkg/freezer/walker.go index a6a1a32..cc0462c 100644 --- a/pkg/freezer/walker.go +++ b/pkg/freezer/walker.go @@ -23,14 +23,14 @@ func isEOF(err error) bool { return false } -// Type Walker implements a method for +// Walker implements a method for // iterating the transaction groups of an // immutable Log. type Walker struct { r io.Reader } -// Type txReader imlpements a checksumming reader, intended +// txReader imlpements a checksumming reader, intended // for reading transaction groups of a Log. // // Besides auto-checksumming the read content, it also @@ -79,7 +79,7 @@ func (txr *txReader) Consumed() int { return txr.consumed } -// Create a new Walker that iterates over the log entries of a given Reader. +// NewReaderWalker creates a new Walker that iterates over the log entries of a given Reader. func NewReaderWalker(r io.Reader) (walker *Walker, err error) { walker = new(Walker) walker.r = r diff --git a/pkg/freezer/writer.go b/pkg/freezer/writer.go index e58d699..b48d37a 100644 --- a/pkg/freezer/writer.go +++ b/pkg/freezer/writer.go @@ -41,7 +41,7 @@ type Log struct { wc io.WriteCloser } -// Type LogTx represents a transaction in the log. +// LogTx represents a transaction in the log. // Transactions can be used to group several changes into an // atomic entity in the log file. type LogTx struct { @@ -51,7 +51,7 @@ type LogTx struct { numops int } -// Create a new log file +// NewLogFile creates a new log file func NewLogFile(fn string) (*Log, error) { f, err := os.Create(fn) if err != nil { @@ -69,7 +69,7 @@ func (log *Log) Close() error { return log.wc.Close() } -// Append a log entry +// Put will append a log entry // // This method implicitly creates a transaction // group for this single Put operation. It is merely @@ -83,7 +83,7 @@ func (log *Log) Put(value interface{}) (err error) { return tx.Commit() } -// Begin a transaction +// BeginTx begins a transaction func (log *Log) BeginTx() *LogTx { tx := &LogTx{} tx.log = log @@ -92,7 +92,7 @@ func (log *Log) BeginTx() *LogTx { return tx } -// Append a log entry to the transaction. +// Put will append a log entry to the transaction. // The transaction's log entries will not be persisted to // the log until the Commit has been called on the transaction. func (tx *LogTx) Put(value interface{}) (err error) { diff --git a/pkg/htmlfilter/htmlfilter.go b/pkg/htmlfilter/htmlfilter.go index 82c34d6..b62d4eb 100644 --- a/pkg/htmlfilter/htmlfilter.go +++ b/pkg/htmlfilter/htmlfilter.go @@ -12,6 +12,7 @@ import ( "strings" ) +// Options contains the different possible HTML filtering options type Options struct { StripHTML bool MaxTextMessageLength int @@ -24,6 +25,7 @@ var defaultOptions Options = Options{ MaxImageMessageLength: 1024 * 1024, } +// Errors that can happen in this module var ( ErrExceedsTextMessageLength = errors.New("Exceeds text message length") ErrExceedsImageMessageLength = errors.New("Exceeds image message length") diff --git a/pkg/logtarget/logtarget.go b/pkg/logtarget/logtarget.go index 46a2eb2..3fd4ad3 100644 --- a/pkg/logtarget/logtarget.go +++ b/pkg/logtarget/logtarget.go @@ -22,6 +22,7 @@ type LogTarget struct { memLog *bytes.Buffer } +// Target is the current log target var Target LogTarget // Write writes a log message to all registered io.Writers diff --git a/pkg/mumbleproto/types.go b/pkg/mumbleproto/types.go index b8e442c..fef738c 100644 --- a/pkg/mumbleproto/types.go +++ b/pkg/mumbleproto/types.go @@ -4,6 +4,7 @@ package mumbleproto +// All different message types const ( MessageVersion uint16 = iota MessageUDPTunnel @@ -32,6 +33,7 @@ const ( MessageServerConfig ) +// All different UDP message types const ( UDPMessageVoiceCELTAlpha = iota UDPMessagePing diff --git a/pkg/packetdata/packetdata.go b/pkg/packetdata/packetdata.go index f71e61f..3232c6c 100644 --- a/pkg/packetdata/packetdata.go +++ b/pkg/packetdata/packetdata.go @@ -9,6 +9,7 @@ import ( "math" ) +// PacketData contains one packet of information type PacketData struct { Buf []byte offset int @@ -17,6 +18,7 @@ type PacketData struct { ok bool } +// New creates a new packet data from the buffer func New(buf []byte) (pds *PacketData) { pds = new(PacketData) pds.Buf = buf @@ -25,10 +27,12 @@ func New(buf []byte) (pds *PacketData) { return } +// IsValid checks whether the current packet data is valid func (pds *PacketData) IsValid() bool { return pds.ok } +// Skip will skip some data func (pds *PacketData) Skip(skip int) { if pds.Left() >= skip { pds.offset += skip @@ -299,7 +303,7 @@ func (pds *PacketData) PutFloat64(val float64) { pds.append(bits & 0xff) } -// Copy a buffer out of the PacketData into dst. +// CopyBytes will copy a buffer out of the PacketData into dst. func (pds *PacketData) CopyBytes(dst []byte) { if pds.Left() >= len(dst) { if copy(dst, pds.Buf[pds.offset:pds.offset+len(dst)]) != len(dst) { @@ -310,7 +314,7 @@ func (pds *PacketData) CopyBytes(dst []byte) { } } -// Put a buffer src into the PacketData at the +// PutBytes will put a buffer src into the PacketData at the // current offset. func (pds *PacketData) PutBytes(src []byte) { if pds.Left() >= len(src) { diff --git a/pkg/replacefile/flags.go b/pkg/replacefile/flags.go index d09f856..9d3e613 100644 --- a/pkg/replacefile/flags.go +++ b/pkg/replacefile/flags.go @@ -4,8 +4,10 @@ package replacefile +// Flag is a flag that allows you to ignore some errors type Flag uint32 +// The types of errors that can be ignored const ( IgnoreMergeErrors Flag = 0x2 IgnoreACLErrors Flag = 0x4 diff --git a/pkg/replacefile/replacefile_stub.go b/pkg/replacefile/replacefile_stub.go index eb91539..d5178b4 100644 --- a/pkg/replacefile/replacefile_stub.go +++ b/pkg/replacefile/replacefile_stub.go @@ -10,6 +10,7 @@ import ( "errors" ) +// The different types of errors that can happen if we're not on windows var ( errOnlyWindows = errors.New("replacefile: only implemented on Windows") ErrUnableToMoveReplacement error = errOnlyWindows @@ -17,6 +18,7 @@ var ( ErrUnableToRemoveReplaced error = errOnlyWindows ) +// ReplaceFile tries to replace the file func ReplaceFile(replaced string, replacement string, backup string, flags Flag) error { return errOnlyWindows } diff --git a/pkg/serverconf/config.go b/pkg/serverconf/config.go index 0eb26d1..31e737c 100644 --- a/pkg/serverconf/config.go +++ b/pkg/serverconf/config.go @@ -22,12 +22,13 @@ var defaultCfg = map[string]string{ "SendVersion": "true", } +// Config contains all configurations type Config struct { cfgMap map[string]string mutex sync.RWMutex } -// Create a new Config using cfgMap as the intial internal config map. +// New creates a new Config using cfgMap as the intial internal config map. // If cfgMap is nil, ConfigWithMap will create a new config map. func New(cfgMap map[string]string) *Config { if cfgMap == nil { diff --git a/pkg/sessionpool/sessionpool.go b/pkg/sessionpool/sessionpool.go index 3e6c2ad..882f006 100644 --- a/pkg/sessionpool/sessionpool.go +++ b/pkg/sessionpool/sessionpool.go @@ -10,7 +10,7 @@ import ( "sync" ) -// A SessionPool is a pool for session IDs. +// SessionPool is a pool for session IDs. // IDs are re-used in MRU order, for ease of implementation in Go. type SessionPool struct { mutex sync.Mutex @@ -19,13 +19,13 @@ type SessionPool struct { cur uint32 } -// Create a new SessionPool container. +// New creates a new SessionPool container. func New() (pool *SessionPool) { pool = new(SessionPool) return } -// Enable use-tracking for the SessionPool. +// EnableUseTracking will enable use-tracking for the SessionPool. // // When enabled, the SessionPool stores all session IDs // returned by Get() internally. When an ID is reclaimed, diff --git a/pkg/web/wslisten.go b/pkg/web/wslisten.go index 4796651..866b83d 100644 --- a/pkg/web/wslisten.go +++ b/pkg/web/wslisten.go @@ -23,6 +23,7 @@ var upgrader = websocket.Upgrader{ }, } +// Listener represents a specific network listener type Listener struct { sockets chan *conn done chan struct{} @@ -31,6 +32,7 @@ type Listener struct { logger *log.Logger } +// NewListener creates a new listener func NewListener(laddr net.Addr, logger *log.Logger) *Listener { return &Listener{ sockets: make(chan *conn), @@ -40,6 +42,7 @@ func NewListener(laddr net.Addr, logger *log.Logger) *Listener { } } +// Accept blocks and waits for a new connection func (l *Listener) Accept() (net.Conn, error) { if atomic.LoadInt32(&l.closed) != 0 { return nil, fmt.Errorf("accept ws %v: use of closed websocket listener", l.addr) @@ -52,6 +55,7 @@ func (l *Listener) Accept() (net.Conn, error) { } } +// Close will close the underlying listener func (l *Listener) Close() error { if !atomic.CompareAndSwapInt32(&l.closed, 0, 1) { return fmt.Errorf("close ws %v: use of closed websocket listener", l.addr) @@ -60,6 +64,7 @@ func (l *Listener) Close() error { return nil } +// Addr returns the internal address func (l *Listener) Addr() net.Addr { return l.addr } From c7c9cedd38cc951962d0df81cbae300820c42602 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 17:30:05 +0000 Subject: [PATCH 05/14] Rename Channel.Id to Channel.ID per Golang code standards --- cmd/grumble/channel.go | 16 ++++++++-------- cmd/grumble/client.go | 6 +++--- cmd/grumble/freeze.go | 24 ++++++++++++------------ cmd/grumble/message.go | 12 ++++++------ cmd/grumble/murmurdb.go | 10 +++++----- cmd/grumble/server.go | 28 ++++++++++++++-------------- cmd/grumble/voicetarget.go | 2 +- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/cmd/grumble/channel.go b/cmd/grumble/channel.go index f9eaabd..2389436 100644 --- a/cmd/grumble/channel.go +++ b/cmd/grumble/channel.go @@ -12,7 +12,7 @@ import ( // Channel represents a Mumble channel type Channel struct { - Id int + ID int Name string Position int @@ -34,7 +34,7 @@ type Channel struct { // NewChannel creates a new Mumble channel func NewChannel(id int, name string) (channel *Channel) { channel = new(Channel) - channel.Id = id + channel.ID = id channel.Name = name channel.clients = make(map[uint32]*Client) channel.children = make(map[int]*Channel) @@ -47,14 +47,14 @@ func NewChannel(id int, name string) (channel *Channel) { func (channel *Channel) AddChild(child *Channel) { child.parent = channel child.ACL.Parent = &channel.ACL - channel.children[child.Id] = child + channel.children[child.ID] = child } // RemoveChild removes a child channel from a parent func (channel *Channel) RemoveChild(child *Channel) { child.parent = nil child.ACL.Parent = nil - delete(channel.children, child.Id) + delete(channel.children, child.ID) } // AddClient adds client @@ -93,8 +93,8 @@ func (channel *Channel) AllLinks() (seen map[int]*Channel) { current := walk[len(walk)-1] walk = walk[0 : len(walk)-1] for _, linked := range current.Links { - if _, alreadySeen := seen[linked.Id]; !alreadySeen { - seen[linked.Id] = linked + if _, alreadySeen := seen[linked.ID]; !alreadySeen { + seen[linked.ID] = linked walk = append(walk, linked) } } @@ -112,8 +112,8 @@ func (channel *Channel) AllSubChannels() (seen map[int]*Channel) { current := walk[len(walk)-1] walk = walk[0 : len(walk)-1] for _, child := range current.children { - if _, alreadySeen := seen[child.Id]; !alreadySeen { - seen[child.Id] = child + if _, alreadySeen := seen[child.ID]; !alreadySeen { + seen[child.ID] = child walk = append(walk, child) } } diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index 233958b..0c5d68c 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -292,7 +292,7 @@ func (c *Client) sendPermissionDeniedTypeUser(denyType mumbleproto.PermissionDen func (c *Client) sendPermissionDenied(who *Client, where *Channel, what acl.Permission) { pd := &mumbleproto.PermissionDenied{ Permission: proto.Uint32(uint32(what)), - ChannelId: proto.Uint32(uint32(where.Id)), + ChannelId: proto.Uint32(uint32(where.ID)), Session: proto.Uint32(who.Session()), Type: mumbleproto.PermissionDenied_Permission.Enum(), } @@ -593,11 +593,11 @@ func (client *Client) sendChannelList() { func (client *Client) sendChannelTree(channel *Channel) { chanstate := &mumbleproto.ChannelState{ - ChannelId: proto.Uint32(uint32(channel.Id)), + ChannelId: proto.Uint32(uint32(channel.ID)), Name: proto.String(channel.Name), } if channel.parent != nil { - chanstate.Parent = proto.Uint32(uint32(channel.parent.Id)) + chanstate.Parent = proto.Uint32(uint32(channel.parent.ID)) } if channel.HasDescription() { diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index 4b289dd..40de458 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -167,10 +167,10 @@ func FreezeBan(ban ban.Ban) (fb *freezer.Ban) { func (channel *Channel) Freeze() (fc *freezer.Channel, err error) { fc = new(freezer.Channel) - fc.Id = proto.Uint32(uint32(channel.Id)) + fc.Id = proto.Uint32(uint32(channel.ID)) fc.Name = proto.String(channel.Name) 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.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, // to make sure the server doesn't re-use channel id's. c := NewChannel(int(*fc.Id), *fc.Name) - if c.Id >= s.nextChanId { - s.nextChanId = c.Id + 1 + if c.ID >= s.nextChanId { + s.nextChanId = c.ID + 1 } // Update the channel with the contents of the freezer.Channel. c.Unfreeze(fc) // 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 if fc.ParentId != nil { @@ -602,8 +602,8 @@ func NewServerFromFrozen(name string) (s *Server, err error) { // Add the channel and increment the server's // nextChanId field to a consistent state. channel = NewChannel(channelId, *fc.Name) - if channel.Id >= s.nextChanId { - s.nextChanId = channel.Id + 1 + if channel.ID >= s.nextChanId { + s.nextChanId = channel.ID + 1 } } @@ -701,7 +701,7 @@ func (server *Server) UpdateFrozenUser(client *Client, state *mumbleproto.UserSt fu := &freezer.User{} fu.Id = proto.Uint32(user.Id) if state.ChannelId != nil { - fu.LastChannelId = proto.Uint32(uint32(client.Channel.Id)) + fu.LastChannelId = proto.Uint32(uint32(client.Channel.ID)) } if state.TextureHash != nil { fu.TextureBlob = proto.String(user.TextureBlob) @@ -725,7 +725,7 @@ func (server *Server) UpdateFrozenUserLastChannel(client *Client) { fu := &freezer.User{} 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())) err := server.freezelog.Put(fu) @@ -751,7 +751,7 @@ func (server *Server) DeleteFrozenUser(user *User) { // frozen.Channel to the datastore. func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.ChannelState) { fc := &freezer.Channel{} - fc.Id = proto.Uint32(uint32(channel.Id)) + fc.Id = proto.Uint32(uint32(channel.ID)) if state.Name != nil { fc.Name = state.Name } @@ -784,7 +784,7 @@ func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.C func (server *Server) UpdateFrozenChannelACLs(channel *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) acls := []*freezer.ACL{} @@ -816,7 +816,7 @@ func (server *Server) UpdateFrozenChannelACLs(channel *Channel) { // DeleteFrozenChannel will mark a channel as deleted in the datastore. 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 { server.Fatal(err) } diff --git a/cmd/grumble/message.go b/cmd/grumble/message.go index b9e9780..4cdced7 100644 --- a/cmd/grumble/message.go +++ b/cmd/grumble/message.go @@ -204,7 +204,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) { name = *chanstate.Name // 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), // 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 @@ -293,7 +293,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) { server.ClearCaches() } - chanstate.ChannelId = proto.Uint32(uint32(channel.Id)) + chanstate.ChannelId = proto.Uint32(uint32(channel.ID)) // Broadcast channel add server.broadcastProtoMessageWithPredicate(chanstate, func(client *Client) bool { @@ -313,7 +313,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) { if channel.IsTemporary() { userstate := &mumbleproto.UserState{} 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.broadcastProtoMessage(userstate) } @@ -325,7 +325,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) { if chanstate.Name != nil { // The client can only rename the channel if it has WritePermission in the 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) return } @@ -1049,7 +1049,7 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { } reply := &mumbleproto.ACL{} - reply.ChannelId = proto.Uint32(uint32(channel.Id)) + reply.ChannelId = proto.Uint32(uint32(channel.ID)) channels := []*Channel{} users := map[int]bool{} @@ -1533,7 +1533,7 @@ func (server *Server) handleRequestBlob(client *Client, msg *Message) { server.Panicf("Blobstore error: %v", err) return } - chanstate.ChannelId = proto.Uint32(uint32(channel.Id)) + chanstate.ChannelId = proto.Uint32(uint32(channel.ID)) chanstate.Description = proto.String(string(buf)) if err := client.sendMessage(chanstate); err != nil { client.Panic(err) diff --git a/cmd/grumble/murmurdb.go b/cmd/grumble/murmurdb.go index 55792e2..5996e53 100644 --- a/cmd/grumble/murmurdb.go +++ b/cmd/grumble/murmurdb.go @@ -146,7 +146,7 @@ func populateChannelInfoFromDatabase(server *Server, c *Channel, db *sql.DB) err } // Fetch description - rows, err := stmt.Query(server.Id, c.Id, ChannelInfoDescription) + rows, err := stmt.Query(server.Id, c.ID, ChannelInfoDescription) if err != nil { return err } @@ -167,7 +167,7 @@ func populateChannelInfoFromDatabase(server *Server, c *Channel, db *sql.DB) err } // Fetch position - rows, err = stmt.Query(server.Id, c.Id, ChannelInfoPosition) + rows, err = stmt.Query(server.Id, c.ID, ChannelInfoPosition) if err != nil { return err } @@ -190,7 +190,7 @@ func populateChannelACLFromDatabase(server *Server, c *Channel, db *sql.DB) erro return err } - rows, err := stmt.Query(server.Id, c.Id) + rows, err := stmt.Query(server.Id, c.ID) if err != nil { return err } @@ -237,7 +237,7 @@ func populateChannelGroupsFromDatabase(server *Server, c *Channel, db *sql.DB) e return err } - rows, err := stmt.Query(server.Id, c.Id) + rows, err := stmt.Query(server.Id, c.ID) if err != nil { return err } @@ -324,7 +324,7 @@ func populateChannelsFromDatabase(server *Server, db *sql.DB, parentId int) erro } c := NewChannel(chanid, name) - server.Channels[c.Id] = c + server.Channels[c.ID] = c c.ACL.InheritACL = inherit parent.AddChild(c) } diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index 03ed4ac..7a585a5 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -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. func (server *Server) AddChannel(name string) (channel *Channel) { channel = NewChannel(server.nextChanId, name) - server.Channels[channel.Id] = channel + server.Channels[channel.ID] = channel server.nextChanId += 1 return @@ -359,24 +359,24 @@ func (server *Server) AddChannel(name string) (channel *Channel) { // RemoveChanel removes a channel from the server. func (server *Server) RemoveChanel(channel *Channel) { - if channel.Id == 0 { + if channel.ID == 0 { server.Printf("Attempted to remove root channel.") return } - delete(server.Channels, channel.Id) + delete(server.Channels, channel.ID) } // LinkChannels will link two channels func (server *Server) LinkChannels(channel *Channel, other *Channel) { - channel.Links[other.Id] = other - other.Links[channel.Id] = channel + channel.Links[other.ID] = other + other.Links[channel.ID] = channel } // UnlinkChannels will unlink two channels func (server *Server) UnlinkChannels(channel *Channel, other *Channel) { - delete(channel.Links, other.Id) - delete(other.Links, channel.Id) + delete(channel.Links, other.ID) + delete(other.Links, channel.ID) } // This is the synchronous handler goroutine. @@ -618,7 +618,7 @@ func (server *Server) finishAuthenticate(client *Client) { userstate := &mumbleproto.UserState{ Session: proto.Uint32(client.Session()), Name: proto.String(client.ShownName()), - ChannelId: proto.Uint32(uint32(channel.Id)), + ChannelId: proto.Uint32(uint32(channel.ID)), } if client.HasCertificate() { @@ -802,7 +802,7 @@ func (server *Server) sendUserList(client *Client) { userstate := &mumbleproto.UserState{ Session: proto.Uint32(connectedClient.Session()), Name: proto.String(connectedClient.ShownName()), - ChannelId: proto.Uint32(uint32(connectedClient.Channel.Id)), + ChannelId: proto.Uint32(uint32(connectedClient.Channel.ID)), } if connectedClient.HasCertificate() { @@ -1183,7 +1183,7 @@ func (server *Server) RemoveChannel(channel *Channel) { // Remove all links for _, linkedChannel := range channel.Links { - delete(linkedChannel.Links, channel.Id) + delete(linkedChannel.Links, channel.ID) } // Remove all subchannels @@ -1200,7 +1200,7 @@ func (server *Server) RemoveChannel(channel *Channel) { userstate := &mumbleproto.UserState{} 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) if err := server.broadcastProtoMessage(userstate); err != nil { server.Panicf("%v", err) @@ -1209,10 +1209,10 @@ func (server *Server) RemoveChannel(channel *Channel) { // Remove the channel itself parent := channel.parent - delete(parent.children, channel.Id) - delete(server.Channels, channel.Id) + delete(parent.children, channel.ID) + delete(server.Channels, channel.ID) chanremove := &mumbleproto.ChannelRemove{ - ChannelId: proto.Uint32(uint32(channel.Id)), + ChannelId: proto.Uint32(uint32(channel.ID)), } if err := server.broadcastProtoMessage(chanremove); err != nil { server.Panicf("%v", err) diff --git a/cmd/grumble/voicetarget.go b/cmd/grumble/voicetarget.go index 74d3175..6f7d4be 100644 --- a/cmd/grumble/voicetarget.go +++ b/cmd/grumble/voicetarget.go @@ -85,7 +85,7 @@ func (vt *VoiceTarget) SendVoiceBroadcast(vb *VoiceBroadcast) { if vtc.links { newchans = channel.AllLinks() } else { - newchans[channel.Id] = channel + newchans[channel.ID] = channel } if vtc.subChannels { subchans := channel.AllSubChannels() From 6fae18a9cd199035ec8a49959aa7a509ea8d9a78 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 17:38:29 +0000 Subject: [PATCH 06/14] Rename all Udp and Tcp to UDP and TCP to follow Golang coding standards --- cmd/grumble/client.go | 12 ++--- cmd/grumble/message.go | 36 +++++++------- cmd/grumble/server.go | 4 +- pkg/mumbleproto/Mumble.pb.go | 96 ++++++++++++++++++------------------ 4 files changed, 74 insertions(+), 74 deletions(-) diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index 0c5d68c..fd174fb 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -49,12 +49,12 @@ type Client struct { voiceTargets map[uint32]*VoiceTarget // Ping stats - UdpPingAvg float32 - UdpPingVar float32 - UdpPackets uint32 - TcpPingAvg float32 - TcpPingVar float32 - TcpPackets uint32 + UDPPingAvg float32 + UDPPingVar float32 + UDPPackets uint32 + TCPPingAvg float32 + TCPPingVar float32 + TCPPackets uint32 // If the client is a registered user on the server, // the user field will point to the registration record. diff --git a/cmd/grumble/message.go b/cmd/grumble/message.go index 4cdced7..ad76599 100644 --- a/cmd/grumble/message.go +++ b/cmd/grumble/message.go @@ -87,24 +87,24 @@ func (server *Server) handlePingMessage(client *Client, msg *Message) { client.crypt.RemoteResync = *ping.Resync } - if ping.UdpPingAvg != nil { - client.UdpPingAvg = *ping.UdpPingAvg + if ping.UDPPingAvg != nil { + client.UDPPingAvg = *ping.UDPPingAvg } - if ping.UdpPingVar != nil { - client.UdpPingVar = *ping.UdpPingVar + if ping.UDPPingVar != nil { + client.UDPPingVar = *ping.UDPPingVar } - if ping.UdpPackets != nil { - client.UdpPackets = *ping.UdpPackets + if ping.UDPPackets != nil { + client.UDPPackets = *ping.UDPPackets } - if ping.TcpPingAvg != nil { - client.TcpPingAvg = *ping.TcpPingAvg + if ping.TCPPingAvg != nil { + client.TCPPingAvg = *ping.TCPPingAvg } - if ping.TcpPingVar != nil { - client.TcpPingVar = *ping.TcpPingVar + if ping.TCPPingVar != nil { + client.TCPPingVar = *ping.TCPPingVar } - if ping.TcpPackets != nil { - client.TcpPackets = *ping.TcpPackets + if ping.TCPPackets != nil { + client.TCPPackets = *ping.TCPPackets } client.sendMessage(&mumbleproto.Ping{ @@ -1358,12 +1358,12 @@ func (server *Server) handleUserStatsMessage(client *Client, msg *Message) { stats.FromServer = fromServer } - stats.UdpPackets = proto.Uint32(target.UdpPackets) - stats.TcpPackets = proto.Uint32(target.TcpPackets) - stats.UdpPingAvg = proto.Float32(target.UdpPingAvg) - stats.UdpPingVar = proto.Float32(target.UdpPingVar) - stats.TcpPingAvg = proto.Float32(target.TcpPingAvg) - stats.TcpPingVar = proto.Float32(target.TcpPingVar) + stats.UDPPackets = proto.Uint32(target.UDPPackets) + stats.TCPPackets = proto.Uint32(target.TCPPackets) + stats.UDPPingAvg = proto.Float32(target.UDPPingAvg) + stats.UDPPingVar = proto.Float32(target.UDPPingVar) + stats.TCPPingAvg = proto.Float32(target.TCPPingAvg) + stats.TCPPingVar = proto.Float32(target.TCPPingVar) if details { version := &mumbleproto.Version{} diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index 7a585a5..a7ef1cd 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -1002,12 +1002,12 @@ func (server *Server) udpListenLoop() { } } else { - server.handleUdpPacket(udpaddr, buf[0:nread]) + server.handleUDPPacket(udpaddr, buf[0:nread]) } } } -func (server *Server) handleUdpPacket(udpaddr *net.UDPAddr, buf []byte) { +func (server *Server) handleUDPPacket(udpaddr *net.UDPAddr, buf []byte) { var match *Client plain := make([]byte, len(buf)) diff --git a/pkg/mumbleproto/Mumble.pb.go b/pkg/mumbleproto/Mumble.pb.go index 965c6a1..db112df 100644 --- a/pkg/mumbleproto/Mumble.pb.go +++ b/pkg/mumbleproto/Mumble.pb.go @@ -410,17 +410,17 @@ type Ping struct { // The amount of nonce resyncs. Resync *uint32 `protobuf:"varint,5,opt,name=resync" json:"resync,omitempty"` // The total amount of UDP packets received. - UdpPackets *uint32 `protobuf:"varint,6,opt,name=udp_packets,json=udpPackets" json:"udp_packets,omitempty"` + UDPPackets *uint32 `protobuf:"varint,6,opt,name=udp_packets,json=udpPackets" json:"udp_packets,omitempty"` // The total amount of TCP packets received. - TcpPackets *uint32 `protobuf:"varint,7,opt,name=tcp_packets,json=tcpPackets" json:"tcp_packets,omitempty"` + TCPPackets *uint32 `protobuf:"varint,7,opt,name=tcp_packets,json=tcpPackets" json:"tcp_packets,omitempty"` // UDP ping average. - UdpPingAvg *float32 `protobuf:"fixed32,8,opt,name=udp_ping_avg,json=udpPingAvg" json:"udp_ping_avg,omitempty"` + UDPPingAvg *float32 `protobuf:"fixed32,8,opt,name=udp_ping_avg,json=udpPingAvg" json:"udp_ping_avg,omitempty"` // UDP ping variance. - UdpPingVar *float32 `protobuf:"fixed32,9,opt,name=udp_ping_var,json=udpPingVar" json:"udp_ping_var,omitempty"` + UDPPingVar *float32 `protobuf:"fixed32,9,opt,name=udp_ping_var,json=udpPingVar" json:"udp_ping_var,omitempty"` // TCP ping average. - TcpPingAvg *float32 `protobuf:"fixed32,10,opt,name=tcp_ping_avg,json=tcpPingAvg" json:"tcp_ping_avg,omitempty"` + TCPPingAvg *float32 `protobuf:"fixed32,10,opt,name=tcp_ping_avg,json=tcpPingAvg" json:"tcp_ping_avg,omitempty"` // TCP ping variance. - TcpPingVar *float32 `protobuf:"fixed32,11,opt,name=tcp_ping_var,json=tcpPingVar" json:"tcp_ping_var,omitempty"` + TCPPingVar *float32 `protobuf:"fixed32,11,opt,name=tcp_ping_var,json=tcpPingVar" json:"tcp_ping_var,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -464,44 +464,44 @@ func (m *Ping) GetResync() uint32 { return 0 } -func (m *Ping) GetUdpPackets() uint32 { - if m != nil && m.UdpPackets != nil { - return *m.UdpPackets +func (m *Ping) GetUDPPackets() uint32 { + if m != nil && m.UDPPackets != nil { + return *m.UDPPackets } return 0 } -func (m *Ping) GetTcpPackets() uint32 { - if m != nil && m.TcpPackets != nil { - return *m.TcpPackets +func (m *Ping) GetTCPPackets() uint32 { + if m != nil && m.TCPPackets != nil { + return *m.TCPPackets } return 0 } -func (m *Ping) GetUdpPingAvg() float32 { - if m != nil && m.UdpPingAvg != nil { - return *m.UdpPingAvg +func (m *Ping) GetUDPPingAvg() float32 { + if m != nil && m.UDPPingAvg != nil { + return *m.UDPPingAvg } return 0 } -func (m *Ping) GetUdpPingVar() float32 { - if m != nil && m.UdpPingVar != nil { - return *m.UdpPingVar +func (m *Ping) GetUDPPingVar() float32 { + if m != nil && m.UDPPingVar != nil { + return *m.UDPPingVar } return 0 } -func (m *Ping) GetTcpPingAvg() float32 { - if m != nil && m.TcpPingAvg != nil { - return *m.TcpPingAvg +func (m *Ping) GetTCPPingAvg() float32 { + if m != nil && m.TCPPingAvg != nil { + return *m.TCPPingAvg } return 0 } -func (m *Ping) GetTcpPingVar() float32 { - if m != nil && m.TcpPingVar != nil { - return *m.TcpPingVar +func (m *Ping) GetTCPPingVar() float32 { + if m != nil && m.TCPPingVar != nil { + return *m.TCPPingVar } return 0 } @@ -1795,17 +1795,17 @@ type UserStats struct { // Packet statistics for packets sent by the server. FromServer *UserStats_Stats `protobuf:"bytes,5,opt,name=from_server,json=fromServer" json:"from_server,omitempty"` // Amount of UDP packets sent. - UdpPackets *uint32 `protobuf:"varint,6,opt,name=udp_packets,json=udpPackets" json:"udp_packets,omitempty"` + UDPPackets *uint32 `protobuf:"varint,6,opt,name=udp_packets,json=udpPackets" json:"udp_packets,omitempty"` // Amount of TCP packets sent. - TcpPackets *uint32 `protobuf:"varint,7,opt,name=tcp_packets,json=tcpPackets" json:"tcp_packets,omitempty"` + TCPPackets *uint32 `protobuf:"varint,7,opt,name=tcp_packets,json=tcpPackets" json:"tcp_packets,omitempty"` // UDP ping average. - UdpPingAvg *float32 `protobuf:"fixed32,8,opt,name=udp_ping_avg,json=udpPingAvg" json:"udp_ping_avg,omitempty"` + UDPPingAvg *float32 `protobuf:"fixed32,8,opt,name=udp_ping_avg,json=udpPingAvg" json:"udp_ping_avg,omitempty"` // UDP ping variance. - UdpPingVar *float32 `protobuf:"fixed32,9,opt,name=udp_ping_var,json=udpPingVar" json:"udp_ping_var,omitempty"` + UDPPingVar *float32 `protobuf:"fixed32,9,opt,name=udp_ping_var,json=udpPingVar" json:"udp_ping_var,omitempty"` // TCP ping average. - TcpPingAvg *float32 `protobuf:"fixed32,10,opt,name=tcp_ping_avg,json=tcpPingAvg" json:"tcp_ping_avg,omitempty"` + TCPPingAvg *float32 `protobuf:"fixed32,10,opt,name=tcp_ping_avg,json=tcpPingAvg" json:"tcp_ping_avg,omitempty"` // TCP ping variance. - TcpPingVar *float32 `protobuf:"fixed32,11,opt,name=tcp_ping_var,json=tcpPingVar" json:"tcp_ping_var,omitempty"` + TCPPingVar *float32 `protobuf:"fixed32,11,opt,name=tcp_ping_var,json=tcpPingVar" json:"tcp_ping_var,omitempty"` // Client version. Version *Version `protobuf:"bytes,12,opt,name=version" json:"version,omitempty"` // A list of CELT bitstream version constants supported by the client of this @@ -1869,44 +1869,44 @@ func (m *UserStats) GetFromServer() *UserStats_Stats { return nil } -func (m *UserStats) GetUdpPackets() uint32 { - if m != nil && m.UdpPackets != nil { - return *m.UdpPackets +func (m *UserStats) GetUDPPackets() uint32 { + if m != nil && m.UDPPackets != nil { + return *m.UDPPackets } return 0 } -func (m *UserStats) GetTcpPackets() uint32 { - if m != nil && m.TcpPackets != nil { - return *m.TcpPackets +func (m *UserStats) GetTCPPackets() uint32 { + if m != nil && m.TCPPackets != nil { + return *m.TCPPackets } return 0 } -func (m *UserStats) GetUdpPingAvg() float32 { - if m != nil && m.UdpPingAvg != nil { - return *m.UdpPingAvg +func (m *UserStats) GetUDPPingAvg() float32 { + if m != nil && m.UDPPingAvg != nil { + return *m.UDPPingAvg } return 0 } -func (m *UserStats) GetUdpPingVar() float32 { - if m != nil && m.UdpPingVar != nil { - return *m.UdpPingVar +func (m *UserStats) GetUDPPingVar() float32 { + if m != nil && m.UDPPingVar != nil { + return *m.UDPPingVar } return 0 } -func (m *UserStats) GetTcpPingAvg() float32 { - if m != nil && m.TcpPingAvg != nil { - return *m.TcpPingAvg +func (m *UserStats) GetTCPPingAvg() float32 { + if m != nil && m.TCPPingAvg != nil { + return *m.TCPPingAvg } return 0 } -func (m *UserStats) GetTcpPingVar() float32 { - if m != nil && m.TcpPingVar != nil { - return *m.TcpPingVar +func (m *UserStats) GetTCPPingVar() float32 { + if m != nil && m.TCPPingVar != nil { + return *m.TCPPingVar } return 0 } From 2937dab654d60f90f5ceaff36a804d2751f09744 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 17:52:27 +0000 Subject: [PATCH 07/14] Rename all Id to ID to conform with Golang coding standards --- cmd/grumble/client.go | 8 ++-- cmd/grumble/freeze.go | 84 ++++++++++++++++++------------------ cmd/grumble/freeze_unix.go | 4 +- cmd/grumble/grumble.go | 6 +-- cmd/grumble/message.go | 34 +++++++-------- cmd/grumble/murmurdb.go | 70 +++++++++++++++--------------- cmd/grumble/server.go | 42 +++++++++--------- cmd/grumble/user.go | 6 +-- pkg/acl/acl.go | 8 ++-- pkg/acl/group.go | 8 ++-- pkg/acl/interfaces.go | 2 +- pkg/freezer/types.pb.go | 16 +++---- pkg/mumbleproto/Mumble.pb.go | 24 +++++------ 13 files changed, 156 insertions(+), 156 deletions(-) diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index fd174fb..0e496e1 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -112,7 +112,7 @@ func (client *Client) IsSuperUser() bool { if client.user == nil { return false } - return client.user.Id == 0 + return client.user.ID == 0 } // ACLContext returns the access control list context for this client @@ -135,13 +135,13 @@ func (client *Client) Tokens() []string { return client.tokens } -// UserId gets the User ID of this client. +// UserID gets the User ID of this client. // Returns -1 if the client is not a registered user. -func (client *Client) UserId() int { +func (client *Client) UserID() int { if client.user == nil { return -1 } - return int(client.user.Id) + return int(client.user.ID) } // ShownName gets the client's shown name. diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index 40de458..dbe8a49 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -52,7 +52,7 @@ func (server *Server) openFreezeLog() error { server.freezelog = nil } - logfn := filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10), "log.fz") + logfn := filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.ID, 10), "log.fz") err := os.Remove(logfn) if os.IsNotExist(err) { // fallthrough @@ -237,10 +237,10 @@ func (c *Channel) Unfreeze(fc *freezer.Channel) { if facl.ApplySubs != nil { aclEntry.ApplySubs = *facl.ApplySubs } - if facl.UserId != nil { - aclEntry.UserId = int(*facl.UserId) + if facl.UserID != nil { + aclEntry.UserID = int(*facl.UserID) } else { - aclEntry.UserId = -1 + aclEntry.UserID = -1 } if facl.Group != nil { aclEntry.Group = *facl.Group @@ -295,13 +295,13 @@ func (c *Channel) Unfreeze(fc *freezer.Channel) { func (user *User) Freeze() (fu *freezer.User, err error) { fu = new(freezer.User) - fu.Id = proto.Uint32(user.Id) + fu.Id = proto.Uint32(user.ID) fu.Name = proto.String(user.Name) fu.CertHash = proto.String(user.CertHash) fu.Email = proto.String(user.Email) fu.TextureBlob = proto.String(user.TextureBlob) fu.CommentBlob = proto.String(user.CommentBlob) - fu.LastChannelId = proto.Uint32(uint32(user.LastChannelId)) + fu.LastChannelID = proto.Uint32(uint32(user.LastChannelID)) fu.LastActive = proto.Uint64(user.LastActive) return @@ -324,8 +324,8 @@ func (u *User) Unfreeze(fu *freezer.User) { if fu.CommentBlob != nil { u.CommentBlob = *fu.CommentBlob } - if fu.LastChannelId != nil { - u.LastChannelId = int(*fu.LastChannelId) + if fu.LastChannelID != nil { + u.LastChannelID = int(*fu.LastChannelID) } if fu.LastActive != nil { u.LastActive = *fu.LastActive @@ -336,8 +336,8 @@ func (u *User) Unfreeze(fu *freezer.User) { // ready to be persisted to disk. func FreezeACL(aclEntry acl.ACL) (*freezer.ACL, error) { frozenAcl := &freezer.ACL{} - if aclEntry.UserId != -1 { - frozenAcl.UserId = proto.Uint32(uint32(aclEntry.UserId)) + if aclEntry.UserID != -1 { + frozenAcl.UserID = proto.Uint32(uint32(aclEntry.UserID)) } else { frozenAcl.Group = proto.String(aclEntry.Group) } @@ -445,8 +445,8 @@ func NewServerFromFrozen(name string) (s *Server, err error) { // Update the server's nextChanId field if it needs to be, // to make sure the server doesn't re-use channel id's. c := NewChannel(int(*fc.Id), *fc.Name) - if c.ID >= s.nextChanId { - s.nextChanId = c.ID + 1 + if c.ID >= s.nextChanID { + s.nextChanID = c.ID + 1 } // Update the channel with the contents of the freezer.Channel. @@ -472,8 +472,8 @@ func NewServerFromFrozen(name string) (s *Server, err error) { if err != nil { return nil, err } - if u.Id >= s.nextUserId { - s.nextUserId = u.Id + 1 + if u.ID >= s.nextUserID { + s.nextUserID = u.ID + 1 } // Merge the contents of the freezer.User into @@ -482,7 +482,7 @@ func NewServerFromFrozen(name string) (s *Server, err error) { // Update the server's user maps to point correctly // to the new user. - s.Users[u.Id] = u + s.Users[u.ID] = u s.UserNameMap[u.Name] = u if len(u.CertHash) > 0 { s.UserCertMap[u.CertHash] = u @@ -520,14 +520,14 @@ func NewServerFromFrozen(name string) (s *Server, err error) { continue } - userId := *fu.Id + userID := *fu.Id // Determine whether the user already exists on the server or not. // If the user already exists, this log entry simply updates the // data for that user. // If the user doesn't exist, we create it with the data given in // this log entry. - user, ok := s.Users[userId] + user, ok := s.Users[userID] if !ok { // If no name is given in the log entry, skip this entry. // Also, warn the admin. @@ -535,14 +535,14 @@ func NewServerFromFrozen(name string) (s *Server, err error) { log.Printf("Skipped User creation log entry: No name given.") continue } - // Create the new user and increment the UserId + // Create the new user and increment the UserID // counter for the server if needed. - user, err = NewUser(userId, *fu.Name) + user, err = NewUser(userID, *fu.Name) if err != nil { return nil, err } - if user.Id >= s.nextUserId { - s.nextUserId = user.Id + 1 + if user.ID >= s.nextUserID { + s.nextUserID = user.ID + 1 } } @@ -552,7 +552,7 @@ func NewServerFromFrozen(name string) (s *Server, err error) { // Update the various user maps in the server to // be able to correctly look up the user. - s.Users[user.Id] = user + s.Users[user.ID] = user s.UserNameMap[user.Name] = user if len(user.CertHash) > 0 { s.UserCertMap[user.CertHash] = user @@ -566,14 +566,14 @@ func NewServerFromFrozen(name string) (s *Server, err error) { continue } - userId := *fu.Id + userID := *fu.Id // Does this user even exist? // Warn if we encounter an illegal delete op. - user, ok := s.Users[userId] + user, ok := s.Users[userID] if ok { // Clear the server maps. That should do it. - delete(s.Users, userId) + delete(s.Users, userID) delete(s.UserNameMap, user.Name) if len(user.CertHash) > 0 { delete(s.UserCertMap, user.CertHash) @@ -591,9 +591,9 @@ func NewServerFromFrozen(name string) (s *Server, err error) { continue } - channelId := int(*fc.Id) + channelID := int(*fc.Id) - channel, alreadyExists := s.Channels[channelId] + channel, alreadyExists := s.Channels[channelID] if !alreadyExists { if fc.Name == nil { log.Printf("Skipped Channel creation log entry: No name given.") @@ -601,9 +601,9 @@ func NewServerFromFrozen(name string) (s *Server, err error) { } // Add the channel and increment the server's // nextChanId field to a consistent state. - channel = NewChannel(channelId, *fc.Name) - if channel.ID >= s.nextChanId { - s.nextChanId = channel.ID + 1 + channel = NewChannel(channelID, *fc.Name) + if channel.ID >= s.nextChanID { + s.nextChanID = channel.ID + 1 } } @@ -612,7 +612,7 @@ func NewServerFromFrozen(name string) (s *Server, err error) { channel.Unfreeze(fc) // Re-add it to the server's channel map (in case // the channel was newly-created) - s.Channels[channelId] = channel + s.Channels[channelID] = channel // Mark the channel's parent if !alreadyExists { @@ -652,12 +652,12 @@ func NewServerFromFrozen(name string) (s *Server, err error) { } // Hook up children with their parents - for chanId, parentId := range parents { - childChan, exists := s.Channels[int(chanId)] + for chanID, parentID := range parents { + childChan, exists := s.Channels[int(chanID)] if !exists { return nil, errors.New("Non-existant child channel") } - parentChan, exists := s.Channels[int(parentId)] + parentChan, exists := s.Channels[int(parentID)] if !exists { return nil, errors.New("Non-existant parent channel") } @@ -669,8 +669,8 @@ func NewServerFromFrozen(name string) (s *Server, err error) { if len(channel.Links) > 0 { links := channel.Links channel.Links = make(map[int]*Channel) - for chanId, _ := range links { - targetChannel := s.Channels[chanId] + for chanID, _ := range links { + targetChannel := s.Channels[chanID] if targetChannel != nil { s.LinkChannels(channel, targetChannel) } @@ -687,7 +687,7 @@ func (server *Server) UpdateFrozenUser(client *Client, state *mumbleproto.UserSt // it includes a registration operation. user := client.user nanos := time.Now().Unix() - if state == nil || state.UserId != nil { + if state == nil || state.UserID != nil { fu, err := user.Freeze() if err != nil { server.Fatal(err) @@ -699,9 +699,9 @@ func (server *Server) UpdateFrozenUser(client *Client, state *mumbleproto.UserSt } } else { fu := &freezer.User{} - fu.Id = proto.Uint32(user.Id) + fu.Id = proto.Uint32(user.ID) if state.ChannelId != nil { - fu.LastChannelId = proto.Uint32(uint32(client.Channel.ID)) + fu.LastChannelID = proto.Uint32(uint32(client.Channel.ID)) } if state.TextureHash != nil { fu.TextureBlob = proto.String(user.TextureBlob) @@ -724,8 +724,8 @@ func (server *Server) UpdateFrozenUserLastChannel(client *Client) { user := client.user fu := &freezer.User{} - fu.Id = proto.Uint32(user.Id) - fu.LastChannelId = proto.Uint32(uint32(client.Channel.ID)) + fu.Id = proto.Uint32(user.ID) + fu.LastChannelID = proto.Uint32(uint32(client.Channel.ID)) fu.LastActive = proto.Uint64(uint64(time.Now().Unix())) err := server.freezelog.Put(fu) @@ -739,7 +739,7 @@ func (server *Server) UpdateFrozenUserLastChannel(client *Client) { // DeleteFrozenUser will mark a user as deleted in the datstore. func (server *Server) DeleteFrozenUser(user *User) { - err := server.freezelog.Put(&freezer.UserRemove{Id: proto.Uint32(user.Id)}) + err := server.freezelog.Put(&freezer.UserRemove{Id: proto.Uint32(user.ID)}) if err != nil { server.Fatal(err) } diff --git a/cmd/grumble/freeze_unix.go b/cmd/grumble/freeze_unix.go index 5974539..8a90891 100644 --- a/cmd/grumble/freeze_unix.go +++ b/cmd/grumble/freeze_unix.go @@ -30,7 +30,7 @@ func (server *Server) freezeToFile() (err error) { if err != nil { return err } - f, err := ioutil.TempFile(filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10)), ".main.fz_") + f, err := ioutil.TempFile(filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.ID, 10)), ".main.fz_") if err != nil { return err } @@ -50,7 +50,7 @@ func (server *Server) freezeToFile() (err error) { if err != nil { return err } - err = os.Rename(f.Name(), filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.Id, 10), "main.fz")) + err = os.Rename(f.Name(), filepath.Join(Args.DataDir, "servers", strconv.FormatInt(server.ID, 10), "main.fz")) if err != nil { return err } diff --git a/cmd/grumble/grumble.go b/cmd/grumble/grumble.go index 56eaa9a..0bd7aaf 100644 --- a/cmd/grumble/grumble.go +++ b/cmd/grumble/grumble.go @@ -185,7 +185,7 @@ func main() { if err != nil { log.Fatalf("Unable to freeze server to disk: %v", err.Error()) } - servers[s.Id] = s + servers[s.ID] = s } } @@ -196,7 +196,7 @@ func main() { log.Fatalf("Couldn't start server: %s", err.Error()) } - servers[s.Id] = s + servers[s.ID] = s os.Mkdir(filepath.Join(serversDirPath, fmt.Sprintf("%v", 1)), 0750) err = s.FreezeToFile() if err != nil { @@ -208,7 +208,7 @@ func main() { for _, server := range servers { err = server.Start() if err != nil { - log.Printf("Unable to start server %v: %v", server.Id, err.Error()) + log.Printf("Unable to start server %v: %v", server.ID, err.Error()) } } diff --git a/cmd/grumble/message.go b/cmd/grumble/message.go index ad76599..77c7650 100644 --- a/cmd/grumble/message.go +++ b/cmd/grumble/message.go @@ -270,7 +270,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) { // Add the creator to the channel's admin group if client.IsRegistered() { grp := acl.EmptyGroupWithName("admin") - grp.Add[client.UserId()] = true + grp.Add[client.UserID()] = true channel.ACL.Groups["admin"] = grp } @@ -281,7 +281,7 @@ func (server *Server) handleChannelStateMessage(client *Client, msg *Message) { aclEntry.ApplyHere = true aclEntry.ApplySubs = true if client.IsRegistered() { - aclEntry.UserId = client.UserId() + aclEntry.UserID = client.UserID() } else { aclEntry.Group = "$" + client.CertHash() } @@ -663,7 +663,7 @@ func (server *Server) handleUserStateMessage(client *Client, msg *Message) { } // Registration - if userstate.UserId != nil { + if userstate.UserID != nil { // If user == actor, check for SelfRegisterPermission on root channel. // If user != actor, check for RegisterPermission permission on root channel. perm := acl.Permission(acl.RegisterPermission) @@ -799,13 +799,13 @@ func (server *Server) handleUserStateMessage(client *Client, msg *Message) { } userRegistrationChanged := false - if userstate.UserId != nil { + if userstate.UserID != nil { uid, err := server.RegisterClient(target) if err != nil { client.Printf("Unable to register: %v", err) - userstate.UserId = nil + userstate.UserID = nil } else { - userstate.UserId = proto.Uint32(uid) + userstate.UserID = proto.Uint32(uid) client.user = server.Users[uid] userRegistrationChanged = true } @@ -1079,9 +1079,9 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { mpacl.Inherited = proto.Bool(iter != channel) mpacl.ApplyHere = proto.Bool(chanacl.ApplyHere) mpacl.ApplySubs = proto.Bool(chanacl.ApplySubs) - if chanacl.UserId >= 0 { - mpacl.UserId = proto.Uint32(uint32(chanacl.UserId)) - users[chanacl.UserId] = true + if chanacl.UserID >= 0 { + mpacl.UserID = proto.Uint32(uint32(chanacl.UserID)) + users[chanacl.UserID] = true } else { mpacl.Group = proto.String(chanacl.Group) } @@ -1210,8 +1210,8 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { chanacl := acl.ACL{} chanacl.ApplyHere = *pbacl.ApplyHere chanacl.ApplySubs = *pbacl.ApplySubs - if pbacl.UserId != nil { - chanacl.UserId = int(*pbacl.UserId) + if pbacl.UserID != nil { + chanacl.UserID = int(*pbacl.UserID) } else { chanacl.Group = *pbacl.Group } @@ -1230,7 +1230,7 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { chanacl.ApplyHere = true chanacl.ApplySubs = false if client.IsRegistered() { - chanacl.UserId = client.UserId() + chanacl.UserID = client.UserID() } else if client.HasCertificate() { chanacl.Group = "$" + client.CertHash() } @@ -1271,7 +1271,7 @@ func (server *Server) handleQueryUsers(client *Client, msg *Message) { for _, name := range query.Names { user, exists := server.UserNameMap[name] if exists { - reply.Ids = append(reply.Ids, user.Id) + reply.Ids = append(reply.Ids, user.ID) reply.Names = append(reply.Names, name) } } @@ -1568,7 +1568,7 @@ func (server *Server) handleUserList(client *Client, msg *Message) { continue } userlist.Users = append(userlist.Users, &mumbleproto.UserList_User{ - UserId: proto.Uint32(uid), + UserID: proto.Uint32(uid), Name: proto.String(user.Name), }) } @@ -1581,7 +1581,7 @@ func (server *Server) handleUserList(client *Client, msg *Message) { if len(userlist.Users) > 0 { tx := server.freezelog.BeginTx() for _, listUser := range userlist.Users { - uid := *listUser.UserId + uid := *listUser.UserID if uid == 0 { continue } @@ -1590,7 +1590,7 @@ func (server *Server) handleUserList(client *Client, msg *Message) { if listUser.Name == nil { // De-register server.RemoveRegistration(uid) - err := tx.Put(&freezer.UserRemove{Id: listUser.UserId}) + err := tx.Put(&freezer.UserRemove{Id: listUser.UserID}) if err != nil { server.Fatal(err) } @@ -1598,7 +1598,7 @@ func (server *Server) handleUserList(client *Client, msg *Message) { // Rename user // todo(mkrautz): Validate name. user.Name = *listUser.Name - err := tx.Put(&freezer.User{Id: listUser.UserId, Name: listUser.Name}) + err := tx.Put(&freezer.User{Id: listUser.UserID, Name: listUser.Name}) if err != nil { server.Fatal(err) } diff --git a/cmd/grumble/murmurdb.go b/cmd/grumble/murmurdb.go index 5996e53..24d4f60 100644 --- a/cmd/grumble/murmurdb.go +++ b/cmd/grumble/murmurdb.go @@ -146,7 +146,7 @@ func populateChannelInfoFromDatabase(server *Server, c *Channel, db *sql.DB) err } // Fetch description - rows, err := stmt.Query(server.Id, c.ID, ChannelInfoDescription) + rows, err := stmt.Query(server.ID, c.ID, ChannelInfoDescription) if err != nil { return err } @@ -167,7 +167,7 @@ func populateChannelInfoFromDatabase(server *Server, c *Channel, db *sql.DB) err } // Fetch position - rows, err = stmt.Query(server.Id, c.ID, ChannelInfoPosition) + rows, err = stmt.Query(server.ID, c.ID, ChannelInfoPosition) if err != nil { return err } @@ -190,36 +190,36 @@ func populateChannelACLFromDatabase(server *Server, c *Channel, db *sql.DB) erro return err } - rows, err := stmt.Query(server.Id, c.ID) + rows, err := stmt.Query(server.ID, c.ID) if err != nil { return err } for rows.Next() { var ( - UserId string + UserID string Group string ApplyHere bool ApplySub bool Allow int64 Deny int64 ) - if err := rows.Scan(&UserId, &Group, &ApplyHere, &ApplySub, &Allow, &Deny); err != nil { + if err := rows.Scan(&UserID, &Group, &ApplyHere, &ApplySub, &Allow, &Deny); err != nil { return err } aclEntry := acl.ACL{} aclEntry.ApplyHere = ApplyHere aclEntry.ApplySubs = ApplySub - if len(UserId) > 0 { - aclEntry.UserId, err = strconv.Atoi(UserId) + if len(UserID) > 0 { + aclEntry.UserID, err = strconv.Atoi(UserID) if err != nil { return err } } else if len(Group) > 0 { aclEntry.Group = Group } else { - return errors.New("Invalid ACL: Neither Group or UserId specified") + return errors.New("Invalid ACL: Neither Group or UserID specified") } aclEntry.Deny = acl.Permission(Deny) @@ -237,7 +237,7 @@ func populateChannelGroupsFromDatabase(server *Server, c *Channel, db *sql.DB) e return err } - rows, err := stmt.Query(server.Id, c.ID) + rows, err := stmt.Query(server.ID, c.ID) if err != nil { return err } @@ -246,13 +246,13 @@ func populateChannelGroupsFromDatabase(server *Server, c *Channel, db *sql.DB) e for rows.Next() { var ( - GroupId int64 + GroupID int64 Name string Inherit bool Inheritable bool ) - if err := rows.Scan(&GroupId, &Name, &Inherit, &Inheritable); err != nil { + if err := rows.Scan(&GroupID, &Name, &Inherit, &Inheritable); err != nil { return err } @@ -260,7 +260,7 @@ func populateChannelGroupsFromDatabase(server *Server, c *Channel, db *sql.DB) e g.Inherit = Inherit g.Inheritable = Inheritable c.ACL.Groups[g.Name] = g - groups[GroupId] = g + groups[GroupID] = g } stmt, err = db.Prepare("SELECT user_id, addit FROM group_members WHERE server_id=? AND group_id=?") @@ -269,25 +269,25 @@ func populateChannelGroupsFromDatabase(server *Server, c *Channel, db *sql.DB) e } for gid, grp := range groups { - rows, err = stmt.Query(server.Id, gid) + rows, err = stmt.Query(server.ID, gid) if err != nil { return err } for rows.Next() { var ( - UserId int64 + UserID int64 Add bool ) - if err := rows.Scan(&UserId, &Add); err != nil { + if err := rows.Scan(&UserID, &Add); err != nil { return err } if Add { - grp.Add[int(UserId)] = true + grp.Add[int(UserID)] = true } else { - grp.Remove[int(UserId)] = true + grp.Remove[int(UserID)] = true } } } @@ -296,8 +296,8 @@ func populateChannelGroupsFromDatabase(server *Server, c *Channel, db *sql.DB) e } // Populate the Server with Channels from the database. -func populateChannelsFromDatabase(server *Server, db *sql.DB, parentId int) error { - parent, exists := server.Channels[parentId] +func populateChannelsFromDatabase(server *Server, db *sql.DB, parentID int) error { + parent, exists := server.Channels[parentID] if !exists { return errors.New("Non-existant parent") } @@ -307,7 +307,7 @@ func populateChannelsFromDatabase(server *Server, db *sql.DB, parentId int) erro return err } - rows, err := stmt.Query(server.Id, parentId) + rows, err := stmt.Query(server.ID, parentID) if err != nil { return err } @@ -371,26 +371,26 @@ func populateChannelLinkInfo(server *Server, db *sql.DB) (err error) { return err } - rows, err := stmt.Query(server.Id) + rows, err := stmt.Query(server.ID) if err != nil { return err } for rows.Next() { var ( - ChannelId int - LinkId int + ChannelID int + LinkID int ) - if err := rows.Scan(&ChannelId, &LinkId); err != nil { + if err := rows.Scan(&ChannelID, &LinkID); err != nil { return err } - channel, exists := server.Channels[ChannelId] + channel, exists := server.Channels[ChannelID] if !exists { return errors.New("Attempt to perform link operation on non-existant channel.") } - other, exists := server.Channels[LinkId] + other, exists := server.Channels[LinkID] if !exists { return errors.New("Attempt to perform link operation on non-existant channel.") } @@ -408,14 +408,14 @@ func populateUsers(server *Server, db *sql.DB) (err error) { return } - rows, err := stmt.Query(server.Id) + rows, err := stmt.Query(server.ID) if err != nil { return } for rows.Next() { var ( - UserId int64 + UserID int64 UserName string SHA1Password string LastChannel int @@ -423,16 +423,16 @@ func populateUsers(server *Server, db *sql.DB) (err error) { LastActive int64 ) - err = rows.Scan(&UserId, &UserName, &SHA1Password, &LastChannel, &Texture, &LastActive) + err = rows.Scan(&UserID, &UserName, &SHA1Password, &LastChannel, &Texture, &LastActive) if err != nil { continue } - if UserId == 0 { + if UserID == 0 { server.cfg.Set("SuperUserPassword", "sha1$$"+SHA1Password) } - user, err := NewUser(uint32(UserId), UserName) + user, err := NewUser(uint32(UserID), UserName) if err != nil { return err } @@ -446,9 +446,9 @@ func populateUsers(server *Server, db *sql.DB) (err error) { } user.LastActive = uint64(LastActive) - user.LastChannelId = LastChannel + user.LastChannelID = LastChannel - server.Users[user.Id] = user + server.Users[user.ID] = user } stmt, err = db.Prepare("SELECT key, value FROM user_info WHERE server_id=? AND user_id=?") @@ -458,7 +458,7 @@ func populateUsers(server *Server, db *sql.DB) (err error) { // Populate users with any new-style UserInfo records for uid, user := range server.Users { - rows, err = stmt.Query(server.Id, uid) + rows, err = stmt.Query(server.ID, uid) if err != nil { return err } @@ -505,7 +505,7 @@ func populateBans(server *Server, db *sql.DB) (err error) { return } - rows, err := stmt.Query(server.Id) + rows, err := stmt.Query(server.ID) if err != nil { return err } diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index a7ef1cd..abb990f 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -71,7 +71,7 @@ type KeyValuePair struct { // Server is a Grumble server instance type Server struct { - Id int64 + ID int64 tcpl *net.TCPListener tlsl net.Listener @@ -112,13 +112,13 @@ type Server struct { // Channels Channels map[int]*Channel - nextChanId int + nextChanID int // Users Users map[uint32]*User UserCertMap map[string]*User UserNameMap map[string]*User - nextUserId uint32 + nextUserID uint32 // Sessions pool *sessionpool.SessionPool @@ -142,7 +142,7 @@ type clientLogForwarder struct { func (lf clientLogForwarder) Write(incoming []byte) (int, error) { buf := new(bytes.Buffer) - buf.WriteString(fmt.Sprintf("<%v:%v(%v)> ", lf.client.Session(), lf.client.ShownName(), lf.client.UserId())) + buf.WriteString(fmt.Sprintf("<%v:%v(%v)> ", lf.client.Session(), lf.client.ShownName(), lf.client.UserID())) buf.Write(incoming) lf.logger.Output(3, buf.String()) return len(incoming), nil @@ -152,7 +152,7 @@ func (lf clientLogForwarder) Write(incoming []byte) (int, error) { func NewServer(id int64) (s *Server, err error) { s = new(Server) - s.Id = id + s.ID = id s.cfg = serverconf.New(nil) @@ -161,13 +161,13 @@ func NewServer(id int64) (s *Server, err error) { s.UserNameMap = make(map[string]*User) s.Users[0], err = NewUser(0, "SuperUser") s.UserNameMap["SuperUser"] = s.Users[0] - s.nextUserId = 1 + s.nextUserID = 1 s.Channels = make(map[int]*Channel) s.Channels[0] = NewChannel(0, "Root") - s.nextChanId = 1 + s.nextChanID = 1 - s.Logger = log.New(&logtarget.Target, fmt.Sprintf("[%v] ", s.Id), log.LstdFlags|log.Lmicroseconds) + s.Logger = log.New(&logtarget.Target, fmt.Sprintf("[%v] ", s.ID), log.LstdFlags|log.Lmicroseconds) return } @@ -350,9 +350,9 @@ func (server *Server) RemoveClient(client *Client, kicked bool) { // AddChannel adds a new channel to the server. Automatically assign it a channel ID. func (server *Server) AddChannel(name string) (channel *Channel) { - channel = NewChannel(server.nextChanId, name) + channel = NewChannel(server.nextChanID, name) server.Channels[channel.ID] = channel - server.nextChanId += 1 + server.nextChanID += 1 return } @@ -565,7 +565,7 @@ func (server *Server) finishAuthenticate(client *Client) { if client.user != nil { found := false for _, connectedClient := range server.clients { - if connectedClient.UserId() == client.UserId() { + if connectedClient.UserID() == client.UserID() { found = true break } @@ -609,7 +609,7 @@ func (server *Server) finishAuthenticate(client *Client) { channel := server.RootChannel() if client.IsRegistered() { - lastChannel := server.Channels[client.user.LastChannelId] + lastChannel := server.Channels[client.user.LastChannelID] if lastChannel != nil { channel = lastChannel } @@ -626,7 +626,7 @@ func (server *Server) finishAuthenticate(client *Client) { } if client.IsRegistered() { - userstate.UserId = proto.Uint32(uint32(client.UserId())) + userstate.UserID = proto.Uint32(uint32(client.UserID())) if client.user.HasTexture() { // Does the client support blobs? @@ -810,7 +810,7 @@ func (server *Server) sendUserList(client *Client) { } if connectedClient.IsRegistered() { - userstate.UserId = proto.Uint32(uint32(connectedClient.UserId())) + userstate.UserID = proto.Uint32(uint32(connectedClient.UserID())) if connectedClient.user.HasTexture() { // Does the client support blobs? @@ -1099,14 +1099,14 @@ func (server *Server) userEnterChannel(client *Client, channel *Channel, usersta // RegisterClient will register a client on the server. func (s *Server) RegisterClient(client *Client) (uid uint32, err error) { - // Increment nextUserId only if registration succeeded. + // Increment nextUserID only if registration succeeded. defer func() { if err == nil { - s.nextUserId += 1 + s.nextUserID += 1 } }() - user, err := NewUser(s.nextUserId, client.Username) + user, err := NewUser(s.nextUserID, client.Username) if err != nil { return 0, err } @@ -1119,7 +1119,7 @@ func (s *Server) RegisterClient(client *Client) (uid uint32, err error) { user.Email = client.Email user.CertHash = client.CertHash() - uid = s.nextUserId + uid = s.nextUserID s.Users[uid] = user s.UserCertMap[client.CertHash()] = user s.UserNameMap[client.Username] = user @@ -1150,7 +1150,7 @@ func (s *Server) removeRegisteredUserFromChannel(uid uint32, channel *Channel) { newACL := []acl.ACL{} for _, chanacl := range channel.ACL.ACLs { - if chanacl.UserId == int(uid) { + if chanacl.UserID == int(uid) { continue } newACL = append(newACL, chanacl) @@ -1361,7 +1361,7 @@ func (server *Server) cleanPerLaunchData() { func (server *Server) Port() int { port := server.cfg.IntValue("Port") if port == 0 { - return DefaultPort + int(server.Id) - 1 + return DefaultPort + int(server.ID) - 1 } return port } @@ -1371,7 +1371,7 @@ func (server *Server) Port() int { func (server *Server) WebPort() int { port := server.cfg.IntValue("WebPort") if port == 0 { - return DefaultWebPort + int(server.Id) - 1 + return DefaultWebPort + int(server.ID) - 1 } return port } diff --git a/cmd/grumble/user.go b/cmd/grumble/user.go index 47ab09b..0c1aae8 100644 --- a/cmd/grumble/user.go +++ b/cmd/grumble/user.go @@ -15,14 +15,14 @@ import ( // User contains all user information type User struct { - Id uint32 + ID uint32 Name string Password string CertHash string Email string TextureBlob string CommentBlob string - LastChannelId int + LastChannelID int LastActive uint64 } @@ -36,7 +36,7 @@ func NewUser(id uint32, name string) (user *User, err error) { } return &User{ - Id: id, + ID: id, Name: name, }, nil } diff --git a/pkg/acl/acl.go b/pkg/acl/acl.go index 08fc761..0cf766d 100644 --- a/pkg/acl/acl.go +++ b/pkg/acl/acl.go @@ -54,7 +54,7 @@ func (perm Permission) Clean() Permission { type ACL struct { // The user id that this ACL applied to. If this // field is -1, the ACL is a group ACL. - UserId int + UserID int // The group that this ACL applies to. Group string @@ -75,7 +75,7 @@ type ACL struct { // IsUserACL returns true if the ACL is defined for a user, // as opposed to a group. func (acl *ACL) IsUserACL() bool { - return acl.UserId != -1 + return acl.UserID != -1 } // IsChannelACL returns true if the ACL is defined for a group, @@ -93,7 +93,7 @@ func HasPermission(ctx *Context, user User, perm Permission) bool { } // SuperUser can't speak or whisper, but everything else is OK - if user.UserId() == 0 { + if user.UserID() == 0 { if perm == SpeakPermission || perm == WhisperPermission { return false } @@ -125,7 +125,7 @@ func HasPermission(ctx *Context, user User, perm Permission) bool { // If it's a group ACL, we have to parse and interpret // the group string in the current context to determine // membership. For that we use GroupMemberCheck. - matchUser := acl.IsUserACL() && acl.UserId == user.UserId() + matchUser := acl.IsUserACL() && acl.UserID == user.UserID() matchGroup := GroupMemberCheck(origCtx, ctx, acl.Group, user) if matchUser || matchGroup { if acl.Allow.isSet(TraversePermission) { diff --git a/pkg/acl/group.go b/pkg/acl/group.go index b2b282f..615e878 100644 --- a/pkg/acl/group.go +++ b/pkg/acl/group.go @@ -201,8 +201,8 @@ func GroupMemberCheck(current *Context, acl *Context, name string, user User) (o return true } else if name == "auth" { // The user is part of the auth group is he is authenticated. That is, - // his UserId is >= 0. - return user.UserId() >= 0 + // his UserID is >= 0. + return user.UserID() >= 0 } else if name == "strong" { // The user is part of the strong group if he is authenticated to the server // via a strong certificate (i.e. non-self-signed, trusted by the server's @@ -325,10 +325,10 @@ func GroupMemberCheck(current *Context, acl *Context, name string, user User) (o isMember := false for _, group := range groups { - if group.AddContains(user.UserId()) || group.TemporaryContains(user.UserId()) || group.TemporaryContains(-int(user.Session())) { + if group.AddContains(user.UserID()) || group.TemporaryContains(user.UserID()) || group.TemporaryContains(-int(user.Session())) { isMember = true } - if group.RemoveContains(user.UserId()) { + if group.RemoveContains(user.UserID()) { isMember = false } } diff --git a/pkg/acl/interfaces.go b/pkg/acl/interfaces.go index 40a3b94..738a569 100644 --- a/pkg/acl/interfaces.go +++ b/pkg/acl/interfaces.go @@ -10,7 +10,7 @@ package acl // permissions in an ACL context. type User interface { Session() uint32 - UserId() int + UserID() int CertHash() string Tokens() []string diff --git a/pkg/freezer/types.pb.go b/pkg/freezer/types.pb.go index 58bd40a..7862e4c 100644 --- a/pkg/freezer/types.pb.go +++ b/pkg/freezer/types.pb.go @@ -137,7 +137,7 @@ type User struct { Email *string `protobuf:"bytes,5,opt,name=email" json:"email,omitempty"` TextureBlob *string `protobuf:"bytes,6,opt,name=texture_blob" json:"texture_blob,omitempty"` CommentBlob *string `protobuf:"bytes,7,opt,name=comment_blob" json:"comment_blob,omitempty"` - LastChannelId *uint32 `protobuf:"varint,8,opt,name=last_channel_id" json:"last_channel_id,omitempty"` + LastChannelID *uint32 `protobuf:"varint,8,opt,name=last_channel_id" json:"last_channel_id,omitempty"` LastActive *uint64 `protobuf:"varint,9,opt,name=last_active" json:"last_active,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -195,9 +195,9 @@ func (this *User) GetCommentBlob() string { return "" } -func (this *User) GetLastChannelId() uint32 { - if this != nil && this.LastChannelId != nil { - return *this.LastChannelId +func (this *User) GetLastChannelID() uint32 { + if this != nil && this.LastChannelID != nil { + return *this.LastChannelID } return 0 } @@ -301,7 +301,7 @@ func (this *ChannelRemove) GetId() uint32 { } type ACL struct { - UserId *uint32 `protobuf:"varint,1,opt,name=user_id" json:"user_id,omitempty"` + UserID *uint32 `protobuf:"varint,1,opt,name=user_id" json:"user_id,omitempty"` Group *string `protobuf:"bytes,2,opt,name=group" json:"group,omitempty"` ApplyHere *bool `protobuf:"varint,3,opt,name=apply_here" json:"apply_here,omitempty"` ApplySubs *bool `protobuf:"varint,4,opt,name=apply_subs" json:"apply_subs,omitempty"` @@ -314,9 +314,9 @@ func (this *ACL) Reset() { *this = ACL{} } func (this *ACL) String() string { return proto.CompactTextString(this) } func (*ACL) ProtoMessage() {} -func (this *ACL) GetUserId() uint32 { - if this != nil && this.UserId != nil { - return *this.UserId +func (this *ACL) GetUserID() uint32 { + if this != nil && this.UserID != nil { + return *this.UserID } return 0 } diff --git a/pkg/mumbleproto/Mumble.pb.go b/pkg/mumbleproto/Mumble.pb.go index db112df..64a5ab3 100644 --- a/pkg/mumbleproto/Mumble.pb.go +++ b/pkg/mumbleproto/Mumble.pb.go @@ -780,7 +780,7 @@ type UserState struct { // User name, UTF-8 encoded. Name *string `protobuf:"bytes,3,opt,name=name" json:"name,omitempty"` // Registered user ID if the user is registered. - UserId *uint32 `protobuf:"varint,4,opt,name=user_id,json=userId" json:"user_id,omitempty"` + UserID *uint32 `protobuf:"varint,4,opt,name=user_id,json=userId" json:"user_id,omitempty"` // Channel on which the user is. ChannelId *uint32 `protobuf:"varint,5,opt,name=channel_id,json=channelId" json:"channel_id,omitempty"` // True if the user is muted by admin. @@ -841,9 +841,9 @@ func (m *UserState) GetName() string { return "" } -func (m *UserState) GetUserId() uint32 { - if m != nil && m.UserId != nil { - return *m.UserId +func (m *UserState) GetUserID() uint32 { + if m != nil && m.UserID != nil { + return *m.UserID } return 0 } @@ -1321,7 +1321,7 @@ type ACL_ChanACL struct { // True if the ACL has been inherited from the parent. Inherited *bool `protobuf:"varint,3,opt,name=inherited,def=1" json:"inherited,omitempty"` // ID of the user that is affected by this ACL. - UserId *uint32 `protobuf:"varint,4,opt,name=user_id,json=userId" json:"user_id,omitempty"` + UserID *uint32 `protobuf:"varint,4,opt,name=user_id,json=userId" json:"user_id,omitempty"` // ID of the group that is affected by this ACL. Group *string `protobuf:"bytes,5,opt,name=group" json:"group,omitempty"` // Bit flag field of the permissions granted by this ACL. @@ -1361,9 +1361,9 @@ func (m *ACL_ChanACL) GetInherited() bool { return Default_ACL_ChanACL_Inherited } -func (m *ACL_ChanACL) GetUserId() uint32 { - if m != nil && m.UserId != nil { - return *m.UserId +func (m *ACL_ChanACL) GetUserID() uint32 { + if m != nil && m.UserID != nil { + return *m.UserID } return 0 } @@ -1561,7 +1561,7 @@ func (m *UserList) GetUsers() []*UserList_User { type UserList_User struct { // Registered user ID. - UserId *uint32 `protobuf:"varint,1,req,name=user_id,json=userId" json:"user_id,omitempty"` + UserID *uint32 `protobuf:"varint,1,req,name=user_id,json=userId" json:"user_id,omitempty"` // Registered user name. Name *string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"` LastSeen *string `protobuf:"bytes,3,opt,name=last_seen,json=lastSeen" json:"last_seen,omitempty"` @@ -1574,9 +1574,9 @@ func (m *UserList_User) String() string { return proto.CompactTextStr func (*UserList_User) ProtoMessage() {} func (*UserList_User) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{18, 0} } -func (m *UserList_User) GetUserId() uint32 { - if m != nil && m.UserId != nil { - return *m.UserId +func (m *UserList_User) GetUserID() uint32 { + if m != nil && m.UserID != nil { + return *m.UserID } return 0 } From 861fae65a2f16509b1de99023502445322843f6c Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 22:41:54 +0000 Subject: [PATCH 08/14] Rename more acronyms to their upper case versions, according to Golang coding standards --- cmd/grumble/freeze.go | 32 ++++++++++++++++---------------- cmd/grumble/message.go | 12 ++++++------ cmd/grumble/register.go | 8 ++++---- cmd/grumble/server.go | 2 +- pkg/ban/ban_test.go | 24 ++++++++++++------------ pkg/freezer/types.pb.go | 10 +++++----- pkg/mumbleproto/Mumble.pb.go | 18 +++++++++--------- 7 files changed, 53 insertions(+), 53 deletions(-) diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index dbe8a49..374a855 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -173,7 +173,7 @@ func (channel *Channel) Freeze() (fc *freezer.Channel, err error) { fc.ParentId = proto.Uint32(uint32(channel.parent.ID)) } fc.Position = proto.Int64(int64(channel.Position)) - fc.InheritAcl = proto.Bool(channel.ACL.InheritACL) + fc.InheritACL = proto.Bool(channel.ACL.InheritACL) // Freeze the channel's ACLs acls := []*freezer.ACL{} @@ -184,7 +184,7 @@ func (channel *Channel) Freeze() (fc *freezer.Channel, err error) { } acls = append(acls, facl) } - fc.Acl = acls + fc.ACL = acls // Freeze the channel's groups groups := []*freezer.Group{} @@ -219,17 +219,17 @@ func (c *Channel) Unfreeze(fc *freezer.Channel) { if fc.Position != nil { c.Position = int(*fc.Position) } - if fc.InheritAcl != nil { - c.ACL.InheritACL = *fc.InheritAcl + if fc.InheritACL != nil { + c.ACL.InheritACL = *fc.InheritACL } if fc.DescriptionBlob != nil { c.DescriptionBlob = *fc.DescriptionBlob } // Update ACLs - if fc.Acl != nil { + if fc.ACL != nil { c.ACL.ACLs = nil - for _, facl := range fc.Acl { + for _, facl := range fc.ACL { aclEntry := acl.ACL{} if facl.ApplyHere != nil { aclEntry.ApplyHere = *facl.ApplyHere @@ -335,17 +335,17 @@ func (u *User) Unfreeze(fu *freezer.User) { // FreezeACL will freeze a ChannelACL into it a flattened protobuf-based structure // ready to be persisted to disk. func FreezeACL(aclEntry acl.ACL) (*freezer.ACL, error) { - frozenAcl := &freezer.ACL{} + frozenACL := &freezer.ACL{} if aclEntry.UserID != -1 { - frozenAcl.UserID = proto.Uint32(uint32(aclEntry.UserID)) + frozenACL.UserID = proto.Uint32(uint32(aclEntry.UserID)) } else { - frozenAcl.Group = proto.String(aclEntry.Group) + frozenACL.Group = proto.String(aclEntry.Group) } - frozenAcl.ApplyHere = proto.Bool(aclEntry.ApplyHere) - frozenAcl.ApplySubs = proto.Bool(aclEntry.ApplySubs) - frozenAcl.Allow = proto.Uint32(uint32(aclEntry.Allow)) - frozenAcl.Deny = proto.Uint32(uint32(aclEntry.Deny)) - return frozenAcl, nil + frozenACL.ApplyHere = proto.Bool(aclEntry.ApplyHere) + frozenACL.ApplySubs = proto.Bool(aclEntry.ApplySubs) + frozenACL.Allow = proto.Uint32(uint32(aclEntry.Allow)) + frozenACL.Deny = proto.Uint32(uint32(aclEntry.Deny)) + return frozenACL, nil } // FreezeGroup will freeze a Group into a flattened protobuf-based structure @@ -785,7 +785,7 @@ func (server *Server) UpdateFrozenChannelACLs(channel *Channel) { fc := &freezer.Channel{} fc.Id = proto.Uint32(uint32(channel.ID)) - fc.InheritAcl = proto.Bool(channel.ACL.InheritACL) + fc.InheritACL = proto.Bool(channel.ACL.InheritACL) acls := []*freezer.ACL{} for _, aclEntry := range channel.ACL.ACLs { @@ -795,7 +795,7 @@ func (server *Server) UpdateFrozenChannelACLs(channel *Channel) { } acls = append(acls, facl) } - fc.Acl = acls + fc.ACL = acls groups := []*freezer.Group{} for _, grp := range channel.ACL.Groups { diff --git a/cmd/grumble/message.go b/cmd/grumble/message.go index 77c7650..4311094 100644 --- a/cmd/grumble/message.go +++ b/cmd/grumble/message.go @@ -1028,7 +1028,7 @@ func (server *Server) handleTextMessage(client *Client, msg *Message) { } // ACL set/query -func (server *Server) handleAclMessage(client *Client, msg *Message) { +func (server *Server) handleACLMessage(client *Client, msg *Message) { pacl := &mumbleproto.ACL{} err := proto.Unmarshal(msg.buf, pacl) if err != nil { @@ -1056,7 +1056,7 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { // Query the current ACL state for the channel if pacl.Query != nil && *pacl.Query != false { - reply.InheritAcls = proto.Bool(channel.ACL.InheritACL) + reply.InheritACLs = proto.Bool(channel.ACL.InheritACL) // Walk the channel tree to get all relevant channels. // (Stop if we reach a channel that doesn't have the InheritACL flag set) iter := channel @@ -1071,7 +1071,7 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { // Construct the protobuf ChanACL objects corresponding to the ACLs defined // in our channel list. - reply.Acls = []*mumbleproto.ACL_ChanACL{} + reply.ACLs = []*mumbleproto.ACL_ChanACL{} for _, iter := range channels { for _, chanacl := range iter.ACL.ACLs { if iter == channel || chanacl.ApplySubs { @@ -1087,7 +1087,7 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { } mpacl.Grant = proto.Uint32(uint32(chanacl.Allow)) mpacl.Deny = proto.Uint32(uint32(chanacl.Deny)) - reply.Acls = append(reply.Acls, mpacl) + reply.ACLs = append(reply.ACLs, mpacl) } } } @@ -1187,7 +1187,7 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { channel.ACL.Groups = map[string]acl.Group{} // Add the received groups to the channel. - channel.ACL.InheritACL = *pacl.InheritAcls + channel.ACL.InheritACL = *pacl.InheritACLs for _, pbgrp := range pacl.Groups { changroup := acl.EmptyGroupWithName(*pbgrp.Name) @@ -1206,7 +1206,7 @@ func (server *Server) handleAclMessage(client *Client, msg *Message) { channel.ACL.Groups[changroup.Name] = changroup } // Add the received ACLs to the channel. - for _, pbacl := range pacl.Acls { + for _, pbacl := range pacl.ACLs { chanacl := acl.ACL{} chanacl.ApplyHere = *pbacl.ApplyHere chanacl.ApplySubs = *pbacl.ApplySubs diff --git a/cmd/grumble/register.go b/cmd/grumble/register.go index 76d318f..0b4e028 100644 --- a/cmd/grumble/register.go +++ b/cmd/grumble/register.go @@ -25,14 +25,14 @@ type Register struct { Host string `xml:"host"` Password string `xml:"password"` Port int `xml:"port"` - Url string `xml:"url"` + URL string `xml:"url"` Digest string `xml:"digest"` Users int `xml:"users"` Channels int `xml:"channels"` Location string `xml:"location"` } -const registerUrl = "https://mumble.info/register.cgi" +const registerURL = "https://mumble.info/register.cgi" // IsPublic Determines whether a server is public by checking whether the // config values required for public registration are set. @@ -84,7 +84,7 @@ func (server *Server) RegisterPublicServer() { Name: server.cfg.StringValue("RegisterName"), Host: server.cfg.StringValue("RegisterHost"), Password: server.cfg.StringValue("RegisterPassword"), - Url: server.cfg.StringValue("RegisterWebUrl"), + URL: server.cfg.StringValue("RegisterWebUrl"), Location: server.cfg.StringValue("RegisterLocation"), Port: server.CurrentPort(), Digest: digest, @@ -106,7 +106,7 @@ func (server *Server) RegisterPublicServer() { TLSClientConfig: config, } client := &http.Client{Transport: tr} - r, err := client.Post(registerUrl, "text/xml", ioutil.NopCloser(buf)) + r, err := client.Post(registerURL, "text/xml", ioutil.NopCloser(buf)) if err != nil { server.Printf("register: unable to post registration request: %v", err) return diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index abb990f..28ebe0e 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -932,7 +932,7 @@ func (server *Server) handleIncomingMessage(client *Client, msg *Message) { case mumbleproto.MessageTextMessage: server.handleTextMessage(msg.client, msg) case mumbleproto.MessageACL: - server.handleAclMessage(msg.client, msg) + server.handleACLMessage(msg.client, msg) case mumbleproto.MessageQueryUsers: server.handleQueryUsers(msg.client, msg) case mumbleproto.MessageCryptSetup: diff --git a/pkg/ban/ban_test.go b/pkg/ban/ban_test.go index 56b0056..2a5608f 100644 --- a/pkg/ban/ban_test.go +++ b/pkg/ban/ban_test.go @@ -33,12 +33,12 @@ func TestMatchV4(t *testing.T) { t.Errorf("Invalid IP") } - clientIp := net.ParseIP("192.168.1.50") - if len(clientIp) == 0 { + clientIP := net.ParseIP("192.168.1.50") + if len(clientIP) == 0 { t.Errorf("Invalid IP") } - if b.Match(clientIp) != true { + if b.Match(clientIP) != true { t.Errorf("IPv4: unexpected match") } } @@ -51,12 +51,12 @@ func TestMismatchV4(t *testing.T) { t.Errorf("Invalid IP") } - clientIp := net.ParseIP("192.168.2.1") - if len(clientIp) == 0 { + clientIP := net.ParseIP("192.168.2.1") + if len(clientIP) == 0 { t.Errorf("Invalid IP") } - if b.Match(clientIp) == true { + if b.Match(clientIP) == true { t.Errorf("IPv4: unexpected mismatch") } } @@ -69,12 +69,12 @@ func TestMatchV6(t *testing.T) { t.Errorf("Invalid IP") } - clientIp := net.ParseIP("2a00:1450:400b:c00::54") - if len(clientIp) == 0 { + clientIP := net.ParseIP("2a00:1450:400b:c00::54") + if len(clientIP) == 0 { t.Errorf("Invalid IP") } - if b.Match(clientIp) != true { + if b.Match(clientIP) != true { t.Errorf("IPv6: unexpected match") } } @@ -88,12 +88,12 @@ func TestMismatchV6(t *testing.T) { t.Errorf("Invalid IP") } - clientIp := net.ParseIP("2a00:1450:400b:deaf:42f0:cafe:babe:54") - if len(clientIp) == 0 { + clientIP := net.ParseIP("2a00:1450:400b:deaf:42f0:cafe:babe:54") + if len(clientIP) == 0 { t.Errorf("Invalid IP") } - if b.Match(clientIp) == true { + if b.Match(clientIP) == true { t.Errorf("IPv6: unexpected mismatch") } } diff --git a/pkg/freezer/types.pb.go b/pkg/freezer/types.pb.go index 7862e4c..5c322d4 100644 --- a/pkg/freezer/types.pb.go +++ b/pkg/freezer/types.pb.go @@ -230,9 +230,9 @@ type Channel struct { Name *string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"` ParentId *uint32 `protobuf:"varint,3,opt,name=parent_id" json:"parent_id,omitempty"` Position *int64 `protobuf:"varint,4,opt,name=position" json:"position,omitempty"` - InheritAcl *bool `protobuf:"varint,5,opt,name=inherit_acl" json:"inherit_acl,omitempty"` + InheritACL *bool `protobuf:"varint,5,opt,name=inherit_acl" json:"inherit_acl,omitempty"` Links []uint32 `protobuf:"varint,6,rep,name=links" json:"links,omitempty"` - Acl []*ACL `protobuf:"bytes,7,rep,name=acl" json:"acl,omitempty"` + ACL []*ACL `protobuf:"bytes,7,rep,name=acl" json:"acl,omitempty"` Groups []*Group `protobuf:"bytes,8,rep,name=groups" json:"groups,omitempty"` DescriptionBlob *string `protobuf:"bytes,9,opt,name=description_blob" json:"description_blob,omitempty"` XXX_unrecognized []byte `json:"-"` @@ -270,9 +270,9 @@ func (this *Channel) GetPosition() int64 { return 0 } -func (this *Channel) GetInheritAcl() bool { - if this != nil && this.InheritAcl != nil { - return *this.InheritAcl +func (this *Channel) GetInheritACL() bool { + if this != nil && this.InheritACL != nil { + return *this.InheritACL } return false } diff --git a/pkg/mumbleproto/Mumble.pb.go b/pkg/mumbleproto/Mumble.pb.go index 64a5ab3..eeaf773 100644 --- a/pkg/mumbleproto/Mumble.pb.go +++ b/pkg/mumbleproto/Mumble.pb.go @@ -1183,11 +1183,11 @@ type ACL struct { // Channel ID of the channel this message affects. ChannelId *uint32 `protobuf:"varint,1,req,name=channel_id,json=channelId" json:"channel_id,omitempty"` // True if the channel inherits its parent's ACLs. - InheritAcls *bool `protobuf:"varint,2,opt,name=inherit_acls,json=inheritAcls,def=1" json:"inherit_acls,omitempty"` + InheritACLs *bool `protobuf:"varint,2,opt,name=inherit_acls,json=inheritACLs,def=1" json:"inherit_acls,omitempty"` // User group specifications. Groups []*ACL_ChanGroup `protobuf:"bytes,3,rep,name=groups" json:"groups,omitempty"` // ACL specifications. - Acls []*ACL_ChanACL `protobuf:"bytes,4,rep,name=acls" json:"acls,omitempty"` + ACLs []*ACL_ChanACL `protobuf:"bytes,4,rep,name=acls" json:"acls,omitempty"` // True if the message is a query for ACLs instead of setting them. Query *bool `protobuf:"varint,5,opt,name=query,def=0" json:"query,omitempty"` XXX_unrecognized []byte `json:"-"` @@ -1198,7 +1198,7 @@ func (m *ACL) String() string { return proto.CompactTextString(m) } func (*ACL) ProtoMessage() {} func (*ACL) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{13} } -const Default_ACL_InheritAcls bool = true +const Default_ACL_InheritACLs bool = true const Default_ACL_Query bool = false func (m *ACL) GetChannelId() uint32 { @@ -1208,11 +1208,11 @@ func (m *ACL) GetChannelId() uint32 { return 0 } -func (m *ACL) GetInheritAcls() bool { - if m != nil && m.InheritAcls != nil { - return *m.InheritAcls +func (m *ACL) GetInheritACLs() bool { + if m != nil && m.InheritACLs != nil { + return *m.InheritACLs } - return Default_ACL_InheritAcls + return Default_ACL_InheritACLs } func (m *ACL) GetGroups() []*ACL_ChanGroup { @@ -1222,9 +1222,9 @@ func (m *ACL) GetGroups() []*ACL_ChanGroup { return nil } -func (m *ACL) GetAcls() []*ACL_ChanACL { +func (m *ACL) GetACLs() []*ACL_ChanACL { if m != nil { - return m.Acls + return m.ACLs } return nil } From 92840d1770207ebd83f1077279bf54fddd235c52 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 22:51:15 +0000 Subject: [PATCH 09/14] Make receiver names consistent according to Golang coding standards --- cmd/grumble/client.go | 16 ++++++++-------- cmd/grumble/freeze.go | 28 ++++++++++++++-------------- cmd/grumble/server.go | 34 +++++++++++++++++----------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index 0e496e1..d87e4b1 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -269,36 +269,36 @@ func (client *Client) readProtoMessage() (msg *Message, err error) { } // Send permission denied by type -func (c *Client) sendPermissionDeniedType(denyType mumbleproto.PermissionDenied_DenyType) { - c.sendPermissionDeniedTypeUser(denyType, nil) +func (client *Client) sendPermissionDeniedType(denyType mumbleproto.PermissionDenied_DenyType) { + client.sendPermissionDeniedTypeUser(denyType, nil) } // Send permission denied by type (and user) -func (c *Client) sendPermissionDeniedTypeUser(denyType mumbleproto.PermissionDenied_DenyType, user *Client) { +func (client *Client) sendPermissionDeniedTypeUser(denyType mumbleproto.PermissionDenied_DenyType, user *Client) { pd := &mumbleproto.PermissionDenied{ Type: denyType.Enum(), } if user != nil { pd.Session = proto.Uint32(uint32(user.Session())) } - err := c.sendMessage(pd) + err := client.sendMessage(pd) if err != nil { - c.Panicf("%v", err.Error()) + client.Panicf("%v", err.Error()) return } } // Send permission denied by who, what, where -func (c *Client) sendPermissionDenied(who *Client, where *Channel, what acl.Permission) { +func (client *Client) sendPermissionDenied(who *Client, where *Channel, what acl.Permission) { pd := &mumbleproto.PermissionDenied{ Permission: proto.Uint32(uint32(what)), ChannelId: proto.Uint32(uint32(where.ID)), Session: proto.Uint32(who.Session()), Type: mumbleproto.PermissionDenied_Permission.Enum(), } - err := c.sendMessage(pd) + err := client.sendMessage(pd) if err != nil { - c.Panicf("%v", err.Error()) + client.Panicf("%v", err.Error()) return } } diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index 374a855..bc5c4d5 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -118,8 +118,8 @@ func (server *Server) Freeze() (fs *freezer.Server, err error) { // UnfreezeBanList will merge the contents of a freezer.BanList into the server's // ban list. -func (s *Server) UnfreezeBanList(fblist *freezer.BanList) { - s.Bans = nil +func (server *Server) UnfreezeBanList(fblist *freezer.BanList) { + server.Bans = nil for _, fb := range fblist.Bans { ban := ban.Ban{} @@ -143,7 +143,7 @@ func (s *Server) UnfreezeBanList(fblist *freezer.BanList) { ban.Duration = *fb.Duration } - s.Bans = append(s.Bans, ban) + server.Bans = append(server.Bans, ban) } } @@ -212,23 +212,23 @@ func (channel *Channel) Freeze() (fc *freezer.Channel, err error) { // Unfreeze unfreezes the contents of a freezer.Channel // into a channel. -func (c *Channel) Unfreeze(fc *freezer.Channel) { +func (channel *Channel) Unfreeze(fc *freezer.Channel) { if fc.Name != nil { - c.Name = *fc.Name + channel.Name = *fc.Name } if fc.Position != nil { - c.Position = int(*fc.Position) + channel.Position = int(*fc.Position) } if fc.InheritACL != nil { - c.ACL.InheritACL = *fc.InheritACL + channel.ACL.InheritACL = *fc.InheritACL } if fc.DescriptionBlob != nil { - c.DescriptionBlob = *fc.DescriptionBlob + channel.DescriptionBlob = *fc.DescriptionBlob } // Update ACLs if fc.ACL != nil { - c.ACL.ACLs = nil + channel.ACL.ACLs = nil for _, facl := range fc.ACL { aclEntry := acl.ACL{} if facl.ApplyHere != nil { @@ -251,13 +251,13 @@ func (c *Channel) Unfreeze(fc *freezer.Channel) { if facl.Allow != nil { aclEntry.Allow = acl.Permission(*facl.Allow) } - c.ACL.ACLs = append(c.ACL.ACLs, aclEntry) + channel.ACL.ACLs = append(channel.ACL.ACLs, aclEntry) } } // Update groups if fc.Groups != nil { - c.ACL.Groups = make(map[string]acl.Group) + channel.ACL.Groups = make(map[string]acl.Group) for _, fgrp := range fc.Groups { if fgrp.Name == nil { continue @@ -275,7 +275,7 @@ func (c *Channel) Unfreeze(fc *freezer.Channel) { for _, uid := range fgrp.Remove { g.Remove[int(uid)] = true } - c.ACL.Groups[g.Name] = g + channel.ACL.Groups[g.Name] = g } } @@ -283,9 +283,9 @@ func (c *Channel) Unfreeze(fc *freezer.Channel) { // We can't be sure that the channels the links point to exist // yet, so we delay hooking up the map 'correctly' to later. if fc.Links != nil { - c.Links = make(map[int]*Channel) + channel.Links = make(map[int]*Channel) for _, link := range fc.Links { - c.Links[int(link)] = c + channel.Links[int(link)] = channel } } } diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index 28ebe0e..c4027a4 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -953,8 +953,8 @@ func (server *Server) handleIncomingMessage(client *Client, msg *Message) { } // SendUDP will send the content of buf as a UDP packet to addr. -func (s *Server) SendUDP(buf []byte, addr *net.UDPAddr) (err error) { - _, err = s.udpconn.WriteTo(buf, addr) +func (server *Server) SendUDP(buf []byte, addr *net.UDPAddr) (err error) { + _, err = server.udpconn.WriteTo(buf, addr) return } @@ -1098,15 +1098,15 @@ func (server *Server) userEnterChannel(client *Client, channel *Channel, usersta } // RegisterClient will register a client on the server. -func (s *Server) RegisterClient(client *Client) (uid uint32, err error) { +func (server *Server) RegisterClient(client *Client) (uid uint32, err error) { // Increment nextUserID only if registration succeeded. defer func() { if err == nil { - s.nextUserID += 1 + server.nextUserID += 1 } }() - user, err := NewUser(s.nextUserID, client.Username) + user, err := NewUser(server.nextUserID, client.Username) if err != nil { return 0, err } @@ -1119,34 +1119,34 @@ func (s *Server) RegisterClient(client *Client) (uid uint32, err error) { user.Email = client.Email user.CertHash = client.CertHash() - uid = s.nextUserID - s.Users[uid] = user - s.UserCertMap[client.CertHash()] = user - s.UserNameMap[client.Username] = user + uid = server.nextUserID + server.Users[uid] = user + server.UserCertMap[client.CertHash()] = user + server.UserNameMap[client.Username] = user return uid, nil } // RemoveRegistration removes a registered user. -func (s *Server) RemoveRegistration(uid uint32) (err error) { - user, ok := s.Users[uid] +func (server *Server) RemoveRegistration(uid uint32) (err error) { + user, ok := server.Users[uid] if !ok { return errors.New("Unknown user ID") } // Remove from user maps - delete(s.Users, uid) - delete(s.UserCertMap, user.CertHash) - delete(s.UserNameMap, user.Name) + delete(server.Users, uid) + delete(server.UserCertMap, user.CertHash) + delete(server.UserNameMap, user.Name) // Remove from groups and ACLs. - s.removeRegisteredUserFromChannel(uid, s.RootChannel()) + server.removeRegisteredUserFromChannel(uid, server.RootChannel()) return nil } // Remove references for user id uid from channel. Traverses subchannels. -func (s *Server) removeRegisteredUserFromChannel(uid uint32, channel *Channel) { +func (server *Server) removeRegisteredUserFromChannel(uid uint32, channel *Channel) { newACL := []acl.ACL{} for _, chanacl := range channel.ACL.ACLs { @@ -1170,7 +1170,7 @@ func (s *Server) removeRegisteredUserFromChannel(uid uint32, channel *Channel) { } for _, subChan := range channel.children { - s.removeRegisteredUserFromChannel(uid, subChan) + server.removeRegisteredUserFromChannel(uid, subChan) } } From 1ca218ec53f0910c2613eb1d35f073a45c103102 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 22:57:15 +0000 Subject: [PATCH 10/14] Remove extranous second arguments in for loops, according to Golang coding standards --- cmd/grumble/client.go | 2 +- cmd/grumble/freeze.go | 6 +++--- cmd/grumble/message.go | 10 +++++----- cmd/grumble/murmurdb.go | 2 +- pkg/acl/group.go | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/grumble/client.go b/cmd/grumble/client.go index d87e4b1..1913bde 100644 --- a/cmd/grumble/client.go +++ b/cmd/grumble/client.go @@ -619,7 +619,7 @@ func (client *Client) sendChannelTree(channel *Channel) { chanstate.Position = proto.Int32(int32(channel.Position)) links := []uint32{} - for cid, _ := range channel.Links { + for cid := range channel.Links { links = append(links, uint32(cid)) } chanstate.Links = links diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index bc5c4d5..36d1242 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -199,7 +199,7 @@ func (channel *Channel) Freeze() (fc *freezer.Channel, err error) { // Add linked channels links := []uint32{} - for cid, _ := range channel.Links { + for cid := range channel.Links { links = append(links, uint32(cid)) } fc.Links = links @@ -669,7 +669,7 @@ func NewServerFromFrozen(name string) (s *Server, err error) { if len(channel.Links) > 0 { links := channel.Links channel.Links = make(map[int]*Channel) - for chanID, _ := range links { + for chanID := range links { targetChannel := s.Channels[chanID] if targetChannel != nil { s.LinkChannels(channel, targetChannel) @@ -760,7 +760,7 @@ func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.C } if len(state.LinksAdd) > 0 || len(state.LinksRemove) > 0 { links := []uint32{} - for cid, _ := range channel.Links { + for cid := range channel.Links { links = append(links, uint32(cid)) } fc.Links = links diff --git a/cmd/grumble/message.go b/cmd/grumble/message.go index 4311094..504c424 100644 --- a/cmd/grumble/message.go +++ b/cmd/grumble/message.go @@ -1131,20 +1131,20 @@ func (server *Server) handleACLMessage(client *Client, msg *Message) { // message that maps user ids to usernames. if hasgroup { toadd := map[int]bool{} - for uid, _ := range group.Add { + for uid := range group.Add { users[uid] = true toadd[uid] = true } - for uid, _ := range group.Remove { + for uid := range group.Remove { users[uid] = true delete(toadd, uid) } - for uid, _ := range toadd { + for uid := range toadd { mpgroup.Add = append(mpgroup.Add, uint32(uid)) } } if haspgroup { - for uid, _ := range pgroup.MembersInContext(&parent.ACL) { + for uid := range pgroup.MembersInContext(&parent.ACL) { users[uid] = true mpgroup.InheritedMembers = append(mpgroup.InheritedMembers, uint32(uid)) } @@ -1160,7 +1160,7 @@ func (server *Server) handleACLMessage(client *Client, msg *Message) { // Map the user ids in the user map to usernames of users. queryusers := &mumbleproto.QueryUsers{} - for uid, _ := range users { + for uid := range users { user, ok := server.Users[uint32(uid)] if !ok { client.Printf("Invalid user id in ACL") diff --git a/cmd/grumble/murmurdb.go b/cmd/grumble/murmurdb.go index 24d4f60..dee16aa 100644 --- a/cmd/grumble/murmurdb.go +++ b/cmd/grumble/murmurdb.go @@ -354,7 +354,7 @@ func populateChannelsFromDatabase(server *Server, db *sql.DB, parentID int) erro } // Add subchannels - for id, _ := range parent.children { + for id := range parent.children { err = populateChannelsFromDatabase(server, db, id) if err != nil { return err diff --git a/pkg/acl/group.go b/pkg/acl/group.go index 615e878..1ac00a7 100644 --- a/pkg/acl/group.go +++ b/pkg/acl/group.go @@ -50,7 +50,7 @@ func (group *Group) AddContains(id int) (ok bool) { // AddUsers gets the list of user ids in the Add set. func (group *Group) AddUsers() []int { users := []int{} - for uid, _ := range group.Add { + for uid := range group.Add { users = append(users, uid) } return users @@ -65,7 +65,7 @@ func (group *Group) RemoveContains(id int) (ok bool) { // RemoveUsers gets the list of user ids in the Remove set. func (group *Group) RemoveUsers() []int { users := []int{} - for uid, _ := range group.Remove { + for uid := range group.Remove { users = append(users, uid) } return users @@ -106,10 +106,10 @@ func (group *Group) MembersInContext(ctx *Context) map[int]bool { } for _, curgroup := range groups { - for uid, _ := range curgroup.Add { + for uid := range curgroup.Add { members[uid] = true } - for uid, _ := range curgroup.Remove { + for uid := range curgroup.Remove { delete(members, uid) } } From 99d5ad7857537a6023d24f74a889a8d64a39c82b Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 23:03:06 +0000 Subject: [PATCH 11/14] Change increment and decrement operations according to Golang coding standards --- cmd/grumble/freeze.go | 18 +++++++++--------- cmd/grumble/message.go | 2 +- cmd/grumble/server.go | 6 +++--- pkg/cryptstate/cryptstate.go | 10 +++++----- pkg/freezer/freezer_test.go | 2 +- pkg/freezer/walker.go | 2 +- pkg/freezer/writer.go | 2 +- pkg/packetdata/packetdata.go | 6 +++--- pkg/sessionpool/sessionpool.go | 2 +- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index 36d1242..28adfec 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -715,7 +715,7 @@ func (server *Server) UpdateFrozenUser(client *Client, state *mumbleproto.UserSt server.Fatal(err) } } - server.numLogOps += 1 + server.numLogOps++ } // UpdateFrozenUserLastChannel will update a user's last active channel @@ -733,7 +733,7 @@ func (server *Server) UpdateFrozenUserLastChannel(client *Client) { server.Fatal(err) } - server.numLogOps += 1 + server.numLogOps++ } } @@ -743,7 +743,7 @@ func (server *Server) DeleteFrozenUser(user *User) { if err != nil { server.Fatal(err) } - server.numLogOps += 1 + server.numLogOps++ } // UpdateFrozenChannel will, given a target channel and a ChannelState protocol message, create a freezer.Channel that @@ -775,7 +775,7 @@ func (server *Server) UpdateFrozenChannel(channel *Channel, state *mumbleproto.C if err != nil { server.Fatal(err) } - server.numLogOps += 1 + server.numLogOps++ } // UpdateFrozenChannelACLs writes a channel's ACL and Group data to disk. Mumble doesn't support @@ -811,7 +811,7 @@ func (server *Server) UpdateFrozenChannelACLs(channel *Channel) { if err != nil { server.Fatal(err) } - server.numLogOps += 1 + server.numLogOps++ } // DeleteFrozenChannel will mark a channel as deleted in the datastore. @@ -820,7 +820,7 @@ func (server *Server) DeleteFrozenChannel(channel *Channel) { if err != nil { server.Fatal(err) } - server.numLogOps += 1 + server.numLogOps++ } // UpdateFrozenBans writes the server's banlist to the datastore. @@ -833,7 +833,7 @@ func (server *Server) UpdateFrozenBans(bans []ban.Ban) { if err != nil { server.Fatal(err) } - server.numLogOps += 1 + server.numLogOps++ } // UpdateConfig writes an updated config value to the datastore. @@ -846,7 +846,7 @@ func (server *Server) UpdateConfig(key, value string) { if err != nil { server.Fatal(err) } - server.numLogOps += 1 + server.numLogOps++ } // ResetConfig writes to the freezelog that the config with key @@ -859,5 +859,5 @@ func (server *Server) ResetConfig(key string) { if err != nil { server.Fatal(err) } - server.numLogOps += 1 + server.numLogOps++ } diff --git a/cmd/grumble/message.go b/cmd/grumble/message.go index 504c424..6d9d253 100644 --- a/cmd/grumble/message.go +++ b/cmd/grumble/message.go @@ -58,7 +58,7 @@ func (server *Server) handleCryptSetup(client *Client, msg *Message) { return } - client.crypt.Resync += 1 + client.crypt.Resync++ if copy(client.crypt.DecryptIV[0:], cs.ClientNonce) != aes.BlockSize { return } diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index c4027a4..762b976 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -352,7 +352,7 @@ func (server *Server) RemoveClient(client *Client, kicked bool) { func (server *Server) AddChannel(name string) (channel *Channel) { channel = NewChannel(server.nextChanID, name) server.Channels[channel.ID] = channel - server.nextChanID += 1 + server.nextChanID++ return } @@ -714,7 +714,7 @@ func (server *Server) updateCodecVersions(connecting *Client) { opus++ } for _, codec := range client.codecs { - codecusers[codec] += 1 + codecusers[codec]++ } } @@ -1102,7 +1102,7 @@ func (server *Server) RegisterClient(client *Client) (uid uint32, err error) { // Increment nextUserID only if registration succeeded. defer func() { if err == nil { - server.nextUserID += 1 + server.nextUserID++ } }() diff --git a/pkg/cryptstate/cryptstate.go b/pkg/cryptstate/cryptstate.go index 74e61d6..9803949 100644 --- a/pkg/cryptstate/cryptstate.go +++ b/pkg/cryptstate/cryptstate.go @@ -145,7 +145,7 @@ func (cs *CryptState) Decrypt(dst, src []byte) error { } else if ivbyte < cs.DecryptIV[0] { cs.DecryptIV[0] = ivbyte for i := 1; i < len(cs.DecryptIV); i++ { - cs.DecryptIV[i] += 1 + cs.DecryptIV[i]++ if cs.DecryptIV[i] > 0 { break } @@ -175,7 +175,7 @@ func (cs *CryptState) Decrypt(dst, src []byte) error { lost = -1 cs.DecryptIV[0] = ivbyte for i := 1; i < len(cs.DecryptIV); i++ { - cs.DecryptIV[i] -= 1 + cs.DecryptIV[i]-- if cs.DecryptIV[i] > 0 { break } @@ -190,7 +190,7 @@ func (cs *CryptState) Decrypt(dst, src []byte) error { lost = int(256 - int(cs.DecryptIV[0]) + int(ivbyte) - 1) cs.DecryptIV[0] = ivbyte for i := 1; i < len(cs.DecryptIV); i++ { - cs.DecryptIV[i] += 1 + cs.DecryptIV[i]++ if cs.DecryptIV[i] > 0 { break } @@ -216,7 +216,7 @@ func (cs *CryptState) Decrypt(dst, src []byte) error { cs.DecryptIV = saveiv } - cs.Good += 1 + cs.Good++ if late > 0 { cs.Late += uint32(late) } else { @@ -237,7 +237,7 @@ func (cs *CryptState) Decrypt(dst, src []byte) error { func (cs *CryptState) Encrypt(dst, src []byte) { // First, increase our IV for i := range cs.EncryptIV { - cs.EncryptIV[i] += 1 + cs.EncryptIV[i]++ if cs.EncryptIV[i] > 0 { break } diff --git a/pkg/freezer/freezer_test.go b/pkg/freezer/freezer_test.go index f07536f..761e45f 100644 --- a/pkg/freezer/freezer_test.go +++ b/pkg/freezer/freezer_test.go @@ -147,7 +147,7 @@ func TestLogging(t *testing.T) { if !proto.Equal(val, testValues[i]) { t.Error("proto message mismatch") } - i += 1 + i++ } } diff --git a/pkg/freezer/walker.go b/pkg/freezer/walker.go index cc0462c..0c5882b 100644 --- a/pkg/freezer/walker.go +++ b/pkg/freezer/walker.go @@ -224,7 +224,7 @@ func (walker *Walker) Next() (entries []interface{}, err error) { entries = append(entries, channelRemove) } - remainOps -= 1 + remainOps-- continue } diff --git a/pkg/freezer/writer.go b/pkg/freezer/writer.go index b48d37a..b554b8c 100644 --- a/pkg/freezer/writer.go +++ b/pkg/freezer/writer.go @@ -156,7 +156,7 @@ func (tx *LogTx) Put(value interface{}) (err error) { return err } - tx.numops += 1 + tx.numops++ return nil } diff --git a/pkg/packetdata/packetdata.go b/pkg/packetdata/packetdata.go index 3232c6c..22ac6c2 100644 --- a/pkg/packetdata/packetdata.go +++ b/pkg/packetdata/packetdata.go @@ -57,7 +57,7 @@ func (pds *PacketData) Size() int { func (pds *PacketData) next() (ret uint64) { if pds.offset < pds.maxsize { ret = uint64(pds.Buf[pds.offset]) - pds.offset += 1 + pds.offset++ return } else { pds.ok = false @@ -69,7 +69,7 @@ func (pds *PacketData) next() (ret uint64) { func (pds *PacketData) Next8() (ret uint8) { if pds.offset < pds.maxsize { ret = uint8(pds.Buf[pds.offset]) - pds.offset += 1 + pds.offset++ return } else { pds.ok = false @@ -87,7 +87,7 @@ func (pds *PacketData) append(val uint64) { if pds.offset < pds.maxsize { pds.Buf[pds.offset] = byte(val) - pds.offset += 1 + pds.offset++ } else { pds.ok = false pds.overshoot++ diff --git a/pkg/sessionpool/sessionpool.go b/pkg/sessionpool/sessionpool.go index 882f006..975cbcc 100644 --- a/pkg/sessionpool/sessionpool.go +++ b/pkg/sessionpool/sessionpool.go @@ -70,7 +70,7 @@ func (pool *SessionPool) Get() (id uint32) { // Increment the next session id and return it. // Note: By incrementing and *then* returning, we skip 0. // This is deliberate, as 0 is an invalid session ID in Mumble. - pool.cur += 1 + pool.cur++ id = pool.cur return } From 74040ab0afd4f0f083aa081cb560a52814f48823 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 23:07:03 +0000 Subject: [PATCH 12/14] Make error strings lower case and without punctuation, to be consistent with Golang coding standards --- cmd/grumble/murmurdb.go | 4 ++-- cmd/grumble/server.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/grumble/murmurdb.go b/cmd/grumble/murmurdb.go index dee16aa..2a680b2 100644 --- a/cmd/grumble/murmurdb.go +++ b/cmd/grumble/murmurdb.go @@ -387,12 +387,12 @@ func populateChannelLinkInfo(server *Server, db *sql.DB) (err error) { channel, exists := server.Channels[ChannelID] if !exists { - return errors.New("Attempt to perform link operation on non-existant channel.") + return errors.New("attempt to perform link operation on non-existant channel") } other, exists := server.Channels[LinkID] if !exists { - return errors.New("Attempt to perform link operation on non-existant channel.") + return errors.New("attempt to perform link operation on non-existant channel") } server.LinkChannels(channel, other) diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index 762b976..ac96503 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -252,7 +252,7 @@ func (server *Server) handleIncomingClient(conn net.Conn) (err error) { client := new(Client) addr := conn.RemoteAddr() if addr == nil { - err = errors.New("Unable to extract address for client.") + err = errors.New("unable to extract address for client") return } From 6bf58a9f583841a0c920572d151298c969840e10 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 23:11:01 +0000 Subject: [PATCH 13/14] Fix more namings to conform to Golang coding standards --- cmd/grumble/freeze.go | 16 ++++++++-------- pkg/cryptstate/cryptstate.go | 4 ++-- pkg/cryptstate/cryptstate_test.go | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cmd/grumble/freeze.go b/cmd/grumble/freeze.go index 28adfec..2f148e8 100644 --- a/cmd/grumble/freeze.go +++ b/cmd/grumble/freeze.go @@ -308,27 +308,27 @@ func (user *User) Freeze() (fu *freezer.User, err error) { } // Unfreeze will merge the contents of a frozen User into an existing user struct. -func (u *User) Unfreeze(fu *freezer.User) { +func (user *User) Unfreeze(fu *freezer.User) { if fu.Name != nil { - u.Name = *fu.Name + user.Name = *fu.Name } if fu.CertHash != nil { - u.CertHash = *fu.CertHash + user.CertHash = *fu.CertHash } if fu.Email != nil { - u.Email = *fu.Email + user.Email = *fu.Email } if fu.TextureBlob != nil { - u.TextureBlob = *fu.TextureBlob + user.TextureBlob = *fu.TextureBlob } if fu.CommentBlob != nil { - u.CommentBlob = *fu.CommentBlob + user.CommentBlob = *fu.CommentBlob } if fu.LastChannelID != nil { - u.LastChannelID = int(*fu.LastChannelID) + user.LastChannelID = int(*fu.LastChannelID) } if fu.LastActive != nil { - u.LastActive = *fu.LastActive + user.LastActive = *fu.LastActive } } diff --git a/pkg/cryptstate/cryptstate.go b/pkg/cryptstate/cryptstate.go index 9803949..192ff5c 100644 --- a/pkg/cryptstate/cryptstate.go +++ b/pkg/cryptstate/cryptstate.go @@ -125,8 +125,8 @@ func (cs *CryptState) Decrypt(dst, src []byte) error { return errors.New("cryptstate: crypted length too short to decrypt") } - plain_len := len(src) - cs.Overhead() - if len(dst) < plain_len { + plainLen := len(src) - cs.Overhead() + if len(dst) < plainLen { return errors.New("cryptstate: not enough space in dst for plain text") } diff --git a/pkg/cryptstate/cryptstate_test.go b/pkg/cryptstate/cryptstate_test.go index 073d656..063b633 100644 --- a/pkg/cryptstate/cryptstate_test.go +++ b/pkg/cryptstate/cryptstate_test.go @@ -27,7 +27,7 @@ func TestOCB2AES128Encrypt(t *testing.T) { expected := [19]byte{ 0x1f, 0xfc, 0xdd, 0xb4, 0x68, 0x13, 0x68, 0xb7, 0x92, 0x67, 0xca, 0x2d, 0xba, 0xb7, 0x0d, 0x44, 0xdf, 0x32, 0xd4, } - expected_eiv := [aes.BlockSize]byte{ + expectedEiv := [aes.BlockSize]byte{ 0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a, } @@ -40,7 +40,7 @@ func TestOCB2AES128Encrypt(t *testing.T) { t.Errorf("Mismatch in output") } - if !bytes.Equal(cs.EncryptIV[:], expected_eiv[:]) { + if !bytes.Equal(cs.EncryptIV[:], expectedEiv[:]) { t.Errorf("EIV mismatch") } } @@ -61,7 +61,7 @@ func TestOCB2AES128Decrypt(t *testing.T) { expected := [15]byte{ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, } - post_div := [aes.BlockSize]byte{ + postDiv := [aes.BlockSize]byte{ 0x1f, 0x2a, 0x9b, 0xd0, 0x2d, 0xa6, 0x8e, 0x46, 0x26, 0x85, 0x83, 0xe9, 0x14, 0x2a, 0xff, 0x2a, } @@ -77,7 +77,7 @@ func TestOCB2AES128Decrypt(t *testing.T) { t.Errorf("Mismatch in output") } - if !bytes.Equal(cs.DecryptIV, post_div[:]) { + if !bytes.Equal(cs.DecryptIV, postDiv[:]) { t.Errorf("Mismatch in DIV") } } From c2b5fd9e9d300e1cbab96783a53547b61a5ab694 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Sat, 21 Dec 2019 23:13:41 +0000 Subject: [PATCH 14/14] Remove unneded else statements to follow Golang coding standards --- cmd/grumble/server.go | 22 ++++++++++------------ pkg/packetdata/packetdata.go | 8 ++++---- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/cmd/grumble/server.go b/cmd/grumble/server.go index ac96503..630cb85 100644 --- a/cmd/grumble/server.go +++ b/cmd/grumble/server.go @@ -492,18 +492,17 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) { if auth.Password == nil { client.RejectAuth(mumbleproto.Reject_WrongUserPW, "") return - } else { - if server.CheckSuperUserPassword(*auth.Password) { - ok := false - client.user, ok = server.UserNameMap[client.Username] - if !ok { - client.RejectAuth(mumbleproto.Reject_InvalidUsername, "") - return - } - } else { - client.RejectAuth(mumbleproto.Reject_WrongUserPW, "") + } + if server.CheckSuperUserPassword(*auth.Password) { + ok := false + client.user, ok = server.UserNameMap[client.Username] + if !ok { + client.RejectAuth(mumbleproto.Reject_InvalidUsername, "") return } + } else { + client.RejectAuth(mumbleproto.Reject_WrongUserPW, "") + return } } else { // First look up registration by name. @@ -1037,9 +1036,8 @@ func (server *Server) handleUDPPacket(udpaddr *net.UDPAddr, buf []byte) { client.Debugf("unable to decrypt incoming packet, requesting resync: %v", err) client.cryptResync() return - } else { - match = client } + match = client } if match != nil { match.udpaddr = udpaddr diff --git a/pkg/packetdata/packetdata.go b/pkg/packetdata/packetdata.go index 22ac6c2..fdf9540 100644 --- a/pkg/packetdata/packetdata.go +++ b/pkg/packetdata/packetdata.go @@ -59,9 +59,9 @@ func (pds *PacketData) next() (ret uint64) { ret = uint64(pds.Buf[pds.offset]) pds.offset++ return - } else { - pds.ok = false } + + pds.ok = false return 0 } @@ -71,9 +71,9 @@ func (pds *PacketData) Next8() (ret uint8) { ret = uint8(pds.Buf[pds.offset]) pds.offset++ return - } else { - pds.ok = false } + + pds.ok = false return 0 }