diff --git a/infrastructure/nats.go b/infrastructure/nats.go index d1d3de4..b663eb8 100644 --- a/infrastructure/nats.go +++ b/infrastructure/nats.go @@ -55,10 +55,6 @@ func ListenNATS() { if resp.FromApp == config.GetAppName() || resp.Datatype != tools.PEER { return } - m := map[string]interface{}{ - "verify": true, - "relation": peer.PENDING_PARTNER, - } p := &peer.Peer{} if err := json.Unmarshal(resp.Payload, &p); err == nil { /*if err := verify(resp.Payload); err != nil { @@ -68,22 +64,25 @@ func ListenNATS() { access := oclib.NewRequestAdmin(oclib.LibDataEnum(resp.Datatype), nil) if data := access.LoadOne(p.GetID()); data.Data != nil { - if !data.ToPeer().Verify && data.ToPeer().Relation == peer.PENDING_PARTNER { - access.UpdateOne(map[string]interface{}{ - "verify": false, - "relation": peer.PARTNER, - }, p.GetID()) - } else if data.ToPeer().Relation != peer.BLACKLIST && data.ToPeer().Relation != peer.SELF { - if p.Relation == peer.NONE { + if p.Relation == peer.PENDING_PARTNER { + if data.ToPeer().Verify { access.UpdateOne(map[string]interface{}{ - "relation": peer.NONE, + "verify": false, + "relation": peer.PARTNER, }, p.GetID()) } else { - access.UpdateOne(m, p.GetID()) + access.UpdateOne(map[string]interface{}{ + "verify": true, + "relation": peer.PENDING_PARTNER, + }, p.GetID()) } + } else if data.ToPeer().Relation != peer.BLACKLIST && data.ToPeer().Relation != peer.SELF { + access.UpdateOne(map[string]interface{}{ + "relation": p.Relation, + }, p.GetID()) } - } else if err := json.Unmarshal(resp.Payload, &m); err == nil { - access.StoreOne(m) + } else if p.Relation != peer.SELF { + access.StoreOne(p.Serialize(p)) } }