github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/pkg/dataexchange/plugin.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 dataexchange 18 19 import ( 20 "context" 21 "io" 22 23 "github.com/kaleido-io/firefly/internal/config" 24 "github.com/kaleido-io/firefly/pkg/fftypes" 25 ) 26 27 // Plugin is the interface implemented by each data exchange plugin 28 type Plugin interface { 29 fftypes.Named 30 31 // InitPrefix initializes the set of configuration options that are valid, with defaults. Called on all plugins. 32 InitPrefix(prefix config.Prefix) 33 34 // Init initializes the plugin, with configuration 35 // Returns the supported featureset of the interface 36 Init(ctx context.Context, prefix config.Prefix, callbacks Callbacks) error 37 38 // Data exchange interface must not deliver any events until start is called 39 Start() error 40 41 // Capabilities returns capabilities - not called until after Init 42 Capabilities() *Capabilities 43 44 // GetEndpointInfo returns the information about the local endpoint 45 GetEndpointInfo(ctx context.Context) (peerID string, endpoint fftypes.JSONObject, err error) 46 47 // AddPeer translates the configuration published by another peer, into a reference string that is used between DX and FireFly to refer to the peer 48 AddPeer(ctx context.Context, node *fftypes.Node) (err error) 49 50 // UploadBLOB streams a blob to storage 51 UploadBLOB(ctx context.Context, ns string, id fftypes.UUID, content io.Reader) (err error) 52 53 // DownloadBLOB streams a blob out of storage 54 DownloadBLOB(ctx context.Context, ns string, id fftypes.UUID) (content io.ReadCloser, err error) 55 56 // SendMessage sends an in-line package of data to another network node. 57 // Should return as quickly as possible for parallelsim, then report completion asynchronously via the operation ID 58 SendMessage(ctx context.Context, node *fftypes.Node, data []byte) (trackingID string, err error) 59 60 // TransferBLOB initiates a transfer of a previoiusly stored blob to another node 61 TransferBLOB(ctx context.Context, node *fftypes.Node, ns string, id fftypes.UUID) (trackingID string, err error) 62 } 63 64 // Callbacks is the interface provided to the data exchange plugin, to allow it to pass events back to firefly. 65 type Callbacks interface { 66 67 // MessageReceived notifies of a message received from another node in the network 68 MessageReceived(peerID string, data []byte) 69 70 // BLOBReceived notifies of the ID of a BLOB that has been stored by DX after being received from another node in the network 71 BLOBReceived(peerID string, ns string, id fftypes.UUID) 72 73 // TransferResult notifies of a status update of a transfer 74 TransferResult(trackingID string, status fftypes.OpStatus, info string, additionalInfo fftypes.JSONObject) 75 } 76 77 // Capabilities the supported featureset of the data exchange 78 // interface implemented by the plugin, with the specified config 79 type Capabilities struct { 80 }