Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint and vet #48

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/grumble/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -85,6 +88,7 @@ func Usage() {
}
}

// Args contains all the possible arguments to the Grumble command
var Args args

func init() {
Expand Down
19 changes: 10 additions & 9 deletions cmd/grumble/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"mumble.info/grumble/pkg/acl"
)

// A Mumble channel
// Channel represents a Mumble channel
type Channel struct {
Id int
ID int
Name string
Position int

Expand All @@ -31,9 +31,10 @@ 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
channel.ID = id
channel.Name = name
channel.clients = make(map[uint32]*Client)
channel.children = make(map[int]*Channel)
Expand All @@ -46,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
Expand Down Expand Up @@ -92,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)
}
}
Expand All @@ -111,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)
}
}
Expand Down
67 changes: 35 additions & 32 deletions cmd/grumble/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -112,32 +112,36 @@ 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
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
}

// 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.
Expand All @@ -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.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()
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -265,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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c is fine, no need to change that

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)),
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
}
}
Expand Down Expand Up @@ -384,18 +388,17 @@ 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 {
if client.udp {
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
Expand Down Expand Up @@ -590,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() {
Expand All @@ -616,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
Expand Down
Loading