open-aea-cli-benchmark 2.0.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aea_cli_benchmark/__init__.py +20 -0
- aea_cli_benchmark/case_acn_communication/__init__.py +20 -0
- aea_cli_benchmark/case_acn_communication/case.py +212 -0
- aea_cli_benchmark/case_acn_communication/command.py +82 -0
- aea_cli_benchmark/case_acn_communication/utils.py +253 -0
- aea_cli_benchmark/case_acn_startup/__init__.py +20 -0
- aea_cli_benchmark/case_acn_startup/case.py +106 -0
- aea_cli_benchmark/case_acn_startup/command.py +81 -0
- aea_cli_benchmark/case_acn_startup/utils.py +253 -0
- aea_cli_benchmark/case_agent_construction_time/__init__.py +20 -0
- aea_cli_benchmark/case_agent_construction_time/case.py +96 -0
- aea_cli_benchmark/case_agent_construction_time/command.py +52 -0
- aea_cli_benchmark/case_decision_maker/__init__.py +20 -0
- aea_cli_benchmark/case_decision_maker/case.py +200 -0
- aea_cli_benchmark/case_decision_maker/command.py +73 -0
- aea_cli_benchmark/case_dialogues_memory_usage/__init__.py +20 -0
- aea_cli_benchmark/case_dialogues_memory_usage/case.py +104 -0
- aea_cli_benchmark/case_dialogues_memory_usage/command.py +59 -0
- aea_cli_benchmark/case_mem_usage/__init__.py +20 -0
- aea_cli_benchmark/case_mem_usage/case.py +86 -0
- aea_cli_benchmark/case_mem_usage/command.py +62 -0
- aea_cli_benchmark/case_messages_memory_usage/__init__.py +20 -0
- aea_cli_benchmark/case_messages_memory_usage/case.py +57 -0
- aea_cli_benchmark/case_messages_memory_usage/command.py +63 -0
- aea_cli_benchmark/case_multiagent/__init__.py +20 -0
- aea_cli_benchmark/case_multiagent/case.py +201 -0
- aea_cli_benchmark/case_multiagent/command.py +83 -0
- aea_cli_benchmark/case_multiagent_http_dialogues/__init__.py +20 -0
- aea_cli_benchmark/case_multiagent_http_dialogues/case.py +235 -0
- aea_cli_benchmark/case_multiagent_http_dialogues/command.py +101 -0
- aea_cli_benchmark/case_proactive/__init__.py +20 -0
- aea_cli_benchmark/case_proactive/case.py +85 -0
- aea_cli_benchmark/case_proactive/command.py +67 -0
- aea_cli_benchmark/case_reactive/__init__.py +20 -0
- aea_cli_benchmark/case_reactive/case.py +136 -0
- aea_cli_benchmark/case_reactive/command.py +84 -0
- aea_cli_benchmark/case_tx_generate/__init__.py +20 -0
- aea_cli_benchmark/case_tx_generate/case.py +505 -0
- aea_cli_benchmark/case_tx_generate/command.py +86 -0
- aea_cli_benchmark/case_tx_generate/core.py +160 -0
- aea_cli_benchmark/case_tx_generate/dialogues.py +228 -0
- aea_cli_benchmark/case_tx_generate/docker_image.py +275 -0
- aea_cli_benchmark/case_tx_generate/ledger_utils.py +146 -0
- aea_cli_benchmark/core.py +166 -0
- aea_cli_benchmark/py.typed +1 -0
- aea_cli_benchmark/utils.py +378 -0
- open_aea_cli_benchmark-2.0.8.dist-info/METADATA +34 -0
- open_aea_cli_benchmark-2.0.8.dist-info/RECORD +52 -0
- open_aea_cli_benchmark-2.0.8.dist-info/WHEEL +5 -0
- open_aea_cli_benchmark-2.0.8.dist-info/entry_points.txt +2 -0
- open_aea_cli_benchmark-2.0.8.dist-info/licenses/LICENSE +201 -0
- open_aea_cli_benchmark-2.0.8.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# ------------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2018-2021 Fetch.AI Limited
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
# ------------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
"""This module contains the implementation of `benchmark` cli command."""
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# ------------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2018-2021 Fetch.AI Limited
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
# ------------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
"""This module contains the implementation of `benchmark` cli command."""
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# ------------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2022 Valory AG
|
|
5
|
+
# Copyright 2018-2021 Fetch.AI Limited
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
# ------------------------------------------------------------------------------
|
|
20
|
+
"""Check amount of time for acn connection communications."""
|
|
21
|
+
import asyncio
|
|
22
|
+
import logging
|
|
23
|
+
import os
|
|
24
|
+
import time
|
|
25
|
+
from contextlib import contextmanager
|
|
26
|
+
from tempfile import TemporaryDirectory
|
|
27
|
+
from typing import Callable, List, Tuple, Union
|
|
28
|
+
|
|
29
|
+
from aea_cli_benchmark.case_acn_communication.utils import (
|
|
30
|
+
DEFAULT_DELEGATE_PORT,
|
|
31
|
+
DEFAULT_MAILBOX_PORT,
|
|
32
|
+
DEFAULT_NODE_PORT,
|
|
33
|
+
_make_libp2p_client_connection,
|
|
34
|
+
_make_libp2p_connection,
|
|
35
|
+
_make_libp2p_mailbox_connection,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
from aea.connections.base import Connection
|
|
39
|
+
from aea.mail.base import Envelope
|
|
40
|
+
|
|
41
|
+
from packages.fetchai.protocols.default.message import DefaultMessage
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class TimeMeasure:
|
|
45
|
+
"""Time measure data class."""
|
|
46
|
+
|
|
47
|
+
def __init__(self):
|
|
48
|
+
"""Init data class instance."""
|
|
49
|
+
self.time = -1
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@contextmanager
|
|
53
|
+
def time_measure():
|
|
54
|
+
"""Get time measure context."""
|
|
55
|
+
start = time.time()
|
|
56
|
+
m = TimeMeasure()
|
|
57
|
+
try:
|
|
58
|
+
yield m
|
|
59
|
+
finally:
|
|
60
|
+
m.time = time.time() - start
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def make_envelope(from_addr: str, to_addr: str) -> Envelope:
|
|
64
|
+
"""Construct an envelope."""
|
|
65
|
+
msg = DefaultMessage(
|
|
66
|
+
dialogue_reference=("", ""),
|
|
67
|
+
message_id=1,
|
|
68
|
+
target=0,
|
|
69
|
+
performative=DefaultMessage.Performative.BYTES,
|
|
70
|
+
content=b"hello",
|
|
71
|
+
)
|
|
72
|
+
envelope = Envelope(
|
|
73
|
+
to=to_addr,
|
|
74
|
+
sender=from_addr,
|
|
75
|
+
message=msg,
|
|
76
|
+
)
|
|
77
|
+
return envelope
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
async def _run(con_maker: Callable[..., Connection]) -> Tuple[float, float]:
|
|
81
|
+
"""Run test case and return times for the first and the second messages sent over ACN."""
|
|
82
|
+
try:
|
|
83
|
+
connections = []
|
|
84
|
+
genesis_node = _make_libp2p_connection(".", relay=True)
|
|
85
|
+
await genesis_node.connect()
|
|
86
|
+
connections.append(genesis_node)
|
|
87
|
+
genesis_multiaddr = genesis_node.node.multiaddrs[0]
|
|
88
|
+
|
|
89
|
+
relay_node1 = _make_libp2p_connection(
|
|
90
|
+
".",
|
|
91
|
+
relay=True,
|
|
92
|
+
entry_peers=[genesis_multiaddr],
|
|
93
|
+
port=DEFAULT_NODE_PORT + 1,
|
|
94
|
+
mailbox=True,
|
|
95
|
+
delegate=True,
|
|
96
|
+
mailbox_port=DEFAULT_MAILBOX_PORT + 1,
|
|
97
|
+
delegate_port=DEFAULT_DELEGATE_PORT + 1,
|
|
98
|
+
)
|
|
99
|
+
await relay_node1.connect()
|
|
100
|
+
connections.append(relay_node1)
|
|
101
|
+
relay_node2 = _make_libp2p_connection(
|
|
102
|
+
".",
|
|
103
|
+
relay=True,
|
|
104
|
+
entry_peers=[genesis_multiaddr],
|
|
105
|
+
port=DEFAULT_NODE_PORT + 2,
|
|
106
|
+
mailbox=True,
|
|
107
|
+
delegate=True,
|
|
108
|
+
mailbox_port=DEFAULT_MAILBOX_PORT + 2,
|
|
109
|
+
delegate_port=DEFAULT_DELEGATE_PORT + 2,
|
|
110
|
+
)
|
|
111
|
+
await relay_node2.connect()
|
|
112
|
+
connections.append(relay_node2)
|
|
113
|
+
|
|
114
|
+
relay_node1_multiaddr = relay_node1.node.multiaddrs[0]
|
|
115
|
+
relay_node2_multiaddr = relay_node2.node.multiaddrs[0]
|
|
116
|
+
await asyncio.sleep(1)
|
|
117
|
+
con1 = con_maker(
|
|
118
|
+
port=DEFAULT_NODE_PORT + 10,
|
|
119
|
+
entry_peer=relay_node1_multiaddr,
|
|
120
|
+
mailbox_port=DEFAULT_MAILBOX_PORT + 1,
|
|
121
|
+
delegate_port=DEFAULT_DELEGATE_PORT + 1,
|
|
122
|
+
pub_key=relay_node1.node.pub,
|
|
123
|
+
)
|
|
124
|
+
await con1.connect()
|
|
125
|
+
connections.append(con1)
|
|
126
|
+
|
|
127
|
+
con2 = con_maker(
|
|
128
|
+
port=DEFAULT_NODE_PORT + 20,
|
|
129
|
+
entry_peer=relay_node2_multiaddr,
|
|
130
|
+
mailbox_port=DEFAULT_MAILBOX_PORT + 2,
|
|
131
|
+
delegate_port=DEFAULT_DELEGATE_PORT + 2,
|
|
132
|
+
pub_key=relay_node2.node.pub,
|
|
133
|
+
)
|
|
134
|
+
await con2.connect()
|
|
135
|
+
connections.append(con2)
|
|
136
|
+
|
|
137
|
+
envelope = make_envelope(con1.address, con2.address)
|
|
138
|
+
|
|
139
|
+
with time_measure() as tm:
|
|
140
|
+
await con1.send(envelope)
|
|
141
|
+
envelope = await con2.receive()
|
|
142
|
+
first_time = tm.time
|
|
143
|
+
|
|
144
|
+
with time_measure() as tm:
|
|
145
|
+
await con1.send(envelope)
|
|
146
|
+
envelope = await con2.receive()
|
|
147
|
+
|
|
148
|
+
second_time = tm.time
|
|
149
|
+
|
|
150
|
+
return first_time, second_time
|
|
151
|
+
|
|
152
|
+
finally:
|
|
153
|
+
for con in reversed(connections):
|
|
154
|
+
await con.disconnect()
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def run(connection: str, run_times: int = 10) -> List[Tuple[str, Union[int, float]]]:
|
|
158
|
+
"""Check construction time and memory usage."""
|
|
159
|
+
logging.basicConfig(level=logging.CRITICAL)
|
|
160
|
+
cwd = os.getcwd()
|
|
161
|
+
try:
|
|
162
|
+
if connection == "p2pnode":
|
|
163
|
+
|
|
164
|
+
def con_maker(
|
|
165
|
+
port: int,
|
|
166
|
+
entry_peer: str,
|
|
167
|
+
mailbox_port: int,
|
|
168
|
+
delegate_port: int,
|
|
169
|
+
pub_key: str,
|
|
170
|
+
):
|
|
171
|
+
return _make_libp2p_connection(".", port=port, entry_peers=[entry_peer])
|
|
172
|
+
|
|
173
|
+
elif connection == "client":
|
|
174
|
+
|
|
175
|
+
def con_maker(
|
|
176
|
+
port: int,
|
|
177
|
+
entry_peer: str,
|
|
178
|
+
mailbox_port: int,
|
|
179
|
+
delegate_port: int,
|
|
180
|
+
pub_key: str,
|
|
181
|
+
):
|
|
182
|
+
return _make_libp2p_client_connection(
|
|
183
|
+
peer_public_key=pub_key, data_dir=".", node_port=delegate_port
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
elif connection == "mailbox":
|
|
187
|
+
|
|
188
|
+
def con_maker(
|
|
189
|
+
port: int,
|
|
190
|
+
entry_peer: str,
|
|
191
|
+
mailbox_port: int,
|
|
192
|
+
delegate_port: int,
|
|
193
|
+
pub_key: str,
|
|
194
|
+
):
|
|
195
|
+
return _make_libp2p_mailbox_connection(
|
|
196
|
+
peer_public_key=pub_key, data_dir=".", node_port=mailbox_port
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
else:
|
|
200
|
+
raise ValueError(f"Unsupported connection: {connection}")
|
|
201
|
+
|
|
202
|
+
with TemporaryDirectory() as tmp_dir:
|
|
203
|
+
os.chdir(tmp_dir)
|
|
204
|
+
coro = _run(con_maker)
|
|
205
|
+
first_time, second_time = asyncio.get_event_loop().run_until_complete(coro)
|
|
206
|
+
|
|
207
|
+
return [
|
|
208
|
+
("first time (seconds)", first_time),
|
|
209
|
+
("second time (seconds)", second_time),
|
|
210
|
+
]
|
|
211
|
+
finally:
|
|
212
|
+
os.chdir(cwd)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# ------------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2022 Valory AG
|
|
5
|
+
# Copyright 2018-2021 Fetch.AI Limited
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
# ------------------------------------------------------------------------------
|
|
20
|
+
"""Check amount of time for acn connection start."""
|
|
21
|
+
|
|
22
|
+
from typing import Any, List, Tuple
|
|
23
|
+
|
|
24
|
+
import click
|
|
25
|
+
from aea_cli_benchmark.utils import (
|
|
26
|
+
multi_run,
|
|
27
|
+
number_of_runs_deco,
|
|
28
|
+
output_format_deco,
|
|
29
|
+
print_results,
|
|
30
|
+
with_packages,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
PACKAGES = [
|
|
35
|
+
("protocol", "valory/acn"),
|
|
36
|
+
("protocol", "fetchai/default"),
|
|
37
|
+
("connection", "valory/p2p_libp2p"),
|
|
38
|
+
("connection", "valory/p2p_libp2p_client"),
|
|
39
|
+
("connection", "valory/p2p_libp2p_mailbox"),
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@click.command(name="acn_communicate")
|
|
44
|
+
@click.option(
|
|
45
|
+
"--connection",
|
|
46
|
+
default="p2pnode",
|
|
47
|
+
help="Connection to use.",
|
|
48
|
+
show_default=True,
|
|
49
|
+
type=click.Choice(["p2pnode", "mailbox", "client"]),
|
|
50
|
+
)
|
|
51
|
+
@click.option(
|
|
52
|
+
"--connect-times",
|
|
53
|
+
default=10,
|
|
54
|
+
help="How many connection attempts.",
|
|
55
|
+
show_default=True,
|
|
56
|
+
)
|
|
57
|
+
@number_of_runs_deco
|
|
58
|
+
@output_format_deco
|
|
59
|
+
def main(
|
|
60
|
+
connection: str, connect_times: int, number_of_runs: int, output_format: str
|
|
61
|
+
) -> Any:
|
|
62
|
+
"""Check connection connect time."""
|
|
63
|
+
with with_packages(PACKAGES):
|
|
64
|
+
from aea_cli_benchmark.case_acn_communication.case import run
|
|
65
|
+
|
|
66
|
+
parameters = {
|
|
67
|
+
"Connection": connection,
|
|
68
|
+
"Number of connects": connect_times,
|
|
69
|
+
"Number of runs": number_of_runs,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
def result_fn() -> List[Tuple[str, Any, Any, Any]]:
|
|
73
|
+
return multi_run(
|
|
74
|
+
int(number_of_runs),
|
|
75
|
+
run,
|
|
76
|
+
(
|
|
77
|
+
connection,
|
|
78
|
+
connect_times,
|
|
79
|
+
),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
return print_results(output_format, parameters, result_fn)
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# ------------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2022-2025 Valory AG
|
|
5
|
+
# Copyright 2018-2021 Fetch.AI Limited
|
|
6
|
+
#
|
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
# you may not use this file except in compliance with the License.
|
|
9
|
+
# You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
# See the License for the specific language governing permissions and
|
|
17
|
+
# limitations under the License.
|
|
18
|
+
#
|
|
19
|
+
# ------------------------------------------------------------------------------
|
|
20
|
+
"""Check amount of time for acn connection start."""
|
|
21
|
+
import os
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Optional, Sequence, Union
|
|
24
|
+
from unittest.mock import patch
|
|
25
|
+
|
|
26
|
+
from aea.configurations.base import ConnectionConfig
|
|
27
|
+
from aea.configurations.constants import DEFAULT_LEDGER
|
|
28
|
+
from aea.crypto.base import Crypto
|
|
29
|
+
from aea.crypto.registries import make_crypto
|
|
30
|
+
from aea.crypto.wallet import CryptoStore
|
|
31
|
+
from aea.helpers.base import CertRequest, SimpleId
|
|
32
|
+
from aea.helpers.multiaddr.base import MultiAddr
|
|
33
|
+
from aea.identity.base import Identity
|
|
34
|
+
|
|
35
|
+
from packages.valory.connections.p2p_libp2p.check_dependencies import build_node
|
|
36
|
+
from packages.valory.connections.p2p_libp2p.connection import (
|
|
37
|
+
P2PLibp2pConnection,
|
|
38
|
+
POR_DEFAULT_SERVICE_ID,
|
|
39
|
+
)
|
|
40
|
+
from packages.valory.connections.p2p_libp2p.consts import (
|
|
41
|
+
LIBP2P_CERT_NOT_AFTER,
|
|
42
|
+
LIBP2P_CERT_NOT_BEFORE,
|
|
43
|
+
LIBP2P_NODE_MODULE_NAME,
|
|
44
|
+
)
|
|
45
|
+
from packages.valory.connections.p2p_libp2p_client.connection import (
|
|
46
|
+
P2PLibp2pClientConnection,
|
|
47
|
+
)
|
|
48
|
+
from packages.valory.connections.p2p_libp2p_mailbox.connection import (
|
|
49
|
+
P2PLibp2pMailboxConnection,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
DEFAULT_DELEGATE_PORT = 11234
|
|
54
|
+
DEFAULT_MAILBOX_PORT = 8888
|
|
55
|
+
DEFAULT_NODE_PORT = 10234
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _process_cert(key: Crypto, cert: CertRequest, path_prefix: str):
|
|
59
|
+
# must match aea/cli/issue_certificates.py:_process_certificate
|
|
60
|
+
assert cert.public_key is not None
|
|
61
|
+
message = cert.get_message(cert.public_key)
|
|
62
|
+
signature = key.sign_message(message).encode("ascii").hex()
|
|
63
|
+
Path(cert.get_absolute_save_path(path_prefix)).write_bytes(
|
|
64
|
+
signature.encode("ascii")
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _make_libp2p_connection(
|
|
69
|
+
data_dir: str,
|
|
70
|
+
port: int = DEFAULT_NODE_PORT,
|
|
71
|
+
host: str = "127.0.0.1",
|
|
72
|
+
relay: bool = True,
|
|
73
|
+
delegate: bool = False,
|
|
74
|
+
mailbox: bool = False,
|
|
75
|
+
entry_peers: Optional[Sequence[MultiAddr]] = None,
|
|
76
|
+
delegate_port: int = DEFAULT_DELEGATE_PORT,
|
|
77
|
+
delegate_host: str = "127.0.0.1",
|
|
78
|
+
mailbox_port: int = DEFAULT_MAILBOX_PORT,
|
|
79
|
+
mailbox_host: str = "127.0.0.1",
|
|
80
|
+
node_key_file: Optional[str] = None,
|
|
81
|
+
agent_key: Optional[Crypto] = None,
|
|
82
|
+
build_directory: Optional[str] = None,
|
|
83
|
+
peer_registration_delay: str = "0.0",
|
|
84
|
+
) -> P2PLibp2pConnection:
|
|
85
|
+
if not os.path.isdir(data_dir) or not os.path.exists(data_dir):
|
|
86
|
+
raise ValueError("Data dir must be directory and exist!")
|
|
87
|
+
log_file = os.path.join(data_dir, "libp2p_node_{}.log".format(port))
|
|
88
|
+
if os.path.exists(log_file):
|
|
89
|
+
os.remove(log_file)
|
|
90
|
+
key = agent_key
|
|
91
|
+
if key is None:
|
|
92
|
+
key = make_crypto(DEFAULT_LEDGER)
|
|
93
|
+
identity = Identity("identity", address=key.address, public_key=key.public_key)
|
|
94
|
+
conn_crypto_store = None
|
|
95
|
+
if node_key_file is not None:
|
|
96
|
+
conn_crypto_store = CryptoStore({DEFAULT_LEDGER: node_key_file})
|
|
97
|
+
else:
|
|
98
|
+
node_key = make_crypto(DEFAULT_LEDGER)
|
|
99
|
+
node_key_path = os.path.join(data_dir, f"{node_key.public_key}.txt")
|
|
100
|
+
node_key.dump(node_key_path)
|
|
101
|
+
conn_crypto_store = CryptoStore({DEFAULT_LEDGER: node_key_path})
|
|
102
|
+
cert_request = CertRequest(
|
|
103
|
+
conn_crypto_store.public_keys[DEFAULT_LEDGER],
|
|
104
|
+
POR_DEFAULT_SERVICE_ID,
|
|
105
|
+
key.identifier,
|
|
106
|
+
LIBP2P_CERT_NOT_BEFORE,
|
|
107
|
+
LIBP2P_CERT_NOT_AFTER,
|
|
108
|
+
"{public_key}",
|
|
109
|
+
f"./{key.address}_cert.txt",
|
|
110
|
+
)
|
|
111
|
+
_process_cert(key, cert_request, path_prefix=data_dir)
|
|
112
|
+
if not build_directory:
|
|
113
|
+
build_directory = os.getcwd()
|
|
114
|
+
if relay and delegate:
|
|
115
|
+
configuration = ConnectionConfig(
|
|
116
|
+
node_key_file=node_key_file,
|
|
117
|
+
local_uri="{}:{}".format(host, port),
|
|
118
|
+
public_uri="{}:{}".format(host, port),
|
|
119
|
+
entry_peers=entry_peers,
|
|
120
|
+
log_file=log_file,
|
|
121
|
+
delegate_uri="{}:{}".format(delegate_host, delegate_port),
|
|
122
|
+
peer_registration_delay=peer_registration_delay,
|
|
123
|
+
connection_id=P2PLibp2pConnection.connection_id,
|
|
124
|
+
build_directory=build_directory,
|
|
125
|
+
cert_requests=[cert_request],
|
|
126
|
+
)
|
|
127
|
+
elif relay and not delegate:
|
|
128
|
+
configuration = ConnectionConfig(
|
|
129
|
+
node_key_file=node_key_file,
|
|
130
|
+
local_uri="{}:{}".format(host, port),
|
|
131
|
+
public_uri="{}:{}".format(host, port),
|
|
132
|
+
entry_peers=entry_peers,
|
|
133
|
+
log_file=log_file,
|
|
134
|
+
peer_registration_delay=peer_registration_delay,
|
|
135
|
+
connection_id=P2PLibp2pConnection.connection_id,
|
|
136
|
+
build_directory=build_directory,
|
|
137
|
+
cert_requests=[cert_request],
|
|
138
|
+
)
|
|
139
|
+
else:
|
|
140
|
+
configuration = ConnectionConfig(
|
|
141
|
+
node_key_file=node_key_file,
|
|
142
|
+
local_uri="{}:{}".format(host, port),
|
|
143
|
+
entry_peers=entry_peers,
|
|
144
|
+
log_file=log_file,
|
|
145
|
+
peer_registration_delay=peer_registration_delay,
|
|
146
|
+
connection_id=P2PLibp2pConnection.connection_id,
|
|
147
|
+
build_directory=build_directory,
|
|
148
|
+
cert_requests=[cert_request],
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
if mailbox:
|
|
152
|
+
configuration.config["mailbox_uri"] = f"{mailbox_host}:{mailbox_port}"
|
|
153
|
+
else:
|
|
154
|
+
configuration.config["mailbox_uri"] = ""
|
|
155
|
+
|
|
156
|
+
if not os.path.exists(os.path.join(build_directory, LIBP2P_NODE_MODULE_NAME)):
|
|
157
|
+
with patch("builtins.print"):
|
|
158
|
+
build_node(build_directory)
|
|
159
|
+
connection = P2PLibp2pConnection(
|
|
160
|
+
configuration=configuration,
|
|
161
|
+
data_dir=data_dir,
|
|
162
|
+
identity=identity,
|
|
163
|
+
crypto_store=conn_crypto_store,
|
|
164
|
+
)
|
|
165
|
+
return connection
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _make_libp2p_client_connection(
|
|
169
|
+
peer_public_key: str,
|
|
170
|
+
data_dir: str,
|
|
171
|
+
node_port: int = DEFAULT_DELEGATE_PORT,
|
|
172
|
+
node_host: str = "127.0.0.1",
|
|
173
|
+
uri: Optional[str] = None,
|
|
174
|
+
ledger_api_id: Union[SimpleId, str] = DEFAULT_LEDGER,
|
|
175
|
+
) -> P2PLibp2pClientConnection:
|
|
176
|
+
if not os.path.isdir(data_dir) or not os.path.exists(data_dir):
|
|
177
|
+
raise ValueError("Data dir must be directory and exist!")
|
|
178
|
+
crypto = make_crypto(ledger_api_id)
|
|
179
|
+
identity = Identity(
|
|
180
|
+
"identity", address=crypto.address, public_key=crypto.public_key
|
|
181
|
+
)
|
|
182
|
+
cert_request = CertRequest(
|
|
183
|
+
peer_public_key,
|
|
184
|
+
POR_DEFAULT_SERVICE_ID,
|
|
185
|
+
ledger_api_id,
|
|
186
|
+
LIBP2P_CERT_NOT_BEFORE,
|
|
187
|
+
LIBP2P_CERT_NOT_AFTER,
|
|
188
|
+
"{public_key}",
|
|
189
|
+
f"./{crypto.address}_cert.txt",
|
|
190
|
+
)
|
|
191
|
+
_process_cert(crypto, cert_request, path_prefix=data_dir)
|
|
192
|
+
configuration = ConnectionConfig(
|
|
193
|
+
tcp_key_file=None,
|
|
194
|
+
nodes=[
|
|
195
|
+
{
|
|
196
|
+
"uri": (
|
|
197
|
+
str(uri)
|
|
198
|
+
if uri is not None
|
|
199
|
+
else "{}:{}".format(node_host, node_port)
|
|
200
|
+
),
|
|
201
|
+
"public_key": peer_public_key,
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
connection_id=P2PLibp2pClientConnection.connection_id,
|
|
205
|
+
cert_requests=[cert_request],
|
|
206
|
+
)
|
|
207
|
+
return P2PLibp2pClientConnection(
|
|
208
|
+
configuration=configuration, data_dir=data_dir, identity=identity
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _make_libp2p_mailbox_connection(
|
|
213
|
+
peer_public_key: str,
|
|
214
|
+
data_dir: str,
|
|
215
|
+
node_port: int = DEFAULT_MAILBOX_PORT,
|
|
216
|
+
node_host: str = "127.0.0.1",
|
|
217
|
+
uri: Optional[str] = None,
|
|
218
|
+
ledger_api_id: Union[SimpleId, str] = DEFAULT_LEDGER,
|
|
219
|
+
) -> P2PLibp2pMailboxConnection:
|
|
220
|
+
if not os.path.isdir(data_dir) or not os.path.exists(data_dir):
|
|
221
|
+
raise ValueError("Data dir must be directory and exist!")
|
|
222
|
+
crypto = make_crypto(ledger_api_id)
|
|
223
|
+
identity = Identity(
|
|
224
|
+
"identity", address=crypto.address, public_key=crypto.public_key
|
|
225
|
+
)
|
|
226
|
+
cert_request = CertRequest(
|
|
227
|
+
peer_public_key,
|
|
228
|
+
POR_DEFAULT_SERVICE_ID,
|
|
229
|
+
ledger_api_id,
|
|
230
|
+
LIBP2P_CERT_NOT_BEFORE,
|
|
231
|
+
LIBP2P_CERT_NOT_AFTER,
|
|
232
|
+
"{public_key}",
|
|
233
|
+
f"./{crypto.address}_cert.txt",
|
|
234
|
+
)
|
|
235
|
+
_process_cert(crypto, cert_request, path_prefix=data_dir)
|
|
236
|
+
configuration = ConnectionConfig(
|
|
237
|
+
tcp_key_file=None,
|
|
238
|
+
nodes=[
|
|
239
|
+
{
|
|
240
|
+
"uri": (
|
|
241
|
+
str(uri)
|
|
242
|
+
if uri is not None
|
|
243
|
+
else "{}:{}".format(node_host, node_port)
|
|
244
|
+
),
|
|
245
|
+
"public_key": peer_public_key,
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
connection_id=P2PLibp2pMailboxConnection.connection_id,
|
|
249
|
+
cert_requests=[cert_request],
|
|
250
|
+
)
|
|
251
|
+
return P2PLibp2pMailboxConnection(
|
|
252
|
+
configuration=configuration, data_dir=data_dir, identity=identity
|
|
253
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# ------------------------------------------------------------------------------
|
|
3
|
+
#
|
|
4
|
+
# Copyright 2018-2021 Fetch.AI Limited
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
#
|
|
18
|
+
# ------------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
"""This module contains the implementation of `benchmark` cli command."""
|