Discovery Neo Oclib
This commit is contained in:
@@ -61,15 +61,17 @@ func (ps *StreamService) PublishCommon(dt *tools.DataType, user string, groups [
|
||||
}
|
||||
stream, err := ps.write(toPeerID, ad, dt, user, resource, proto)
|
||||
if err != nil {
|
||||
if _, ok := dntProtocols[proto]; ok {
|
||||
ps.dnt.enqueue(&dntEntry{
|
||||
did: toPeerID,
|
||||
addr: *ad,
|
||||
dt: dt,
|
||||
user: user,
|
||||
payload: resource,
|
||||
proto: proto,
|
||||
addedAt: time.Now().UTC(),
|
||||
if _, ok := DTNProtocols[proto]; ok {
|
||||
ps.dnt.enqueue(&DTNEntry{
|
||||
did: toPeerID,
|
||||
resourceID: extractResourceID(resource),
|
||||
forceCritical: pe.Relation == peer.NANO,
|
||||
addr: *ad,
|
||||
dt: dt,
|
||||
user: user,
|
||||
payload: resource,
|
||||
proto: proto,
|
||||
addedAt: time.Now().UTC(),
|
||||
})
|
||||
}
|
||||
return nil, err
|
||||
@@ -125,20 +127,45 @@ func (ps *StreamService) ToPartnerPublishEvent(
|
||||
|
||||
return nil
|
||||
}
|
||||
ks := []protocol.ID{}
|
||||
for k := range protocolsPartners {
|
||||
ks = append(ks, k)
|
||||
// Extract creator_id to route to the correct nano.
|
||||
// A master must only forward a resource to the nano that owns it.
|
||||
var creatorID string
|
||||
var minPayload struct {
|
||||
CreatorID string `json:"creator_id"`
|
||||
}
|
||||
for _, rel := range []peer.PeerRelation{peer.PARTNER, peer.MASTER, peer.NANO} {
|
||||
if json.Unmarshal(payload, &minPayload) == nil {
|
||||
creatorID = minPayload.CreatorID
|
||||
}
|
||||
|
||||
// PARTNER and MASTER receive every resource unconditionally.
|
||||
for _, rel := range []peer.PeerRelation{peer.PARTNER, peer.MASTER} {
|
||||
ps.PublishesCommon(dt, user, groups, &dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"relation": {{Operator: dbs.EQUAL.String(), Value: rel}},
|
||||
},
|
||||
}, payload, proto)
|
||||
}
|
||||
|
||||
// NANO: only send to the nano whose UUID matches the resource creator.
|
||||
if creatorID != "" {
|
||||
ps.PublishesCommon(dt, user, groups, &dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"relation": {{Operator: dbs.EQUAL.String(), Value: peer.NANO}},
|
||||
"id": {{Operator: dbs.EQUAL.String(), Value: creatorID}},
|
||||
},
|
||||
}, payload, proto)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// forwardToNano sends a booking mutation directly to a known NANO peer.
|
||||
// The NANO peer is already resolved by the caller (resolveBookingNano).
|
||||
// DTN critical is applied automatically by PublishCommon (Relation == NANO).
|
||||
func (abs *StreamService) forwardToNano(nano *peer.Peer, evt *common.Event, proto string) {
|
||||
dt := tools.DataType(evt.DataType)
|
||||
abs.PublishCommon(&dt, evt.User, evt.Groups, nano.PeerID, protocol.ID(proto), evt.Payload)
|
||||
}
|
||||
|
||||
func (s *StreamService) write(
|
||||
did string,
|
||||
peerID *pp.AddrInfo,
|
||||
|
||||
Reference in New Issue
Block a user