From 4bb4ca5cce2868fe9f32ea094b4feb658cfe43b9 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Tue, 4 Jun 2024 22:55:36 +0100 Subject: [PATCH] chore(no-torrent)_: Implemented build OS conditional build instructions --- protocol/communities/manager_archive.go | 3 +++ protocol/communities/manager_archive_mobile.go | 3 +++ protocol/communities/manager_torrent.go | 9 ++++++++- protocol/communities/manager_torrent_mobile.go | 15 +++++++++++++++ protocol/messenger.go | 5 ++++- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/protocol/communities/manager_archive.go b/protocol/communities/manager_archive.go index 29fea684e..d6411525f 100644 --- a/protocol/communities/manager_archive.go +++ b/protocol/communities/manager_archive.go @@ -1,3 +1,6 @@ +//go:build windows || linux || darwin +// +build windows linux darwin + package communities import ( diff --git a/protocol/communities/manager_archive_mobile.go b/protocol/communities/manager_archive_mobile.go index 0ee90a4b4..a5bdff82e 100644 --- a/protocol/communities/manager_archive_mobile.go +++ b/protocol/communities/manager_archive_mobile.go @@ -1,3 +1,6 @@ +//go:build android || ios +// +build android ios + package communities import ( diff --git a/protocol/communities/manager_torrent.go b/protocol/communities/manager_torrent.go index 6ead6439d..168450db8 100644 --- a/protocol/communities/manager_torrent.go +++ b/protocol/communities/manager_torrent.go @@ -1,3 +1,6 @@ +//go:build windows || linux || darwin +// +build windows linux darwin + package communities import ( @@ -96,7 +99,11 @@ type TorrentManager struct { publisher Publisher } -func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) (*TorrentManager, error) { +// NewTorrentManager this function is only built and called when the "windows || linux || darwin" build OS criteria are met +// In this case this version of NewTorrentManager will return the full Desktop TorrentManager 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_torrent_mobile.go" +func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) (TorrentContract, error) { stdoutLogger, err := zap.NewDevelopment() if err != nil { return nil, fmt.Errorf("failed to create archive logger %w", err) diff --git a/protocol/communities/manager_torrent_mobile.go b/protocol/communities/manager_torrent_mobile.go index cfcbe613b..debd90ab2 100644 --- a/protocol/communities/manager_torrent_mobile.go +++ b/protocol/communities/manager_torrent_mobile.go @@ -1,10 +1,15 @@ +//go:build android || ios +// +build android ios + 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" @@ -15,6 +20,16 @@ type TorrentManagerMobile struct { logger *zap.Logger } +// NewTorrentManager this function is only built and called when the "android || ios" build OS criteria are met +// In this case this version of NewTorrentManager will return the mobile "nil" TorrentManagerMobile 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_torrent.go" +func NewTorrentManager(torrentConfig *params.TorrentConfig, logger *zap.Logger, persistence *Persistence, transport *transport.Transport, identity *ecdsa.PrivateKey, encryptor *encryption.Protocol, publisher Publisher) (TorrentContract, error) { + return &TorrentManagerMobile{ + logger: logger, + }, nil +} + func (tmm *TorrentManagerMobile) LogStdout(input string, fields ...zap.Field) { tmm.logger.Debug(input, fields...) } diff --git a/protocol/messenger.go b/protocol/messenger.go index 0d02479cc..df6ae5f46 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -113,7 +113,7 @@ type Messenger struct { pushNotificationClient *pushnotificationclient.Client pushNotificationServer *pushnotificationserver.Server communitiesManager *communities.Manager - torrentManager *communities.TorrentManager + torrentManager communities.TorrentContract communitiesKeyDistributor communities.KeyDistributor accountsManager account.Manager mentionsManager *MentionManager @@ -498,6 +498,9 @@ func NewMessenger( return nil, err } + // Depending on the OS go will choose whether to use the "communities/manager_torrent_mobile.go" or + // "communities/manager_torrent.go" version of this function based on the build instructions for those files. + // See those file for more details. torrentManager, err := communities.NewTorrentManager(c.torrentConfig, logger, communitiesManager.GetPersistence(), transp, identity, encryptionProtocol, communitiesManager) if err != nil { return nil, err