|
| 1 | +/* |
| 2 | +Copyright IBM Corp. 2016 All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package api |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/hyperledger/fabric/gossip/discovery" |
| 21 | + "google.golang.org/grpc" |
| 22 | +) |
| 23 | + |
| 24 | +type GossipEmitterFactory interface { |
| 25 | + NewGossipEmitter(id string, discSvc discovery.DiscoveryService) GossipService |
| 26 | +} |
| 27 | + |
| 28 | +// GossipService is used to publish new blocks to the gossip network |
| 29 | +type GossipService interface { |
| 30 | + // payload: Holds the block's content, hash and seqNum |
| 31 | + Publish(payload Payload) error |
| 32 | +} |
| 33 | + |
| 34 | +type BindAddress struct { |
| 35 | + Host string |
| 36 | + Port int16 |
| 37 | +} |
| 38 | + |
| 39 | +// Payload defines an object that contains a ledger block |
| 40 | +type Payload struct { |
| 41 | + Data []byte // The content of the message, possibly encrypted or signed |
| 42 | + Hash string // The message hash |
| 43 | + SeqNum uint64 // The message sequence number |
| 44 | +} |
| 45 | + |
| 46 | +type GossipMemberFactory interface { |
| 47 | + NewGossipMember(discovery.DiscoveryService, ReplicationProvider, MessageCryptoService, MessagePolicyVerifier, *grpc.Server) GossipMember |
| 48 | + |
| 49 | + NewGossipMemberWithRPCServer(discovery.DiscoveryService, ReplicationProvider, MessageCryptoService, MessagePolicyVerifier, BindAddress) (GossipMember, error) |
| 50 | +} |
| 51 | + |
| 52 | +// GossipMember is used to obtain new blocks from the gossip network |
| 53 | +type GossipMember interface { |
| 54 | + // RegisterCallback registers a callback that is invoked on messages |
| 55 | + // from startSeq to endSeq and invokes the callback when they arrive |
| 56 | + RegisterCallback(startSeq uint64, endSeq uint64, callback func([]Payload)) |
| 57 | +} |
| 58 | + |
| 59 | +// ReplicationProvider used by the GossipMember in order to obtain Blocks of |
| 60 | +// certain seqNum range to be sent to the requester |
| 61 | +type ReplicationProvider interface { |
| 62 | + // GetData used by the gossip component to obtain certain blocks from the ledger. |
| 63 | + // Returns the blocks requested with the given sequence numbers, or an error if |
| 64 | + // some block requested is not available. |
| 65 | + GetData(startSeqNum uint64, endSeqNum uint64) ([]Payload, error) |
| 66 | + |
| 67 | + // LastBlockSeq used by the gossip component to obtain the last sequence of a block the ledger has. |
| 68 | + LastBlockSeq() uint64 |
| 69 | +} |
| 70 | + |
| 71 | +// MessageCryptoVerifier verifies the message's authenticity, |
| 72 | +// if messages are cryptographically signed |
| 73 | +type MessageCryptoService interface { |
| 74 | + // Verify returns nil whether the message and its identifier are authentic, |
| 75 | + // otherwise returns an error |
| 76 | + Verify(seqNum uint64, sender string, payload Payload) error |
| 77 | + |
| 78 | + // Sign signs the payload |
| 79 | + Sign(sender string, Payload Payload) Payload |
| 80 | + |
| 81 | + // SignBlob signs a blob |
| 82 | + SignBlob([]byte) []byte |
| 83 | + |
| 84 | + // VerifyBlob verifies a blob, returns error on failure |
| 85 | + // and nil if the blob is correctly signed |
| 86 | + VerifyBlob(sender string, blob []byte) error |
| 87 | +} |
| 88 | + |
| 89 | +// MessagePolicyVerifier verifies whether the message conforms to all required policies, |
| 90 | +// and can be safely delivered to the user. |
| 91 | +type MessagePolicyVerifier interface { |
| 92 | + Verify(seqNum uint64, sender string, payload Payload) error |
| 93 | +} |
0 commit comments