From 62e45afe5469466b532f0d0b75f9d57a260c8f0d Mon Sep 17 00:00:00 2001 From: YACOVM Date: Mon, 7 Nov 2016 19:32:02 +0200 Subject: [PATCH] FAB-1018 Gossip multi-channel support API design https://jira.hyperledger.org/browse/FAB-1018 This commit contains code that should be implemented by layers that use the gossip component. This code enables the gossip component to determine to which peers it may forward a certain block according to the channel Change-Id: I01d274ef91837b5d5b4e8bc0d78a49df90957185 Signed-off-by: Yacov Manevich --- gossip/api/api.go | 10 ++----- gossip/api/channel.go | 62 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 gossip/api/channel.go diff --git a/gossip/api/api.go b/gossip/api/api.go index 226f3c61442..477289ed01b 100644 --- a/gossip/api/api.go +++ b/gossip/api/api.go @@ -16,18 +16,12 @@ limitations under the License. package api - // GossipService is used to publish new blocks to the gossip network type GossipService interface { // payload: Holds the block's content, hash and seqNum Publish(payload Payload) error } -type BindAddress struct { - Host string - Port int16 -} - // Payload defines an object that contains a ledger block type Payload struct { Data []byte // The content of the message, possibly encrypted or signed @@ -54,12 +48,12 @@ type ReplicationProvider interface { LastBlockSeq() uint64 } -// MessageCryptoVerifier verifies the message's authenticity, +// MessageCryptoService verifies the message's authenticity, // if messages are cryptographically signed type MessageCryptoService interface { // Verify returns nil whether the message and its identifier are authentic, // otherwise returns an error - VerifyBlock(seqNum uint64, pkiId []byte, payload Payload) error + VerifyBlock(seqNum uint64, pkiID []byte, payload Payload) error // Sign signs msg with this peer's signing key and outputs // the signature if no error occurred. diff --git a/gossip/api/channel.go b/gossip/api/channel.go new file mode 100644 index 00000000000..e19ee78127e --- /dev/null +++ b/gossip/api/channel.go @@ -0,0 +1,62 @@ +/* +Copyright IBM Corp. 2016 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import "time" + +// SecurityAdvisor defines an external auxiliary object +// that provides security and identity related capabilities +type SecurityAdvisor interface { + // IsInMyOrg returns whether the given peer's certificate represents + // a peer in the invoker's organization + IsInMyOrg(PeerCert) bool + + // Verify verifies a JoinChannelMessage, returns nil on success, + // and an error on failure + Verify(JoinChannelMessage) error +} + +// ChannelNotifier is implemented by the gossip component and is used for the peer +// layer to notify the gossip component of a JoinChannel event +type ChannelNotifier interface { + JoinChannel(joinMsg JoinChannelMessage, chainID ChainID) +} + +// JoinChannelMessage is the message that asserts a creation or mutation +// of a channel's membership list, and is the message that is gossipped +// among the peers +type JoinChannelMessage interface { + + // GetTimestamp returns the timestamp of the message's creation + GetTimestamp() time.Time + + // PeerList returns all the peers that are in the channel + PeerList() []RemotePeer +} + +// ChainID defines the identity representation of a chain +type ChainID []byte + +// RemotePeer is a peer's certificate and endpoint (host:port) +type RemotePeer struct { + cert PeerCert + host string + port int +} + +// PeerCert defines the cryptographic identity of a peer +type PeerCert []byte