From f0ac9715e8bf5800e2f3bcca7600134bc532a1ed Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Tue, 4 Jun 2024 00:15:00 +0100 Subject: [PATCH] chore(no-torrent)_: Created TorrentContract and ArchiveContract interfaces --- protocol/communities/manager_archive.go | 13 +++++++++- protocol/communities/torrent_manager.go | 32 +++++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/protocol/communities/manager_archive.go b/protocol/communities/manager_archive.go index 04e0d5436..29fea684e 100644 --- a/protocol/communities/manager_archive.go +++ b/protocol/communities/manager_archive.go @@ -2,7 +2,6 @@ package communities import ( "crypto/ecdsa" - "go.uber.org/zap" "os" "path" "time" @@ -18,8 +17,20 @@ import ( "github.com/anacrolix/torrent/bencode" "github.com/anacrolix/torrent/metainfo" "github.com/golang/protobuf/proto" + "go.uber.org/zap" ) +type ArchiveContract interface { + CreateHistoryArchiveTorrentFromMessages(communityID types.HexBytes, messages []*types.Message, topics []types.TopicType, startDate time.Time, endDate time.Time, partition time.Duration, encrypt bool) ([]string, error) + CreateHistoryArchiveTorrentFromDB(communityID types.HexBytes, topics []types.TopicType, startDate time.Time, endDate time.Time, partition time.Duration, encrypt bool) ([]string, error) + SaveMessageArchiveID(communityID types.HexBytes, hash string) error + GetMessageArchiveIDsToImport(communityID types.HexBytes) ([]string, error) + SetMessageArchiveIDImported(communityID types.HexBytes, hash string, imported bool) error + ExtractMessagesFromHistoryArchive(communityID types.HexBytes, archiveID string) ([]*protobuf.WakuMessage, error) + GetHistoryArchiveMagnetlink(communityID types.HexBytes) (string, error) + LoadHistoryArchiveIndexFromFile(myKey *ecdsa.PrivateKey, communityID types.HexBytes) (*protobuf.WakuMessageArchiveIndex, error) +} + type ArchiveManager struct { torrentConfig *params.TorrentConfig diff --git a/protocol/communities/torrent_manager.go b/protocol/communities/torrent_manager.go index 91693c452..6ead6439d 100644 --- a/protocol/communities/torrent_manager.go +++ b/protocol/communities/torrent_manager.go @@ -11,15 +11,15 @@ import ( "sync" "time" - "github.com/anacrolix/torrent" - "github.com/anacrolix/torrent/metainfo" - "go.uber.org/zap" - "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/params" "github.com/status-im/status-go/protocol/encryption" "github.com/status-im/status-go/protocol/transport" "github.com/status-im/status-go/signal" + + "github.com/anacrolix/torrent" + "github.com/anacrolix/torrent/metainfo" + "go.uber.org/zap" ) type archiveMDSlice []*archiveMetadata @@ -52,6 +52,30 @@ type HistoryArchiveDownloadTaskInfo struct { Cancelled bool } +type TorrentContract interface { + ArchiveContract + + LogStdout(string, ...zap.Field) + SetOnline(bool) + SetTorrentConfig(*params.TorrentConfig) + StartTorrentClient() error + Stop() error + IsReady() bool + GetCommunityChatsFilters(communityID types.HexBytes) ([]*transport.Filter, error) + GetCommunityChatsTopics(communityID types.HexBytes) ([]types.TopicType, error) + GetHistoryArchivePartitionStartTimestamp(communityID types.HexBytes) (uint64, error) + CreateAndSeedHistoryArchive(communityID types.HexBytes, topics []types.TopicType, startDate time.Time, endDate time.Time, partition time.Duration, encrypt bool) error + StartHistoryArchiveTasksInterval(community *Community, interval time.Duration) + StopHistoryArchiveTasksInterval(communityID types.HexBytes) + SeedHistoryArchiveTorrent(communityID types.HexBytes) error + UnseedHistoryArchiveTorrent(communityID types.HexBytes) + IsSeedingHistoryArchiveTorrent(communityID types.HexBytes) bool + GetHistoryArchiveDownloadTask(communityID string) *HistoryArchiveDownloadTask + AddHistoryArchiveDownloadTask(communityID string, task *HistoryArchiveDownloadTask) + DownloadHistoryArchivesByMagnetlink(communityID types.HexBytes, magnetlink string, cancelTask chan struct{}) (*HistoryArchiveDownloadTaskInfo, error) + TorrentFileExists(communityID string) bool +} + type TorrentManager struct { torrentConfig *params.TorrentConfig torrentClient *torrent.Client