本文整理汇总了Python中stp_core.network.port_dispenser.genHa函数的典型用法代码示例。如果您正苦于以下问题:Python genHa函数的具体用法?Python genHa怎么用?Python genHa使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了genHa函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testZStackSendRecvHugeDataUnderLimit
def testZStackSendRecvHugeDataUnderLimit(set_info_log_level, tdir, looper, tconf):
names = ['Alpha', 'Beta']
genKeys(tdir, names)
# we use json serializer now, so final form will be {'k':'vvv...vvv'}
# so here we try to prepare exactly tconf.MSG_LEN_LIMIT bytes after serialization
msg = {'k': 'v' * (tconf.MSG_LEN_LIMIT - len("{'k':''}"))}
betaHandler = [False]
def recvHandlerAlpha(wrpMsg):
pass
def recvHandlerBeta(wrpMsg):
rmsg, frm = wrpMsg
betaHandler[0] = True
assert frm == 'Alpha'
assert rmsg == msg
alpha = ZStack(names[0], ha=genHa(), basedirpath=tdir, msgHandler=recvHandlerAlpha, restricted=True,
config=adict(**tconf.__dict__), msgRejectHandler=None)
beta = ZStack(names[1], ha=genHa(), basedirpath=tdir, msgHandler=recvHandlerBeta, restricted=True,
config=adict(**tconf.__dict__), msgRejectHandler=None)
assert len(alpha.serializeMsg(msg)) == tconf.MSG_LEN_LIMIT
prepStacks(looper, *(alpha, beta), connect=True, useKeys=True)
stat = alpha.send(msg, beta.name)
assert stat[0] is True
looper.runFor(5)
assert betaHandler[0] is True
示例2: getPoolTxnData
def getPoolTxnData(nodeAndClientInfoFilePath, poolId, newPoolTxnNodeNames):
data={}
data["seeds"]={}
data["txns"]=[]
for index, n in enumerate(newPoolTxnNodeNames, start=1):
newStewardAlias = poolId + "Steward" + str(index)
stewardSeed = (newStewardAlias + "0" * (32 - len(newStewardAlias))).encode()
data["seeds"][newStewardAlias] = stewardSeed
stewardSigner = SimpleSigner(seed=stewardSeed)
data["txns"].append({
TARGET_NYM: stewardSigner.verkey,
ROLE: STEWARD, TXN_TYPE: NYM,
ALIAS: poolId + "Steward" + str(index),
TXN_ID: sha256("{}".format(stewardSigner.verkey).encode()).hexdigest()
})
newNodeAlias = n
nodeSeed = (newNodeAlias + "0" * (32 - len(newNodeAlias))).encode()
data["seeds"][newNodeAlias] = nodeSeed
nodeSigner = SimpleSigner(seed=nodeSeed)
data["txns"].append({
TARGET_NYM: nodeSigner.verkey,
TXN_TYPE: NODE,
f.IDENTIFIER.nm: stewardSigner.verkey,
DATA: {
CLIENT_IP: "127.0.0.1",
ALIAS: newNodeAlias,
NODE_IP: "127.0.0.1",
NODE_PORT: genHa()[1],
CLIENT_PORT: genHa()[1],
SERVICES: [VALIDATOR],
},
TXN_ID: sha256("{}".format(nodeSigner.verkey).encode()).hexdigest()
})
return data
示例3: registry
def registry():
return {
'Alpha': genHa(),
'Beta': genHa(),
'Gamma': genHa(),
'Delta': genHa()
}
示例4: testManyMessages
def testManyMessages(set_info_log_level, tdir, looper, tconf):
names = ['Alpha', 'Beta']
genKeys(tdir, names)
alphaP = Printer(names[0])
betaMsgHandler = CounterMsgsHandler()
alpha = ZStack(names[0],
ha=genHa(),
basedirpath=tdir,
msgHandler=alphaP.print,
restricted=True)
beta = ZStack(names[1],
ha=genHa(),
basedirpath=tdir,
msgHandler=betaMsgHandler.handler,
restricted=True)
prepStacks(looper, alpha, beta, connect=True, useKeys=True)
looper.runFor(1)
msgNum = BIG_NUM_OF_MSGS
msgSender = MessageSender(msgNum, alpha, beta.name)
looper.add(msgSender)
def checkAllReceived():
assert msgSender.sentMsgCount == msgNum
assert betaMsgHandler.receivedMsgCount == msgNum
looper.run(eventually(checkAllReceived,
retryWait=1,
timeout=60))
示例5: testMessageQuota
def testMessageQuota(set_info_log_level, tdir, looper):
names = ['Alpha', 'Beta']
genKeys(tdir, names)
alphaP = Printer(names[0])
betaMsgHandler = CollectingMsgsHandler()
alpha = ZStack(names[0], ha=genHa(), basedirpath=tdir, msgHandler=alphaP.print,
restricted=True)
beta = ZStack(names[1], ha=genHa(), basedirpath=tdir, msgHandler=betaMsgHandler.handler,
restricted=True, onlyListener=True)
prepStacks(looper, alpha, beta, connect=True, useKeys=True)
messages = []
numMessages = 150 * beta.listenerQuota
for i in range(numMessages):
msg = json.dumps({'random': randomSeed().decode()}).encode()
if alpha.send(msg, beta.name):
messages.append(json.loads(msg.decode()))
def checkAllReceived():
assert len(messages) == len(betaMsgHandler.receivedMessages)
assert messages == betaMsgHandler.receivedMessages
looper.run(eventually(checkAllReceived, retryWait=0.5,
timeout=5))
示例6: testSimpleZStacksMsgs
def testSimpleZStacksMsgs(tdir, looper):
names = ['Alpha', 'Beta']
genKeys(tdir, names)
names = ['Alpha', 'Beta']
aseed = randomSeed()
bseed = randomSeed()
size = 100000
msg = json.dumps({'random': randomSeed(size).decode()}).encode()
def aHandler(m):
str_m = "{}".format(m)
print('{} printing... {}'.format(names[0], str_m[:100]))
d, _ = m
print('Message size is {}'.format(len(d['random'])))
assert len(d['random']) == size
def bHandler(m):
print(beta.msgHandler)
a = m[1]
try:
beta.listener.send_multipart([a, msg],
flags=zmq.NOBLOCK)
except zmq.Again:
return False
str_m = "{}".format(m)
print('{} printing... {}'.format(names[1], str_m[:100]))
stackParams = {
"name": names[0],
"ha": genHa(),
"auto": 2,
"basedirpath": tdir
}
alpha = SimpleZStack(stackParams, aHandler, aseed, False)
stackParams = {
"name": names[1],
"ha": genHa(),
"auto": 2,
"basedirpath": tdir
}
beta = SimpleZStack(stackParams, bHandler, bseed, True)
amotor = SMotor(alpha)
looper.add(amotor)
bmotor = SMotor(beta)
looper.add(bmotor)
alpha.connect(name=beta.name, ha=beta.ha,
verKeyRaw=beta.verKeyRaw, publicKeyRaw=beta.publicKeyRaw)
looper.runFor(0.25)
alpha.send({'greetings': 'hi'}, beta.name)
looper.runFor(1)
示例7: testConsecutiveAddSameNodeWithNonAliasChange
def testConsecutiveAddSameNodeWithNonAliasChange(be, do, newStewardCli,
newNodeVals, newNodeAdded):
be(newStewardCli)
nodeIp, nodePort = genHa()
clientIp, clientPort = genHa()
newNodeVals['newNodeData'][NODE_IP] = nodeIp
newNodeVals['newNodeData'][NODE_PORT] = nodePort
newNodeVals['newNodeData'][CLIENT_IP] = nodeIp
newNodeVals['newNodeData'][CLIENT_PORT] = clientPort
doSendNodeCmd(do, newNodeVals)
exitFromCli(do)
示例8: testChangeNodeHaBack
def testChangeNodeHaBack(looper, txnPoolNodeSet,
sdk_pool_handle,
sdk_node_theta_added,
tconf, tdir):
"""
The case:
The Node HA is updated with some HA (let's name it 'correct' HA).
Then the Steward makes a mistake and sends the NODE txn with other HA
('wrong' HA). The Steward replaces back 'wrong' HA by 'correct' HA sending
yet another one NODE txn.
"""
new_steward_wallet, new_node = sdk_node_theta_added
client_ha = new_node.cliNodeReg['ThetaC'] # use the same client HA
# do all exercises without the Node
new_node.stop()
looper.removeProdable(name=new_node.name)
# step 1: set 'correct' HA
correct_node_ha = genHa(1)
node_dest = hexToFriendly(new_node.nodestack.verhex)
sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle,
node_dest, new_node.name,
correct_node_ha.host, correct_node_ha.port,
client_ha.host, client_ha.port)
# step 2: set 'wrong' HA
wrong_node_ha = genHa(1)
sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle,
node_dest, new_node.name,
wrong_node_ha.host, wrong_node_ha.port,
client_ha.host, client_ha.port)
# step 3: set 'correct' HA back
sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle,
node_dest, new_node.name,
correct_node_ha.host, correct_node_ha.port,
client_ha.host, client_ha.port)
# In order to save the time the pool connection is not maintaining
# during the steps, only the final result is checked.
config_helper = PNodeConfigHelper(new_node.name, tconf, chroot=tdir)
restartedNode = TestNode(new_node.name,
config_helper=config_helper,
config=tconf, ha=correct_node_ha, cliha=client_ha)
looper.add(restartedNode)
txnPoolNodeSet[-1] = restartedNode
looper.run(checkNodesConnected(txnPoolNodeSet))
# check Theta HA
for n in txnPoolNodeSet:
assert n.nodeReg['Theta'] == correct_node_ha
示例9: test_queue_size_limit_set
def test_queue_size_limit_set(tdir, tconf):
stack = ZStack("Alpha", ha=genHa(), basedirpath=tdir, msgHandler=None,
restricted=False, seed=randomSeed(), config=tconf)
stack.start()
assert stack.listener.get_hwm() == 0
stack.stop()
queue_size = 100
stack = ZStack("Alpha", ha=genHa(), basedirpath=tdir, msgHandler=None,
restricted=False, seed=randomSeed(), config=tconf, queue_size=queue_size)
stack.start()
assert stack.listener.get_hwm() == queue_size
stack.stop()
示例10: _
def _(wallet, basedir=None):
basedir = basedir or tdirWithPoolTxns
_, port = genHa()
_, clientPort = genHa()
client = TestClient(randomString(6),
ha=("0.0.0.0", clientPort),
basedirpath=basedir)
agent = WalletedAgent(name=wallet.name,
basedirpath=basedir,
client=client,
wallet=wallet,
port=port)
return agent
示例11: test_get_msgs_from_rxMsgs_queue
def test_get_msgs_from_rxMsgs_queue(create_node_and_not_start, looper):
node = create_node_and_not_start
node.view_changer = ViewChanger(node)
node.view_changer.view_no = 0
"""pre_view_change stage"""
node.view_changer.startViewChange(1)
assert node.view_changer.view_no == 0
prepare = Prepare(
0,
0,
1,
get_utc_epoch(),
'f99937241d4c891c08e92a3cc25966607315ca66b51827b170d492962d58a9be',
'CZecK1m7VYjSNCC7pGHj938DSW2tfbqoJp1bMJEtFqvG',
'7WrAMboPTcMaQCU1raoj28vnhu2bPMMd2Lr9tEcsXeCJ')
inst_change = InstanceChange(1, 25)
m = node.nodeInBox.popleft()
assert isinstance(m[0], ViewChangeStartMessage)
node.nodestack.addRemote('someNode', genHa(), b'1DYuELN<SHbv1?NJ=][4De%^Hge887B0I!s<YGdD', 'pubkey')
node.nodestack.rxMsgs.append((json.dumps(prepare._asdict()), 'pubkey'))
node.nodestack.rxMsgs.append((json.dumps(inst_change._asdict()), 'pubkey'))
node.msgHasAcceptableViewNo = lambda *args, **kwargs: True
"""While processing ViewChangeStartMessage from nodeInBox queue, should be:
- move msgs from rxMsgs queue to nodeInBox queue
- process all 3PC msgs (for Prepare msg it should be moved to inBox queue of master_replica)
- add ViewChangeContinue msg into master_replica's inBox queue
- all not 3PC msgs will be stashed in strategy queue"""
looper.run(node.process_one_node_message(m))
m = node.master_replica.inBox.popleft()
assert isinstance(m[0], Prepare)
m = node.master_replica.inBox.popleft()
assert isinstance(m, ViewChangeContinueMessage)
m = node.view_changer.pre_vc_strategy.stashedNodeInBox.popleft()
assert isinstance(m[0], InstanceChange)
示例12: put_load
def put_load():
port = genHa()[1]
ha = HA('0.0.0.0', port)
name = "hello"
wallet = Wallet(name)
wallet.addIdentifier(
signer=DidSigner(seed=b'000000000000000000000000Steward1'))
client = Client(name, ha=ha)
with Looper(debug=getConfig().LOOPER_DEBUG) as looper:
looper.add(client)
print('Will send {} reqs in all'.format(numReqs))
requests = sendRandomRequests(wallet, client, numReqs)
start = perf_counter()
for i in range(0, numReqs, numReqs // splits):
print('Will wait for {} now'.format(numReqs // splits))
s = perf_counter()
reqs = requests[i:i + numReqs // splits + 1]
waitForSufficientRepliesForRequests(looper, client, requests=reqs,
customTimeoutPerReq=100,
override_timeout_limit=True)
print('>>> Got replies for {} requests << in {}'.
format(numReqs // splits, perf_counter() - s))
end = perf_counter()
print('>>>Total {} in {}<<<'.format(numReqs, end - start))
exit(0)
示例13: prepare_new_node_data
def prepare_new_node_data(tconf, tdir, newNodeName, configClass=PNodeConfigHelper):
sigseed = randomString(32).encode()
(nodeIp, nodePort), (clientIp, clientPort) = genHa(2)
config_helper = configClass(newNodeName, tconf, chroot=tdir)
pubkey, verkey, bls_key, key_proof = initNodeKeysForBothStacks(newNodeName, config_helper.keys_dir,
sigseed, override=True)
return sigseed, verkey, bls_key, nodeIp, nodePort, clientIp, clientPort, key_proof
示例14: testChangeHaPersistsPostNodesRestart
def testChangeHaPersistsPostNodesRestart(looper, txnPoolNodeSet,
tdir, tconf,
sdk_pool_handle,
sdk_wallet_client,
sdk_wallet_steward):
new_steward_wallet, new_node = \
sdk_add_new_steward_and_node(looper,
sdk_pool_handle,
sdk_wallet_steward,
'AnotherSteward' + randomString(4),
'AnotherNode' + randomString(4),
tdir,
tconf)
txnPoolNodeSet.append(new_node)
looper.run(checkNodesConnected(txnPoolNodeSet))
sdk_pool_refresh(looper, sdk_pool_handle)
node_new_ha, client_new_ha = genHa(2)
logger.debug("{} changing HAs to {} {}".format(new_node, node_new_ha,
client_new_ha))
# Making the change HA txn an confirming its succeeded
node_dest = hexToFriendly(new_node.nodestack.verhex)
sdk_send_update_node(looper, new_steward_wallet, sdk_pool_handle,
node_dest, new_node.name,
node_new_ha.host, node_new_ha.port,
client_new_ha.host, client_new_ha.port)
# Stopping existing nodes
for node in txnPoolNodeSet:
node.stop()
looper.removeProdable(node)
# Starting nodes again by creating `Node` objects since that simulates
# what happens when starting the node with script
restartedNodes = []
for node in txnPoolNodeSet[:-1]:
config_helper = PNodeConfigHelper(node.name, tconf, chroot=tdir)
restartedNode = TestNode(node.name,
config_helper=config_helper,
config=tconf, ha=node.nodestack.ha,
cliha=node.clientstack.ha)
looper.add(restartedNode)
restartedNodes.append(restartedNode)
# Starting the node whose HA was changed
config_helper = PNodeConfigHelper(new_node.name, tconf, chroot=tdir)
node = TestNode(new_node.name,
config_helper=config_helper,
config=tconf,
ha=node_new_ha, cliha=client_new_ha)
looper.add(node)
restartedNodes.append(node)
looper.run(checkNodesConnected(restartedNodes))
waitNodeDataEquality(looper, node, *restartedNodes[:-1])
sdk_pool_refresh(looper, sdk_pool_handle)
sdk_ensure_pool_functional(looper, restartedNodes, sdk_wallet_client, sdk_pool_handle)
示例15: getPoolTxnData
def getPoolTxnData(poolId, newPoolTxnNodeNames):
data = {}
data["seeds"] = {}
data["txns"] = []
data['nodesWithBls'] = {}
for index, n in enumerate(newPoolTxnNodeNames, start=1):
newStewardAlias = poolId + "Steward" + str(index)
stewardSeed = (newStewardAlias + "0" *
(32 - len(newStewardAlias))).encode()
data["seeds"][newStewardAlias] = stewardSeed
stewardSigner = SimpleSigner(seed=stewardSeed)
data["txns"].append({
TARGET_NYM: stewardSigner.verkey,
ROLE: STEWARD, TXN_TYPE: NYM,
ALIAS: poolId + "Steward" + str(index),
TXN_ID: sha256("{}".format(stewardSigner.verkey).encode()).hexdigest()
})
newNodeAlias = n
nodeSeed = (newNodeAlias + "0" * (32 - len(newNodeAlias))).encode()
data["seeds"][newNodeAlias] = nodeSeed
nodeSigner = SimpleSigner(seed=nodeSeed)
node_txn = {
TARGET_NYM: nodeSigner.verkey,
TXN_TYPE: NODE,
f.IDENTIFIER.nm: stewardSigner.verkey,
DATA: {
CLIENT_IP: "127.0.0.1",
ALIAS: newNodeAlias,
NODE_IP: "127.0.0.1",
NODE_PORT: genHa()[1],
CLIENT_PORT: genHa()[1],
SERVICES: [VALIDATOR],
},
TXN_ID: sha256("{}".format(nodeSigner.verkey).encode()).hexdigest()
}
_, bls_key = create_default_bls_crypto_factory().generate_bls_keys(
seed=data['seeds'][n])
node_txn[DATA][BLS_KEY] = bls_key
data['nodesWithBls'][n] = True
data["txns"].append(node_txn)
return data