diff --git a/fileshare/event_manager.go b/fileshare/event_manager.go index f98bd5733..42bfa01f0 100644 --- a/fileshare/event_manager.go +++ b/fileshare/event_manager.go @@ -259,21 +259,6 @@ func (em *EventManager) handleFileDownloadedEvent(event EventKindFileDownloaded) fileStatusInNotification, ) } - - em.finalizeFinishedTransfer(transfer) -} - -func (em *EventManager) finalizeFinishedTransfer(transfer *LiveTransfer) { - // Libdrop will not clean up the transfer after transferring all of the files, so we have to - // finalize it manually - after all of the files have finished downloading/uploading or are - // failed/rejected. - // This will generate a [norddrop.EventKindTransferFinalized] event, which is processed in - // [EventManager.handleTransferFinalizedEvent] and will trigger the finalization of transfer. - if isLiveTransferFinished(transfer) && transfer.Direction == pb.Direction_INCOMING { - if err := em.fileshare.Finalize(transfer.ID); err != nil { - log.Printf(internal.WarningPrefix+" failed to finalize transfer %s: %s\n", transfer.ID, err) - } - } } func (em *EventManager) handleFileUploadedEvent(event EventKindFileUploaded) { @@ -299,8 +284,6 @@ func (em *EventManager) handleFileUploadedEvent(event EventKindFileUploaded) { fileStatusInNotification, ) } - - em.finalizeFinishedTransfer(transfer) } func (em *EventManager) handleFileFailedEvent(event EventKindFileFailed) { @@ -327,8 +310,6 @@ func (em *EventManager) handleFileFailedEvent(event EventKindFileFailed) { fileStatusInNotification, ) } - - em.finalizeFinishedTransfer(transfer) } func (em *EventManager) handleFileRejectedEvent(event EventKindFileRejected) { @@ -355,17 +336,9 @@ func (em *EventManager) handleFileRejectedEvent(event EventKindFileRejected) { fileStatusInNotification, ) } - - em.finalizeFinishedTransfer(transfer) } func (em *EventManager) handleTransferFailedEvent(event EventKindTransferFailed) { - transfer, err := em.getLiveTransfer(event.TransferId) - if err != nil { - log.Println(internal.ErrorPrefix, "failed to get live transfer:", err) - return - } - em.finalizeTransfer(transfer, pb.Status(event.Status.Status)) } func (em *EventManager) handleTransferFinalizedEvent(event EventKindTransferFinalized) { diff --git a/fileshare/libdrop/libdrop.go b/fileshare/libdrop/libdrop.go index c5784dfa5..999e56d0f 100644 --- a/fileshare/libdrop/libdrop.go +++ b/fileshare/libdrop/libdrop.go @@ -11,7 +11,7 @@ import ( "sync" "time" - norddrop "github.com/NordSecurity/libdrop-go/v7" + norddrop "github.com/NordSecurity/libdrop-go/v8" "github.com/NordSecurity/nordvpn-linux/fileshare" "github.com/NordSecurity/nordvpn-linux/fileshare/pb" "github.com/NordSecurity/nordvpn-linux/internal" @@ -230,7 +230,6 @@ func (f *Fileshare) Enable(listenAddr netip.Addr) (err error) { } return fmt.Errorf("starting drop: %w", err) } - return nil } @@ -240,12 +239,14 @@ func (f *Fileshare) start( isProd bool, storagePath string, ) error { + var autoRetryIntervalMs uint32 = 5000 config := norddrop.Config{ - DirDepthLimit: fileshare.DirDepthLimit, - TransferFileLimit: fileshare.TransferFileLimit, - MooseEventPath: eventsDbPath, - MooseProd: isProd, - StoragePath: storagePath, + DirDepthLimit: fileshare.DirDepthLimit, + TransferFileLimit: fileshare.TransferFileLimit, + MooseEventPath: eventsDbPath, + MooseProd: isProd, + StoragePath: storagePath, + AutoRetryIntervalMs: &autoRetryIntervalMs, } return f.norddrop.Start(listenAddr.String(), config) @@ -343,13 +344,7 @@ func (f *Fileshare) Load() (map[string]*pb.Transfer, error) { func (f *Fileshare) PurgeTransfersUntil(until time.Time) error { f.mutex.Lock() defer f.mutex.Unlock() - // TODO: In the calculation below: `until.Unix() * 100` it should be - // multiplied by 1000 to get number of milliseconds. The issue is that there - // is a bug on the libdrop side here: https://github.com/NordSecurity/libdrop/blob/v7.0.0/norddrop/src/uni.rs#L100 - // It converts milliseconds to seconds by dividing by 100 instead of 1000 - // resulting in incorrect dates in the year ~2515 and purging of all transfers. - // This will be fixed with migration to v8.0.0 of libdrop. - return f.norddrop.PurgeTransfersUntil(until.Unix() * 100) + return f.norddrop.PurgeTransfersUntil(until.Unix() * 1000) } func norddropTransferToPBTransfer(ti norddrop.TransferInfo) *pb.Transfer { diff --git a/go.mod b/go.mod index 129d05fc1..ca10abfbf 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ toolchain go1.22.2 // NOTE: If you are chaning the binding versions here, keep in mind that you // may also need to update versions in `./lib-versions.env` file. require ( - github.com/NordSecurity/libdrop-go/v7 v7.0.0-rc1 + github.com/NordSecurity/libdrop-go/v8 v8.0.0-20241017064027-670787595588 github.com/NordSecurity/libtelio-go/v5 v5.0.0 ) diff --git a/go.sum b/go.sum index 8d23a1004..d87291a49 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/NordSecurity/gopenvpn v0.0.0-20230117114932-2252c52984b4 h1:2ozEjYEw4 github.com/NordSecurity/gopenvpn v0.0.0-20230117114932-2252c52984b4/go.mod h1:tguhorMSnkMcQExNIHWBX6TRhFeGYlERzbeAWZ4j9Uw= github.com/NordSecurity/libdrop-go/v7 v7.0.0-rc1 h1:YnMQXlt/nG4Gy1MX7uAhU3OdaDPWW3aCiAGTkUSJ7Cc= github.com/NordSecurity/libdrop-go/v7 v7.0.0-rc1/go.mod h1:RtQP2i5NfKk5kcTnT2kDJ7s6Um2pgIoudXFZ8SLYREc= +github.com/NordSecurity/libdrop-go/v8 v8.0.0-20241017064027-670787595588 h1:L/nAbQXJGCOFqw1eTTRYEBKmiuaQQeS7b863+0Ifevw= +github.com/NordSecurity/libdrop-go/v8 v8.0.0-20241017064027-670787595588/go.mod h1:SRYI0D0K6hSMBskvcB2/t/5ktSTNLPGbOvLaQ5p/sAE= github.com/NordSecurity/libtelio-go/v5 v5.0.0 h1:MEd8XjgPp9YlTiG3ed40aiIcob2p0jaOpOTvDAWeAYc= github.com/NordSecurity/libtelio-go/v5 v5.0.0/go.mod h1:mnoTGgXOu8dBQgPxG8MBju4d9C+ljKIT2p8OX5GFom4= github.com/NordSecurity/systray v0.0.0-20240327004800-3e3b59c1b83d h1:oUEFXgFRa9Svcjr+O1stzR3vEXZ5OfQxLUcDjqFcOuo= diff --git a/lib-versions.env b/lib-versions.env index 9fc96bdb5..459cfe515 100644 --- a/lib-versions.env +++ b/lib-versions.env @@ -4,6 +4,6 @@ # shellcheck disable=SC2034 # used in the build process later LIBTELIO_VERSION=v5.0.0 -LIBDROP_VERSION=v7.0.0 +LIBDROP_VERSION=v8.1.1 LIBMOOSE_NORDVPNAPP_VERSION=v12.0.0-nordVpnApp LIBMOOSE_WORKER_VERSION=v10.0.4-worker