Skip to content

Commit

Permalink
Remove github.com/hashicorp/golang-lru
Browse files Browse the repository at this point in the history
  • Loading branch information
rod-hynes committed Jul 4, 2024
1 parent 1c05ff9 commit 445148a
Show file tree
Hide file tree
Showing 14 changed files with 12 additions and 1,400 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
github.com/google/gopacket v1.1.19
github.com/grafov/m3u8 v0.0.0-20171211212457-6ab8f28ed427
github.com/hashicorp/golang-lru v1.0.2
github.com/marusama/semaphore v0.0.0-20171214154724-565ffd8e868a
github.com/miekg/dns v1.1.44-0.20210804161652-ab67aa642300
github.com/mitchellh/panicwrap v0.0.0-20170106182340-fce601fe5557
Expand Down
20 changes: 12 additions & 8 deletions psiphon/common/quic/gquic-go/internal/crypto/cert_cache.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package crypto

import (
"fmt"
"hash/fnv"
"sync"

"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/internal/protocol"
"github.com/hashicorp/golang-lru"
"github.com/golang/groupcache/lru"
)

var (
compressedCertsCache *lru.Cache
// [Psiphon]
// Replace github.com/hashicorp/golang-lru with github.com/golang/groupcache/lru,
// adding mutex for safe concurrent access.
compressedCertsCacheMutex sync.Mutex
compressedCertsCache *lru.Cache
)

func getCompressedCert(chain [][]byte, pCommonSetHashes, pCachedHashes []byte) ([]byte, error) {
Expand All @@ -24,7 +28,9 @@ func getCompressedCert(chain [][]byte, pCommonSetHashes, pCachedHashes []byte) (

var result []byte

compressedCertsCacheMutex.Lock()
resultI, isCached := compressedCertsCache.Get(hash)
compressedCertsCacheMutex.Unlock()
if isCached {
result = resultI.([]byte)
} else {
Expand All @@ -33,16 +39,14 @@ func getCompressedCert(chain [][]byte, pCommonSetHashes, pCachedHashes []byte) (
if err != nil {
return nil, err
}
compressedCertsCacheMutex.Lock()
compressedCertsCache.Add(hash, result)
compressedCertsCacheMutex.Unlock()
}

return result, nil
}

func init() {
var err error
compressedCertsCache, err = lru.New(protocol.NumCachedCertificates)
if err != nil {
panic(fmt.Sprintf("fatal error in quic-go: could not create lru cache: %s", err.Error()))
}
compressedCertsCache = lru.New(protocol.NumCachedCertificates)
}
23 changes: 0 additions & 23 deletions vendor/github.com/hashicorp/golang-lru/.gitignore

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/github.com/hashicorp/golang-lru/.golangci.yml

This file was deleted.

222 changes: 0 additions & 222 deletions vendor/github.com/hashicorp/golang-lru/2q.go

This file was deleted.

Loading

0 comments on commit 445148a

Please sign in to comment.