Discovery Nano the light version.

This commit is contained in:
mr
2026-04-29 07:41:00 +02:00
parent fa341494d9
commit 7f951afd41
34 changed files with 2961 additions and 1501 deletions

View File

@@ -92,10 +92,6 @@ type SearchQuery struct {
// SearchPeerResult is sent by a responding indexer to the emitting indexer
// via ProtocolSearchPeerResponse, and forwarded by the emitting indexer to
// the node on the open ProtocolSearchPeer stream.
type SearchPeerResult struct {
QueryID string `json:"query_id"`
Records []SearchHit `json:"records"`
}
// SearchHit is a single peer found during distributed search.
type SearchHit struct {

View File

@@ -203,6 +203,9 @@ func waitResults[T interface{}](topic *pubsub.Topic, s *LongLivedPubSubService,
if errors.Is(err, context.DeadlineExceeded) {
// timeout hit, no message before deadline kill subsciption.
s.PubsubMu.Lock()
if s.LongLivedPubSubs[proto] != nil {
s.LongLivedPubSubs[proto].Close()
}
delete(s.LongLivedPubSubs, proto)
s.PubsubMu.Unlock()
return
@@ -214,6 +217,5 @@ func waitResults[T interface{}](topic *pubsub.Topic, s *LongLivedPubSubService,
continue
}
f(ctx, evt, fmt.Sprintf("%v", proto))
fmt.Println("DEADLOCK ?")
}
}

View File

@@ -101,6 +101,10 @@ func (ix *LongLivedStreamRecordedService[T]) gc() {
evicted = append(evicted, gcEntry{pid, name, did})
for _, sstreams := range ix.StreamRecords {
if sstreams[pid] != nil {
if sstreams[pid].HeartbeatStream != nil && sstreams[pid].HeartbeatStream.Stream != nil {
sstreams[pid].HeartbeatStream.Stream.Close()
}
delete(sstreams, pid)
}
}

View File

@@ -184,12 +184,15 @@ func TempStream(h host.Host, ad pp.AddrInfo, proto protocol.ID, did string, stre
}
ctxTTL, cancelTTL := context.WithTimeout(context.Background(), expiry)
defer cancelTTL()
if h.Network().Connectedness(ad.ID) != network.Connected {
if err := h.Connect(ctxTTL, ad); err != nil {
fmt.Println("Connectedness", ad.ID, err)
return streams, err
}
}
fmt.Println("PROTO", streams[proto])
if streams[proto] != nil && streams[proto][ad.ID] != nil {
return streams, nil
} else if s, err := h.NewStream(ctxTTL, ad.ID, proto); err == nil {
@@ -200,6 +203,9 @@ func TempStream(h host.Host, ad pp.AddrInfo, proto protocol.ID, did string, stre
mu.Unlock()
time.AfterFunc(expiry, func() {
mu.Lock()
if streams[proto] != nil && streams[proto][ad.ID] != nil && streams[proto][ad.ID].Stream != nil {
streams[proto][ad.ID].Stream.Close()
}
delete(streams[proto], ad.ID)
mu.Unlock()
})
@@ -212,6 +218,7 @@ func TempStream(h host.Host, ad pp.AddrInfo, proto protocol.ID, did string, stre
mu.Unlock()
return streams, nil
} else {
fmt.Println("ERRER", err)
return streams, err
}
}