Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ginkgo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
vjrj
ginkgo
Commits
c57f7092
Commit
c57f7092
authored
2 years ago
by
vjrj
Browse files
Options
Downloads
Patches
Plain Diff
Better parsing of network/peers
parent
f8b74005
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/g1/g1_helper.dart
+39
-32
39 additions, 32 deletions
lib/g1/g1_helper.dart
lib/g1/node_bloc.dart
+13
-11
13 additions, 11 deletions
lib/g1/node_bloc.dart
with
52 additions
and
43 deletions
lib/g1/g1_helper.dart
+
39
−
32
View file @
c57f7092
...
@@ -4,6 +4,8 @@ import 'dart:typed_data';
...
@@ -4,6 +4,8 @@ import 'dart:typed_data';
import
'package:durt/durt.dart'
;
import
'package:durt/durt.dart'
;
import
'../main.dart'
;
Random
createRandom
()
{
Random
createRandom
()
{
try
{
try
{
return
Random
.
secure
();
return
Random
.
secure
();
...
@@ -42,38 +44,43 @@ String generateSalt(int length) {
...
@@ -42,38 +44,43 @@ String generateSalt(int length) {
length
,
(
int
index
)
=
>
charset
[
random
.
nextInt
(
charset
.
length
)])
.
join
();
length
,
(
int
index
)
=
>
charset
[
random
.
nextInt
(
charset
.
length
)])
.
join
();
}
}
String
parseHost
(
String
endpointUnParsed
)
{
String
?
parseHost
(
String
endpointUnParsed
)
{
final
List
<
String
>
parts
=
endpointUnParsed
.
split
(
' '
);
try
{
// FIXME (vjrj): figure out if exists a way to detect http or https
final
List
<
String
>
parts
=
endpointUnParsed
.
split
(
' '
);
const
String
protocol
=
'https'
;
// FIXME (vjrj): figure out if exists a way to detect http or https
final
String
lastPart
=
parts
.
removeLast
();
const
String
protocol
=
'https'
;
String
path
=
final
String
lastPart
=
parts
.
removeLast
();
RegExp
(
r'^\/[a-zA-Z0-9\-\/]+$'
)
.
hasMatch
(
lastPart
)
?
lastPart
:
''
;
String
path
=
RegExp
(
r'^\/[a-zA-Z0-9\-\/]+$'
)
.
hasMatch
(
lastPart
)
?
lastPart
:
''
;
final
String
nextToLast
=
parts
[
parts
.
length
-
1
];
final
String
nextToLast
=
parts
[
parts
.
length
-
1
];
final
String
port
=
lastPart
==
''
final
String
port
=
lastPart
==
''
?
(
RegExp
(
r'^\/[0-9]$'
)
.
hasMatch
(
lastPart
)
?
lastPart
:
'443'
)
?
(
RegExp
(
r'^\/[0-9]$'
)
.
hasMatch
(
lastPart
)
?
lastPart
:
'443'
)
:
RegExp
(
r'^\/[0-9]$'
)
.
hasMatch
(
nextToLast
)
:
RegExp
(
r'^\/[0-9]$'
)
.
hasMatch
(
nextToLast
)
?
nextToLast
?
nextToLast
:
'443'
;
:
'443'
;
final
List
<
String
>
hostSplited
=
parts
[
1
]
.
split
(
'/'
);
final
List
<
String
>
hostSplited
=
parts
[
1
]
.
split
(
'/'
);
// Process hosts like monnaie-libre.ortie.org/bma/
// Process hosts like monnaie-libre.ortie.org/bma/
final
String
host
=
hostSplited
[
0
];
final
String
host
=
hostSplited
[
0
];
path
=
path
.
isEmpty
path
=
path
.
isEmpty
?
((
hostSplited
.
length
>
1
&&
hostSplited
[
1
]
.
isNotEmpty
?
((
hostSplited
.
length
>
1
&&
hostSplited
[
1
]
.
isNotEmpty
?
hostSplited
[
1
]
?
hostSplited
[
1
]
:
''
)
:
''
)
.
isNotEmpty
.
isNotEmpty
?
hostSplited
.
length
>
1
&&
hostSplited
[
1
]
.
isNotEmpty
?
hostSplited
.
length
>
1
&&
hostSplited
[
1
]
.
isNotEmpty
?
'/
${hostSplited[1]}
'
?
'/
${hostSplited[1]}
'
:
''
:
''
:
path
)
:
path
)
:
path
;
:
path
;
//final bool hasIp =
//final bool hasIp =
// RegExp(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}').hasMatch(parts[2]);
// RegExp(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}').hasMatch(parts[2]);
// final String port = hasIp ? parts[3] : parts[2];
// final String port = hasIp ? parts[3] : parts[2];
//final int pathIndex = hasIp ? 4 : 3;
//final int pathIndex = hasIp ? 4 : 3;
//final String path = parts.length > pathIndex ? parts[pathIndex] : '';
//final String path = parts.length > pathIndex ? parts[pathIndex] : '';
final
String
endpoint
=
'
$protocol
://
$host
:
$port$path
'
.
trim
();
final
String
endpoint
=
'
$protocol
://
$host
:
$port$path
'
.
trim
();
return
endpoint
;
return
endpoint
;
}
catch
(
e
)
{
logger
(
'Cannot parse endpoint
$endpointUnParsed
'
);
return
null
;
}
}
}
This diff is collapsed.
Click to expand it.
lib/g1/node_bloc.dart
+
13
−
11
View file @
c57f7092
...
@@ -120,19 +120,21 @@ class NodeBloc extends HydratedBloc<NodeEvent, NodeState> {
...
@@ -120,19 +120,21 @@ class NodeBloc extends HydratedBloc<NodeEvent, NodeState> {
for
(
int
j
=
0
;
j
<
endpoints
.
length
;
j
++
)
{
for
(
int
j
=
0
;
j
<
endpoints
.
length
;
j
++
)
{
if
(
endpoints
[
j
]
.
startsWith
(
'BMAS'
))
{
if
(
endpoints
[
j
]
.
startsWith
(
'BMAS'
))
{
final
String
endpointUnParsed
=
endpoints
[
j
];
final
String
endpointUnParsed
=
endpoints
[
j
];
final
String
endpoint
=
parseHost
(
endpointUnParsed
);
final
String
?
endpoint
=
parseHost
(
endpointUnParsed
);
final
Duration
latency
=
await
_pingNode
(
endpoint
);
if
(
endpoint
!=
null
)
{
if
(
fastestNode
==
null
||
latency
<
fastestLatency
)
{
final
Duration
latency
=
await
_pingNode
(
endpoint
);
fastestNode
=
endpoint
;
if
(
fastestNode
==
null
||
latency
<
fastestLatency
)
{
fastestLatency
=
latency
;
fastestNode
=
endpoint
;
if
(
!
kReleaseMode
)
{
fastestLatency
=
latency
;
logger
(
'Node bloc: Current faster node
$fastestNode
'
);
if
(
!
kReleaseMode
)
{
logger
(
'Node bloc: Current faster node
$fastestNode
'
);
}
}
}
final
Node
node
=
Node
(
url:
endpoint
,
latency:
latency
.
inSeconds
);
add
(
InsertNode
(
node:
node
));
nodes
.
insert
(
0
,
node
);
}
}
final
Node
node
=
Node
(
url:
endpoint
,
latency:
latency
.
inSeconds
);
add
(
InsertNode
(
node:
node
));
nodes
.
insert
(
0
,
node
);
}
}
}
}
}
}
...
...
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