]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/client_conn.go
Fix failing tests
[rbdr/mobius] / hotline / client_conn.go
index c1ae4e3c8fb9f5f4fb0d5b4bb09cffaba2e30da3..4e703c2762b53961cecd0db5d8af94c5d9a10954 100644 (file)
@@ -2,9 +2,11 @@ package hotline
 
 import (
        "encoding/binary"
 
 import (
        "encoding/binary"
+       "go.uber.org/zap"
        "golang.org/x/crypto/bcrypt"
        "io"
        "math/big"
        "golang.org/x/crypto/bcrypt"
        "io"
        "math/big"
+       "sort"
 )
 
 type byClientID []*ClientConn
 )
 
 type byClientID []*ClientConn
@@ -64,6 +66,7 @@ type ClientConn struct {
        AutoReply  []byte
        Transfers  map[int][]*FileTransfer
        Agreed     bool
        AutoReply  []byte
        Transfers  map[int][]*FileTransfer
        Agreed     bool
+       logger     *zap.SugaredLogger
 }
 
 func (cc *ClientConn) sendAll(t int, fields ...Field) {
 }
 
 func (cc *ClientConn) sendAll(t int, fields ...Field) {
@@ -96,10 +99,8 @@ func (cc *ClientConn) handleTransaction(transaction *Transaction) error {
                        }
                }
 
                        }
                }
 
-               cc.Server.Logger.Infow(
+               cc.logger.Infow(
                        "Received Transaction",
                        "Received Transaction",
-                       "login", cc.Account.Login,
-                       "name", string(cc.UserName),
                        "RequestType", handler.Name,
                )
 
                        "RequestType", handler.Name,
                )
 
@@ -164,9 +165,9 @@ func (cc *ClientConn) Authorize(access int) bool {
                return true
        }
 
                return true
        }
 
-       accessBitmap := big.NewInt(int64(binary.BigEndian.Uint64(*cc.Account.Access)))
+       i := big.NewInt(int64(binary.BigEndian.Uint64(*cc.Account.Access)))
 
 
-       return accessBitmap.Bit(63-access) == 1
+       return i.Bit(63-access) == 1
 }
 
 // Disconnect notifies other clients that a client has disconnected
 }
 
 // Disconnect notifies other clients that a client has disconnected
@@ -222,3 +223,13 @@ func (cc *ClientConn) NewErrReply(t *Transaction, errMsg string) Transaction {
                },
        }
 }
                },
        }
 }
+
+// sortedClients is a utility function that takes a map of *ClientConn and returns a sorted slice of the values.
+// The purpose of this is to ensure that the ordering of client connections is deterministic so that test assertions work.
+func sortedClients(unsortedClients map[uint16]*ClientConn) (clients []*ClientConn) {
+       for _, c := range unsortedClients {
+               clients = append(clients, c)
+       }
+       sort.Sort(byClientID(clients))
+       return clients
+}