From d71f8bcf790b76fb037b9ac0982707194da5427c Mon Sep 17 00:00:00 2001 From: Mitchel Disveld Date: Sat, 9 Jan 2021 17:15:13 +0100 Subject: [PATCH 1/3] fixed on session closed deadlock --- surge/sessionmanager/session.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/surge/sessionmanager/session.go b/surge/sessionmanager/session.go index b40731c..9857bb2 100644 --- a/surge/sessionmanager/session.go +++ b/surge/sessionmanager/session.go @@ -234,9 +234,7 @@ func closeSession(address string) { sessionLockMapLock.Lock() defer sessionLockMapLock.Unlock() - sessionLockMapLock.Lock() session, exists := sessionMap[address] - sessionLockMapLock.Unlock() //Close nkn session, nill out the pointers if exists { @@ -249,9 +247,7 @@ func closeSession(address string) { session = nil //Delete from the map - sessionLockMapLock.Lock() delete(sessionMap, address) - sessionLockMapLock.Unlock() log.Println("Download Session closed for: ", address) fmt.Println(string("\033[31m"), "Download Session closed for: ", address, string("\033[0m")) From aed1d0edca01a5ab0954514899f739e6b87783b4 Mon Sep 17 00:00:00 2001 From: Mitchel Disveld Date: Sat, 9 Jan 2021 17:35:07 +0100 Subject: [PATCH 2/3] remove file no longer in db as error because its handled --- surge/download.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/surge/download.go b/surge/download.go index a5c52ff..ed1773a 100644 --- a/surge/download.go +++ b/surge/download.go @@ -141,7 +141,6 @@ func downloadChunks(file *File, randomChunks []int) { //Check if file is still tracked in surge if err != nil { log.Println("Download Job Terminated", "File no longer in DB") - pushError("Download Job Terminated", "File no longer in DB") return } @@ -151,7 +150,6 @@ func downloadChunks(file *File, randomChunks []int) { dbFile, err = dbGetFile(file.FileHash) if err != nil { log.Println("Download Job Terminated", "File no longer in DB") - pushError("Download Job Terminated", "File no longer in DB") return } From 60cd0102fd952e11c814c126023598e0a86de9a9 Mon Sep 17 00:00:00 2001 From: Mitchel Disveld Date: Sat, 9 Jan 2021 17:37:36 +0100 Subject: [PATCH 3/3] tolower before sort string compares --- surge/FileListSorting.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/surge/FileListSorting.go b/surge/FileListSorting.go index ff40db5..ae2031f 100644 --- a/surge/FileListSorting.go +++ b/surge/FileListSorting.go @@ -1,5 +1,7 @@ package surge +import "strings" + /*type Interface interface { // Len is the number of elements in the collection. Len() int @@ -24,15 +26,19 @@ func (a sortBySeederCountDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } type sortByFileNameAsc []FileListing -func (a sortByFileNameAsc) Len() int { return len(a) } -func (a sortByFileNameAsc) Less(i, j int) bool { return a[i].FileName < a[j].FileName } -func (a sortByFileNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a sortByFileNameAsc) Len() int { return len(a) } +func (a sortByFileNameAsc) Less(i, j int) bool { + return strings.ToLower(a[i].FileName) < strings.ToLower(a[j].FileName) +} +func (a sortByFileNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } type sortByFileNameDesc []FileListing -func (a sortByFileNameDesc) Len() int { return len(a) } -func (a sortByFileNameDesc) Less(i, j int) bool { return a[i].FileName > a[j].FileName } -func (a sortByFileNameDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a sortByFileNameDesc) Len() int { return len(a) } +func (a sortByFileNameDesc) Less(i, j int) bool { + return strings.ToLower(a[i].FileName) > strings.ToLower(a[j].FileName) +} +func (a sortByFileNameDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } type sortByFileSizeAsc []FileListing @@ -48,12 +54,16 @@ func (a sortByFileSizeDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } type sortLocalByFileNameAsc []File -func (a sortLocalByFileNameAsc) Len() int { return len(a) } -func (a sortLocalByFileNameAsc) Less(i, j int) bool { return a[i].FileName < a[j].FileName } -func (a sortLocalByFileNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a sortLocalByFileNameAsc) Len() int { return len(a) } +func (a sortLocalByFileNameAsc) Less(i, j int) bool { + return strings.ToLower(a[i].FileName) < strings.ToLower(a[j].FileName) +} +func (a sortLocalByFileNameAsc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } type sortLocalByFileNameDesc []File -func (a sortLocalByFileNameDesc) Len() int { return len(a) } -func (a sortLocalByFileNameDesc) Less(i, j int) bool { return a[i].FileName > a[j].FileName } -func (a sortLocalByFileNameDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a sortLocalByFileNameDesc) Len() int { return len(a) } +func (a sortLocalByFileNameDesc) Less(i, j int) bool { + return strings.ToLower(a[i].FileName) > strings.ToLower(a[j].FileName) +} +func (a sortLocalByFileNameDesc) Swap(i, j int) { a[i], a[j] = a[j], a[i] }