搭建代码框架并更新文档
This commit is contained in:
81
core/CMakeLists.txt
Normal file
81
core/CMakeLists.txt
Normal file
@@ -0,0 +1,81 @@
|
||||
# 核心库 CMakeLists.txt
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
# 核心库源文件
|
||||
set(CORE_SOURCES
|
||||
src/network/network_manager.cpp
|
||||
src/network/network_interface.cpp
|
||||
src/network/nat_traversal/stun_client.cpp
|
||||
src/network/nat_traversal/turn_client.cpp
|
||||
src/network/nat_traversal/ice_agent.cpp
|
||||
src/network/nat_traversal/candidate.cpp
|
||||
src/network/nat_traversal/nat_type.cpp
|
||||
src/protocol/protocol_handler.cpp
|
||||
src/protocol/message_serializer.cpp
|
||||
src/session/session_manager.cpp
|
||||
src/session/session.cpp
|
||||
src/codec/codec_manager.cpp
|
||||
src/codec/codec_interface.cpp
|
||||
src/role/role_manager.cpp
|
||||
src/role/host_role.cpp
|
||||
src/role/client_role.cpp
|
||||
src/role/peer_role.cpp
|
||||
src/file_transfer/file_transfer_manager.cpp
|
||||
src/file_transfer/file_transfer_session.cpp
|
||||
src/utils/logger.cpp
|
||||
src/utils/timer.cpp
|
||||
)
|
||||
|
||||
# 核心库头文件
|
||||
set(CORE_HEADERS
|
||||
include/displayflow/core/network/network_manager.h
|
||||
include/displayflow/core/network/network_interface.h
|
||||
include/displayflow/core/network/nat_traversal/stun_client.h
|
||||
include/displayflow/core/network/nat_traversal/turn_client.h
|
||||
include/displayflow/core/network/nat_traversal/ice_agent.h
|
||||
include/displayflow/core/network/nat_traversal/candidate.h
|
||||
include/displayflow/core/network/nat_traversal/nat_type.h
|
||||
include/displayflow/core/protocol/protocol_handler.h
|
||||
include/displayflow/core/protocol/message_serializer.h
|
||||
include/displayflow/core/session/session_manager.h
|
||||
include/displayflow/core/session/session.h
|
||||
include/displayflow/core/codec/codec_manager.h
|
||||
include/displayflow/core/codec/codec_interface.h
|
||||
include/displayflow/core/role/role_manager.h
|
||||
include/displayflow/core/role/host_role.h
|
||||
include/displayflow/core/role/client_role.h
|
||||
include/displayflow/core/role/peer_role.h
|
||||
include/displayflow/core/role/role_interface.h
|
||||
include/displayflow/core/file_transfer/file_transfer_manager.h
|
||||
include/displayflow/core/file_transfer/file_transfer_session.h
|
||||
include/displayflow/core/file_transfer/file_chunk.h
|
||||
include/displayflow/core/file_transfer/transfer_progress.h
|
||||
include/displayflow/core/utils/logger.h
|
||||
include/displayflow/core/utils/timer.h
|
||||
include/displayflow/core/common/types.h
|
||||
include/displayflow/core/common/constants.h
|
||||
)
|
||||
|
||||
# 创建核心库
|
||||
add_library(displayflow_core STATIC
|
||||
${CORE_SOURCES}
|
||||
${CORE_HEADERS}
|
||||
)
|
||||
|
||||
# 包含目录
|
||||
target_include_directories(displayflow_core PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/flatbuffers/include
|
||||
)
|
||||
|
||||
# 链接库(根据实际依赖调整)
|
||||
# target_link_libraries(displayflow_core
|
||||
# flatbuffers
|
||||
# )
|
||||
|
||||
# 编译定义
|
||||
target_compile_definitions(displayflow_core PUBLIC
|
||||
DISPLAYFLOW_CORE_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
|
||||
DISPLAYFLOW_CORE_VERSION_MINOR=${PROJECT_VERSION_MINOR}
|
||||
)
|
||||
|
||||
39
core/include/displayflow/core/codec/codec_interface.h
Normal file
39
core/include/displayflow/core/codec/codec_interface.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include <memory>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
// 前向声明
|
||||
struct VideoFrame;
|
||||
|
||||
/**
|
||||
* @brief 编解码器接口
|
||||
*
|
||||
* 所有编解码器必须实现此接口
|
||||
*/
|
||||
class ICodec {
|
||||
public:
|
||||
virtual ~ICodec() = default;
|
||||
|
||||
/**
|
||||
* @brief 获取编解码器类型
|
||||
*/
|
||||
virtual CodecType GetType() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 编码视频帧
|
||||
*/
|
||||
virtual ByteArray Encode(const VideoFrame& frame) = 0;
|
||||
|
||||
/**
|
||||
* @brief 解码视频帧
|
||||
*/
|
||||
virtual bool Decode(const ByteArray& data, VideoFrame& frame) = 0;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
36
core/include/displayflow/core/codec/codec_manager.h
Normal file
36
core/include/displayflow/core/codec/codec_manager.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/codec/codec_interface.h"
|
||||
#include <memory>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 编解码器管理器
|
||||
*
|
||||
* 负责管理和选择编解码器
|
||||
*/
|
||||
class CodecManager {
|
||||
public:
|
||||
CodecManager();
|
||||
~CodecManager();
|
||||
|
||||
/**
|
||||
* @brief 初始化编解码器管理器
|
||||
*/
|
||||
bool Initialize();
|
||||
|
||||
/**
|
||||
* @brief 获取指定类型的编解码器
|
||||
*/
|
||||
std::shared_ptr<ICodec> GetCodec(CodecType type);
|
||||
|
||||
private:
|
||||
// TODO: 添加私有成员
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
31
core/include/displayflow/core/common/constants.h
Normal file
31
core/include/displayflow/core/common/constants.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
// 版本信息
|
||||
constexpr uint32_t VERSION_MAJOR = 1;
|
||||
constexpr uint32_t VERSION_MINOR = 0;
|
||||
constexpr uint32_t VERSION_PATCH = 0;
|
||||
|
||||
// 网络配置
|
||||
constexpr uint16_t DEFAULT_PORT = 8888;
|
||||
constexpr uint32_t MAX_CLIENTS = 20;
|
||||
constexpr uint32_t DEFAULT_BUFFER_SIZE = 1024 * 1024; // 1MB
|
||||
|
||||
// 性能指标
|
||||
constexpr uint32_t MAX_FPS = 60;
|
||||
constexpr uint32_t TARGET_FPS = 30;
|
||||
constexpr uint32_t MAX_RESOLUTION_WIDTH = 3840; // 4K
|
||||
constexpr uint32_t MAX_RESOLUTION_HEIGHT = 2160; // 4K
|
||||
constexpr uint32_t TARGET_LATENCY_MS = 30; // 目标延迟 30ms
|
||||
|
||||
// 协议配置
|
||||
constexpr uint32_t PROTOCOL_VERSION = 1;
|
||||
constexpr uint32_t MAX_MESSAGE_SIZE = 10 * 1024 * 1024; // 10MB
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
54
core/include/displayflow/core/common/types.h
Normal file
54
core/include/displayflow/core/common/types.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
// 基础类型定义
|
||||
using Byte = uint8_t;
|
||||
using ByteArray = std::vector<Byte>;
|
||||
|
||||
// 角色类型
|
||||
enum class RoleType {
|
||||
Host, // 主机角色
|
||||
Client, // 客户端角色
|
||||
Peer // 对等角色
|
||||
};
|
||||
|
||||
// 网络类型
|
||||
enum class NetworkType {
|
||||
RNDIS, // USB RNDIS
|
||||
WiFi, // Wi-Fi 局域网
|
||||
Ethernet // 有线以太网
|
||||
};
|
||||
|
||||
// 编解码器类型
|
||||
enum class CodecType {
|
||||
H264, // H.264 硬件加速
|
||||
VP8, // VP8 软件编解码
|
||||
MJPEG // MJPEG
|
||||
};
|
||||
|
||||
// 分辨率
|
||||
struct Resolution {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
|
||||
bool operator==(const Resolution& other) const {
|
||||
return width == other.width && height == other.height;
|
||||
}
|
||||
};
|
||||
|
||||
// 会话 ID
|
||||
using SessionId = uint64_t;
|
||||
|
||||
// 设备 ID
|
||||
using DeviceId = std::string;
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
30
core/include/displayflow/core/file_transfer/file_chunk.h
Normal file
30
core/include/displayflow/core/file_transfer/file_chunk.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 文件块
|
||||
*
|
||||
* 文件被分割成固定大小的块进行传输
|
||||
*/
|
||||
struct FileChunk {
|
||||
uint64_t transferId; // 传输会话 ID
|
||||
uint32_t chunkIndex; // 块索引
|
||||
uint32_t chunkSize; // 块大小
|
||||
ByteArray data; // 块数据
|
||||
bool isLastChunk; // 是否为最后一块
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 文件块大小(建议值)
|
||||
*/
|
||||
constexpr uint32_t DEFAULT_CHUNK_SIZE = 64 * 1024; // 64KB
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/file_transfer/file_transfer_session.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <functional>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 文件传输管理器
|
||||
*
|
||||
* 负责管理所有文件传输会话
|
||||
*/
|
||||
class FileTransferManager {
|
||||
public:
|
||||
FileTransferManager();
|
||||
~FileTransferManager();
|
||||
|
||||
/**
|
||||
* @brief 发送文件
|
||||
* @param filePath 文件路径
|
||||
* @param sessionId 会话 ID
|
||||
* @return 传输会话 ID
|
||||
*/
|
||||
uint64_t SendFile(const std::string& filePath, SessionId sessionId);
|
||||
|
||||
/**
|
||||
* @brief 接收文件
|
||||
* @param fileName 文件名
|
||||
* @param fileSize 文件大小
|
||||
* @param savePath 保存路径
|
||||
* @param sessionId 会话 ID
|
||||
* @return 传输会话 ID
|
||||
*/
|
||||
uint64_t ReceiveFile(const std::string& fileName, uint64_t fileSize,
|
||||
const std::string& savePath, SessionId sessionId);
|
||||
|
||||
/**
|
||||
* @brief 暂停传输
|
||||
*/
|
||||
bool PauseTransfer(uint64_t transferId);
|
||||
|
||||
/**
|
||||
* @brief 恢复传输
|
||||
*/
|
||||
bool ResumeTransfer(uint64_t transferId);
|
||||
|
||||
/**
|
||||
* @brief 取消传输
|
||||
*/
|
||||
bool CancelTransfer(uint64_t transferId);
|
||||
|
||||
/**
|
||||
* @brief 获取传输进度
|
||||
*/
|
||||
double GetTransferProgress(uint64_t transferId) const;
|
||||
|
||||
private:
|
||||
std::unordered_map<uint64_t, std::shared_ptr<FileTransferSession>> transfers_;
|
||||
uint64_t nextTransferId_ = 1;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/file_transfer/transfer_progress.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
enum class TransferDirection {
|
||||
Send, // 发送文件
|
||||
Receive // 接收文件
|
||||
};
|
||||
|
||||
enum class TransferStatus {
|
||||
Pending, // 等待中
|
||||
InProgress, // 传输中
|
||||
Paused, // 已暂停
|
||||
Completed, // 已完成
|
||||
Failed, // 失败
|
||||
Cancelled // 已取消
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 文件传输会话
|
||||
*/
|
||||
class FileTransferSession {
|
||||
public:
|
||||
FileTransferSession(uint64_t id, TransferDirection direction);
|
||||
~FileTransferSession();
|
||||
|
||||
uint64_t GetId() const { return id_; }
|
||||
TransferDirection GetDirection() const { return direction_; }
|
||||
TransferStatus GetStatus() const { return status_; }
|
||||
|
||||
void Start();
|
||||
void Pause();
|
||||
void Resume();
|
||||
void Cancel();
|
||||
|
||||
TransferProgress GetProgress() const;
|
||||
|
||||
// 设置进度回调
|
||||
void SetProgressCallback(std::function<void(const TransferProgress&)> callback);
|
||||
|
||||
private:
|
||||
uint64_t id_;
|
||||
TransferDirection direction_;
|
||||
TransferStatus status_ = TransferStatus::Pending;
|
||||
TransferProgress progress_;
|
||||
std::function<void(const TransferProgress&)> progressCallback_;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 传输进度信息
|
||||
*/
|
||||
struct TransferProgress {
|
||||
uint64_t transferId; // 传输会话 ID
|
||||
std::string fileName; // 文件名
|
||||
uint64_t totalSize; // 总大小(字节)
|
||||
uint64_t transferredSize; // 已传输大小(字节)
|
||||
double progress; // 进度百分比 (0.0 - 1.0)
|
||||
uint64_t speed; // 传输速度(字节/秒)
|
||||
uint32_t remainingTime; // 预计剩余时间(秒)
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
enum class CandidateType {
|
||||
Host, // 本地主机地址
|
||||
ServerReflexive, // STUN 服务器反射地址
|
||||
PeerReflexive, // 对端反射地址
|
||||
Relayed // TURN 中继地址
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ICE 候选地址
|
||||
*/
|
||||
struct Candidate {
|
||||
CandidateType type;
|
||||
std::string ip;
|
||||
uint16_t port;
|
||||
uint32_t priority; // 优先级(用于 ICE 排序)
|
||||
std::string foundation; // 基础标识符
|
||||
std::string componentId; // 组件 ID
|
||||
std::string relatedAddress; // 相关地址(用于服务器反射和中继)
|
||||
uint16_t relatedPort;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 候选地址优先级计算
|
||||
*/
|
||||
uint32_t CalculateCandidatePriority(const Candidate& candidate);
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/network/nat_traversal/candidate.h"
|
||||
#include "displayflow/core/network/nat_traversal/stun_client.h"
|
||||
#include "displayflow/core/network/nat_traversal/turn_client.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
struct IceConfig {
|
||||
StunServerConfig stunServer;
|
||||
TurnServerConfig turnServer;
|
||||
uint32_t connectionTimeout = 5000; // 连接超时(毫秒)
|
||||
uint32_t candidateTimeout = 3000; // 候选地址收集超时(毫秒)
|
||||
};
|
||||
|
||||
struct IceCandidatePair {
|
||||
Candidate local;
|
||||
Candidate remote;
|
||||
bool valid = false;
|
||||
uint32_t priority = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief ICE 代理
|
||||
*
|
||||
* 实现 ICE (Interactive Connectivity Establishment) 协议
|
||||
* 自动选择最佳连接路径
|
||||
*/
|
||||
class IceAgent {
|
||||
public:
|
||||
IceAgent();
|
||||
~IceAgent();
|
||||
|
||||
/**
|
||||
* @brief 初始化 ICE 代理
|
||||
*/
|
||||
bool Initialize(const IceConfig& config);
|
||||
|
||||
/**
|
||||
* @brief 收集候选地址
|
||||
* @return 候选地址列表
|
||||
*/
|
||||
std::vector<Candidate> GatherCandidates();
|
||||
|
||||
/**
|
||||
* @brief 设置远程候选地址
|
||||
*/
|
||||
void SetRemoteCandidates(const std::vector<Candidate>& candidates);
|
||||
|
||||
/**
|
||||
* @brief 执行连接检查
|
||||
* @return 是否成功建立连接
|
||||
*/
|
||||
bool PerformConnectivityChecks();
|
||||
|
||||
/**
|
||||
* @brief 获取选定的候选地址对
|
||||
*/
|
||||
IceCandidatePair GetSelectedPair() const;
|
||||
|
||||
/**
|
||||
* @brief 获取连接类型
|
||||
*/
|
||||
std::string GetConnectionType() const; // "local", "stun", "turn"
|
||||
|
||||
/**
|
||||
* @brief 清理资源
|
||||
*/
|
||||
void Cleanup();
|
||||
|
||||
private:
|
||||
IceConfig config_;
|
||||
std::vector<Candidate> localCandidates_;
|
||||
std::vector<Candidate> remoteCandidates_;
|
||||
IceCandidatePair selectedPair_;
|
||||
StunClient stunClient_;
|
||||
TurnClient turnClient_;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief NAT 类型
|
||||
*
|
||||
* 根据 RFC 3489 定义的 NAT 类型
|
||||
*/
|
||||
enum class NatType {
|
||||
Unknown, // 未知
|
||||
Open, // 开放(无 NAT)
|
||||
FullCone, // 完全锥形 NAT
|
||||
RestrictedCone, // 受限锥形 NAT
|
||||
PortRestrictedCone, // 端口受限锥形 NAT
|
||||
Symmetric // 对称 NAT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief NAT 类型字符串转换
|
||||
*/
|
||||
const char* NatTypeToString(NatType type);
|
||||
|
||||
/**
|
||||
* @brief 判断 NAT 类型是否支持直连
|
||||
*/
|
||||
bool IsNatTypeDirectConnectable(NatType type);
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/network/nat_traversal/nat_type.h"
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
struct StunServerConfig {
|
||||
std::string host;
|
||||
uint16_t port = 3478; // 默认 STUN 端口
|
||||
};
|
||||
|
||||
struct StunResponse {
|
||||
std::string publicIp;
|
||||
uint16_t publicPort;
|
||||
NatType natType;
|
||||
bool success;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STUN 客户端
|
||||
*
|
||||
* 用于 NAT 类型检测和获取公网 IP 地址
|
||||
*/
|
||||
class StunClient {
|
||||
public:
|
||||
StunClient();
|
||||
~StunClient();
|
||||
|
||||
/**
|
||||
* @brief 设置 STUN 服务器配置
|
||||
*/
|
||||
void SetServer(const StunServerConfig& config);
|
||||
|
||||
/**
|
||||
* @brief 执行 STUN 绑定请求
|
||||
* @param localPort 本地端口
|
||||
* @return STUN 响应结果
|
||||
*/
|
||||
StunResponse PerformBindingRequest(uint16_t localPort);
|
||||
|
||||
/**
|
||||
* @brief 检测 NAT 类型
|
||||
* @return NAT 类型
|
||||
*/
|
||||
NatType DetectNatType();
|
||||
|
||||
/**
|
||||
* @brief 获取公网 IP 地址
|
||||
* @return 公网 IP 地址
|
||||
*/
|
||||
std::string GetPublicIp();
|
||||
|
||||
private:
|
||||
StunServerConfig serverConfig_;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/network/nat_traversal/candidate.h"
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
struct TurnServerConfig {
|
||||
std::string host;
|
||||
uint16_t port = 3478; // 默认 TURN 端口
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string realm;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief TURN 客户端
|
||||
*
|
||||
* 用于通过 TURN 服务器中继流量(当直连失败时)
|
||||
*/
|
||||
class TurnClient {
|
||||
public:
|
||||
TurnClient();
|
||||
~TurnClient();
|
||||
|
||||
/**
|
||||
* @brief 设置 TURN 服务器配置
|
||||
*/
|
||||
void SetServer(const TurnServerConfig& config);
|
||||
|
||||
/**
|
||||
* @brief 分配中继地址
|
||||
* @return 中继候选地址
|
||||
*/
|
||||
Candidate AllocateRelayAddress();
|
||||
|
||||
/**
|
||||
* @brief 创建权限(允许对端发送数据)
|
||||
*/
|
||||
bool CreatePermission(const std::string& peerIp);
|
||||
|
||||
/**
|
||||
* @brief 发送数据到对端(通过中继)
|
||||
*/
|
||||
bool SendData(const ByteArray& data, const std::string& peerIp, uint16_t peerPort);
|
||||
|
||||
/**
|
||||
* @brief 接收数据(从对端通过中继)
|
||||
*/
|
||||
bool ReceiveData(ByteArray& data, std::string& peerIp, uint16_t& peerPort);
|
||||
|
||||
/**
|
||||
* @brief 释放中继地址
|
||||
*/
|
||||
void ReleaseAllocation();
|
||||
|
||||
private:
|
||||
TurnServerConfig serverConfig_;
|
||||
Candidate relayCandidate_;
|
||||
bool allocated_ = false;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
24
core/include/displayflow/core/network/network_interface.h
Normal file
24
core/include/displayflow/core/network/network_interface.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include <string>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 网络接口信息
|
||||
*/
|
||||
struct NetworkInterface {
|
||||
NetworkType type; // 网络类型
|
||||
std::string name; // 接口名称
|
||||
std::string address; // IP 地址
|
||||
uint16_t port; // 端口号
|
||||
uint32_t bandwidth; // 带宽(Mbps)
|
||||
uint32_t latency; // 延迟(ms)
|
||||
bool isAvailable; // 是否可用
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
47
core/include/displayflow/core/network/network_manager.h
Normal file
47
core/include/displayflow/core/network/network_manager.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/network/network_interface.h"
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 网络管理器
|
||||
*
|
||||
* 负责管理所有网络连接,包括 RNDIS、Wi-Fi、以太网等
|
||||
*/
|
||||
class NetworkManager {
|
||||
public:
|
||||
NetworkManager();
|
||||
~NetworkManager();
|
||||
|
||||
/**
|
||||
* @brief 初始化网络管理器
|
||||
*/
|
||||
bool Initialize();
|
||||
|
||||
/**
|
||||
* @brief 获取所有可用的网络接口
|
||||
*/
|
||||
std::vector<NetworkInterface> GetAvailableInterfaces();
|
||||
|
||||
/**
|
||||
* @brief 连接到指定的网络接口
|
||||
*/
|
||||
bool Connect(const NetworkInterface& interface);
|
||||
|
||||
/**
|
||||
* @brief 断开当前连接
|
||||
*/
|
||||
void Disconnect();
|
||||
|
||||
private:
|
||||
// TODO: 添加私有成员
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
34
core/include/displayflow/core/protocol/message_serializer.h
Normal file
34
core/include/displayflow/core/protocol/message_serializer.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 消息序列化器
|
||||
*
|
||||
* 基于 FlatBuffers 的消息序列化和反序列化
|
||||
*/
|
||||
class MessageSerializer {
|
||||
public:
|
||||
MessageSerializer();
|
||||
~MessageSerializer();
|
||||
|
||||
/**
|
||||
* @brief 序列化消息
|
||||
*/
|
||||
ByteArray Serialize(const void* message);
|
||||
|
||||
/**
|
||||
* @brief 反序列化消息
|
||||
*/
|
||||
bool Deserialize(const ByteArray& data, void* message);
|
||||
|
||||
private:
|
||||
// TODO: 添加私有成员
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
27
core/include/displayflow/core/protocol/protocol_handler.h
Normal file
27
core/include/displayflow/core/protocol/protocol_handler.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 协议处理器
|
||||
*
|
||||
* 负责处理 FlatBuffers 协议的序列化和反序列化
|
||||
*/
|
||||
class ProtocolHandler {
|
||||
public:
|
||||
ProtocolHandler();
|
||||
~ProtocolHandler();
|
||||
|
||||
/**
|
||||
* @brief 初始化协议处理器
|
||||
*/
|
||||
bool Initialize();
|
||||
|
||||
private:
|
||||
// TODO: 添加私有成员
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
29
core/include/displayflow/core/role/client_role.h
Normal file
29
core/include/displayflow/core/role/client_role.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/role/role_interface.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 客户端角色
|
||||
*
|
||||
* 负责接收、解码和渲染
|
||||
*/
|
||||
class ClientRole : public IRole {
|
||||
public:
|
||||
ClientRole();
|
||||
~ClientRole() override;
|
||||
|
||||
RoleType GetType() const override;
|
||||
bool Start(std::shared_ptr<Session> session) override;
|
||||
void Stop() override;
|
||||
bool IsRunning() const override;
|
||||
|
||||
private:
|
||||
bool isRunning_ = false;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
29
core/include/displayflow/core/role/host_role.h
Normal file
29
core/include/displayflow/core/role/host_role.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/role/role_interface.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 主机角色
|
||||
*
|
||||
* 负责屏幕捕获、编码和发送
|
||||
*/
|
||||
class HostRole : public IRole {
|
||||
public:
|
||||
HostRole();
|
||||
~HostRole() override;
|
||||
|
||||
RoleType GetType() const override;
|
||||
bool Start(std::shared_ptr<Session> session) override;
|
||||
void Stop() override;
|
||||
bool IsRunning() const override;
|
||||
|
||||
private:
|
||||
bool isRunning_ = false;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
29
core/include/displayflow/core/role/peer_role.h
Normal file
29
core/include/displayflow/core/role/peer_role.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/role/role_interface.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 对等角色
|
||||
*
|
||||
* 同时作为主机和客户端,实现双向屏幕共享
|
||||
*/
|
||||
class PeerRole : public IRole {
|
||||
public:
|
||||
PeerRole();
|
||||
~PeerRole() override;
|
||||
|
||||
RoleType GetType() const override;
|
||||
bool Start(std::shared_ptr<Session> session) override;
|
||||
void Stop() override;
|
||||
bool IsRunning() const override;
|
||||
|
||||
private:
|
||||
bool isRunning_ = false;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
45
core/include/displayflow/core/role/role_interface.h
Normal file
45
core/include/displayflow/core/role/role_interface.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include <memory>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
class Session;
|
||||
|
||||
/**
|
||||
* @brief 角色接口
|
||||
*
|
||||
* 所有角色(Host、Client、Peer)必须实现此接口
|
||||
*/
|
||||
class IRole {
|
||||
public:
|
||||
virtual ~IRole() = default;
|
||||
|
||||
/**
|
||||
* @brief 获取角色类型
|
||||
*/
|
||||
virtual RoleType GetType() const = 0;
|
||||
|
||||
/**
|
||||
* @brief 启动角色
|
||||
* @param session 会话对象
|
||||
* @return 是否成功
|
||||
*/
|
||||
virtual bool Start(std::shared_ptr<Session> session) = 0;
|
||||
|
||||
/**
|
||||
* @brief 停止角色
|
||||
*/
|
||||
virtual void Stop() = 0;
|
||||
|
||||
/**
|
||||
* @brief 是否正在运行
|
||||
*/
|
||||
virtual bool IsRunning() const = 0;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
37
core/include/displayflow/core/role/role_manager.h
Normal file
37
core/include/displayflow/core/role/role_manager.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/role/role_interface.h"
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 角色管理器
|
||||
*
|
||||
* 负责管理和切换设备角色
|
||||
*/
|
||||
class RoleManager {
|
||||
public:
|
||||
RoleManager();
|
||||
~RoleManager();
|
||||
|
||||
/**
|
||||
* @brief 注册角色
|
||||
*/
|
||||
bool RegisterRole(RoleType type, std::shared_ptr<IRole> role);
|
||||
|
||||
/**
|
||||
* @brief 切换角色
|
||||
*/
|
||||
bool SwitchRole(SessionId sessionId, RoleType newRole);
|
||||
|
||||
private:
|
||||
std::unordered_map<RoleType, std::shared_ptr<IRole>> roles_;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
52
core/include/displayflow/core/session/session.h
Normal file
52
core/include/displayflow/core/session/session.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include <memory>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 显示会话
|
||||
*
|
||||
* 表示一个显示协作会话
|
||||
*/
|
||||
class Session {
|
||||
public:
|
||||
Session(SessionId id, RoleType role);
|
||||
~Session();
|
||||
|
||||
/**
|
||||
* @brief 获取会话 ID
|
||||
*/
|
||||
SessionId GetId() const;
|
||||
|
||||
/**
|
||||
* @brief 获取角色类型
|
||||
*/
|
||||
RoleType GetRole() const;
|
||||
|
||||
/**
|
||||
* @brief 是否处于活动状态
|
||||
*/
|
||||
bool IsActive() const;
|
||||
|
||||
/**
|
||||
* @brief 启动会话
|
||||
*/
|
||||
void Start();
|
||||
|
||||
/**
|
||||
* @brief 停止会话
|
||||
*/
|
||||
void Stop();
|
||||
|
||||
private:
|
||||
SessionId id_;
|
||||
RoleType role_;
|
||||
bool isActive_ = false;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
43
core/include/displayflow/core/session/session_manager.h
Normal file
43
core/include/displayflow/core/session/session_manager.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include "displayflow/core/common/types.h"
|
||||
#include "displayflow/core/session/session.h"
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 会话管理器
|
||||
*
|
||||
* 负责创建、管理和销毁显示会话
|
||||
*/
|
||||
class SessionManager {
|
||||
public:
|
||||
SessionManager();
|
||||
~SessionManager();
|
||||
|
||||
/**
|
||||
* @brief 创建新会话
|
||||
*/
|
||||
std::shared_ptr<Session> CreateSession(RoleType role);
|
||||
|
||||
/**
|
||||
* @brief 销毁会话
|
||||
*/
|
||||
void DestroySession(SessionId sessionId);
|
||||
|
||||
/**
|
||||
* @brief 获取会话
|
||||
*/
|
||||
std::shared_ptr<Session> GetSession(SessionId sessionId);
|
||||
|
||||
private:
|
||||
std::unordered_map<SessionId, std::shared_ptr<Session>> sessions_;
|
||||
SessionId nextSessionId_ = 1;
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
31
core/include/displayflow/core/utils/logger.h
Normal file
31
core/include/displayflow/core/utils/logger.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
enum class LogLevel {
|
||||
Debug,
|
||||
Info,
|
||||
Warning,
|
||||
Error
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 日志记录器
|
||||
*/
|
||||
class Logger {
|
||||
public:
|
||||
Logger();
|
||||
~Logger();
|
||||
|
||||
void Log(LogLevel level, const std::string& message);
|
||||
|
||||
private:
|
||||
// TODO: 添加私有成员
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
27
core/include/displayflow/core/utils/timer.h
Normal file
27
core/include/displayflow/core/utils/timer.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
/**
|
||||
* @brief 定时器工具
|
||||
*/
|
||||
class Timer {
|
||||
public:
|
||||
Timer();
|
||||
~Timer();
|
||||
|
||||
/**
|
||||
* @brief 获取当前时间(毫秒)
|
||||
*/
|
||||
uint64_t GetCurrentTimeMs();
|
||||
|
||||
private:
|
||||
// TODO: 添加私有成员
|
||||
};
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
11
core/src/codec/codec_interface.cpp
Normal file
11
core/src/codec/codec_interface.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "displayflow/core/codec/codec_interface.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
// ICodec 接口实现
|
||||
// 目前只有头文件定义,此文件保留用于未来扩展
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
26
core/src/codec/codec_manager.cpp
Normal file
26
core/src/codec/codec_manager.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "displayflow/core/codec/codec_manager.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
CodecManager::CodecManager() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
CodecManager::~CodecManager() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
bool CodecManager::Initialize() {
|
||||
// TODO: 实现初始化逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<ICodec> CodecManager::GetCodec(CodecType type) {
|
||||
// TODO: 实现获取编解码器逻辑
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
47
core/src/file_transfer/file_transfer_manager.cpp
Normal file
47
core/src/file_transfer/file_transfer_manager.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "displayflow/core/file_transfer/file_transfer_manager.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
FileTransferManager::FileTransferManager() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
FileTransferManager::~FileTransferManager() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
uint64_t FileTransferManager::SendFile(const std::string& filePath, SessionId sessionId) {
|
||||
// TODO: 实现发送文件逻辑
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t FileTransferManager::ReceiveFile(const std::string& fileName, uint64_t fileSize,
|
||||
const std::string& savePath, SessionId sessionId) {
|
||||
// TODO: 实现接收文件逻辑
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FileTransferManager::PauseTransfer(uint64_t transferId) {
|
||||
// TODO: 实现暂停传输逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileTransferManager::ResumeTransfer(uint64_t transferId) {
|
||||
// TODO: 实现恢复传输逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileTransferManager::CancelTransfer(uint64_t transferId) {
|
||||
// TODO: 实现取消传输逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
double FileTransferManager::GetTransferProgress(uint64_t transferId) const {
|
||||
// TODO: 实现获取传输进度逻辑
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
45
core/src/file_transfer/file_transfer_session.cpp
Normal file
45
core/src/file_transfer/file_transfer_session.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "displayflow/core/file_transfer/file_transfer_session.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
FileTransferSession::FileTransferSession(uint64_t id, TransferDirection direction)
|
||||
: id_(id), direction_(direction) {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
FileTransferSession::~FileTransferSession() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
void FileTransferSession::Start() {
|
||||
// TODO: 实现启动传输逻辑
|
||||
status_ = TransferStatus::InProgress;
|
||||
}
|
||||
|
||||
void FileTransferSession::Pause() {
|
||||
// TODO: 实现暂停逻辑
|
||||
status_ = TransferStatus::Paused;
|
||||
}
|
||||
|
||||
void FileTransferSession::Resume() {
|
||||
// TODO: 实现恢复逻辑
|
||||
status_ = TransferStatus::InProgress;
|
||||
}
|
||||
|
||||
void FileTransferSession::Cancel() {
|
||||
// TODO: 实现取消逻辑
|
||||
status_ = TransferStatus::Cancelled;
|
||||
}
|
||||
|
||||
TransferProgress FileTransferSession::GetProgress() const {
|
||||
return progress_;
|
||||
}
|
||||
|
||||
void FileTransferSession::SetProgressCallback(std::function<void(const TransferProgress&)> callback) {
|
||||
progressCallback_ = callback;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
34
core/src/network/nat_traversal/candidate.cpp
Normal file
34
core/src/network/nat_traversal/candidate.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "displayflow/core/network/nat_traversal/candidate.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
uint32_t CalculateCandidatePriority(const Candidate& candidate) {
|
||||
// 根据 RFC 8445 计算候选地址优先级
|
||||
// priority = (2^24) * (type preference) + (2^8) * (local preference) + (2^0) * (component ID)
|
||||
|
||||
uint32_t typePreference = 0;
|
||||
switch (candidate.type) {
|
||||
case CandidateType::Host:
|
||||
typePreference = 126; // 最高优先级
|
||||
break;
|
||||
case CandidateType::ServerReflexive:
|
||||
typePreference = 100;
|
||||
break;
|
||||
case CandidateType::PeerReflexive:
|
||||
typePreference = 110;
|
||||
break;
|
||||
case CandidateType::Relayed:
|
||||
typePreference = 0; // 最低优先级
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t localPreference = 65535; // 默认值
|
||||
uint32_t componentId = 1; // 默认值
|
||||
|
||||
return (typePreference << 24) | (localPreference << 8) | componentId;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
69
core/src/network/nat_traversal/ice_agent.cpp
Normal file
69
core/src/network/nat_traversal/ice_agent.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "displayflow/core/network/nat_traversal/ice_agent.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
IceAgent::IceAgent() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
IceAgent::~IceAgent() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
bool IceAgent::Initialize(const IceConfig& config) {
|
||||
config_ = config;
|
||||
stunClient_.SetServer(config.stunServer);
|
||||
turnClient_.SetServer(config.turnServer);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<Candidate> IceAgent::GatherCandidates() {
|
||||
// TODO: 实现收集候选地址
|
||||
// 1. 收集本地网络接口地址
|
||||
// 2. 通过 STUN 获取服务器反射地址
|
||||
// 3. 通过 TURN 获取中继地址
|
||||
return {};
|
||||
}
|
||||
|
||||
void IceAgent::SetRemoteCandidates(const std::vector<Candidate>& candidates) {
|
||||
remoteCandidates_ = candidates;
|
||||
}
|
||||
|
||||
bool IceAgent::PerformConnectivityChecks() {
|
||||
// TODO: 实现连接检查
|
||||
// 1. 生成候选地址对
|
||||
// 2. 按优先级排序
|
||||
// 3. 执行连接检查
|
||||
// 4. 选择最佳路径
|
||||
return false;
|
||||
}
|
||||
|
||||
IceCandidatePair IceAgent::GetSelectedPair() const {
|
||||
return selectedPair_;
|
||||
}
|
||||
|
||||
std::string IceAgent::GetConnectionType() const {
|
||||
if (selectedPair_.valid) {
|
||||
switch (selectedPair_.local.type) {
|
||||
case CandidateType::Host:
|
||||
return "local";
|
||||
case CandidateType::ServerReflexive:
|
||||
return "stun";
|
||||
case CandidateType::Relayed:
|
||||
return "turn";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
void IceAgent::Cleanup() {
|
||||
// TODO: 实现清理逻辑
|
||||
turnClient_.ReleaseAllocation();
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
32
core/src/network/nat_traversal/nat_type.cpp
Normal file
32
core/src/network/nat_traversal/nat_type.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "displayflow/core/network/nat_traversal/nat_type.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
const char* NatTypeToString(NatType type) {
|
||||
switch (type) {
|
||||
case NatType::Unknown:
|
||||
return "Unknown";
|
||||
case NatType::Open:
|
||||
return "Open";
|
||||
case NatType::FullCone:
|
||||
return "Full Cone";
|
||||
case NatType::RestrictedCone:
|
||||
return "Restricted Cone";
|
||||
case NatType::PortRestrictedCone:
|
||||
return "Port Restricted Cone";
|
||||
case NatType::Symmetric:
|
||||
return "Symmetric";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
bool IsNatTypeDirectConnectable(NatType type) {
|
||||
// 只有开放和完全锥形 NAT 可以直接连接
|
||||
return type == NatType::Open || type == NatType::FullCone;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
37
core/src/network/nat_traversal/stun_client.cpp
Normal file
37
core/src/network/nat_traversal/stun_client.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "displayflow/core/network/nat_traversal/stun_client.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
StunClient::StunClient() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
StunClient::~StunClient() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
void StunClient::SetServer(const StunServerConfig& config) {
|
||||
serverConfig_ = config;
|
||||
}
|
||||
|
||||
StunResponse StunClient::PerformBindingRequest(uint16_t localPort) {
|
||||
// TODO: 实现 STUN 绑定请求
|
||||
StunResponse response;
|
||||
response.success = false;
|
||||
return response;
|
||||
}
|
||||
|
||||
NatType StunClient::DetectNatType() {
|
||||
// TODO: 实现 NAT 类型检测
|
||||
return NatType::Unknown;
|
||||
}
|
||||
|
||||
std::string StunClient::GetPublicIp() {
|
||||
// TODO: 实现获取公网 IP
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
47
core/src/network/nat_traversal/turn_client.cpp
Normal file
47
core/src/network/nat_traversal/turn_client.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "displayflow/core/network/nat_traversal/turn_client.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
TurnClient::TurnClient() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
TurnClient::~TurnClient() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
void TurnClient::SetServer(const TurnServerConfig& config) {
|
||||
serverConfig_ = config;
|
||||
}
|
||||
|
||||
Candidate TurnClient::AllocateRelayAddress() {
|
||||
// TODO: 实现分配中继地址
|
||||
Candidate candidate;
|
||||
candidate.type = CandidateType::Relayed;
|
||||
return candidate;
|
||||
}
|
||||
|
||||
bool TurnClient::CreatePermission(const std::string& peerIp) {
|
||||
// TODO: 实现创建权限
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TurnClient::SendData(const ByteArray& data, const std::string& peerIp, uint16_t peerPort) {
|
||||
// TODO: 实现发送数据
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TurnClient::ReceiveData(ByteArray& data, std::string& peerIp, uint16_t& peerPort) {
|
||||
// TODO: 实现接收数据
|
||||
return false;
|
||||
}
|
||||
|
||||
void TurnClient::ReleaseAllocation() {
|
||||
// TODO: 实现释放分配
|
||||
allocated_ = false;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
11
core/src/network/network_interface.cpp
Normal file
11
core/src/network/network_interface.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "displayflow/core/network/network_interface.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
// NetworkInterface 结构体实现
|
||||
// 目前只有头文件定义,此文件保留用于未来扩展
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
35
core/src/network/network_manager.cpp
Normal file
35
core/src/network/network_manager.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "displayflow/core/network/network_manager.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
NetworkManager::NetworkManager() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
NetworkManager::~NetworkManager() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
bool NetworkManager::Initialize() {
|
||||
// TODO: 实现初始化逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<NetworkInterface> NetworkManager::GetAvailableInterfaces() {
|
||||
// TODO: 实现获取可用网络接口
|
||||
return {};
|
||||
}
|
||||
|
||||
bool NetworkManager::Connect(const NetworkInterface& interface) {
|
||||
// TODO: 实现连接逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
void NetworkManager::Disconnect() {
|
||||
// TODO: 实现断开连接逻辑
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
26
core/src/protocol/message_serializer.cpp
Normal file
26
core/src/protocol/message_serializer.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "displayflow/core/protocol/message_serializer.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
MessageSerializer::MessageSerializer() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
MessageSerializer::~MessageSerializer() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
ByteArray MessageSerializer::Serialize(const void* message) {
|
||||
// TODO: 实现序列化逻辑
|
||||
return {};
|
||||
}
|
||||
|
||||
bool MessageSerializer::Deserialize(const ByteArray& data, void* message) {
|
||||
// TODO: 实现反序列化逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
21
core/src/protocol/protocol_handler.cpp
Normal file
21
core/src/protocol/protocol_handler.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "displayflow/core/protocol/protocol_handler.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
ProtocolHandler::ProtocolHandler() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
ProtocolHandler::~ProtocolHandler() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
bool ProtocolHandler::Initialize() {
|
||||
// TODO: 实现初始化逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
33
core/src/role/client_role.cpp
Normal file
33
core/src/role/client_role.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "displayflow/core/role/client_role.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
ClientRole::ClientRole() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
ClientRole::~ClientRole() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
RoleType ClientRole::GetType() const {
|
||||
return RoleType::Client;
|
||||
}
|
||||
|
||||
bool ClientRole::Start(std::shared_ptr<Session> session) {
|
||||
// TODO: 实现启动逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClientRole::Stop() {
|
||||
// TODO: 实现停止逻辑
|
||||
}
|
||||
|
||||
bool ClientRole::IsRunning() const {
|
||||
return isRunning_;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
33
core/src/role/host_role.cpp
Normal file
33
core/src/role/host_role.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "displayflow/core/role/host_role.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
HostRole::HostRole() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
HostRole::~HostRole() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
RoleType HostRole::GetType() const {
|
||||
return RoleType::Host;
|
||||
}
|
||||
|
||||
bool HostRole::Start(std::shared_ptr<Session> session) {
|
||||
// TODO: 实现启动逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
void HostRole::Stop() {
|
||||
// TODO: 实现停止逻辑
|
||||
}
|
||||
|
||||
bool HostRole::IsRunning() const {
|
||||
return isRunning_;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
33
core/src/role/peer_role.cpp
Normal file
33
core/src/role/peer_role.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "displayflow/core/role/peer_role.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
PeerRole::PeerRole() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
PeerRole::~PeerRole() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
RoleType PeerRole::GetType() const {
|
||||
return RoleType::Peer;
|
||||
}
|
||||
|
||||
bool PeerRole::Start(std::shared_ptr<Session> session) {
|
||||
// TODO: 实现启动逻辑(同时启动 Host 和 Client)
|
||||
return false;
|
||||
}
|
||||
|
||||
void PeerRole::Stop() {
|
||||
// TODO: 实现停止逻辑
|
||||
}
|
||||
|
||||
bool PeerRole::IsRunning() const {
|
||||
return isRunning_;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
26
core/src/role/role_manager.cpp
Normal file
26
core/src/role/role_manager.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "displayflow/core/role/role_manager.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
RoleManager::RoleManager() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
RoleManager::~RoleManager() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
bool RoleManager::RegisterRole(RoleType type, std::shared_ptr<IRole> role) {
|
||||
// TODO: 实现角色注册逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RoleManager::SwitchRole(SessionId sessionId, RoleType newRole) {
|
||||
// TODO: 实现角色切换逻辑
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
39
core/src/session/session.cpp
Normal file
39
core/src/session/session.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "displayflow/core/session/session.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
Session::Session(SessionId id, RoleType role)
|
||||
: id_(id), role_(role) {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
Session::~Session() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
SessionId Session::GetId() const {
|
||||
return id_;
|
||||
}
|
||||
|
||||
RoleType Session::GetRole() const {
|
||||
return role_;
|
||||
}
|
||||
|
||||
bool Session::IsActive() const {
|
||||
return isActive_;
|
||||
}
|
||||
|
||||
void Session::Start() {
|
||||
// TODO: 实现启动逻辑
|
||||
isActive_ = true;
|
||||
}
|
||||
|
||||
void Session::Stop() {
|
||||
// TODO: 实现停止逻辑
|
||||
isActive_ = false;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
30
core/src/session/session_manager.cpp
Normal file
30
core/src/session/session_manager.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "displayflow/core/session/session_manager.h"
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
SessionManager::SessionManager() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
SessionManager::~SessionManager() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
std::shared_ptr<Session> SessionManager::CreateSession(RoleType role) {
|
||||
// TODO: 实现会话创建逻辑
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SessionManager::DestroySession(SessionId sessionId) {
|
||||
// TODO: 实现会话销毁逻辑
|
||||
}
|
||||
|
||||
std::shared_ptr<Session> SessionManager::GetSession(SessionId sessionId) {
|
||||
// TODO: 实现获取会话逻辑
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
22
core/src/utils/logger.cpp
Normal file
22
core/src/utils/logger.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "displayflow/core/utils/logger.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
Logger::Logger() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
Logger::~Logger() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
void Logger::Log(LogLevel level, const std::string& message) {
|
||||
// TODO: 实现日志记录逻辑
|
||||
std::cout << "[" << static_cast<int>(level) << "] " << message << std::endl;
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
23
core/src/utils/timer.cpp
Normal file
23
core/src/utils/timer.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "displayflow/core/utils/timer.h"
|
||||
#include <chrono>
|
||||
|
||||
namespace displayflow {
|
||||
namespace core {
|
||||
|
||||
Timer::Timer() {
|
||||
// TODO: 实现构造函数
|
||||
}
|
||||
|
||||
Timer::~Timer() {
|
||||
// TODO: 实现析构函数
|
||||
}
|
||||
|
||||
uint64_t Timer::GetCurrentTimeMs() {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto duration = now.time_since_epoch();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace displayflow
|
||||
|
||||
Reference in New Issue
Block a user