|
| 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 peer |
| 18 | + |
| 19 | +import ( |
| 20 | + "sync" |
| 21 | + |
| 22 | + pb "github.com/hyperledger/fabric/protos" |
| 23 | +) |
| 24 | + |
| 25 | +// EngineImpl implements a struct to manage Peer default engine functionality |
| 26 | +type EngineImpl struct { |
| 27 | + //consenter consensus.Consenter |
| 28 | + peerEndpoint *pb.PeerEndpoint |
| 29 | +} |
| 30 | + |
| 31 | +// GetHandlerFactory returns new NewConsensusHandler |
| 32 | +func (eng *EngineImpl) GetHandlerFactory() HandlerFactory { |
| 33 | + return eng.GetNewPeerHandler |
| 34 | +} |
| 35 | + |
| 36 | +//GetNewPeerHandler handlerFactory function for simple peer discovery |
| 37 | +func (eng *EngineImpl) GetNewPeerHandler(coord MessageHandlerCoordinator, chatStream ChatStream, initiatedStream bool, next MessageHandler) (MessageHandler, error) { |
| 38 | + return NewPeerHandler(coord, chatStream, initiatedStream, next) |
| 39 | +} |
| 40 | + |
| 41 | +// ProcessTransactionMsg processes a Message in context of a Transaction |
| 42 | +func (eng *EngineImpl) ProcessTransactionMsg(msg *pb.Message, tx *pb.Transaction) (response *pb.Response) { |
| 43 | + return nil |
| 44 | +} |
| 45 | + |
| 46 | +var engineOnce sync.Once |
| 47 | + |
| 48 | +var engine *EngineImpl |
| 49 | + |
| 50 | +func getEngineImpl() *EngineImpl { |
| 51 | + return engine |
| 52 | +} |
| 53 | + |
| 54 | +// GetEngine returns initialized Engine |
| 55 | +func GetEngine(coord MessageHandlerCoordinator) (Engine, error) { |
| 56 | + var err error |
| 57 | + engineOnce.Do(func() { |
| 58 | + engine = new(EngineImpl) |
| 59 | + engine.peerEndpoint, err = coord.GetPeerEndpoint() |
| 60 | + |
| 61 | + //go func() { |
| 62 | + // peerLogger.Debug("Starting up message thread for consenter") |
| 63 | + // |
| 64 | + // // The channel never closes, so this should never break |
| 65 | + // for msg := range engine.consensusFan.GetOutChannel() { |
| 66 | + // engine.consenter.RecvMsg(msg.Msg, msg.Sender) |
| 67 | + // } |
| 68 | + //}() |
| 69 | + }) |
| 70 | + return engine, err |
| 71 | +} |
0 commit comments