Discovery Neo Oclib
This commit is contained in:
@@ -79,6 +79,11 @@ type IndexerService struct {
|
||||
// eventQueue holds SWIM membership events to be piggybacked on responses
|
||||
// (infection-style dissemination toward connected nodes).
|
||||
eventQueue *common.MembershipEventQueue
|
||||
// pendingContactIndex is an inverted index built from Heartbeat.PendingContact.
|
||||
// Maps target peer ID → { caller peer ID → expiry time }.
|
||||
// Returned in HeartbeatResponse.PendingCallers when the target reconnects.
|
||||
pendingContactIndex map[string]map[string]time.Time
|
||||
pendingContactIndexMu sync.Mutex
|
||||
}
|
||||
|
||||
// NewIndexerService creates an IndexerService.
|
||||
@@ -95,6 +100,7 @@ func NewIndexerService(h host.Host, ps *pubsub.PubSub, maxNode int) *IndexerServ
|
||||
behavior: newNodeBehaviorTracker(),
|
||||
deletedDIDs: make(map[string]time.Time),
|
||||
eventQueue: &common.MembershipEventQueue{},
|
||||
pendingContactIndex: map[string]map[string]time.Time{},
|
||||
}
|
||||
if ps == nil {
|
||||
ps, err = pubsub.NewGossipSub(context.Background(), ix.Host)
|
||||
@@ -408,6 +414,24 @@ func NewIndexerService(h host.Host, ps *pubsub.PubSub, maxNode int) *IndexerServ
|
||||
resp.Incarnation = ix.incarnation.Load()
|
||||
resp.MembershipEvents = ix.eventQueue.Drain(5)
|
||||
|
||||
// PendingCallers: look up who has undelivered messages for this node.
|
||||
// Clean up expired entries at the same time.
|
||||
ix.pendingContactIndexMu.Lock()
|
||||
if callers, ok := ix.pendingContactIndex[remotePeer.String()]; ok {
|
||||
now := time.Now()
|
||||
for callerID, exp := range callers {
|
||||
if now.Before(exp) {
|
||||
resp.PendingCallers = append(resp.PendingCallers, callerID)
|
||||
} else {
|
||||
delete(callers, callerID)
|
||||
}
|
||||
}
|
||||
if len(callers) == 0 {
|
||||
delete(ix.pendingContactIndex, remotePeer.String())
|
||||
}
|
||||
}
|
||||
ix.pendingContactIndexMu.Unlock()
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user