feat: add provide support to HashQuery

This commit is contained in:
Derrick Hammer 2024-01-24 03:01:59 -05:00
parent 69bed0a0bf
commit 96be8235f9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 21 additions and 0 deletions

View File

@ -128,6 +128,27 @@ func (h *HashQuery) HandleMessage(node interfaces.Node, peer net.Peer, verifyId
} }
} }
if node.ProviderStore() != nil {
if node.ProviderStore().CanProvide(h.hash, h.kinds) {
location, err := node.ProviderStore().Provide(h.hash, h.kinds)
if err != nil {
return err
}
message := node.Services().P2P().PrepareProvideMessage(h.hash, location)
err = node.AddStorageLocation(h.hash, node.Services().P2P().NodeId(), location, message)
if err != nil {
return err
}
err = peer.SendMessage(message)
if err != nil {
return err
}
}
}
var peers *hashset.Set var peers *hashset.Set
hashString, err := h.hash.ToString() hashString, err := h.hash.ToString()
node.Logger().Debug("HashQuery", zap.Any("hashString", hashString)) node.Logger().Debug("HashQuery", zap.Any("hashString", hashString))