Discovery Nano the light version.
This commit is contained in:
@@ -113,6 +113,7 @@ func InitNode(isNode bool, isIndexer bool) (*Node, error) {
|
||||
if ttl <= 0 {
|
||||
ttl = indexer.DefaultTTLSeconds * time.Second
|
||||
}
|
||||
fresh.UpdateDate = time.Now().UTC()
|
||||
fresh.PeerRecordPayload.ExpiryDate = time.Now().UTC().Add(ttl)
|
||||
payload, _ := json.Marshal(fresh.PeerRecordPayload)
|
||||
fresh.Signature, err = priv.Sign(payload)
|
||||
@@ -141,7 +142,7 @@ func InitNode(isNode bool, isIndexer bool) (*Node, error) {
|
||||
And: map[string][]dbs.Filter{
|
||||
"peer_id": {{Operator: dbs.EQUAL.String(), Value: pid.String()}},
|
||||
},
|
||||
}, pid.String(), false)
|
||||
}, pid.String(), false, 0, 1)
|
||||
for _, item := range results.Data {
|
||||
p, ok := item.(*peer.Peer)
|
||||
if !ok || p.PeerID != pid.String() {
|
||||
@@ -228,7 +229,7 @@ func (d *Node) isPeerKnown(pid pp.ID) bool {
|
||||
And: map[string][]dbs.Filter{
|
||||
"peer_id": {{Operator: dbs.EQUAL.String(), Value: pid.String()}},
|
||||
},
|
||||
}, pid.String(), false)
|
||||
}, pid.String(), false, 0, 1)
|
||||
for _, item := range results.Data {
|
||||
p, ok := item.(*peer.Peer)
|
||||
if !ok || p.PeerID != pid.String() {
|
||||
@@ -267,15 +268,8 @@ func (d *Node) publishPeerRecord(
|
||||
if ttl <= 0 {
|
||||
ttl = indexer.DefaultTTLSeconds * time.Second
|
||||
}
|
||||
base := indexer.PeerRecordPayload{
|
||||
Name: rec.Name,
|
||||
DID: rec.DID,
|
||||
PubKey: rec.PubKey,
|
||||
TTLSeconds: rec.TTLSeconds,
|
||||
ExpiryDate: time.Now().UTC().Add(ttl),
|
||||
}
|
||||
payload, _ := json.Marshal(base)
|
||||
rec.PeerRecordPayload = base
|
||||
rec.ExpiryDate = time.Now().UTC().Add(ttl)
|
||||
payload, _ := json.Marshal(rec.PeerRecordPayload)
|
||||
rec.Signature, err = priv.Sign(payload)
|
||||
if err := json.NewEncoder(stream.Stream).Encode(&rec); err != nil { // then publish on stream
|
||||
return err
|
||||
@@ -288,7 +282,7 @@ func (d *Node) publishPeerRecord(
|
||||
// A new call for the same userKey cancels any previous search.
|
||||
// Results are pushed to onResult as they arrive; the function returns when
|
||||
// the stream closes (idle timeout, explicit cancel, or indexer unreachable).
|
||||
func (d *Node) SearchPeerRecord(userKey, needle string, onResult func(common.SearchHit)) {
|
||||
func (d *Node) SearchPeerRecord(userKey, needle string, onResult func(indexer.PeerRecord)) {
|
||||
logger := oclib.GetLogger()
|
||||
|
||||
idleTimeout := common.SearchIdleTimeout()
|
||||
@@ -306,7 +300,7 @@ func (d *Node) SearchPeerRecord(userKey, needle string, onResult func(common.Sea
|
||||
} else {
|
||||
req.Name = needle
|
||||
}
|
||||
|
||||
fmt.Println("PROPALGATE PEER", needle, common.Indexers.GetAddrs())
|
||||
for _, ad := range common.Indexers.GetAddrs() {
|
||||
if ad.Info == nil {
|
||||
continue
|
||||
@@ -330,7 +324,7 @@ func (d *Node) SearchPeerRecord(userKey, needle string, onResult func(common.Sea
|
||||
seen := map[string]struct{}{}
|
||||
dec := json.NewDecoder(s)
|
||||
for {
|
||||
var result common.SearchPeerResult
|
||||
var result indexer.SearchPeerResult
|
||||
if err := dec.Decode(&result); err != nil {
|
||||
break
|
||||
}
|
||||
@@ -416,7 +410,7 @@ func (d *Node) claimInfo(
|
||||
And: map[string][]dbs.Filter{ // search by name if no filters are provided
|
||||
"peer_id": {{Operator: dbs.EQUAL.String(), Value: d.Host.ID().String()}},
|
||||
},
|
||||
}, "", false)
|
||||
}, "", false, 0, 1)
|
||||
if len(peers.Data) > 0 {
|
||||
did = peers.Data[0].GetID() // if already existing set up did as made
|
||||
}
|
||||
@@ -435,9 +429,11 @@ func (d *Node) claimInfo(
|
||||
|
||||
now := time.Now().UTC()
|
||||
pRec := indexer.PeerRecordPayload{
|
||||
Name: name,
|
||||
DID: did, // REAL PEER ID
|
||||
PubKey: pubBytes,
|
||||
Name: name,
|
||||
DID: did, // REAL PEER ID
|
||||
PubKey: pubBytes,
|
||||
|
||||
IsNano: oclib.GetConfig().IsNano,
|
||||
TTLSeconds: indexer.DefaultTTLSeconds,
|
||||
ExpiryDate: now.Add(indexer.DefaultTTLSeconds * time.Second),
|
||||
}
|
||||
@@ -447,6 +443,8 @@ func (d *Node) claimInfo(
|
||||
rec := &indexer.PeerRecord{
|
||||
PeerRecordPayload: pRec,
|
||||
}
|
||||
rec.CreationDate = time.Now().UTC()
|
||||
rec.UpdateDate = time.Now().UTC()
|
||||
rec.Signature, err = priv.Sign(payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user