From 39a1dce12af7390da22d4402b2d0ff501ad580fc Mon Sep 17 00:00:00 2001 From: YACOVM Date: Mon, 14 Nov 2016 20:19:04 +0200 Subject: [PATCH] FAB-1065 Gossip leader election scaffolding This commit is a scaffolding for a to-be implemented leader election module that is going to be used for peers of a same organization to all agree on a single peer that will connect to the ordering service https://jira.hyperledger.org/browse/FAB-1065 Change-Id: I1dd04aad05a7cd524c2ef1d6dd55daa537eaa68a Signed-off-by: Yacov Manevich --- gossip/election/election.go | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 gossip/election/election.go diff --git a/gossip/election/election.go b/gossip/election/election.go new file mode 100644 index 00000000000..5210a73f443 --- /dev/null +++ b/gossip/election/election.go @@ -0,0 +1,45 @@ +/* +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 election + +import ( + "github.com/hyperledger/fabric/gossip/common" + "github.com/hyperledger/fabric/gossip/proto" +) + +// LeaderElectionAdapter is used by the leader election module +// to send and receive messages, as well as notify a leader change +type LeaderElectionAdapter interface { + + // Gossip gossips a message to other peers + Gossip(msg *proto.GossipMessage) + + // Accept returns a channel that emits messages that fit + // the given predicate + Accept(common.MessageAcceptor) <-chan *proto.GossipMessage +} + +// LeaderElectionService is the object that runs the leader election algorithm +type LeaderElectionService interface { + // IsLeader returns whether this peer is a leader or not + IsLeader() bool +} + +// LeaderElectionService is the implementation of LeaderElectionService +type leaderElectionServiceImpl struct { + adapter LeaderElectionAdapter +}