Skip to content

Commit

Permalink
Merge range-based set reconciliation implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
burdiyan committed Jun 26, 2024
1 parent 12fc75b commit f2682c6
Show file tree
Hide file tree
Showing 10 changed files with 1,429 additions and 3 deletions.
474 changes: 474 additions & 0 deletions backend/genproto/p2p/v1alpha/syncing.pb.go

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions backend/genproto/p2p/v1alpha/syncing_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions backend/syncing/rbsr/fingerprint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package rbsr

import (
"crypto/sha256"
"encoding/binary"
"unsafe"
)

type Fingerprint [fingerprintSize]byte

type accumulator struct {
len int
sum [32]byte
}

func (acc *accumulator) Add(other [32]byte) {
var currCarry, nextCarry uint64

// Treating [32]byte as [4]uint64 when adding.
p := (*[4]uint64)(unsafe.Pointer(&acc.sum[0]))
po := (*[4]uint64)(unsafe.Pointer(&other[0]))

for i := 0; i < 4; i++ {
orig := p[i]
otherV := po[i]

next := orig

next += currCarry
if next < orig {
nextCarry = 1
}

next += otherV
if next < otherV {
nextCarry = 1
}

p[i] = next

currCarry = nextCarry
nextCarry = 0
}
}

func (acc *accumulator) Fingerprint() Fingerprint {
buf := make([]byte, 0, len(acc.sum)+8) // sum + len will be hashed.
buf = append(buf, acc.sum[:]...)
buf = binary.LittleEndian.AppendUint64(buf, uint64(acc.len))

hash := sha256.Sum256(buf)

var fingerprint Fingerprint
copy(fingerprint[:], hash[:fingerprintSize])
return fingerprint
}
Loading

0 comments on commit f2682c6

Please sign in to comment.