]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/server.go
Misc cleanup
[rbdr/mobius] / hotline / server.go
index 61cd7fa0a7e82fae0fb4f63df7b534695c23efc7..1da2859ba479773c65d3176ab3c87f41e34459b3 100644 (file)
@@ -8,7 +8,6 @@ import (
        "go.uber.org/zap"
        "io"
        "io/ioutil"
-       "log"
        "math/big"
        "math/rand"
        "net"
@@ -21,7 +20,6 @@ import (
        "sync"
        "time"
 
-       "golang.org/x/crypto/bcrypt"
        "gopkg.in/yaml.v2"
 )
 
@@ -50,8 +48,8 @@ type Server struct {
        APIListener  net.Listener
        FileListener net.Listener
 
-       newsReader io.Reader
-       newsWriter io.WriteCloser
+       // newsReader io.Reader
+       // newsWriter io.WriteCloser
 
        outbox chan Transaction
 
@@ -278,8 +276,8 @@ func (s *Server) keepaliveHandler() {
                s.mux.Lock()
 
                for _, c := range s.Clients {
-                       *c.IdleTime += idleCheckInterval
-                       if *c.IdleTime > userIdleSeconds && !c.Idle {
+                       c.IdleTime += idleCheckInterval
+                       if c.IdleTime > userIdleSeconds && !c.Idle {
                                c.Idle = true
 
                                flagBitmap := big.NewInt(int64(binary.BigEndian.Uint16(*c.Flags)))
@@ -327,16 +325,13 @@ func (s *Server) NewClientConn(conn net.Conn) *ClientConn {
                Connection: conn,
                Server:     s,
                Version:    &[]byte{},
-               IdleTime:   new(int),
-               AutoReply:  &[]byte{},
+               AutoReply:  []byte{},
                Transfers:  make(map[int][]*FileTransfer),
                Agreed:     false,
        }
        *s.NextGuestID++
        ID := *s.NextGuestID
 
-       *clientConn.IdleTime = 0
-
        binary.BigEndian.PutUint16(*clientConn.ID, ID)
        s.Clients[ID] = clientConn
 
@@ -379,7 +374,7 @@ func (s *Server) connectedUsers() []Field {
 
        var connectedUsers []Field
        for _, c := range sortedClients(s.Clients) {
-               if c.Agreed == false {
+               if !c.Agreed {
                        continue
                }
                user := User{
@@ -580,21 +575,6 @@ func (s *Server) handleNewConnection(conn net.Conn) error {
        }
 }
 
-func hashAndSalt(pwd []byte) string {
-       // Use GenerateFromPassword to hash & salt pwd.
-       // MinCost is just an integer constant provided by the bcrypt
-       // package along with DefaultCost & MaxCost.
-       // The cost can be any value you want provided it isn't lower
-       // than the MinCost (4)
-       hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
-       if err != nil {
-               log.Println(err)
-       }
-       // GenerateFromPassword returns a byte slice so we need to
-       // convert the bytes to a string and return it
-       return string(hash)
-}
-
 // NewTransactionRef generates a random ID for the file transfer.  The Hotline client includes this ID
 // in the file transfer request payload, and the file transfer server will use it to map the request
 // to a transfer
@@ -799,7 +779,7 @@ func (s *Server) TransferFile(conn net.Conn) error {
                        }
 
                        // Read the client's Next Action request
-                       //TODO: Remove hardcoded behavior and switch behaviors based on the next action send
+                       // TODO: Remove hardcoded behavior and switch behaviors based on the next action send
                        if _, err := conn.Read(readBuffer); err != nil {
                                return err
                        }
@@ -851,7 +831,7 @@ func (s *Server) TransferFile(conn net.Conn) error {
                                bytesRead, err := file.Read(sendBuffer)
                                if err == io.EOF {
                                        // Read the client's Next Action request
-                                       //TODO: Remove hardcoded behavior and switch behaviors based on the next action send
+                                       // TODO: Remove hardcoded behavior and switch behaviors based on the next action send
                                        if _, err := conn.Read(readBuffer); err != nil {
                                                s.Logger.Errorf("error reading next action: %v", err)
                                                return err