Skip to content

Commit

Permalink
Librdop v8
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszWojciechO authored Oct 21, 2024
1 parent 7398385 commit b14aac3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 43 deletions.
27 changes: 0 additions & 27 deletions fileshare/event_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -299,8 +284,6 @@ func (em *EventManager) handleFileUploadedEvent(event EventKindFileUploaded) {
fileStatusInNotification,
)
}

em.finalizeFinishedTransfer(transfer)
}

func (em *EventManager) handleFileFailedEvent(event EventKindFileFailed) {
Expand All @@ -327,8 +310,6 @@ func (em *EventManager) handleFileFailedEvent(event EventKindFileFailed) {
fileStatusInNotification,
)
}

em.finalizeFinishedTransfer(transfer)
}

func (em *EventManager) handleFileRejectedEvent(event EventKindFileRejected) {
Expand All @@ -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) {
Expand Down
23 changes: 9 additions & 14 deletions fileshare/libdrop/libdrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -230,7 +230,6 @@ func (f *Fileshare) Enable(listenAddr netip.Addr) (err error) {
}
return fmt.Errorf("starting drop: %w", err)
}

return nil
}

Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion lib-versions.env
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b14aac3

Please sign in to comment.