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 }