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
7e86e199
Commit
7e86e199
authored
Jan 08, 2026
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean
parent
c89091fc
Pipeline
#42464
passed with stages
in 51 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
29 deletions
+13
-29
rustfmt.toml
rustfmt.toml
+1
-1
src/router.rs
src/router.rs
+12
-28
No files found.
rustfmt.toml
View file @
7e86e199
max_width
=
180
\ No newline at end of file
max_width
=
200
\ No newline at end of file
src/router.rs
View file @
7e86e199
...
...
@@ -51,14 +51,6 @@ impl Router {
last_update
:
Instant
::
now
(),
addr
:
None
,
}
// router.reset(all_router_ids);
// router
}
pub
fn
reset
(
&
mut
self
)
{
for
(
to
,
via
)
in
self
.via
.iter_mut
()
{
*
via
=
*
to
;
}
}
pub
fn
online
(
&
mut
self
,
addr
:
SocketAddr
,
now
:
Instant
)
{
...
...
@@ -80,7 +72,7 @@ impl Router {
self
.addr
.is_some
()
}
pub
fn
apply_peers
(
&
mut
self
,
uplink
:
&
mut
Uplink
)
{
pub
fn
on_message
(
&
mut
self
,
uplink
:
&
mut
Uplink
,
addr
:
SocketAddr
,
updating
:
&
mut
UpdatingState
,
now
:
Instant
)
->
Option
<
Downlink
>
{
if
uplink
.peers
.len
()
==
self
.peers
.len
()
{
for
(
current
,
new
)
in
self
.peers
.values_mut
()
.zip
(
&
mut
uplink
.peers
)
{
*
current
=
*
new
...
...
@@ -88,23 +80,20 @@ impl Router {
}
else
if
uplink
.peers
.len
()
!=
0
{
tracing
::
error!
(
"router {} peers count wrong. local {} remote {}"
,
self
.id
,
self
.peers
.len
(),
uplink
.peers
.len
());
}
}
pub
fn
on_message
(
&
mut
self
,
uplink
:
&
mut
Uplink
,
addr
:
SocketAddr
,
updating
:
&
mut
UpdatingState
,
now
:
Instant
)
->
Option
<
Downlink
>
{
match
uplink
.action
{
MessageType
::
Query
=>
{
self
.apply_peers
(
uplink
);
Some
(
Downlink
{
action
:
MessageType
::
Full
,
version
:
self
.version
,
ack
:
uplink
.version
,
via
:
self
.via
.iter
()
.filter
(|(
k
,
v
)|
k
!=
v
)
.map
(|(
&
k
,
&
v
)|
(
k
,
v
))
.collect
(),
plan
:
self
.plan
.clone
(),
})
}
MessageType
::
Query
=>
Some
(
Downlink
{
action
:
MessageType
::
Full
,
version
:
self
.version
,
ack
:
uplink
.version
,
via
:
self
.via
.iter
()
.filter
(|(
k
,
v
)|
k
!=
v
)
.map
(|(
&
k
,
&
v
)|
(
k
,
v
))
.collect
(),
plan
:
self
.plan
.clone
(),
}),
MessageType
::
Full
=>
{
if
uplink
.version
==
self
.version
{
self
.reset
();
for
(
to
,
via
)
in
self
.via
.iter_mut
()
{
*
via
=
*
to
;
}
self
.via
.append
(
&
mut
uplink
.via
);
self
.plan
.append
(
&
mut
uplink
.plan
);
self
.online
(
addr
,
now
);
...
...
@@ -112,7 +101,6 @@ impl Router {
None
}
MessageType
::
Update
=>
{
self
.apply_peers
(
uplink
);
if
uplink
.version
==
self
.version
{
self
.online
(
addr
,
now
);
if
updating
.router_id
==
self
.id
{
...
...
@@ -140,12 +128,8 @@ impl Router {
}
}
pub
fn
penalty
(
&
self
,
now
:
Instant
)
->
i32
{
PENALTY_MIN
+
(
PENALTY
as
f32
*
f32
::
exp2
(
-
now
.duration_since
(
self
.last_update
)
.div_duration_f32
(
HALF_LIFE
)))
as
i32
}
pub
fn
update
(
&
self
,
now
:
Instant
,
routers
:
&
BTreeMap
<
u8
,
Router
>
,
connections
:
&
BTreeMap
<
u8
,
BTreeMap
<
u8
,
ConnectionData
>>
)
->
Option
<
Downlink
>
{
let
penalty
=
self
.penalty
(
now
)
;
let
penalty
=
PENALTY_MIN
+
(
PENALTY
as
f32
*
f32
::
exp2
(
-
now
.duration_since
(
self
.last_update
)
.div_duration_f32
(
HALF_LIFE
)))
as
i32
;
let
mut
changed_via
:
BTreeMap
<
u8
,
u8
>
=
BTreeMap
::
new
();
// let mut metric: BTreeMap<u8, i32> = BTreeMap::new();
let
mut
overcome
=
false
;
...
...
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