Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
matograine
silkaj
Commits
27798a06
Commit
27798a06
authored
Mar 19, 2019
by
Moul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[mod] #157: net: use for x in y, and rename endpoint to info
parent
bcc46437
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
36 deletions
+34
-36
silkaj/commands.py
silkaj/commands.py
+34
-36
No files found.
silkaj/commands.py
View file @
27798a06
...
...
@@ -174,83 +174,81 @@ async def network_info(discover, sort):
message_exit
(
"Wide screen need to be larger than 146. Current width: "
+
str
(
width
))
# discover peers
# and make sure fields are always ordered the same
endpoint
s
=
[
info
s
=
[
OrderedDict
(
(
i
,
p
.
get
(
i
,
None
))
for
i
in
(
"domain"
,
"port"
,
"ip4"
,
"ip6"
,
"pubkey"
)
)
for
p
in
await
discover_peers
(
discover
)
]
# Todo : renommer endpoints en info
client
=
ClientInstance
().
client
diffi
=
await
client
(
blockchain
.
difficulties
)
i
,
members
=
0
,
0
print
(
"Getting informations about nodes:"
)
while
i
<
len
(
endpoints
)
:
ep
=
endpoints
[
i
]
for
info
in
infos
:
ep
=
info
api
=
"BASIC_MERKLED_API "
if
ep
[
"port"
]
!=
"443"
else
"BMAS "
api
+=
ep
.
get
(
"domain"
)
+
" "
if
ep
[
"domain"
]
else
""
api
+=
ep
.
get
(
"ip4"
)
+
" "
if
ep
[
"ip4"
]
else
""
api
+=
ep
.
get
(
"ip6"
)
+
" "
if
ep
[
"ip6"
]
else
""
api
+=
ep
.
get
(
"port"
)
print
(
"{0:.0f}%"
.
format
(
i
/
len
(
endpoint
s
)
*
100
,
1
),
end
=
" "
)
best_ep
=
best_node
(
endpoints
[
i
]
,
False
)
print
(
best_ep
if
best_ep
is
None
else
endpoints
[
i
]
[
best_ep
],
end
=
" "
)
print
(
endpoints
[
i
]
[
"port"
])
print
(
"{0:.0f}%"
.
format
(
i
/
len
(
info
s
)
*
100
,
1
),
end
=
" "
)
best_ep
=
best_node
(
info
,
False
)
print
(
best_ep
if
best_ep
is
None
else
info
[
best_ep
],
end
=
" "
)
print
(
info
[
"port"
])
try
:
endpoints
[
i
]
[
"uid"
]
=
await
get_uid_from_pubkey
(
ep
,
endpoints
[
i
]
[
"pubkey"
])
if
endpoints
[
i
]
[
"uid"
]
is
NO_MATCHING_ID
:
endpoints
[
i
]
[
"uid"
]
=
None
info
[
"uid"
]
=
await
get_uid_from_pubkey
(
ep
,
info
[
"pubkey"
])
if
info
[
"uid"
]
is
NO_MATCHING_ID
:
info
[
"uid"
]
=
None
else
:
endpoints
[
i
]
[
"member"
]
=
"yes"
info
[
"member"
]
=
"yes"
members
+=
1
except
:
pass
if
endpoints
[
i
]
.
get
(
"member"
)
is
None
:
endpoints
[
i
]
[
"member"
]
=
"no"
endpoints
[
i
]
[
"pubkey"
]
=
endpoints
[
i
]
[
"pubkey"
][:
5
]
+
"…"
if
info
.
get
(
"member"
)
is
None
:
info
[
"member"
]
=
"no"
info
[
"pubkey"
]
=
info
[
"pubkey"
][:
5
]
+
"…"
for
d
in
diffi
[
"levels"
]:
if
endpoints
[
i
]
.
get
(
"uid"
)
is
not
None
:
if
endpoints
[
i
]
[
"uid"
]
==
d
[
"uid"
]:
endpoints
[
i
]
[
"diffi"
]
=
d
[
"level"
]
if
len
(
endpoints
[
i
]
[
"uid"
])
>
10
:
endpoints
[
i
][
"uid"
]
=
endpoints
[
i
]
[
"uid"
][:
9
]
+
"…"
if
info
.
get
(
"uid"
)
is
not
None
:
if
info
[
"uid"
]
==
d
[
"uid"
]:
info
[
"diffi"
]
=
d
[
"level"
]
if
len
(
info
[
"uid"
])
>
10
:
info
[
"uid"
]
=
info
[
"uid"
][:
9
]
+
"…"
sub_client
=
Client
(
api
)
current_blk
=
await
sub_client
(
blockchain
.
current
)
if
current_blk
is
not
None
:
endpoints
[
i
]
[
"gen_time"
]
=
convert_time
(
current_blk
[
"time"
],
"hour"
)
info
[
"gen_time"
]
=
convert_time
(
current_blk
[
"time"
],
"hour"
)
if
width
>
171
:
endpoints
[
i
]
[
"mediantime"
]
=
convert_time
(
info
[
"mediantime"
]
=
convert_time
(
current_blk
[
"medianTime"
],
"hour"
)
if
width
>
185
:
endpoints
[
i
]
[
"difftime"
]
=
convert_time
(
info
[
"difftime"
]
=
convert_time
(
current_blk
[
"time"
]
-
current_blk
[
"medianTime"
],
"hour"
)
endpoints
[
i
]
[
"block"
]
=
current_blk
[
"number"
]
endpoints
[
i
]
[
"hash"
]
=
current_blk
[
"hash"
][:
10
]
+
"…"
info
[
"block"
]
=
current_blk
[
"number"
]
info
[
"hash"
]
=
current_blk
[
"hash"
][:
10
]
+
"…"
summary
=
await
sub_client
(
node
.
summary
)
endpoints
[
i
]
[
"version"
]
=
summary
[
"duniter"
][
"version"
]
info
[
"version"
]
=
summary
[
"duniter"
][
"version"
]
await
sub_client
.
close
()
if
endpoints
[
i
]
.
get
(
"domain"
)
is
not
None
and
len
(
endpoints
[
i
]
[
"domain"
])
>
20
:
endpoints
[
i
]
[
"domain"
]
=
"…"
+
endpoints
[
i
]
[
"domain"
][
-
20
:]
if
endpoints
[
i
]
.
get
(
"ip6"
)
is
not
None
:
if
info
.
get
(
"domain"
)
is
not
None
and
len
(
info
[
"domain"
])
>
20
:
info
[
"domain"
]
=
"…"
+
info
[
"domain"
][
-
20
:]
if
info
.
get
(
"ip6"
)
is
not
None
:
if
width
<
156
:
endpoints
[
i
]
.
pop
(
"ip6"
)
info
.
pop
(
"ip6"
)
else
:
endpoints
[
i
][
"ip6"
]
=
endpoints
[
i
][
"ip6"
][:
8
]
+
"…"
i
+=
1
info
[
"ip6"
]
=
info
[
"ip6"
][:
8
]
+
"…"
await
client
.
close
()
print
(
len
(
endpoint
s
),
len
(
info
s
),
"peers ups, with"
,
members
,
"members and"
,
len
(
endpoint
s
)
-
members
,
len
(
info
s
)
-
members
,
"non-members at"
,
datetime
.
now
().
strftime
(
"%H:%M:%S"
),
)
endpoint
s
=
sorted
(
endpoint
s
,
key
=
get_network_sort_key
)
print
(
tabulate
(
endpoint
s
,
headers
=
"keys"
,
tablefmt
=
"orgtbl"
,
stralign
=
"center"
))
info
s
=
sorted
(
info
s
,
key
=
get_network_sort_key
)
print
(
tabulate
(
info
s
,
headers
=
"keys"
,
tablefmt
=
"orgtbl"
,
stralign
=
"center"
))
@
command
(
"blocks"
,
help
=
"Display blocks: default: 0 for current window size"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment