github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/pkg/fftypes/node.go (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package fftypes 18 19 import ( 20 "context" 21 22 "github.com/kaleido-io/firefly/internal/i18n" 23 ) 24 25 // Node is a FireFly node within the network 26 type Node struct { 27 ID *UUID `json:"id"` 28 Message *UUID `json:"message,omitempty"` 29 Owner string `json:"owner,omitempty"` 30 Name string `json:"name,omitempty"` 31 Description string `json:"description,omitempty"` 32 DX DXInfo `json:"dx"` 33 Created *FFTime `json:"created,omitempty"` 34 } 35 36 // DXInfo is the data exchange information 37 type DXInfo struct { 38 Peer string `json:"peer,omitempty"` 39 Endpoint JSONObject `json:"endpoint,omitempty"` 40 } 41 42 func (n *Node) Validate(ctx context.Context, existing bool) (err error) { 43 if err = ValidateFFNameField(ctx, n.Name, "name"); err != nil { 44 return err 45 } 46 if err = ValidateLength(ctx, n.Description, "description", 4096); err != nil { 47 return err 48 } 49 if n.Owner == "" { 50 return i18n.NewError(ctx, i18n.MsgOwnerMissing) 51 } 52 if existing { 53 if n.ID == nil { 54 return i18n.NewError(ctx, i18n.MsgNilID) 55 } 56 } 57 return nil 58 } 59 60 func (n *Node) Topic() string { 61 return orgTopic(n.Owner) 62 } 63 64 func (n *Node) SetBroadcastMessage(msgID *UUID) { 65 n.Message = msgID 66 }