package model import ( "crypto/sha256" "encoding/hex" "time" "github.com/google/uuid" ) // TestBlock 表示单个测试数据块 type TestBlock struct { ID string `json:"id"` Data []byte `json:"data"` Size int `json:"size"` // 数据块大小(字节) Checksum string `json:"checksum"` // SHA-256校验和 CreatedAt time.Time `json:"created_at"` // 创建时间 Sequence int `json:"sequence"` // 数据块序列号 } // NewTestBlock 创建一个新的测试数据块 func NewTestBlock(data []byte, sequence int) *TestBlock { hash := sha256.Sum256(data) checksum := hex.EncodeToString(hash[:]) return &TestBlock{ ID: uuid.New().String(), Data: data, Size: len(data), Checksum: checksum, CreatedAt: time.Now(), Sequence: sequence, } } // Verify 验证数据块的完整性 func (tb *TestBlock) Verify() bool { hash := sha256.Sum256(tb.Data) checksum := hex.EncodeToString(hash[:]) return checksum == tb.Checksum } // TestResult 表示测试结果 type TestResult struct { ID string `json:"id"` TestName string `json:"test_name"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"end_time"` Duration float64 `json:"duration"` // 持续时间(秒) BlocksWritten int `json:"blocks_written"` BlocksVerified int `json:"blocks_verified"` DataWrittenMB float64 `json:"data_written_mb"` Success bool `json:"success"` Error string `json:"error,omitempty"` WriteSpeedMBs float64 `json:"write_speed_mbs"` // MB/s Metrics TestMetrics `json:"metrics"` } // TestMetrics 包含测试的性能指标 type TestMetrics struct { WriteLatencyMs float64 `json:"write_latency_ms"` // 平均写入延迟(毫秒) ReadLatencyMs float64 `json:"read_latency_ms"` // 平均读取延迟(毫秒) IOPS float64 `json:"iops"` // 每秒IO操作数 DataIntegrityLoss int `json:"data_integrity_loss"` // 数据完整性丢失次数 RecoveryTimeMs float64 `json:"recovery_time_ms"` // 断电后恢复时间(毫秒) } // TestRequest 表示客户端发送的测试请求 type TestRequest struct { TestType string `json:"test_type"` BlockSize int `json:"block_size"` DataSizeMB int `json:"data_size_mb"` Concurrency int `json:"concurrency"` Parameters map[string]string `json:"parameters"` ClientID string `json:"client_id"` RequestTime time.Time `json:"request_time"` } // TestResponse 表示服务器对测试请求的响应 type TestResponse struct { RequestID string `json:"request_id"` Status string `json:"status"` // success, error Message string `json:"message,omitempty"` Result *TestResult `json:"result,omitempty"` ServerTime time.Time `json:"server_time"` } // PowerCutInfo 表示断电信息 type PowerCutInfo struct { Timestamp time.Time `json:"timestamp"` Duration int `json:"duration"` // 断电持续时间(秒) BlocksWritten int `json:"blocks_written"` RecoverySuccess bool `json:"recovery_success"` DataLossMB float64 `json:"data_loss_mb"` } // TestStatus 表示测试状态 type TestStatus struct { TestID string `json:"test_id"` TestType string `json:"test_type"` Status string `json:"status"` // running, completed, failed Progress float64 `json:"progress"` // 0-100% StartTime time.Time `json:"start_time"` CurrentPhase string `json:"current_phase"` Message string `json:"message,omitempty"` } // HealthStatus 表示服务器健康状态 type HealthStatus struct { Status string `json:"status"` // ok, error Timestamp time.Time `json:"timestamp"` DiskSpace float64 `json:"disk_space"` CpuUsage float64 `json:"cpu_usage"` MemoryUsage float64 `json:"memory_usage"` Message string `json:"message,omitempty"` } // IntegrityInfo 表示数据完整性信息 type IntegrityInfo struct { TestID string `json:"test_id"` TestType string `json:"test_type"` CheckTime time.Time `json:"check_time"` TotalBlocks int `json:"total_blocks"` ExpectedBlocks int `json:"expected_blocks"` AvailableBlocks int `json:"available_blocks"` CorruptedBlocks int `json:"corrupted_blocks"` MissingBlocks int `json:"missing_blocks"` DataLossMB float64 `json:"data_loss_mb"` RecoverySuccess bool `json:"recovery_success"` RecoveryDuration float64 `json:"recovery_duration_ms"` BlocksMap map[int]BlockStatus `json:"blocks_map,omitempty"` } // BlockStatus 表示数据块状态 type BlockStatus struct { Available bool `json:"available"` Corrupted bool `json:"corrupted"` Checksum string `json:"checksum,omitempty"` FilePath string `json:"file_path,omitempty"` } // StreamUpdate 表示流式更新的数据 type StreamUpdate struct { Type string `json:"type"` // "status", "progress", "integrity", "error" TestID string `json:"test_id"` Timestamp time.Time `json:"timestamp"` Progress float64 `json:"progress,omitempty"` CurrentPhase string `json:"current_phase,omitempty"` Message string `json:"message,omitempty"` Data interface{} `json:"data,omitempty"` }