MCPcopy
hub / github.com/tinode/chat / Add

Method Add

server/ringhash/ringhash.go:70–97  ·  view source on GitHub ↗

Add adds keys to the ring.

(keys ...string)

Source from the content-addressed store, hash-verified

68
69// Add adds keys to the ring.
70func (ring *Ring) Add(keys ...string) {
71 for _, key := range keys {
72 for i := range ring.replicas {
73 ring.keys = append(ring.keys, elem{
74 hash: ring.hashfunc([]byte(strconv.Itoa(i) + key)),
75 key: key})
76 }
77 }
78 sort.Sort(sortable(ring.keys))
79
80 // Calculate signature
81 hash := fnv.New128a()
82 b := make([]byte, 4)
83 for _, key := range ring.keys {
84 b[0] = byte(key.hash)
85 b[1] = byte(key.hash >> 8)
86 b[2] = byte(key.hash >> 16)
87 b[3] = byte(key.hash >> 24)
88 hash.Write(b)
89 hash.Write([]byte(key.key))
90 }
91
92 b = []byte{}
93 b = hash.Sum(b)
94 dst := make([]byte, ascii85.MaxEncodedLen(len(b)))
95 ascii85.Encode(dst, b)
96 ring.signature = string(dst)
97}
98
99// Get returns the closest item in the ring to the provided key.
100func (ring *Ring) Get(key string) string {

Callers 15

genDbFunction · 0.45
getCreatedTimeFunction · 0.45
readLoopMethod · 0.45
wsWriteFunction · 0.45
statsUpdaterFunction · 0.45
TestDispatchHelloFunction · 0.45
TestDispatchLoginFunction · 0.45
TestDispatchSubscribeFunction · 0.45

Calls 2

sortableTypeAlias · 0.85
WriteMethod · 0.80

Tested by 15

TestDispatchHelloFunction · 0.36
TestDispatchLoginFunction · 0.36
TestDispatchSubscribeFunction · 0.36
TestDispatchLeaveFunction · 0.36
TestDispatchLeaveUnsubMeFunction · 0.36
TestDispatchPublishFunction · 0.36