예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="paramList">
        /// 1,string groupName
        /// 2,string fileName
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 2)
            {
                throw new FDFSException("param count is wrong");
            }

            QUERY_UPDATE result    = new QUERY_UPDATE();
            string       groupName = (string)paramList[0];
            string       fileName  = (string)paramList[1];

            if (groupName.Length > Consts.FDFS_GROUP_NAME_MAX_LEN)
            {
                throw new FDFSException("GroupName is too long");
            }

            byte[] groupNameBuffer = FDFSUtil.StringToByte(groupName);
            byte[] fileNameBuffer  = FDFSUtil.StringToByte(fileName);
            int    length          = Consts.FDFS_GROUP_NAME_MAX_LEN + fileNameBuffer.Length;

            byte[] body = new byte[length];

            Array.Copy(groupNameBuffer, 0, body, 0, groupNameBuffer.Length);
            Array.Copy(fileNameBuffer, 0, body, Consts.FDFS_GROUP_NAME_MAX_LEN, fileNameBuffer.Length);

            result.Body   = body;
            result.Header = new FDFSHeader(length,
                                           Consts.TRACKER_PROTO_CMD_SERVICE_QUERY_UPDATE, 0);
            return(result);
        }
예제 #2
0
        public FDFSHeader(Stream stream)
        {
            int count = Consts.FDFS_PROTO_PKG_LEN_SIZE + 2;

            byte[] headerBuffer = new byte[count];
            var    offset       = 0;

            while (count > 0)
            {
                var readCount = stream.Read(headerBuffer, offset, count);
                if (readCount <= 0)
                {
                    throw new FDFSException("Get Response Header Error,readCount <= 0");
                }

                offset += readCount;
                count  -= readCount;
            }


            //int bytesRead = stream.Read(headerBuffer, 0, headerBuffer.Length);

            //if (bytesRead == 0)
            //    throw new FDFSException("Init Header Exeption : Cann't Read Stream");

            _length  = FDFSUtil.BufferToLong(headerBuffer, 0);
            _command = headerBuffer[Consts.FDFS_PROTO_PKG_LEN_SIZE];
            _status  = headerBuffer[Consts.FDFS_PROTO_PKG_LEN_SIZE + 1];
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="paramList">
        /// 1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        /// 2,string groupName
        /// 3,string fileName
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 3)
            {
                throw new FDFSException("param count is wrong");
            }
            IPEndPoint endPoint = (IPEndPoint)paramList[0];

            string groupName = (string)paramList[1];
            string fileName  = (string)paramList[2];

            DELETE_FILE result = new DELETE_FILE();

            result.Connection = ConnectionManager.GetStorageConnection(endPoint);

            if (groupName.Length > Consts.FDFS_GROUP_NAME_MAX_LEN)
            {
                throw new FDFSException("groupName is too long");
            }

            long length = Consts.FDFS_GROUP_NAME_MAX_LEN +
                          fileName.Length;

            byte[] bodyBuffer      = new byte[length];
            byte[] groupNameBuffer = FDFSUtil.StringToByte(groupName);
            byte[] fileNameBuffer  = FDFSUtil.StringToByte(fileName);

            Array.Copy(groupNameBuffer, 0, bodyBuffer, 0, groupNameBuffer.Length);
            Array.Copy(fileNameBuffer, 0, bodyBuffer, Consts.FDFS_GROUP_NAME_MAX_LEN, fileNameBuffer.Length);

            result.Body   = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_DELETE_FILE, 0);
            return(result);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="paramList">
        /// 1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        /// 2,string        FileName
        /// 3,byte[]        File bytes
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 3)
            {
                throw new FDFSException("param count is wrong");
            }
            IPEndPoint endPoint = (IPEndPoint)paramList[0];

            string fileName = (string)paramList[1];

            byte[] contentBuffer = (byte[])paramList[2];

            APPEND_FILE result = new APPEND_FILE();

            result.Connection = ConnectionManager.GetStorageConnection(endPoint);

            long length = Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE + fileName.Length + contentBuffer.Length;

            byte[] bodyBuffer = new byte[length];

            byte[] fileNameLenBuffer = FDFSUtil.LongToBuffer(fileName.Length);
            Array.Copy(fileNameLenBuffer, 0, bodyBuffer, 0, fileNameLenBuffer.Length);

            byte[] fileSizeBuffer = FDFSUtil.LongToBuffer(contentBuffer.Length);
            Array.Copy(fileSizeBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE, fileSizeBuffer.Length);

            byte[] fileNameBuffer = FDFSUtil.StringToByte(fileName);
            Array.Copy(fileNameBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE, fileNameBuffer.Length);

            Array.Copy(contentBuffer, 0, bodyBuffer, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE + fileNameBuffer.Length, contentBuffer.Length);

            result.Body   = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_APPEND_FILE, 0);
            return(result);
        }
예제 #5
0
 public byte[] ToByte()
 {
     byte[] result = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE + 2];
     byte[] pkglen = FDFSUtil.LongToBuffer(this._length);
     Array.Copy(pkglen, 0, result, 0, pkglen.Length);
     result[Consts.FDFS_PROTO_PKG_LEN_SIZE]     = this._command;
     result[Consts.FDFS_PROTO_PKG_LEN_SIZE + 1] = this._status;
     return(result);
 }
예제 #6
0
            public Response(byte[] responseBody)
            {
                byte[] groupNameBuffer = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN];
                Array.Copy(responseBody, groupNameBuffer, Consts.FDFS_GROUP_NAME_MAX_LEN);
                GroupName = FDFSUtil.ByteToString(groupNameBuffer).TrimEnd('\0');

                byte[] fileNameBuffer = new byte[responseBody.Length - Consts.FDFS_GROUP_NAME_MAX_LEN];
                Array.Copy(responseBody, Consts.FDFS_GROUP_NAME_MAX_LEN, fileNameBuffer, 0, fileNameBuffer.Length);
                FileName = FDFSUtil.ByteToString(fileNameBuffer).TrimEnd('\0');
            }
예제 #7
0
 public Response(byte[] responseByte)
 {
     byte[] groupNameBuffer = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN];
     Array.Copy(responseByte, groupNameBuffer, Consts.FDFS_GROUP_NAME_MAX_LEN);
     GroupName = FDFSUtil.ByteToString(groupNameBuffer).TrimEnd('\0');
     byte[] ipAddressBuffer = new byte[Consts.IP_ADDRESS_SIZE - 1];
     Array.Copy(responseByte, Consts.FDFS_GROUP_NAME_MAX_LEN, ipAddressBuffer, 0, Consts.IP_ADDRESS_SIZE - 1);
     IPStr = new string(FDFSConfig.Charset.GetChars(ipAddressBuffer)).TrimEnd('\0');
     byte[] portBuffer = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];
     Array.Copy(responseByte, Consts.FDFS_GROUP_NAME_MAX_LEN + Consts.IP_ADDRESS_SIZE - 1,
                portBuffer, 0, Consts.FDFS_PROTO_PKG_LEN_SIZE);
     Port = (int)FDFSUtil.BufferToLong(portBuffer, 0);
 }
예제 #8
0
        public FDFSFileInfo(byte[] responseByte)
        {
            byte[] fileSizeBuffer   = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];
            byte[] createTimeBuffer = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];
            byte[] crcBuffer        = new byte[Consts.FDFS_PROTO_PKG_LEN_SIZE];

            Array.Copy(responseByte, 0, fileSizeBuffer, 0, fileSizeBuffer.Length);
            Array.Copy(responseByte, Consts.FDFS_PROTO_PKG_LEN_SIZE, createTimeBuffer, 0, createTimeBuffer.Length);
            Array.Copy(responseByte, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE, crcBuffer, 0, crcBuffer.Length);

            FileSize   = FDFSUtil.BufferToLong(responseByte, 0);
            CreateTime = new System.DateTime(1970, 1, 1).AddSeconds(FDFSUtil.BufferToLong(responseByte, Consts.FDFS_PROTO_PKG_LEN_SIZE));

            Crc32 = FDFSUtil.BufferToLong(responseByte, Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_PROTO_PKG_LEN_SIZE);
        }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="paramList">
        /// 1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        /// 2,Byte          StorePathIndex
        /// 3,long          FileSize
        /// 4,string        File Ext
        /// 5,byte[FileSize]    File Content
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 5)
            {
                throw new FDFSException("param count is wrong");
            }
            IPEndPoint endPoint = (IPEndPoint)paramList[0];

            byte   storePathIndex = (byte)paramList[1];
            int    fileSize       = (int)paramList[2];
            string ext            = (string)paramList[3];

            byte[] contentBuffer = (byte[])paramList[4];

            #region 拷贝后缀扩展名值
            byte[] extBuffer    = new byte[Consts.FDFS_FILE_EXT_NAME_MAX_LEN];
            byte[] bse          = FDFSUtil.StringToByte(ext);
            int    ext_name_len = bse.Length;
            if (ext_name_len > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                ext_name_len = Consts.FDFS_FILE_EXT_NAME_MAX_LEN;
            }
            Array.Copy(bse, 0, extBuffer, 0, ext_name_len);
            #endregion

            UPLOAD_FILE result = new UPLOAD_FILE();
            result.Connection = ConnectionManager.GetStorageConnection(endPoint);
            if (ext.Length > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                throw new FDFSException("file ext is too long");
            }

            long   length     = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + contentBuffer.Length;
            byte[] bodyBuffer = new byte[length];
            bodyBuffer[0] = storePathIndex;

            byte[] fileSizeBuffer = FDFSUtil.LongToBuffer(fileSize);
            Array.Copy(fileSizeBuffer, 0, bodyBuffer, 1, fileSizeBuffer.Length);

            //byte[] extBuffer = Util.StringToByte(ext);
            Array.Copy(extBuffer, 0, bodyBuffer, 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE, extBuffer.Length);

            Array.Copy(contentBuffer, 0, bodyBuffer, 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN, contentBuffer.Length);

            result.Body   = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_UPLOAD_FILE, 0);
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="paramList">
        /// 1,string groupName-->the storage groupName
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length == 0)
            {
                throw new FDFSException("GroupName is null");
            }
            QUERY_STORE_WITH_GROUP_ONE result = new QUERY_STORE_WITH_GROUP_ONE();

            byte[] groupName = FDFSUtil.StringToByte((string)paramList[0]);
            if (groupName.Length > Consts.FDFS_GROUP_NAME_MAX_LEN)
            {
                throw new FDFSException("GroupName is too long");
            }
            byte[] body = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN];
            Array.Copy(groupName, 0, body, 0, groupName.Length);
            result.Body   = body;
            result.Header = new FDFSHeader(Consts.FDFS_GROUP_NAME_MAX_LEN,
                                           Consts.TRACKER_PROTO_CMD_SERVICE_QUERY_STORE_WITH_GROUP_ONE, 0);
            return(result);
        }
예제 #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="paramList">
        /// 1,IPEndPoint    IPEndPoint-->the storage IPEndPoint
        /// 2,Byte          StorePathIndex
        /// 3,long          FileSize
        /// 4,string        File Ext
        /// 5,byte[FileSize]    File Content
        /// </param>
        /// <returns></returns>
        public override FDFSRequest GetRequest(params object[] paramList)
        {
            if (paramList.Length != 6)
            {
                throw new FDFSException("param count is wrong");
            }
            IPEndPoint endPoint = (IPEndPoint)paramList[0];

            int    fileSize       = (int)paramList[1];
            string masterFilename = paramList[2].ToString();
            string prefix_name    = (string)paramList[3];
            string ext            = (string)paramList[4];

            byte[] contentBuffer = (byte[])paramList[5];
            byte[] sizeBytes;
            byte[] hexLenBytes;
            byte[] masterFilenameBytes = FDFSUtil.StringToByte(masterFilename);
            int    offset;

            #region 拷贝后缀扩展名值
            byte[] extBuffer    = new byte[Consts.FDFS_FILE_EXT_NAME_MAX_LEN];
            byte[] bse          = FDFSUtil.StringToByte(ext);
            int    ext_name_len = bse.Length;
            if (ext_name_len > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                ext_name_len = Consts.FDFS_FILE_EXT_NAME_MAX_LEN;
            }
            Array.Copy(bse, 0, extBuffer, 0, ext_name_len);
            #endregion

            UPLOAD_SLAVE_FILE result = new UPLOAD_SLAVE_FILE();
            result.Connection = ConnectionManager.GetStorageConnection(endPoint);
            if (ext.Length > Consts.FDFS_FILE_EXT_NAME_MAX_LEN)
            {
                throw new FDFSException("file ext is too long");
            }

            sizeBytes = new byte[2 * Consts.FDFS_PROTO_PKG_LEN_SIZE];
            //long length = 1 + Consts.FDFS_PROTO_PKG_LEN_SIZE + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + contentBuffer.Length;
            long length = sizeBytes.Length + +Consts.FDFS_FILE_PREFIX_MAX_LEN + Consts.FDFS_FILE_EXT_NAME_MAX_LEN + masterFilenameBytes.Length + contentBuffer.Length;
            //body_len = sizeBytes.length + ProtoCommon.FDFS_FILE_PREFIX_MAX_LEN + ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN
            //             + masterFilenameBytes.length + file_size;
            byte[] bodyBuffer = new byte[length];
            hexLenBytes = FDFSUtil.LongToBuffer(masterFilename.Length);
            offset      = hexLenBytes.Length;

            //Array.Copy(hexLenBytes, 0, sizeBytes, 0, hexLenBytes.Length);

            Array.Copy(hexLenBytes, 0, bodyBuffer, 0, hexLenBytes.Length);
            //System.arraycopy(sizeBytes, 0, wholePkg, header.length, sizeBytes.length);

            byte[] fileSizeBuffer = FDFSUtil.LongToBuffer(fileSize);
            Array.Copy(fileSizeBuffer, 0, bodyBuffer, offset, fileSizeBuffer.Length);

            offset = sizeBytes.Length;

            byte[] prefix_name_bs  = new byte[Consts.FDFS_FILE_PREFIX_MAX_LEN];
            byte[] bs              = FDFSUtil.StringToByte(prefix_name);
            int    prefix_name_len = bs.Length;
            if (prefix_name_len > Consts.FDFS_FILE_PREFIX_MAX_LEN)
            {
                prefix_name_len = Consts.FDFS_FILE_PREFIX_MAX_LEN;
            }
            if (prefix_name_len > 0)
            {
                Array.Copy(bs, 0, prefix_name_bs, 0, prefix_name_len);
            }
            Array.Copy(prefix_name_bs, 0, bodyBuffer, offset, prefix_name_bs.Length);

            offset += prefix_name_bs.Length;

            Array.Copy(extBuffer, 0, bodyBuffer, offset, extBuffer.Length);

            offset += extBuffer.Length;

            Array.Copy(masterFilenameBytes, 0, bodyBuffer, offset, masterFilenameBytes.Length);
            offset += masterFilenameBytes.Length;

            Array.Copy(contentBuffer, 0, bodyBuffer, offset, contentBuffer.Length);

            result.Body   = bodyBuffer;
            result.Header = new FDFSHeader(length, Consts.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, 0);
            return(result);
        }