Documentation ¶
Index ¶
Constants ¶
const (
HashStoreTypeMem = iota
)
we could extend this with alternative hash stores
const (
HashTypeSHA512 = iota
)
we could extend this with more hashing algorithms
Variables ¶
var ErrNilJobID error = errors.New("encountered nil job ID")
var ErrNilPassword error = errors.New("encountered a nil password")
Functions ¶
This section is empty.
Types ¶
type AtomicFlag ¶
type AtomicFlag struct {
// contains filtered or unexported fields
}
Golang implementation of std::atomic_flag from C++11
Used for lock-free coordination between workers for shutdown
func (*AtomicFlag) Clear ¶
func (a *AtomicFlag) Clear()
Atomically clears AtomicFlag and sets it to false
func (*AtomicFlag) TestAndSet ¶
func (a *AtomicFlag) TestAndSet() bool
Atomically sets AtomicFlag to true and returns its previous value
type HashStore ¶
Implements a generic way to store and load job IDs and their corresponding hashes Lets us easily swap out backends, eg; in-memory, RDBMS like Postgres, NoSQL store Underlying type *must be thread safe*
type HashingEngine ¶
Generic hashing interface allows us to swap out hashing algorithms Not thread-safe! Use 1 per worker
type MemHashStore ¶
type MemHashStore struct {
// contains filtered or unexported fields
}
In-memory hash store using granular locking to prevent contention
Items are routed to a bucket based on first 4 bytes of job ID ¶
Ideally, we size this to the hardware concurrency of the machine
func NewMemHashStore ¶
func NewMemHashStore(size int) *MemHashStore
Creates a new MemHashStore object
type SHA512Engine ¶
type SHA512Engine struct {
// contains filtered or unexported fields
}
func NewSHA512Engine ¶
func NewSHA512Engine() *SHA512Engine
type UUID ¶
type UUID [16]byte //use a fixed size array so it's hashable (i.e. usable as map[UUID]interface{})
func UUIDv4 ¶
Generates an RFC 4122 compliant UUIDv4.
Returns a 128 bit byte slice containing the UUID ¶
Note: uses crypto/rand for secure entropy so it will be slow if the underlying CPU doesn't support the RDRAND instruction. Since we only need low collision probability and even distribution, hashing the output of a faster PRNG (eg; mersenne-twister) through something like 64 bit xxhash twice (to get 16 bytes) will be considerably less CPU intensive.
func (*UUID) Equals ¶
Convenience function to compare two UUIDs
Will return false if either input is nil
func (*UUID) MarshalText ¶
Outputs a UUID in unhyphenated hex
Technically, this isn't the standard format but it's easier to deal with than hyphenated variants
Implements encoding.TextMarshaler interface which allows easy usage with JSON