X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/7cd900d61edbd6d322db3cecb913adf574389320..8fc43f8e53a60144f49b92a0c28b0c939a69d1c9:/hotline/transaction.go?ds=sidebyside diff --git a/hotline/transaction.go b/hotline/transaction.go index 077e6f3..88e17df 100644 --- a/hotline/transaction.go +++ b/hotline/transaction.go @@ -31,6 +31,7 @@ const ( tranNotifyChatSubject = 119 tranSetChatSubject = 120 tranAgreed = 121 + tranServerBanner = 122 tranGetFileNameList = 200 tranDownloadFile = 202 tranUploadFile = 203 @@ -42,7 +43,7 @@ const ( tranMakeFileAlias = 209 tranDownloadFldr = 210 // tranDownloadInfo = 211 TODO: implement file transfer queue - // tranDownloadBanner = 212 TODO: figure out what this is used for + tranDownloadBanner = 212 tranUploadFldr = 213 tranGetUserNameList = 300 tranNotifyChangeUser = 301 @@ -130,23 +131,24 @@ func ReadTransaction(buf []byte) (*Transaction, int, error) { }, tranLen, nil } -func readTransactions(buf []byte) ([]Transaction, int, error) { - var transactions []Transaction +const tranHeaderLen = 20 // fixed length of transaction fields before the variable length fields - bufLen := len(buf) +// transactionScanner implements bufio.SplitFunc for parsing incoming byte slices into complete tokens +func transactionScanner(data []byte, _ bool) (advance int, token []byte, err error) { + // The bytes that contain the size of a transaction are from 12:16, so we need at least 16 bytes + if len(data) < 16 { + return 0, nil, nil + } - var bytesRead = 0 - for bytesRead < bufLen { - t, tReadLen, err := ReadTransaction(buf[bytesRead:]) - if err != nil { - return transactions, bytesRead, err - } - bytesRead += tReadLen + totalSize := binary.BigEndian.Uint32(data[12:16]) - transactions = append(transactions, *t) + // tranLen represents the length of bytes that are part of the transaction + tranLen := int(tranHeaderLen + totalSize) + if tranLen > len(data) { + return 0, nil, nil } - return transactions, bytesRead, nil + return tranLen, data[0:tranLen], nil } const minFieldLen = 4