Skip to content
Snippets Groups Projects
Select Git revision
  • 2bdcc4ab910a2327749c28a837f3c78f72891299
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

search.go

Blame
  • search.go 4.46 KiB
    package ud
    
    import (
    	"fmt"
    	"github.com/golang/protobuf/proto"
    	"github.com/pkg/errors"
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/crypto/contact"
    	"gitlab.com/elixxir/crypto/factID"
    	"gitlab.com/elixxir/primitives/fact"
    	"gitlab.com/xx_network/primitives/id"
    	"time"
    )
    
    // SearchTag specifies which callback to trigger when UD receives a search
    // request.
    const SearchTag = "xxNetwork_UdSearch"
    
    // TODO: reconsider where this comes from
    const maxSearchMessages = 20
    
    type searchCallback func([]contact.Contact, error)
    
    // Search searches for the passed Facts. The searchCallback will return a list
    // of contacts, each having the facts it hit against. This is NOT intended to be
    // used to search for multiple users at once; that can have a privacy reduction.
    // Instead, it is intended to be used to search for a user where multiple pieces
    // of information is known.
    func (m *Manager) Search(list fact.FactList, callback searchCallback, timeout time.Duration) error {
    	jww.INFO.Printf("ud.Search(%s, %s)", list.Stringify(), timeout)
    
    	factHashes, factMap := hashFactList(list)
    
    	// Build the request and marshal it
    	request := &SearchSend{Fact: factHashes}
    	requestMarshaled, err := proto.Marshal(request)
    	if err != nil {
    		return errors.WithMessage(err, "Failed to form outgoing search request.")
    	}
    
    	f := func(payload []byte, err error) {
    		m.searchResponseHandler(factMap, callback, payload, err)
    	}
    
    	// Get UD contact
    	c, err := m.getContact()
    	if err != nil {
    		return err
    	}
    
    	err = m.single.TransmitSingleUse(c, requestMarshaled, SearchTag,
    		maxSearchMessages, f, timeout)
    	if err != nil {
    		return errors.WithMessage(err, "Failed to transmit search request.")
    	}
    
    	if m.client != nil {
    		m.client.ReportEvent(1, "UserDiscovery", "SearchRequest",
    			fmt.Sprintf("Sent: %+v", request))
    	}
    
    	return nil
    }
    
    func (m *Manager) searchResponseHandler(factMap map[string]fact.Fact,
    	callback searchCallback, payload []byte, err error) {
    
    	if err != nil {
    		go callback(nil, errors.WithMessage(err, "Failed to search."))
    		return