Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
railgun-routing-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
railgun-routing-server
Commits
4c5c1cd4
Commit
4c5c1cd4
authored
Aug 27, 2022
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
98bdb218
Pipeline
#16067
passed with stages
in 2 minutes and 18 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
54 deletions
+53
-54
web/src/app/api.service.ts
web/src/app/api.service.ts
+20
-8
web/src/app/app.component.ts
web/src/app/app.component.ts
+15
-16
web/src/app/dashboard/dashboard.component.html
web/src/app/dashboard/dashboard.component.html
+2
-2
web/src/app/dashboard/dashboard.component.ts
web/src/app/dashboard/dashboard.component.ts
+15
-27
web/tsconfig.json
web/tsconfig.json
+1
-1
No files found.
web/src/app/api.service.ts
View file @
4c5c1cd4
...
@@ -3,18 +3,19 @@ import { HttpClient } from '@angular/common/http';
...
@@ -3,18 +3,19 @@ import { HttpClient } from '@angular/common/http';
import
{
firstValueFrom
,
mergeMap
,
timer
}
from
'
rxjs
'
;
import
{
firstValueFrom
,
mergeMap
,
timer
}
from
'
rxjs
'
;
@
Injectable
({
@
Injectable
({
providedIn
:
'
root
'
,
providedIn
:
'
root
'
})
})
export
class
ApiService
{
export
class
ApiService
{
routers
!
:
any
[];
routers
!
:
any
[];
connections
!
:
Record
<
number
,
Record
<
number
,
any
>>
;
connections
!
:
Record
<
number
,
Record
<
number
,
Connection
>>
;
constructor
(
private
http
:
HttpClient
)
{
constructor
(
private
http
:
HttpClient
)
{
}
}
async
init
()
{
async
init
()
{
this
.
routers
=
await
firstValueFrom
(
this
.
http
.
get
<
any
[]
>
(
'
http://10.198.0.7:500/api/routers
'
));
this
.
connections
=
await
firstValueFrom
(
this
.
http
.
get
<
Record
<
number
,
Record
<
number
,
Connection
>>>
(
'
http://10.198.0.7:500/api/connections
'
));
this
.
connections
=
await
firstValueFrom
(
this
.
http
.
get
<
Record
<
number
,
Record
<
number
,
any
>>>
(
'
http://10.198.0.7:500/api/routers
'
));
this
.
routers
=
await
firstValueFrom
(
this
.
http
.
get
<
RouterStatus
[]
>
(
'
http://10.198.0.7:500/api/routers
'
));
console
.
log
(
console
.
log
(
this
.
routers
this
.
routers
...
@@ -23,7 +24,7 @@ export class ApiService {
...
@@ -23,7 +24,7 @@ export class ApiService {
Host
:
item
.
name
,
Host
:
item
.
name
,
HostName
:
item
.
host
,
HostName
:
item
.
host
,
User
:
item
.
user
,
User
:
item
.
user
,
Port
:
item
.
sshPort
,
Port
:
item
.
sshPort
})
})
.
filter
(([
key
,
value
])
=>
value
)
.
filter
(([
key
,
value
])
=>
value
)
.
map
((
line
)
=>
line
.
join
(
'
'
))
.
map
((
line
)
=>
line
.
join
(
'
'
))
...
@@ -43,9 +44,6 @@ export class ApiService {
...
@@ -43,9 +44,6 @@ export class ApiService {
export
interface
RouterStatus
{
export
interface
RouterStatus
{
id
:
number
,
id
:
number
,
name
:
string
,
address
:
string
,
location
:
string
,
peers
:
Record
<
number
,
PeerQuality
>
,
peers
:
Record
<
number
,
PeerQuality
>
,
via
:
Record
<
number
,
number
>
via
:
Record
<
number
,
number
>
}
}
...
@@ -56,6 +54,20 @@ export interface PeerQuality {
...
@@ -56,6 +54,20 @@ export interface PeerQuality {
reliability
:
number
;
reliability
:
number
;
}
}
export
interface
Router
{
id
:
number
;
name
:
string
;
location
:
string
;
host
:
string
;
port
:
number
;
user
:
string
;
}
export
interface
Connection
{
metric
:
number
;
protocol
:
string
;
}
// const connected: Record<number, Record<number, string>> = {};
// const connected: Record<number, Record<number, string>> = {};
// for (const from of data) {
// for (const from of data) {
// if (!connected[from.id]) connected[from.id] = {}
// if (!connected[from.id]) connected[from.id] = {}
...
...
web/src/app/app.component.ts
View file @
4c5c1cd4
...
@@ -15,21 +15,20 @@ export class AppComponent implements OnInit {
...
@@ -15,21 +15,20 @@ export class AppComponent implements OnInit {
async
ngOnInit
()
{
async
ngOnInit
()
{
await
this
.
api
.
init
();
await
this
.
api
.
init
();
const
protos
=
[];
// const protos = [];
const
routers
=
this
.
api
.
routers
;
// for (const from of this.api.routers) {
for
(
const
from
of
routers
)
{
// for (const [id1, peer] of Object.entries(from.peers)) {
for
(
const
[
id1
,
peer
]
of
Object
.
entries
(
from
.
peers
))
{
// const id = parseInt(id1);
const
id
=
parseInt
(
id1
);
// const reverse = this.api.routers.find(r => r.id === id)?.peers?.[from.id];
const
reverse
=
routers
.
find
(
r
=>
r
.
id
===
id
)?.
peers
?.[
from
.
id
];
// if (!reverse) continue;
if
(
!
reverse
)
continue
;
// const link = this.api.connections[from.id][id];
const
link
=
this
.
api
.
connections
[
from
.
id
][
id
];
// if (!link) continue;
if
(
!
link
)
continue
;
// // @ts-ignore
// @ts-ignore
// if (peer.reliability * reverse.reliability <= 0.01) {
if
(
peer
.
reliability
*
reverse
.
reliability
<=
0.01
)
{
// protos.push(link.proto);
protos
.
push
(
link
.
proto
);
// }
}
// }
}
// }
}
// console.log(_.groupBy(protos));
console
.
log
(
_
.
groupBy
(
protos
));
}
}
}
}
web/src/app/dashboard/dashboard.component.html
View file @
4c5c1cd4
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
</mat-card-title>
</mat-card-title>
</mat-card-header>
</mat-card-header>
<mat-card-content>
<mat-card-content>
<table
mat-table
[dataSource]=
"links"
*ngIf=
"routers"
fixedLayout
[trackBy]=
"trackById"
>
<table
mat-table
[dataSource]=
"links"
*ngIf=
"
api.
routers"
fixedLayout
[trackBy]=
"trackById"
>
<ng-container
matColumnDef=
"name"
>
<ng-container
matColumnDef=
"name"
>
<th
mat-header-cell
*matHeaderCellDef
>
name
</th>
<th
mat-header-cell
*matHeaderCellDef
>
name
</th>
<td
mat-cell
*matCellDef=
"let element"
>
{{element.name}}
</td>
<td
mat-cell
*matCellDef=
"let element"
>
{{element.name}}
</td>
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
<th
mat-header-cell
*matHeaderCellDef
>
id
</th>
<th
mat-header-cell
*matHeaderCellDef
>
id
</th>
<td
mat-cell
*matCellDef=
"let element"
>
{{element.id}}
</td>
<td
mat-cell
*matCellDef=
"let element"
>
{{element.id}}
</td>
</ng-container>
</ng-container>
<ng-container
*ngFor=
"let router of routers"
>
<ng-container
*ngFor=
"let router of
api.
routers"
>
<ng-container
[matColumnDef]=
"router.name"
>
<ng-container
[matColumnDef]=
"router.name"
>
<th
mat-header-cell
*matHeaderCellDef
><span
class=
"id"
>
{{router.id}}
</span><span
<th
mat-header-cell
*matHeaderCellDef
><span
class=
"id"
>
{{router.id}}
</span><span
class=
"head"
>
{{router.name}}
</span></th>
class=
"head"
>
{{router.name}}
</span></th>
...
...
web/src/app/dashboard/dashboard.component.ts
View file @
4c5c1cd4
import
{
Component
,
OnInit
}
from
'
@angular/core
'
;
import
{
Component
,
OnInit
}
from
'
@angular/core
'
;
import
{
map
}
from
'
rxjs/operators
'
;
import
{
map
}
from
'
rxjs/operators
'
;
import
{
ApiService
,
RouterStatus
}
from
"
../api.service
"
;
import
{
ApiService
,
RouterStatus
}
from
'
../api.service
'
;
import
*
as
_
from
"
lodash-es
"
;
import
*
as
_
from
'
lodash-es
'
;
import
{
firstValueFrom
}
from
"
rxjs
"
;
import
{
Quality
}
from
'
../Quality
'
;
import
{
Quality
}
from
"
../Quality
"
;
@
Component
({
@
Component
({
selector
:
'
app-dashboard
'
,
selector
:
'
app-dashboard
'
,
templateUrl
:
'
./dashboard.component.html
'
,
templateUrl
:
'
./dashboard.component.html
'
,
styleUrls
:
[
'
./dashboard.component.scss
'
]
,
styleUrls
:
[
'
./dashboard.component.scss
'
]
// changeDetection: ChangeDetectionStrategy.OnPush
// changeDetection: ChangeDetectionStrategy.OnPush
})
})
export
class
DashboardComponent
implements
OnInit
{
export
class
DashboardComponent
implements
OnInit
{
routers
:
RouterStatus
[]
=
[];
//
routers: RouterStatus[] = [];
displayedColumns
:
string
[]
=
[];
displayedColumns
:
string
[]
=
[];
links
=
this
.
api
.
state
().
pipe
(
links
=
this
.
api
.
state
().
pipe
(
map
(
routers
=>
routers
.
map
(
router
=>
map
(
routers
=>
routers
.
map
(
router
=>
({
({
id
:
router
.
id
,
id
:
router
.
id
,
name
:
router
.
name
,
name
:
this
.
api
.
routers
.
find
(
r
=>
r
.
id
==
router
.
id
)
!
.
name
,
peers
:
_
.
mapValues
(
router
.
peers
,
(
quality
,
id1
)
=>
this
.
displayQuality
(
routers
,
router
,
parseInt
(
id1
)))
peers
:
_
.
mapValues
(
router
.
peers
,
(
quality
,
id1
)
=>
this
.
displayQuality
(
routers
,
router
,
parseInt
(
id1
)))
})
})
))
))
);
);
routed
=
false
;
routed
=
false
;
constructor
(
p
rivate
api
:
ApiService
)
{
constructor
(
p
ublic
api
:
ApiService
)
{
}
}
displayQuality
(
routers
:
RouterStatus
[],
from
:
RouterStatus
,
toId
:
number
)
{
displayQuality
(
routers
:
RouterStatus
[],
from
:
RouterStatus
,
toId
:
number
)
{
...
@@ -45,7 +44,8 @@ export class DashboardComponent implements OnInit {
...
@@ -45,7 +44,8 @@ export class DashboardComponent implements OnInit {
decoration
:
quality
.
hop
<=
2
?
''
:
`underline hsl(
${
this
.
mapNumber
(
quality
.
hop
,
4
,
8
,
120
,
0
)}
, 100%, 40%)`
decoration
:
quality
.
hop
<=
2
?
''
:
`underline hsl(
${
this
.
mapNumber
(
quality
.
hop
,
4
,
8
,
120
,
0
)}
, 100%, 40%)`
};
};
}
else
{
}
else
{
const
link
=
this
.
api
.
link
(
from
.
id
,
toId
);
const
link
=
this
.
api
.
connections
[
from
.
id
]?.[
toId
];
console
.
log
(
link
);
if
(
!
link
)
return
;
if
(
!
link
)
return
;
if
(
!
to
.
peers
[
from
.
id
])
return
;
if
(
!
to
.
peers
[
from
.
id
])
return
;
...
@@ -56,35 +56,23 @@ export class DashboardComponent implements OnInit {
...
@@ -56,35 +56,23 @@ export class DashboardComponent implements OnInit {
const
decorations
:
Record
<
string
,
string
>
=
{
const
decorations
:
Record
<
string
,
string
>
=
{
oc
:
'
underline blue
'
,
oc
:
'
underline blue
'
,
wg
:
'
underline red
'
,
wg
:
'
underline red
'
,
tun
:
'
underline greed
'
,
tun
:
'
underline greed
'
}
}
;
return
{
return
{
delay
:
quality
.
reliability
<=
0.01
?
'
x
'
:
quality
.
delay
,
delay
:
quality
.
reliability
<=
0.01
?
'
x
'
:
quality
.
delay
,
color
:
`hsl(
${
this
.
mapNumber
(
quality
.
reliability
,
0.9
,
1
,
0
,
120
)}
, 100%, 40%)`
,
color
:
`hsl(
${
this
.
mapNumber
(
quality
.
reliability
,
0.9
,
1
,
0
,
120
)}
, 100%, 40%)`
,
decoration
:
decorations
[
link
.
split
(
'
,
'
)[
1
]
]
decoration
:
decorations
[
link
.
protocol
]
};
};
}
}
}
}
displayQuality2
(
router
:
RouterStatus
,
routers
:
RouterStatus
[])
{
return
{
name
:
router
.
name
,
peers
:
_
.
mapValues
(
router
.
peers
,
(
quality
,
id
)
=>
{
// const reverse = routers.find(r => r.id === parseInt(id))?.peers?.[router.id];
// if (!reverse) return undefined;
// return this.displayQuality2(quality, reverse);
})
}
}
mapNumber
(
value
:
number
,
minFrom
:
number
,
maxFrom
:
number
,
minTo
:
number
,
maxTo
:
number
)
{
mapNumber
(
value
:
number
,
minFrom
:
number
,
maxFrom
:
number
,
minTo
:
number
,
maxTo
:
number
)
{
return
minTo
+
(
maxTo
-
minTo
)
*
((
_
.
clamp
(
value
,
minFrom
,
maxFrom
)
-
minFrom
)
/
(
maxFrom
-
minFrom
));
return
minTo
+
(
maxTo
-
minTo
)
*
((
_
.
clamp
(
value
,
minFrom
,
maxFrom
)
-
minFrom
)
/
(
maxFrom
-
minFrom
));
}
}
async
ngOnInit
()
{
async
ngOnInit
()
{
this
.
routers
=
await
firstValueFrom
(
this
.
api
.
state
())
this
.
displayedColumns
=
[
'
name
'
,
'
id
'
].
concat
(
this
.
api
.
routers
.
map
(
r
=>
r
.
name
));
this
.
displayedColumns
=
[
'
name
'
,
'
id
'
].
concat
(
this
.
routers
.
map
(
r
=>
r
.
name
));
}
}
value
(
from
:
number
,
to
:
number
)
{
value
(
from
:
number
,
to
:
number
)
{
...
...
web/tsconfig.json
View file @
4c5c1cd4
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
"target"
:
"es2020"
,
"target"
:
"es2020"
,
"module"
:
"es2020"
,
"module"
:
"es2020"
,
"lib"
:
[
"lib"
:
[
"es202
2
"
,
"es202
1
"
,
"dom"
"dom"
]
]
},
},
...
...
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