github.com/braveheart12/insolar-09-08-19@v0.8.7/network/servicenetwork/wrappers_test.go (about) 1 /* 2 * The Clear BSD License 3 * 4 * Copyright (c) 2019 Insolar Technologies 5 * 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: 9 * 10 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 12 * Neither the name of Insolar Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 * 14 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 * 16 */ 17 18 package servicenetwork 19 20 import ( 21 "context" 22 "time" 23 24 consensus "github.com/insolar/insolar/consensus/packets" 25 "github.com/insolar/insolar/consensus/phases" 26 "github.com/insolar/insolar/core" 27 "github.com/insolar/insolar/network" 28 "github.com/insolar/insolar/network/transport/host" 29 ) 30 31 type nodeKeeperTestInterface interface { 32 // Wipe all active nodes for test purposes 33 Wipe(isDiscovery bool) 34 } 35 36 type nodeKeeperWrapper struct { 37 original network.NodeKeeper 38 } 39 40 func (n *nodeKeeperWrapper) GetWorkingNode(ref core.RecordRef) core.Node { 41 return n.original.GetWorkingNode(ref) 42 } 43 44 func (n *nodeKeeperWrapper) GetWorkingNodes() []core.Node { 45 return n.original.GetWorkingNodes() 46 } 47 48 func (n *nodeKeeperWrapper) GetWorkingNodesByRole(role core.DynamicRole) []core.RecordRef { 49 return n.original.GetWorkingNodesByRole(role) 50 } 51 52 func (n *nodeKeeperWrapper) Wipe(isDiscovery bool) { 53 n.original.(nodeKeeperTestInterface).Wipe(isDiscovery) 54 } 55 56 func (n *nodeKeeperWrapper) AddTemporaryMapping(nodeID core.RecordRef, shortID core.ShortNodeID, address string) error { 57 return n.original.AddTemporaryMapping(nodeID, shortID, address) 58 } 59 60 func (n *nodeKeeperWrapper) ResolveConsensus(shortID core.ShortNodeID) *host.Host { 61 return n.original.ResolveConsensus(shortID) 62 } 63 64 func (n *nodeKeeperWrapper) ResolveConsensusRef(nodeID core.RecordRef) *host.Host { 65 return n.original.ResolveConsensusRef(nodeID) 66 } 67 68 type phaseManagerWrapper struct { 69 original phases.PhaseManager 70 result chan error 71 } 72 73 func (p *phaseManagerWrapper) OnPulse(ctx context.Context, pulse *core.Pulse, pulseStartTime time.Time) error { 74 res := p.original.OnPulse(ctx, pulse, pulseStartTime) 75 p.result <- res 76 return res 77 } 78 79 func (n *nodeKeeperWrapper) GetOrigin() core.Node { 80 return n.original.GetOrigin() 81 } 82 83 func (n *nodeKeeperWrapper) GetActiveNode(ref core.RecordRef) core.Node { 84 return n.original.GetActiveNode(ref) 85 } 86 87 func (n *nodeKeeperWrapper) GetActiveNodes() []core.Node { 88 tmp := n.original.GetActiveNodes() 89 return tmp 90 } 91 92 func (n *nodeKeeperWrapper) GetCloudHash() []byte { 93 return n.original.GetCloudHash() 94 } 95 96 func (n *nodeKeeperWrapper) IsBootstrapped() bool { 97 return n.original.IsBootstrapped() 98 } 99 100 func (n *nodeKeeperWrapper) SetIsBootstrapped(isBootstrap bool) { 101 n.original.SetIsBootstrapped(isBootstrap) 102 } 103 104 func (n *nodeKeeperWrapper) SetCloudHash(hash []byte) { 105 n.original.SetCloudHash(hash) 106 } 107 108 func (n *nodeKeeperWrapper) AddActiveNodes(nodes []core.Node) { 109 n.original.AddActiveNodes(nodes) 110 } 111 112 func (n *nodeKeeperWrapper) GetActiveNodeByShortID(shortID core.ShortNodeID) core.Node { 113 return n.original.GetActiveNodeByShortID(shortID) 114 } 115 116 func (n *nodeKeeperWrapper) SetState(state core.NodeNetworkState) { 117 n.original.SetState(state) 118 } 119 120 func (n *nodeKeeperWrapper) GetState() core.NodeNetworkState { 121 return n.original.GetState() 122 } 123 124 func (n *nodeKeeperWrapper) GetOriginJoinClaim() (*consensus.NodeJoinClaim, error) { 125 return n.original.GetOriginJoinClaim() 126 } 127 128 func (n *nodeKeeperWrapper) GetOriginAnnounceClaim(mapper consensus.BitSetMapper) (*consensus.NodeAnnounceClaim, error) { 129 return n.original.GetOriginAnnounceClaim(mapper) 130 } 131 132 func (n *nodeKeeperWrapper) NodesJoinedDuringPreviousPulse() bool { 133 return n.original.NodesJoinedDuringPreviousPulse() 134 } 135 136 func (n *nodeKeeperWrapper) AddPendingClaim(claim consensus.ReferendumClaim) bool { 137 return n.original.AddPendingClaim(claim) 138 } 139 140 func (n *nodeKeeperWrapper) GetClaimQueue() network.ClaimQueue { 141 return n.original.GetClaimQueue() 142 } 143 144 func (n *nodeKeeperWrapper) GetUnsyncList() network.UnsyncList { 145 return n.original.GetUnsyncList() 146 } 147 148 func (n *nodeKeeperWrapper) GetSparseUnsyncList(length int) network.UnsyncList { 149 return n.original.GetSparseUnsyncList(length) 150 } 151 152 func (n *nodeKeeperWrapper) Sync(list network.UnsyncList) { 153 n.original.Sync(list) 154 } 155 156 func (n *nodeKeeperWrapper) MoveSyncToActive(ctx context.Context) error { 157 return n.original.MoveSyncToActive(ctx) 158 }