Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
27c038c6
Commit
27c038c6
authored
7 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[tui] add url in connections view
parent
71eb99c0
No related branches found
No related tags found
1 merge request
!58
Resolve "Add crates blockchain, conf, core, dal, message, module, network, tui and ws2p"
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
network/lib.rs
+7
-1
7 additions, 1 deletion
network/lib.rs
network/network_endpoint.rs
+6
-2
6 additions, 2 deletions
network/network_endpoint.rs
tui/lib.rs
+34
-81
34 additions, 81 deletions
tui/lib.rs
with
47 additions
and
84 deletions
network/lib.rs
+
7
−
1
View file @
27c038c6
...
...
@@ -99,6 +99,12 @@ impl NodeFullId {
sha256
.input_str
(
&
format!
(
"{}"
,
self
));
Hash
::
from_hex
(
&
sha256
.result_str
())
.unwrap
()
}
/// To human string
pub
fn
to_human_string
(
&
self
)
->
String
{
let
mut
pubkey_string
=
self
.1
.to_string
();
pubkey_string
.truncate
(
8
);
format!
(
"{:8x}-{:8}"
,
(
self
.0
)
.0
,
pubkey_string
)
}
}
/// Trait to be implemented by the configuration object of the module managing the inter-node network.
...
...
@@ -267,7 +273,7 @@ pub enum NetworkEvent {
/// Receiving a response to a network request
ReqResponse
(
Box
<
NetworkResponse
>
),
/// A connection has changed state(`u32` is the new state, `Option<String>` est l'uid du noeud)
ConnectionStateChange
(
NodeFullId
,
u32
,
Option
<
String
>
),
ConnectionStateChange
(
NodeFullId
,
u32
,
Option
<
String
>
,
String
),
/// Receiving Pending Documents
ReceiveDocuments
(
Vec
<
NetworkDocument
>
),
/// Receipt of peer cards
...
...
This diff is collapsed.
Click to expand it.
network/network_endpoint.rs
+
6
−
2
View file @
27c038c6
...
...
@@ -150,7 +150,7 @@ impl NetworkEndpoint {
}
}
/// Generate endpoint url
pub
fn
get_url
(
&
self
)
->
String
{
pub
fn
get_url
(
&
self
,
get_protocol
:
bool
)
->
String
{
match
*
self
{
NetworkEndpoint
::
V1
(
ref
ep
)
=>
{
let
protocol
=
match
&
ep
.api
.0
[
..
]
{
...
...
@@ -165,7 +165,11 @@ impl NetworkEndpoint {
Some
(
ref
path_string
)
=>
path_string
.clone
(),
None
=>
String
::
new
(),
};
if
get_protocol
{
format!
(
"{}{}://{}:{}/{}"
,
protocol
,
tls
,
ep
.host
,
ep
.port
,
path
)
}
else
{
format!
(
"{}:{}/{}"
,
ep
.host
,
ep
.port
,
path
)
}
}
_
=>
panic!
(
"Endpoint version is not supported !"
),
}
...
...
This diff is collapsed.
Click to expand it.
tui/lib.rs
+
34
−
81
View file @
27c038c6
...
...
@@ -72,8 +72,10 @@ pub struct TuiModule {}
#[derive(Debug,
Clone)]
/// Network connexion (data to display)
pub
struct
Connection
{
///
c
onnexion status
///
C
onnexion status
status
:
u32
,
/// Endpoint url
url
:
String
,
/// Node uid at the other end of the connection (member nodes only)
uid
:
Option
<
String
>
,
}
...
...
@@ -91,8 +93,6 @@ pub struct TuiModuleDatas {
pub
connections_status
:
HashMap
<
NodeFullId
,
Connection
>
,
/// Number of connections in `Established` status
pub
established_conns_count
:
usize
,
/// Position of the 1st connection displayed on the screen
pub
conns_index
:
usize
,
}
impl
TuiModuleDatas
{
...
...
@@ -109,7 +109,6 @@ impl TuiModuleDatas {
heads_index
:
usize
,
out_connections_status
:
&
HashMap
<
NodeFullId
,
Connection
>
,
_in_connections_status
:
&
HashMap
<
NodeFullId
,
Connection
>
,
conns_index
:
usize
,
)
{
// Get Terminal size
let
(
w
,
h
)
=
termion
::
terminal_size
()
.expect
(
"Fail to get terminal size !"
);
...
...
@@ -128,7 +127,11 @@ impl TuiModuleDatas {
1
|
3
|
5
|
7
|
8
|
9
=>
out_trying_conns_count
+=
1
,
10
=>
out_denial_conns_count
+=
1
,
11
=>
out_disconnected_conns_count
+=
1
,
12
=>
out_established_conns
.push
((
node_full_id
,
connection
.uid
.clone
())),
12
=>
out_established_conns
.push
((
node_full_id
,
connection
.uid
.clone
(),
connection
.url
.clone
(),
)),
_
=>
{}
}
}
...
...
@@ -168,13 +171,6 @@ impl TuiModuleDatas {
color
::
Fg
(
color
::
White
),
style
::
Italic
,
)
.unwrap
();
line
+=
1
;
write!
(
stdout
,
"{}{}/
\\
"
,
cursor
::
Goto
(
29
,
line
),
color
::
Fg
(
color
::
Black
),
)
.unwrap
();
// Draw inter-nodes established connections
if
out_established_conns
.is_empty
()
{
...
...
@@ -187,38 +183,19 @@ impl TuiModuleDatas {
style
::
Bold
,
)
.unwrap
();
}
else
{
let
mut
count_conns
=
0
;
let
max_index
=
if
out_established_conns
.len
()
<
5
{
0
}
else
{
out_established_conns
.len
()
-
5
};
let
conns_index_use
=
if
conns_index
>
max_index
{
max_index
}
else
{
conns_index
};
for
&
(
node_full_id
,
ref
uid
)
in
&
out_established_conns
[
conns_index_use
..
]
{
for
(
ref
node_full_id
,
ref
uid
,
ref
url
)
in
out_established_conns
{
line
+=
1
;
count_conns
+=
1
;
let
mut
uid_string
=
uid
.clone
()
.unwrap_or
(
String
::
from
(
"----------------"
));
uid_string
.truncate
(
16
);
write!
(
stdout
,
"{}{} {} {}"
,
"{}{} {}
{:16}
{}"
,
cursor
::
Goto
(
2
,
line
),
color
::
Fg
(
color
::
Green
),
node_full_id
,
uid
.clone
()
.unwrap_or_else
(
String
::
new
),
)
.unwrap
();
if
count_conns
==
5
{
line
+=
1
;
write!
(
stdout
,
"{}{}
\\
/"
,
cursor
::
Goto
(
29
,
line
),
color
::
Fg
(
color
::
Black
)
node_full_id
.to_human_string
(),
uid_string
,
url
,
)
.unwrap
();
break
;
}
}
}
...
...
@@ -405,7 +382,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
heads_index
:
0
,
connections_status
:
HashMap
::
new
(),
established_conns_count
:
0
,
conns_index
:
0
,
};
// Create tui main thread channel
...
...
@@ -463,7 +439,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
tui
.heads_index
,
&
tui
.connections_status
,
&
HashMap
::
with_capacity
(
0
),
tui
.conns_index
,
);
// Launch stdin thread
...
...
@@ -529,8 +504,9 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
ref
node_full_id
,
ref
status
,
ref
uid
,
ref
url
,
)
=>
{
if
let
Some
(
conn
)
=
tui
.connections_status
.get
(
node_full_id
)
{
if
let
Some
(
conn
)
=
tui
.connections_status
.get
(
&
node_full_id
)
{
if
*
status
==
12
&&
(
*
conn
)
.status
!=
12
{
tui
.established_conns_count
+=
1
;
}
else
if
*
status
!=
12
...
...
@@ -544,6 +520,7 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
*
node_full_id
,
Connection
{
status
:
*
status
,
url
:
url
.clone
(),
uid
:
uid
.clone
(),
},
);
...
...
@@ -581,25 +558,11 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
break
;
}
&
Event
::
Mouse
(
ref
me
)
=>
match
me
{
&
MouseEvent
::
Press
(
ref
button
,
ref
_a
,
ref
b
)
=>
match
button
{
&
MouseEvent
::
Press
(
ref
button
,
ref
_a
,
ref
_
b
)
=>
match
button
{
&
MouseButton
::
WheelDown
=>
{
// Get Terminal size
let
(
_w
,
h
)
=
termion
::
terminal_size
()
.expect
(
"Fail to get terminal size !"
);
if
*
b
<
11
{
// conns_index
let
conns_index_max
=
if
tui
.established_conns_count
>
5
{
tui
.established_conns_count
-
5
}
else
{
0
};
if
tui
.heads_index
<
conns_index_max
{
tui
.conns_index
+=
1
;
user_event
=
true
;
}
else
{
tui
.conns_index
=
conns_index_max
;
}
}
else
{
// heads_index
if
h
>
16
{
let
heads_index_max
=
...
...
@@ -616,22 +579,13 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
}
}
}
}
&
MouseButton
::
WheelUp
=>
{
if
*
b
<
11
{
// conns_index
if
tui
.conns_index
>
0
{
tui
.conns_index
-=
1
;
user_event
=
true
;
}
}
else
{
// heads_index
if
tui
.heads_index
>
0
{
tui
.heads_index
-=
1
;
user_event
=
true
;
}
}
}
_
=>
{}
},
&
MouseEvent
::
Release
(
ref
_a
,
ref
_b
)
...
...
@@ -662,7 +616,6 @@ impl DuniterModule<ed25519::KeyPair, DuniterMessage> for TuiModule {
tui
.heads_index
,
&
tui
.connections_status
,
&
HashMap
::
with_capacity
(
0
),
tui
.conns_index
,
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment