happyfish100 / fastdfs

FastDFS is an open source high performance distributed file system (DFS). It's major functions include: file storing, file syncing and file accessing, and design for high capacity and load balance. Wechat/Weixin public account (Chinese Language): fastdfs
GNU General Public License v3.0
8.91k stars 1.97k forks source link

protocol format error #704

Closed FunkyYang closed 3 months ago

FunkyYang commented 3 months ago

receive from server response,the protocol format may be error,

    if _, err := tcpConn.Read(buf); err != nil {
        return err
    }
    // 通信协议详情地址: https://mp.weixin.qq.com/s/lpWEv3NCLkfKmtzKJ5lGzQ
    // 响应body:
    //@group_name:16字节字符串,组名
    //@ip_addr:15字节字符串, storage server IP地址
    //@port:8字节整数,storage server端口号
    //@store_path_index:1字节整数,基于0的存储路径顺序号
    log.Printf("buff:%s", string(buf))

and print

buff:group1          192.168.1.89                                       Y� 

I don't see port param in reponse ?why?

FunkyYang commented 3 months ago

server version: fdfs_trackerd V6.12.1 fdfs_storaged V6.12.1

happyfish100 commented 3 months ago

see the issue: #703

FunkyYang commented 3 months ago
t.storageInfo.port = bytesToInt(getBytesByPosition(buf, 31, 8))
    log.Printf("%d", t.storageInfo.port)

//bytesToInt 字节转换成整形
// @bys 需要转换的字节
func bytesToInt(bys []byte) int64 {
    bytesBuffer := bytes.NewBuffer(bys)
    // 注意:这里转换的结果是 : 8字节整数
    var x int64
    _ = binary.Read(bytesBuffer, binary.BigEndian, &x)
    return x
}

// getBytesByPosition  截取指定长度的字节切片
// @bys 原始字节切片
// @start 开始位置,
// @num 截取的字节数目
func getBytesByPosition(bys []byte, start, num int) []byte {
    var newBytes = bys[start:]
    endPosition := bytes.IndexByte(newBytes, 0x0)
    if endPosition > 0 {
        num = endPosition
    }
    return newBytes[:num]
}

and print will be 0

FunkyYang commented 3 months ago

image

happyfish100 commented 3 months ago

t.storageInfo.port = bytesToInt(getBytesByPosition(buf, 31, 8)) 31 should changed to 61,as: t.storageInfo.port = bytesToInt(getBytesByPosition(buf, 61, 8))

FunkyYang commented 3 months ago

yes ,solved