No Blacklisted + Hoping and diffused research

This commit is contained in:
mr
2026-02-02 12:14:01 +01:00
parent c3352499fa
commit 0ffe98045e
6 changed files with 57 additions and 18 deletions

View File

@@ -26,6 +26,8 @@ type PeerRecord struct {
WalletAddress string `json:"wallet_address"`
Signature []byte `json:"signature"`
ExpiryDate time.Time `json:"expiry_date"`
TTL int `json:"ttl"` // max of hop diffusion
}
func (p *PeerRecord) Sign() error {
@@ -155,6 +157,19 @@ func (ix *IndexerService) handleNodePublish(s network.Stream) {
LastSeen: time.Now(),
}
}
if rec.TTL > 0 {
for _, ad := range common.StaticIndexers {
if common.StreamIndexers[common.ProtocolPublish][ad.ID] == nil {
continue
}
stream := common.StreamIndexers[common.ProtocolPublish][ad.ID]
rec.TTL -= 1
if err := json.NewEncoder(stream.Stream).Encode(&rec); err != nil { // then publish on stream
continue
}
}
}
}
func (ix *IndexerService) handleNodeGet(s network.Stream) {
@@ -184,6 +199,33 @@ func (ix *IndexerService) handleNodeGet(s network.Stream) {
return
}
}
// if not found ask to my neighboor indexers
if common.StreamIndexers[common.ProtocolPublish] == nil {
_ = json.NewEncoder(s).Encode(GetResponse{Found: false})
return
}
for _, ad := range common.StaticIndexers {
if common.StreamIndexers[common.ProtocolPublish][ad.ID] == nil {
continue
}
stream := common.StreamIndexers[common.ProtocolPublish][ad.ID]
if err := json.NewEncoder(stream.Stream).Encode(GetValue{Key: req.Key}); err != nil {
continue
}
var resp GetResponse
if err := json.NewDecoder(stream.Stream).Decode(&resp); err != nil {
continue
}
if resp.Found {
_ = json.NewEncoder(s).Encode(GetResponse{
Found: true,
Record: resp.Record,
})
return
}
}
// Not found
_ = json.NewEncoder(s).Encode(GetResponse{Found: false})
}