Keep Peer Caching + Resource Verification.

This commit is contained in:
mr
2026-02-09 13:28:00 +01:00
parent 1c0b2b4312
commit fa914958b6
14 changed files with 221 additions and 133 deletions

View File

@@ -36,7 +36,7 @@ type PeerRecord struct {
}
func (p *PeerRecord) Sign() error {
priv, err := common.LoadKeyFromFilePrivate()
priv, err := tools.LoadKeyFromFilePrivate()
if err != nil {
return err
}
@@ -53,7 +53,6 @@ func (p *PeerRecord) Sign() error {
}
func (p *PeerRecord) Verify() (crypto.PubKey, error) {
fmt.Println(p.PubKey)
pubKey, err := crypto.UnmarshalPublicKey(p.PubKey) // retrieve pub key in message
if err != nil {
fmt.Println("UnmarshalPublicKey")
@@ -183,18 +182,17 @@ func (ix *IndexerService) handleNodePublish(s network.Stream) {
}
if ix.LongLivedPubSubs[common.TopicPubSubNodeActivity] != nil && !rec.NoPub {
ad, err := peer.AddrInfoFromString("/ip4/" + conf.GetConfig().Hostname + "/tcp/" + fmt.Sprintf("%v", conf.GetConfig().NodeEndpointPort) + "/p2p/" + ix.Host.ID().String())
if err == nil {
if b, err := json.Marshal(common.TopicNodeActivityPub{
Disposer: *ad,
DID: rec.DID,
Name: rec.Name,
PeerID: pid.String(),
NodeActivity: pp.ONLINE,
}); err == nil {
ix.LongLivedPubSubs[common.TopicPubSubNodeActivity].Publish(context.Background(), b)
}
if b, err := json.Marshal(common.TopicNodeActivityPub{
Disposer: "/ip4/" + conf.GetConfig().Hostname + "/tcp/" + fmt.Sprintf("%v", conf.GetConfig().NodeEndpointPort) + "/p2p/" + ix.Host.ID().String(),
DID: rec.DID,
Name: rec.Name,
PeerID: pid.String(),
NodeActivity: pp.ONLINE.EnumIndex(),
}); err == nil {
ix.LongLivedPubSubs[common.TopicPubSubNodeActivity].Publish(context.Background(), b)
}
}
if rec.TTL > 0 {
@@ -257,26 +255,28 @@ func (ix *IndexerService) handleNodeGet(s network.Stream) {
continue
}
if ix.Host.Network().Connectedness(pid) != network.Connected {
_ = ix.Host.Connect(ctxTTL, dsp.Disposer)
str, err := ix.Host.NewStream(ctxTTL, pid, common.ProtocolGet)
if err != nil {
continue
}
for {
if ctxTTL.Err() == context.DeadlineExceeded {
break
}
var subResp GetResponse
if err := json.NewDecoder(str).Decode(&resp); err != nil {
if ad, err := peer.AddrInfoFromString(dsp.Disposer); err == nil {
_ = ix.Host.Connect(ctxTTL, *ad)
str, err := ix.Host.NewStream(ctxTTL, pid, common.ProtocolGet)
if err != nil {
continue
}
if subResp.Found {
for k, v := range subResp.Records {
if _, ok := resp.Records[k]; !ok {
resp.Records[k] = v
}
for {
if ctxTTL.Err() == context.DeadlineExceeded {
break
}
var subResp GetResponse
if err := json.NewDecoder(str).Decode(&resp); err != nil {
continue
}
if subResp.Found {
for k, v := range subResp.Records {
if _, ok := resp.Records[k]; !ok {
resp.Records[k] = v
}
}
break
}
break
}
}
}