aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2025-12-05 18:42:57 -0800
committerJeff Halter <868228+jhalter@users.noreply.github.com>2025-12-05 18:42:57 -0800
commit472ec3556a66530e7d2255f75ced81cbbf3a1c74 (patch)
treeb9c39907d0a9056cd706a9c6fcde534b6e065ac4
parente4bdf40802188262c1049edfd41a19bbe76e632e (diff)
Improve error handling, logging, and fix race condition in Disconnect
- Add logging for unhandled transaction types in Client.HandleTransaction - Fix race condition in Client.Disconnect by protecting done channel with mutex - Add TranServerMsg to transaction type names map - Use Time type instead of raw byte array in File.flattenedFileObject - Improve error message in handleFileTransfer to include reference number - Simplify return statement in HandleGetFileInfo
-rw-r--r--hotline/client.go5
-rw-r--r--hotline/file_wrapper.go2
-rw-r--r--hotline/server.go3
-rw-r--r--hotline/transaction.go1
-rw-r--r--internal/mobius/transaction_handlers.go5
5 files changed, 10 insertions, 6 deletions
diff --git a/hotline/client.go b/hotline/client.go
index f8d9c34..23bfe9c 100644
--- a/hotline/client.go
+++ b/hotline/client.go
@@ -186,15 +186,20 @@ func (c *Client) HandleTransaction(ctx context.Context, t *Transaction) error {
return err
}
}
+ } else {
+ c.Logger.Info("Unhandled transaction", "type", tranTypeNames[t.Type], "id", int(binary.BigEndian.Uint16(t.Type[:])))
}
return nil
}
func (c *Client) Disconnect() error {
+ c.mu.Lock()
if c.done != nil {
close(c.done)
+ c.done = nil
}
+ c.mu.Unlock()
return c.Connection.Close()
}
diff --git a/hotline/file_wrapper.go b/hotline/file_wrapper.go
index b80bc4b..de3cbe4 100644
--- a/hotline/file_wrapper.go
+++ b/hotline/file_wrapper.go
@@ -209,7 +209,7 @@ func (f *File) Delete() error {
func (f *File) flattenedFileObject() (*flattenedFileObject, error) {
dataSize := make([]byte, 4)
- mTime := [8]byte{}
+ var mTime Time
ft := defaultFileType
diff --git a/hotline/server.go b/hotline/server.go
index 9b74d99..d797c1e 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -7,7 +7,6 @@ import (
"crypto/rand"
"crypto/tls"
"encoding/binary"
- "errors"
"fmt"
"io"
"log"
@@ -677,7 +676,7 @@ func (s *Server) handleFileTransfer(ctx context.Context, rwc io.ReadWriter) erro
fileTransfer := s.FileTransferMgr.Get(t.ReferenceNumber)
if fileTransfer == nil {
- return errors.New("invalid transaction ID")
+ return fmt.Errorf("invalid transaction ID: %v", t.ReferenceNumber)
}
defer func() {
diff --git a/hotline/transaction.go b/hotline/transaction.go
index 068a083..4637463 100644
--- a/hotline/transaction.go
+++ b/hotline/transaction.go
@@ -90,6 +90,7 @@ type Transaction struct {
}
var tranTypeNames = map[TranType]string{
+ TranServerMsg: "Server Message",
TranChatMsg: "Receive chat",
TranNotifyChangeUser: "User change",
TranError: "Error",
diff --git a/internal/mobius/transaction_handlers.go b/internal/mobius/transaction_handlers.go
index 20a315d..c2578bb 100644
--- a/internal/mobius/transaction_handlers.go
+++ b/internal/mobius/transaction_handlers.go
@@ -324,7 +324,7 @@ func HandleGetFileInfo(cc *hotline.ClientConn, t *hotline.Transaction) (res []ho
hotline.NewField(hotline.FieldFileCreateDate, fw.Ffo.FlatFileInformationFork.CreateDate[:]),
hotline.NewField(hotline.FieldFileModifyDate, fw.Ffo.FlatFileInformationFork.ModifyDate[:]),
}
-
+
// Include the optional FileComment field if there is a comment.
if len(fw.Ffo.FlatFileInformationFork.Comment) != 0 {
fields = append(fields, hotline.NewField(hotline.FieldFileComment, fw.Ffo.FlatFileInformationFork.Comment))
@@ -335,8 +335,7 @@ func HandleGetFileInfo(cc *hotline.ClientConn, t *hotline.Transaction) (res []ho
fields = append(fields, hotline.NewField(hotline.FieldFileSize, fw.TotalSize()))
}
- res = append(res, cc.NewReply(t, fields...))
- return res
+ return append(res, cc.NewReply(t, fields...))
}
// HandleSetFileInfo updates a file or folder Name and/or comment from the Get Info window