Source File
keycache.go
Belonging Package
github.com/tmc/go-iroh/internal/relayproto
package relayprotoimport ()const keyCacheCapacity = 4096// keyCache memoises curve-point validation of endpoint IDs: every relayed// datagram carries one, and validating costs a field square root. Mirrors// Rust iroh-relay's KeyCache.type keyCache struct {mu sync.RWMutexm map[[key.PublicKeySize]byte]struct{}}var validKeys = keyCache{m: make(map[[key.PublicKeySize]byte]struct{})}func ( *keyCache) ( []byte) (key.EndpointID, error) {if len() != key.PublicKeySize {return key.EndpointID{}, key.ErrInvalidKeyLength}:= [key.PublicKeySize]byte().mu.RLock(), := .m[].mu.RUnlock()if {return key.UncheckedEndpointID(), nil}, := key.NewEndpointID()if != nil {return key.EndpointID{},}.mu.Lock()if len(.m) >= keyCacheCapacity {for := range .m { // random evictiondelete(.m, )break}}.m[] = struct{}{}.mu.Unlock()return , nil}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |