show results over RPC

This commit is contained in:
Victor Shyba 2021-10-03 04:51:03 -03:00
parent 8fd87dfc31
commit d11230aaf8

View file

@ -102,6 +102,7 @@ type RpcIterativeFindValueArgs struct {
type RpcIterativeFindValueResult struct { type RpcIterativeFindValueResult struct {
Contacts []Contact Contacts []Contact
FoundValue bool FoundValue bool
Values []Contact
} }
func (rpc *rpcReceiver) IterativeFindValue(r *http.Request, args *RpcIterativeFindValueArgs, result *RpcIterativeFindValueResult) error { func (rpc *rpcReceiver) IterativeFindValue(r *http.Request, args *RpcIterativeFindValueArgs, result *RpcIterativeFindValueResult) error {
@ -109,12 +110,19 @@ func (rpc *rpcReceiver) IterativeFindValue(r *http.Request, args *RpcIterativeFi
if err != nil { if err != nil {
return err return err
} }
foundContacts, found, err := FindContacts(rpc.dht.node, key, false, nil) foundContacts, found, err := FindContacts(rpc.dht.node, key, true, nil)
if err != nil { if err != nil {
return err return err
} }
result.Contacts = foundContacts result.Contacts = foundContacts
result.FoundValue = found result.FoundValue = found
if found {
for _, contact := range foundContacts {
if contact.PeerPort > 0 {
result.Values = append(result.Values, contact)
}
}
}
return nil return nil
} }