Documentation ¶
Index ¶
- func Download(db *sqlites.SqliteDB, registry *eventbus.EventRegistry, pool *pool.MemoryPool, ...) error
- func HandleFileDownloadRequestPubSub(p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, res *streams.RequestMessage)
- func HandleFileDownloadResponsePubSub(p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, db *sqlites.SqliteDB, ...)
- func ProcessDownloadResponseChecklist(pool *pool.MemoryPool, db *sqlites.SqliteDB, p2p *dep2p.DeP2P, ...)
- func ProcessDownloadResponseContent(p2p *dep2p.DeP2P, db *sqlites.SqliteDB, downloadChan chan *core.DownloadChan, ...)
- func RegisterFileDownloadCheckEvent(opt *opts.Options, p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, ...) error
- func RegisterFileDownloadStartEvent(opt *opts.Options, p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, ...) error
- func SendDownloadInfo(downloadChans chan *core.DownloadChan, fileID, sliceHash string, ...)
- func SendDownloadRequestContents(pool *pool.MemoryPool, p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, ...)
- type FileDownloadRequestChecklistPayload
- type FileDownloadRequestContentPayload
- type FileDownloadResponseChecklistPayload
- type FileDownloadResponseContentPayload
- type StreamProtocol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Download ¶
func Download( db *sqlites.SqliteDB, registry *eventbus.EventRegistry, pool *pool.MemoryPool, fileID string, fileKey string, userPubHash []byte, ) error
func HandleFileDownloadRequestPubSub ¶
func HandleFileDownloadRequestPubSub(p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, res *streams.RequestMessage)
HandleFileDownloadRequestPubSub 处理文件下载请求的订阅消息
func HandleFileDownloadResponsePubSub ¶
func HandleFileDownloadResponsePubSub(p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, db *sqlites.SqliteDB, downloadChan chan *core.DownloadChan, registry *eventbus.EventRegistry, pool *pool.MemoryPool, res *streams.RequestMessage)
HandleFileDownloadResponsePubSub 处理文件下载响应的订阅消息
func ProcessDownloadResponseChecklist ¶
func ProcessDownloadResponseChecklist(pool *pool.MemoryPool, db *sqlites.SqliteDB, p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, payload *FileDownloadResponseChecklistPayload, receiver peer.ID)
ProcessDownloadResponseChecklist 处理文件下载响应清单
func ProcessDownloadResponseContent ¶
func ProcessDownloadResponseContent(p2p *dep2p.DeP2P, db *sqlites.SqliteDB, downloadChan chan *core.DownloadChan, registry *eventbus.EventRegistry, pool *pool.MemoryPool, payload *FileDownloadResponseContentPayload)
ProcessDownloadResponseContent 处理文件下载响应内容
func RegisterFileDownloadCheckEvent ¶
func RegisterFileDownloadCheckEvent( opt *opts.Options, p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, db *sqlites.SqliteDB, registry *eventbus.EventRegistry, pool *pool.MemoryPool, ) error
registerFileDownloadCheckEvent 注册文件下载检查事件
- 先从文件夹读取文件片段: 在尝试恢复数据之前,首先应从指定的子目录中读取所有文件片段。 检查每个文件片段是否真的存在于文件系统中。
- 内存池的数据一致性检查: 如果内存池中某个片段被标记为已下载,但实际上在文件系统中不存在,需要提供一种方法来处理这种不一致。 这可以是一个修复程序,它清除内存池中的错误标记,并可能重新触发下载这些丢失的片段。
- 增加一步从文件夹读取文件片段的逻辑: 在尝试进行数据恢复之前,应该验证所有必要的片段是否都在本地文件夹中可用。
- 如果发现不一致,进行处理: 如果发现任何不一致(如文件系统中缺少标记为已下载的片段),应触发相应的修复逻辑。
func RegisterFileDownloadStartEvent ¶
func RegisterFileDownloadStartEvent( opt *opts.Options, p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, db *sqlites.SqliteDB, registry *eventbus.EventRegistry, pool *pool.MemoryPool, ) error
registerFileDownloadStartEvent 注册文件下载开始事件
func SendDownloadInfo ¶
func SendDownloadInfo(downloadChans chan *core.DownloadChan, fileID, sliceHash string, totalPieces, index int)
SendDownloadInfo 向下载通道发送信息
func SendDownloadRequestContents ¶
func SendDownloadRequestContents(pool *pool.MemoryPool, p2p *dep2p.DeP2P, pubsub *pubsub.DeP2PPubSub, payload *FileDownloadResponseChecklistPayload, receiver peer.ID)
SendDownloadRequestContents 发送文件下载请求(内容)
Types ¶
type FileDownloadRequestChecklistPayload ¶
type FileDownloadRequestChecklistPayload struct { FileID string // 文件的唯一标识(外部标识) UserPubHash []byte // 用户的公钥哈希 }
文件下载请求(清单)
type FileDownloadRequestContentPayload ¶
type FileDownloadRequestContentPayload struct { FileID string // 文件的唯一标识(外部标识) SliceHash string // 待下载的切片哈希 Index int // 文件片段的索引(该片段在文件中的顺序位置) }
文件下载请求(内容)
type FileDownloadResponseChecklistPayload ¶
type FileDownloadResponseChecklistPayload struct { FileID string // 文件的唯一标识 FileKey string // 文件的密钥 Name string // 文件的名称 Size int64 // 文件的长度(以字节为单位) SliceTable map[int]core.HashTable // 文件片段的哈希表 AvailableSlices map[int]string // 本地存储的文件片段信息 }
文件下载响应(清单)
type FileDownloadResponseContentPayload ¶
type FileDownloadResponseContentPayload struct { FileID string // 文件的唯一标识(外部标识) SliceHash string // 下载的切片哈希 Index int // 文件片段的索引(该片段在文件中的顺序位置) SliceContent []byte // 切片内容 }
文件下载响应(内容)
type StreamProtocol ¶
type StreamProtocol struct { Ctx context.Context // 全局上下文 Opt *opts.Options // 文件存储选项配置 P2P *dep2p.DeP2P // DeP2P网络主机 PubSub *pubsub.DeP2PPubSub // DeP2P网络订阅 DB *sqlites.SqliteDB // sqlite数据库服务 UploadChan chan *core.UploadChan // 用于刷新上传的通道 DownloadChan chan *core.DownloadChan // 用于刷新下载的通道 Registry *eventbus.EventRegistry // 事件总线 Cache *ristretto.Cache // 缓存实例 Pool *pool.MemoryPool // 内存池 }
流协议
func (*StreamProtocol) HandleFileDownloadResponseStream ¶
func (sp *StreamProtocol) HandleFileDownloadResponseStream(req *streams.RequestMessage, res *streams.ResponseMessage) error
HandleFileDownloadResponseStream 处理文件下载响应的流消息
Click to show internal directories.
Click to hide internal directories.