mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-12 11:39:58 +02: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 (
|
const (
|
||||||
protocolVersion byte = 0x61 // version 1
|
protocolVersion byte = 0x61 // version 1
|
||||||
maxTimestamp = nostr.Timestamp(math.MaxInt64)
|
maxTimestamp = nostr.Timestamp(math.MaxInt64)
|
||||||
|
buckets = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
var infiniteBound = Bound{Item: Item{Timestamp: maxTimestamp}}
|
var infiniteBound = Bound{Item: Item{Timestamp: maxTimestamp}}
|
||||||
@ -39,6 +40,8 @@ func NewNegentropy(storage Storage, frameSizeLimit int) *Negentropy {
|
|||||||
return &Negentropy{
|
return &Negentropy{
|
||||||
storage: storage,
|
storage: storage,
|
||||||
frameSizeLimit: frameSizeLimit,
|
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.seal()
|
||||||
n.isClient = true
|
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 := NewStringHexWriter(make([]byte, 0, 1+n.storage.Size()*64))
|
||||||
output.WriteByte(protocolVersion)
|
output.WriteByte(protocolVersion)
|
||||||
n.SplitRange(0, n.storage.Size(), infiniteBound, output)
|
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) {
|
func (n *Negentropy) SplitRange(lower, upper int, upperBound Bound, output *StringHexWriter) {
|
||||||
numElems := upper - lower
|
numElems := upper - lower
|
||||||
const buckets = 16
|
|
||||||
|
|
||||||
if numElems < buckets*2 {
|
if numElems < buckets*2 {
|
||||||
// we just send the full ids here
|
// we just send the full ids here
|
||||||
|
Loading…
x
Reference in New Issue
Block a user