mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
negentropy: create Haves and HaveNots channels so they can be listened to immediately.
This commit is contained in:
parent
b1dd120ec7
commit
3d58ac5ec2
@ -13,6 +13,7 @@ import (
|
||||
const (
|
||||
protocolVersion byte = 0x61 // version 1
|
||||
maxTimestamp = nostr.Timestamp(math.MaxInt64)
|
||||
buckets = 16
|
||||
)
|
||||
|
||||
var infiniteBound = Bound{Item: Item{Timestamp: maxTimestamp}}
|
||||
@ -39,6 +40,8 @@ func NewNegentropy(storage Storage, frameSizeLimit int) *Negentropy {
|
||||
return &Negentropy{
|
||||
storage: storage,
|
||||
frameSizeLimit: frameSizeLimit,
|
||||
Haves: make(chan string, buckets*4),
|
||||
HaveNots: make(chan string, buckets*4),
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,9 +74,6 @@ func (n *Negentropy) Initiate() string {
|
||||
n.seal()
|
||||
n.isClient = true
|
||||
|
||||
n.Haves = make(chan string, n.storage.Size()/2)
|
||||
n.HaveNots = make(chan string, n.storage.Size()/2)
|
||||
|
||||
output := NewStringHexWriter(make([]byte, 0, 1+n.storage.Size()*64))
|
||||
output.WriteByte(protocolVersion)
|
||||
n.SplitRange(0, n.storage.Size(), infiniteBound, output)
|
||||
@ -257,7 +257,6 @@ func (n *Negentropy) reconcileAux(reader *StringHexReader) (string, error) {
|
||||
|
||||
func (n *Negentropy) SplitRange(lower, upper int, upperBound Bound, output *StringHexWriter) {
|
||||
numElems := upper - lower
|
||||
const buckets = 16
|
||||
|
||||
if numElems < buckets*2 {
|
||||
// we just send the full ids here
|
||||
|
Loading…
x
Reference in New Issue
Block a user