本文整理汇总了Golang中hash/fnv.New32a函数的典型用法代码示例。如果您正苦于以下问题:Golang New32a函数的具体用法?Golang New32a怎么用?Golang New32a使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New32a函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewEventFactory
func NewEventFactory(processName, threadName string) *EventFactory {
processHash := fnv.New32a()
processHash.Write([]byte(processName))
threadHash := fnv.New32a()
threadHash.Write([]byte(threadName))
return &EventFactory{
processName: processName,
threadName: threadName,
pid: int(processHash.Sum32()),
tid: int(threadHash.Sum32()),
}
}
开发者ID:lhchavez,项目名称:quark,代码行数:12,代码来源:tracing.go
示例2: handler
func handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
params := strings.SplitN(strings.Trim(r.URL.Path, "/"), "/", 2)
// / -> redirect
if len(params[0]) == 0 {
http.Redirect(w, r, "https://github.com/igrigorik/ga-beacon", http.StatusFound)
return
}
// /account -> account template
// /account/page -> GIF + log pageview to GA collector
if len(params) == 1 {
account := map[string]interface{}{"Account": params[0]}
if err := pageTemplate.ExecuteTemplate(w, "page", account); err != nil {
panic("Cannot execute template")
}
} else {
hash := fnv.New32a()
hash.Write([]byte(strings.Split(r.RemoteAddr, ":")[0]))
hash.Write([]byte(r.Header.Get("User-Agent")))
cid := fmt.Sprintf("%d", hash.Sum32())
w.Header().Set("Content-Type", "image/gif")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("CID", cid)
payload := url.Values{
"v": {"1"}, // protocol version = 1
"t": {"pageview"}, // hit type
"tid": {params[0]}, // tracking / property ID
"cid": {cid}, // unique client ID (IP + UA hash)
"dp": {params[1]}, // page path
}
req, _ := http.NewRequest("POST", beaconURL,
strings.NewReader(payload.Encode()))
req.Header.Add("User-Agent", r.Header.Get("User-Agent"))
client := urlfetch.Client(c)
resp, err := client.Do(req)
if err != nil {
c.Errorf("GA collector POST error: %s", err.Error())
}
c.Infof("GA collector status: %v, cid: %v", resp.Status, cid)
// write out GIF pixel
query, _ := url.ParseQuery(r.URL.RawQuery)
_, ok_pixel := query["pixel"]
if ok_pixel {
io.WriteString(w, string(pixel))
} else {
io.WriteString(w, string(badge))
}
}
return
}
开发者ID:BlastarIndia,项目名称:ga-beacon,代码行数:60,代码来源:ga-beacon.go
示例3: ReadVMessUDP
func ReadVMessUDP(buffer []byte, userset user.UserSet) (*VMessUDP, error) {
userHash := buffer[:user.IDBytesLen]
userId, timeSec, valid := userset.GetUser(userHash)
if !valid {
return nil, errors.NewAuthenticationError(userHash)
}
buffer = buffer[user.IDBytesLen:]
aesCipher, err := aes.NewCipher(userId.CmdKey())
if err != nil {
return nil, err
}
aesStream := cipher.NewCFBDecrypter(aesCipher, user.Int64Hash(timeSec))
aesStream.XORKeyStream(buffer, buffer)
fnvHash := binary.BigEndian.Uint32(buffer[:4])
fnv1a := fnv.New32a()
fnv1a.Write(buffer[4:])
fnvHashActual := fnv1a.Sum32()
if fnvHash != fnvHashActual {
log.Warning("Unexpected fhv hash %d, should be %d", fnvHashActual, fnvHash)
return nil, errors.NewCorruptedPacketError()
}
buffer = buffer[4:]
vmess := &VMessUDP{
user: *userId,
version: buffer[0],
token: binary.BigEndian.Uint16(buffer[1:3]),
}
// buffer[3] is reserved
port := binary.BigEndian.Uint16(buffer[4:6])
addrType := buffer[6]
var address v2net.Address
switch addrType {
case addrTypeIPv4:
address = v2net.IPAddress(buffer[7:11], port)
buffer = buffer[11:]
case addrTypeIPv6:
address = v2net.IPAddress(buffer[7:23], port)
buffer = buffer[23:]
case addrTypeDomain:
domainLength := buffer[7]
domain := string(buffer[8 : 8+domainLength])
address = v2net.DomainAddress(domain, port)
buffer = buffer[8+domainLength:]
default:
log.Warning("Unexpected address type %d", addrType)
return nil, errors.NewCorruptedPacketError()
}
vmess.address = address
vmess.data = buffer
return vmess, nil
}
开发者ID:s752550916,项目名称:v2ray-core,代码行数:60,代码来源:udp.go
示例4: hashn
func hashn(s string) (h1, h2 uint32) {
// This construction comes from
// http://www.eecs.harvard.edu/~michaelm/postscripts/tr-02-05.pdf
// "Building a Better Bloom Filter", by Kirsch and Mitzenmacher. Their
// proof that this is allowed for count-min requires the h functions to
// be from the 2-universal hash family, w be a prime and d be larger
// than the traditional CM-sketch requirements.
// Empirically, though, this seems to work "just fine".
// TODO(dgryski): Switch to something that is actually validated by the literature.
fnv1a := fnv.New32a()
fnv1a.Write([]byte(s))
h1 = fnv1a.Sum32()
// inlined jenkins one-at-a-time hash
h2 = uint32(0)
for _, c := range s {
h2 += uint32(c)
h2 += h2 << 10
h2 ^= h2 >> 6
}
h2 += (h2 << 3)
h2 ^= (h2 >> 11)
h2 += (h2 << 15)
return h1, h2
}
开发者ID:hsavit1,项目名称:go-probably,代码行数:30,代码来源:count.go
示例5: NewNode
func NewNode(hn coconet.Host, suite abstract.Suite, random cipher.Stream) *Node {
sn := &Node{Host: hn, suite: suite}
msgSuite = suite
sn.PrivKey = suite.Secret().Pick(random)
sn.PubKey = suite.Point().Mul(nil, sn.PrivKey)
sn.peerKeys = make(map[string]abstract.Point)
sn.Rounds = make(map[int]*Round)
sn.closed = make(chan error, 20)
sn.done = make(chan int, 10)
sn.commitsDone = make(chan int, 10)
sn.viewChangeCh = make(chan string, 0)
sn.FailureRate = 0
h := fnv.New32a()
h.Write([]byte(hn.Name()))
seed := h.Sum32()
sn.Rand = rand.New(rand.NewSource(int64(seed)))
sn.Host.SetSuite(suite)
sn.VoteLog = NewVoteLog()
sn.Actions = make(map[int][]*Vote)
sn.RoundsPerView = 100
return sn
}
开发者ID:ineiti,项目名称:prifi,代码行数:25,代码来源:signingNode.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng