chore(no-torrent)_: Refactored NewArchiveManager to use config pattern
This commit is contained in:
parent
65fc455e4f
commit
1be465d23c
|
@ -198,6 +198,16 @@ type ArchiveService interface {
|
|||
TorrentFileExists(communityID string) bool
|
||||
}
|
||||
|
||||
type ArchiveManagerConfig struct {
|
||||
TorrentConfig *params.TorrentConfig
|
||||
Logger *zap.Logger
|
||||
Persistence *Persistence
|
||||
Transport *transport.Transport
|
||||
Identity *ecdsa.PrivateKey
|
||||
Encryptor *encryption.Protocol
|
||||
Publisher Publisher
|
||||
}
|
||||
|
||||
func (t *HistoryArchiveDownloadTask) IsCancelled() bool {
|
||||
t.m.RLock()
|
||||
defer t.m.RUnlock()
|
||||
|
|
|
@ -77,21 +77,20 @@ type ArchiveManager struct {
|
|||
// In this case this version of NewArchiveManager will return the full Desktop ArchiveManager ensuring that the
|
||||
// build command will import and build the torrent deps for the Desktop OSes.
|
||||
// NOTE: It is intentional that this file contains the identical function name as in "manager_archive_nop.go"
|
||||
func NewArchiveManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) *ArchiveManager {
|
||||
func NewArchiveManager(amc *ArchiveManagerConfig) *ArchiveManager {
|
||||
return &ArchiveManager{
|
||||
torrentConfig: torrentConfig,
|
||||
torrentConfig: amc.TorrentConfig,
|
||||
torrentTasks: make(map[string]metainfo.Hash),
|
||||
historyArchiveDownloadTasks: make(map[string]*HistoryArchiveDownloadTask),
|
||||
|
||||
logger: logger,
|
||||
logger: amc.Logger,
|
||||
persistence: amc.Persistence,
|
||||
transport: amc.Transport,
|
||||
identity: amc.Identity,
|
||||
encryptor: amc.Encryptor,
|
||||
|
||||
persistence: persistence,
|
||||
transport: transport,
|
||||
identity: identity,
|
||||
encryptor: encryptor,
|
||||
|
||||
publisher: publisher,
|
||||
ArchiveFileManager: NewArchiveFileManager(torrentConfig, logger, persistence, identity, encryptor, publisher),
|
||||
publisher: amc.Publisher,
|
||||
ArchiveFileManager: NewArchiveFileManager(amc),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,14 +40,14 @@ type ArchiveFileManager struct {
|
|||
publisher Publisher
|
||||
}
|
||||
|
||||
func NewArchiveFileManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) *ArchiveFileManager {
|
||||
func NewArchiveFileManager(amc *ArchiveManagerConfig) *ArchiveFileManager {
|
||||
return &ArchiveFileManager{
|
||||
torrentConfig: torrentConfig,
|
||||
logger: logger,
|
||||
persistence: persistence,
|
||||
identity: identity,
|
||||
encryptor: encryptor,
|
||||
publisher: publisher,
|
||||
torrentConfig: amc.TorrentConfig,
|
||||
logger: amc.Logger,
|
||||
persistence: amc.Persistence,
|
||||
identity: amc.Identity,
|
||||
encryptor: amc.Encryptor,
|
||||
publisher: amc.Publisher,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
package communities
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type ArchiveManagerNop struct {
|
||||
|
@ -23,7 +19,7 @@ type ArchiveManagerNop struct {
|
|||
// In this case this version of NewArchiveManager will return the mobile "nil" ArchiveManagerNop ensuring that the
|
||||
// build command will not import or build the torrent deps for the mobile OS.
|
||||
// NOTE: It is intentional that this file contains the identical function name as in "manager_archive.go"
|
||||
func NewArchiveManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) *ArchiveManagerNop {
|
||||
func NewArchiveManager(amc *ArchiveManagerConfig) *ArchiveManagerNop {
|
||||
return &ArchiveManagerNop{
|
||||
&ArchiveFileManagerNop{},
|
||||
}
|
||||
|
|
|
@ -64,8 +64,16 @@ func (s *ManagerSuite) buildManagers(ownerVerifier OwnerVerifier) (*Manager, *Ar
|
|||
s.Require().NoError(err)
|
||||
s.Require().NoError(m.Start())
|
||||
|
||||
tc := buildTorrentConfig()
|
||||
t := NewArchiveManager(&tc, logger, m.GetPersistence(), nil, key, nil, m)
|
||||
amc := &ArchiveManagerConfig{
|
||||
TorrentConfig: buildTorrentConfig(),
|
||||
Logger: logger,
|
||||
Persistence: m.GetPersistence(),
|
||||
Transport: nil,
|
||||
Identity: key,
|
||||
Encryptor: nil,
|
||||
Publisher: m,
|
||||
}
|
||||
t := NewArchiveManager(amc)
|
||||
s.Require().NoError(err)
|
||||
|
||||
return m, t
|
||||
|
@ -1567,14 +1575,13 @@ func (s *ManagerSuite) TestCheckAllChannelsPermissions() {
|
|||
s.Require().Len(response.Channels[chatID2].ViewOnlyPermissions.Permissions, 0)
|
||||
}
|
||||
|
||||
func buildTorrentConfig() params.TorrentConfig {
|
||||
torrentConfig := params.TorrentConfig{
|
||||
func buildTorrentConfig() *params.TorrentConfig {
|
||||
return ¶ms.TorrentConfig{
|
||||
Enabled: true,
|
||||
DataDir: os.TempDir() + "/archivedata",
|
||||
TorrentDir: os.TempDir() + "/torrents",
|
||||
Port: 0,
|
||||
}
|
||||
return torrentConfig
|
||||
}
|
||||
|
||||
func buildMessage(timestamp time.Time, topic types.TopicType, hash []byte) types.Message {
|
||||
|
|
|
@ -498,10 +498,20 @@ func NewMessenger(
|
|||
return nil, err
|
||||
}
|
||||
|
||||
amc := &communities.ArchiveManagerConfig{
|
||||
TorrentConfig: c.torrentConfig,
|
||||
Logger: logger,
|
||||
Persistence: communitiesManager.GetPersistence(),
|
||||
Transport: transp,
|
||||
Identity: identity,
|
||||
Encryptor: encryptionProtocol,
|
||||
Publisher: communitiesManager,
|
||||
}
|
||||
|
||||
// Depending on the OS go will choose whether to use the "communities/manager_archive_nop.go" or
|
||||
// "communities/manager_archive.go" version of this function based on the build instructions for those files.
|
||||
// See those file for more details.
|
||||
torrentManager := communities.NewArchiveManager(c.torrentConfig, logger, communitiesManager.GetPersistence(), transp, identity, encryptionProtocol, communitiesManager)
|
||||
archiveManager := communities.NewArchiveManager(amc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -536,7 +546,7 @@ func NewMessenger(
|
|||
pushNotificationServer: pushNotificationServer,
|
||||
communitiesManager: communitiesManager,
|
||||
communitiesKeyDistributor: communitiesKeyDistributor,
|
||||
archiveManager: torrentManager,
|
||||
archiveManager: archiveManager,
|
||||
accountsManager: c.accountsManager,
|
||||
ensVerifier: ensVerifier,
|
||||
featureFlags: c.featureFlags,
|
||||
|
@ -582,7 +592,7 @@ func NewMessenger(
|
|||
ensVerifier.Stop,
|
||||
pushNotificationClient.Stop,
|
||||
communitiesManager.Stop,
|
||||
torrentManager.Stop,
|
||||
archiveManager.Stop,
|
||||
encryptionProtocol.Stop,
|
||||
func() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
|
|
Loading…
Reference in New Issue