本文整理汇总了Golang中github.com/spaolacci/murmur3.Sum128函数的典型用法代码示例。如果您正苦于以下问题:Golang Sum128函数的具体用法?Golang Sum128怎么用?Golang Sum128使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sum128函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RevokeAddrFS
// RevokeAddrFS ...
func (s *FileSystemAPIServer) RevokeAddrFS(ctx context.Context, r *pb.RevokeAddrFSRequest) (*pb.RevokeAddrFSResponse, error) {
var err error
srcAddr := ""
// Get incomming ip
pr, ok := peer.FromContext(ctx)
if ok {
srcAddr = pr.Addr.String()
}
// Validate Token
_, err = s.validateToken(r.Token)
if err != nil {
log.Printf("%s REVOKE FAILED %s\n", srcAddr, "PermissionDenied")
return nil, errf(codes.PermissionDenied, "%v", "Invalid Token")
}
// REVOKE an file system entry for the addr
// delete /fs/FSID/addr addr AddrRef
pKey := fmt.Sprintf("/fs/%s/addr", r.FSid)
pKeyA, pKeyB := murmur3.Sum128([]byte(pKey))
cKeyA, cKeyB := murmur3.Sum128([]byte(r.Addr))
timestampMicro := brimtime.TimeToUnixMicro(time.Now())
_, err = s.gstore.Delete(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, timestampMicro)
if store.IsNotFound(err) {
log.Printf("%s REVOKE FAILED %s %s\n", srcAddr, r.FSid, r.Addr)
return nil, errf(codes.NotFound, "%v", "Not Found")
}
// return Addr was revoked
// Log Operation
log.Printf("%s REVOKE SUCCESS %s %s\n", srcAddr, r.FSid, r.Addr)
return &pb.RevokeAddrFSResponse{Data: r.FSid}, nil
}
示例2: RevokeAddrFS
// RevokeAddrFS ...
func (s *FileSystemAPIServer) RevokeAddrFS(ctx context.Context, r *pb.RevokeAddrFSRequest) (*pb.RevokeAddrFSResponse, error) {
var err error
var acctID string
var value []byte
var fsRef FileSysRef
srcAddr := ""
// Get incomming ip
pr, ok := peer.FromContext(ctx)
if ok {
srcAddr = pr.Addr.String()
}
// Validate Token
acctID, err = s.validateToken(r.Token)
if err != nil {
log.Printf("%s REVOKE FAILED %s\n", srcAddr, "PermissionDenied")
return nil, errf(codes.PermissionDenied, "%v", "Invalid Token")
}
// Validate Token/Account owns this file system
// Read FileSysRef entry to determine if it exists
pKey := fmt.Sprintf("/fs")
pKeyA, pKeyB := murmur3.Sum128([]byte(pKey))
cKeyA, cKeyB := murmur3.Sum128([]byte(r.FSid))
_, value, err = s.gstore.Read(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, nil)
if store.IsNotFound(err) {
log.Printf("%s REVOKE FAILED %s NOTFOUND", srcAddr, r.FSid)
return nil, errf(codes.NotFound, "%v", "Not Found")
}
if err != nil {
log.Printf("%s REVOKE FAILED %v\n", srcAddr, err)
return nil, errf(codes.Internal, "%v", err)
}
err = json.Unmarshal(value, &fsRef)
if err != nil {
log.Printf("%s REVOKE FAILED %v\n", srcAddr, err)
return nil, errf(codes.Internal, "%v", err)
}
if fsRef.AcctID != acctID {
log.Printf("$s REVOKE FAILED %v ACCOUNT MISMATCH", r.FSid)
return nil, errf(codes.FailedPrecondition, "%v", "Account Mismatch")
}
// REVOKE an file system entry for the addr
// delete /fs/FSID/addr addr AddrRef
pKey = fmt.Sprintf("/fs/%s/addr", r.FSid)
pKeyA, pKeyB = murmur3.Sum128([]byte(pKey))
cKeyA, cKeyB = murmur3.Sum128([]byte(r.Addr))
timestampMicro := brimtime.TimeToUnixMicro(time.Now())
_, err = s.gstore.Delete(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, timestampMicro)
if store.IsNotFound(err) {
log.Printf("%s REVOKE FAILED %s %s\n", srcAddr, r.FSid, r.Addr)
return nil, errf(codes.NotFound, "%v", "Not Found")
}
// return Addr was revoked
// Log Operation
log.Printf("%s REVOKE SUCCESS %s %s\n", srcAddr, r.FSid, r.Addr)
return &pb.RevokeAddrFSResponse{Data: r.FSid}, nil
}
示例3: GrantAddrFS
// GrantAddrFS ...
func (s *FileSystemAPIServer) GrantAddrFS(ctx context.Context, r *fb.GrantAddrFSRequest) (*fb.GrantAddrFSResponse, error) {
var status string
var err error
var acctData AcctPayLoad
var fsData FileSysPayLoad
var addrData AddrPayLoad
var dataB []byte
// Get incomming ip
pr, ok := peer.FromContext(ctx)
if ok {
fmt.Println(pr.Addr)
}
// getAcct data
acctData, err = s.getAcct("/acct", r.Acctnum)
if err != nil {
log.Printf("Error %v on lookup for account %s", err, r.Acctnum)
return nil, err
}
// validate token
if acctData.Token != r.Token {
return nil, errf(codes.PermissionDenied, "%s", "Invalid Token")
}
// getFS data
fs := fmt.Sprintf("/acct/%s/fs", r.Acctnum)
fsData, err = s.getFS(fs, r.FSid)
if err != nil {
log.Printf("Error %v on lookup for File system %s", err, r.Acctnum)
return nil, err
}
if fsData.Status == "active" {
log.Println("FileSystem is active")
}
// write out the ip address
parentKey := fmt.Sprintf("/fs/%s/addr", r.FSid)
childKey := r.Addr
parentKeyA, parentKeyB := murmur3.Sum128([]byte(parentKey))
childKeyA, childKeyB := murmur3.Sum128([]byte(childKey))
timestampMicro := brimtime.TimeToUnixMicro(time.Now())
addrData.Addr = r.Addr
dataB, err = json.Marshal(addrData)
if err != nil {
log.Printf("Marshal Error: %v\n...", err)
return nil, errf(codes.Internal, "%v", err)
}
_, err = s.fsws.gstore.Write(context.Background(), parentKeyA, parentKeyB, childKeyA, childKeyB, timestampMicro, dataB)
if err != nil {
log.Printf("Write Error: %v", err)
return nil, errf(codes.Internal, "%v", err)
}
// DO stuff
status = fmt.Sprintf("addr %s for filesystem %s with account id %s was granted", r.Addr, r.FSid, r.Acctnum)
return &fb.GrantAddrFSResponse{Status: status}, nil
}
示例4: DeleteGroupItemTS
func (o *StoreComms) DeleteGroupItemTS(ctx context.Context, key, childKey []byte, tsm int64) error {
keyA, keyB := murmur3.Sum128(key)
childKeyA, childKeyB := murmur3.Sum128(childKey)
oldTimestampMicro, err := o.gstore.Delete(ctx, keyA, keyB, childKeyA, childKeyB, tsm)
if err != nil {
return err
}
if oldTimestampMicro >= tsm {
return ErrStoreHasNewerValue
}
return nil
}
示例5: writeGStore
// writeGStore ...
func (fsws *FileSystemWS) writeGStore(g string, m string, p []byte) (string, error) {
// prepare groupVal and memberVal
log.Println("Starting a Write to the Group Store")
keyA, keyB := murmur3.Sum128([]byte(g))
childKeyA, childKeyB := murmur3.Sum128([]byte(m))
timestampMicro := brimtime.TimeToUnixMicro(time.Now())
newTimestampMicro, err := fsws.gstore.Write(context.Background(), keyA, keyB, childKeyA, childKeyB, timestampMicro, p)
if err != nil {
return "", err
}
log.Println("Successfully wrote something to the Group Store")
return fmt.Sprintf("TSM: %d", newTimestampMicro), nil
}
示例6: getGStore
// lookupAccount ...
func (fsws *FileSystemWS) getGStore(g string, m string) (string, error) {
log.Println("Starting a Read from the Group Store")
keyA, keyB := murmur3.Sum128([]byte(g))
childKeyA, childKeyB := murmur3.Sum128([]byte(m))
_, value, err := fsws.gstore.Read(context.Background(), keyA, keyB, childKeyA, childKeyB, nil)
if store.IsNotFound(err) {
log.Printf(" Not Found Key: %d, %d ChildKey: %d, %d", keyA, keyB, childKeyA, childKeyB)
return "", nil
} else if err != nil {
return "", err
}
log.Println("Successfully read an item from the Group Store")
return fmt.Sprintf("%s", value), nil
}
示例7: ShowFS
// ShowFS ...
func (s *FileSystemAPIServer) ShowFS(ctx context.Context, r *fb.ShowFSRequest) (*fb.ShowFSResponse, error) {
var status string
var acctData AcctPayLoad
var fsData FileSysPayLoad
var fsDataB []byte
var err error
// Get incomming ip
pr, ok := peer.FromContext(ctx)
if ok {
fmt.Println(pr.Addr)
}
// getAcct data
acctData, err = s.getAcct("/acct", r.Acctnum)
if err != nil {
log.Printf("Error %v on lookup for account %s", err, r.Acctnum)
return nil, err
}
// validate token
if acctData.Token != r.Token {
return nil, errf(codes.PermissionDenied, "%s", "Invalid Token")
}
pKey := fmt.Sprintf("/acct/%s/fs", r.Acctnum)
pKeyA, pKeyB := murmur3.Sum128([]byte(pKey))
cKeyA, cKeyB := murmur3.Sum128([]byte(r.FSid))
_, fsDataB, err = s.fsws.gstore.Read(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, nil)
if store.IsNotFound(err) {
return nil, errf(codes.NotFound, "%v", "File System Not Found")
}
if err != nil {
return nil, errf(codes.Internal, "%s", err)
}
err = json.Unmarshal(fsDataB, &fsData)
if err != nil {
return nil, errf(codes.Internal, "%s", err)
}
// Get list of Addr
fsData.Addr, err = s.addrList(fsData.ID)
if err != nil {
return nil, errf(codes.Internal, "%s", err)
}
fsDataB, err = json.Marshal(&fsData)
if err != nil {
return nil, errf(codes.Internal, "%s", err)
}
// Prep things to return
status = "OK"
return &fb.ShowFSResponse{Payload: string(fsDataB), Status: status}, nil
}
示例8: ReadValue
// Helper methods to get data from value and group store
func (o *StoreComms) ReadValue(ctx context.Context, id []byte) ([]byte, error) {
// TODO: You might want to make this whole area pass in reusable []byte to
// lessen gc pressure.
keyA, keyB := murmur3.Sum128(id)
_, v, err := o.vstore.Read(ctx, keyA, keyB, nil)
return v, err
}
示例9: mayHave
func (ktbf *groupKTBloomFilter) mayHave(keyA uint64, keyB uint64, childKeyA uint64, childKeyB uint64, timestamp uint64) bool {
scratch := ktbf.scratch
binary.BigEndian.PutUint64(scratch[4:], keyA)
binary.BigEndian.PutUint64(scratch[12:], keyB)
binary.BigEndian.PutUint64(scratch[20:], childKeyA)
binary.BigEndian.PutUint64(scratch[28:], childKeyB)
binary.BigEndian.PutUint64(scratch[36:], timestamp)
for i := ktbf.kDiv4; i > 0; i-- {
binary.BigEndian.PutUint32(scratch, ktbf.salt|i)
h1, h2 := murmur3.Sum128(scratch)
bit := uint32(h1>>32) % ktbf.m
if ktbf.bits[bit/8]&(1<<(bit%8)) == 0 {
return false
}
bit = uint32(h1&0xffffffff) % ktbf.m
if ktbf.bits[bit/8]&(1<<(bit%8)) == 0 {
return false
}
bit = uint32(h2>>32) % ktbf.m
if ktbf.bits[bit/8]&(1<<(bit%8)) == 0 {
return false
}
bit = uint32(h2&0xffffffff) % ktbf.m
if ktbf.bits[bit/8]&(1<<(bit%8)) == 0 {
return false
}
}
return true
}
示例10: add
func (ktbf *groupKTBloomFilter) add(keyA uint64, keyB uint64, childKeyA uint64, childKeyB uint64, timestamp uint64) {
// CONSIDER: There are optimization opportunities here as the keys can be
// considered to already have good bit distribution and using a hashing
// function to mix-in timestamp, salt, and i instead of redoing the whole
// hash each time would be good to test and benchmark.
scratch := ktbf.scratch
binary.BigEndian.PutUint64(scratch[4:], keyA)
binary.BigEndian.PutUint64(scratch[12:], keyB)
binary.BigEndian.PutUint64(scratch[20:], childKeyA)
binary.BigEndian.PutUint64(scratch[28:], childKeyB)
binary.BigEndian.PutUint64(scratch[36:], timestamp)
for i := ktbf.kDiv4; i > 0; i-- {
binary.BigEndian.PutUint32(scratch, ktbf.salt|i)
h1, h2 := murmur3.Sum128(scratch)
bit := uint32(h1>>32) % ktbf.m
ktbf.bits[bit/8] |= 1 << (bit % 8)
bit = uint32(h1&0xffffffff) % ktbf.m
ktbf.bits[bit/8] |= 1 << (bit % 8)
bit = uint32(h2>>32) % ktbf.m
ktbf.bits[bit/8] |= 1 << (bit % 8)
bit = uint32(h2&0xffffffff) % ktbf.m
ktbf.bits[bit/8] |= 1 << (bit % 8)
}
}
示例11: ReadGroup
func (o *StoreComms) ReadGroup(ctx context.Context, key []byte) ([]store.ReadGroupItem, error) {
keyA, keyB := murmur3.Sum128(key)
items, err := o.gstore.ReadGroup(ctx, keyA, keyB)
if err != nil {
return nil, err
}
return items, nil
}
示例12: DeleteValueTS
func (o *StoreComms) DeleteValueTS(ctx context.Context, id []byte, tsm int64) error {
keyA, keyB := murmur3.Sum128(id)
oldTimestampMicro, err := o.vstore.Delete(ctx, keyA, keyB, tsm)
if oldTimestampMicro >= tsm {
return ErrStoreHasNewerValue
}
return err
}
示例13: HashBytes
// HashBytes will return the hash for the provided byte slice.
func HashBytes(b []byte) []byte {
h1, h2 := murmur3.Sum128(b)
return []byte{
byte(h1 >> 56), byte(h1 >> 48), byte(h1 >> 40), byte(h1 >> 32),
byte(h1 >> 24), byte(h1 >> 16), byte(h1 >> 8), byte(h1),
byte(h2 >> 56), byte(h2 >> 48), byte(h2 >> 40), byte(h2 >> 32),
byte(h2 >> 24), byte(h2 >> 16), byte(h2 >> 8), byte(h2),
}
}
示例14: validateToken
// validateToken ...
func (s *FileSystemAPIServer) validateToken(t string) (string, error) {
var tData TokenRef
var aData AcctPayLoad
var tDataByte []byte
var aDataByte []byte
var err error
// Read Token
pKeyA, pKeyB := murmur3.Sum128([]byte("/token"))
cKeyA, cKeyB := murmur3.Sum128([]byte(t))
_, tDataByte, err = s.gstore.Read(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, nil)
if store.IsNotFound(err) {
return "", errors.New("Not Found")
}
err = json.Unmarshal(tDataByte, &tData)
if err != nil {
log.Printf("TOKEN FAILED %v\n", err)
return "", err
}
// Read Account
pKeyA, pKeyB = murmur3.Sum128([]byte("/acct"))
cKeyA, cKeyB = murmur3.Sum128([]byte(tData.AcctID))
_, aDataByte, err = s.gstore.Read(context.Background(), pKeyA, pKeyB, cKeyA, cKeyB, nil)
if store.IsNotFound(err) {
return "", errors.New("Not Found")
}
err = json.Unmarshal(aDataByte, &aData)
if err != nil {
log.Printf("TOKEN FAILED %v\n", err)
return "", err
}
if tData.TokenID != aData.Token {
// Log Failed Operation
log.Printf("TOKEN FAIL %s\n", t)
return "", errors.New("Invalid Token")
}
// Return Account UUID
// Log Operation
log.Printf("TOKEN SUCCESS %s\n", tData.AcctID)
return tData.AcctID, nil
}
示例15: VSTests
func VSTests() {
vsconfigs := make([]ValueClientConfig, *clients)
var wg sync.WaitGroup
for w := 0; w < *clients; w++ {
vsconfigs[w].addr = *vsServer
vsconfigs[w].id = w
vsconfigs[w].count = perClient
vsconfigs[w].value = &value
vsconfigs[w].wg = &wg
vsconfigs[w].wm = make([]*vp.WriteRequest, perClient)
vsconfigs[w].rm = make([]*vp.ReadRequest, perClient)
for k := 0; k < perClient; k++ {
vsconfigs[w].wm[k] = &vp.WriteRequest{}
vsconfigs[w].rm[k] = &vp.ReadRequest{}
vsconfigs[w].wm[k].KeyA, vsconfigs[w].wm[k].KeyB = murmur3.Sum128([]byte(fmt.Sprintf("somethingtestkey%d-%d", vsconfigs[w].id, k)))
vsconfigs[w].wm[k].TimestampMicro = brimtime.TimeToUnixMicro(time.Now())
vsconfigs[w].rm[k].KeyA = vsconfigs[w].wm[k].KeyA
vsconfigs[w].rm[k].KeyB = vsconfigs[w].wm[k].KeyB
}
}
log.Println("ValueStore Key/hash generation complete. Spawning tests.")
// ValueStore Tests
if *vsWriteTest {
t := time.Now()
for w := 0; w < *clients; w++ {
wg.Add(1)
if *streamTest {
go ValueStreamWrite(&vsconfigs[w])
} else {
go ValueWrite(&vsconfigs[w])
}
}
wg.Wait()
log.Println("Issued", *clients*perClient, "VS WRITES")
ts := time.Since(t).Seconds()
log.Println("Total run time was:", ts, "seconds")
log.Printf("Per second: %.2f\n", float64(*clients*perClient)/ts)
}
if *vsReadTest {
t := time.Now()
for w := 0; w < *clients; w++ {
wg.Add(1)
if *streamTest {
go ValueStreamRead(&vsconfigs[w])
} else {
go ValueRead(&vsconfigs[w])
}
}
wg.Wait()
log.Println("Issued", *clients*perClient, "VS READS")
ts := time.Since(t).Seconds()
log.Println("Total run time was:", ts, "seconds")
log.Printf("Per second: %.2f\n", float64(*clients*perClient)/ts)
}
}