Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
railgun-routing-client
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-client
Commits
02909afa
Commit
02909afa
authored
Jan 06, 2026
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
learn
parent
35667ab5
Pipeline
#42433
passed with stages
in 56 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
24 deletions
+11
-24
src/main.rs
src/main.rs
+2
-2
src/router.rs
src/router.rs
+4
-4
src/settings.rs
src/settings.rs
+5
-18
No files found.
src/main.rs
View file @
02909afa
...
...
@@ -3,7 +3,7 @@ use crate::data::Router as RouterData;
use
crate
::
protocol
::{
Hello
,
MessageType
,
Uplink
};
use
crate
::
router
::
Router
;
use
crate
::
server
::
Server
;
use
crate
::
settings
::{
Settings
,
INTERVAL
,
TIMEOUT
};
use
crate
::
settings
::{
Settings
,
INTERVAL
,
LEARN
};
use
config
::
Config
;
use
std
::
collections
::
BTreeMap
;
use
std
::
fs
;
...
...
@@ -85,7 +85,7 @@ async fn main() -> anyhow::Result<()> {
id
:
config
.id
,
action
:
if
server
.online
{
MessageType
::
Update
}
else
{
MessageType
::
Query
},
version
:
server
.version
,
peers
:
if
now
.duration_since
(
start
)
<
TIMEOUT
{
Default
::
default
()
}
else
{
connections
peers
:
if
now
.duration_since
(
start
)
<
LEARN
{
Default
::
default
()
}
else
{
connections
.iter
()
.filter
(|(
_
,
to
)|
to
.contains_key
(
&
config
.id
))
.map
(|(
from
,
_
)|
routers
.get_mut
(
from
)
.unwrap
()
.update
(
now
,
start
))
...
...
src/router.rs
View file @
02909afa
use
crate
::
data
::
Router
as
RouterData
;
use
crate
::
protocol
::{
Hello
,
PeerQuality
};
use
crate
::
settings
::{
Settings
,
INTERVAL
,
TIMEOUT
};
use
crate
::
settings
::{
Settings
,
INTERVAL
};
use
saturating_cast
::
SaturatingCast
;
use
std
::
collections
::
BTreeMap
;
use
std
::
net
::{
IpAddr
,
Ipv4Addr
,
SocketAddr
};
...
...
@@ -75,15 +75,15 @@ impl Router {
let
max
=
now
.duration_since
(
start
)
.div_duration_f32
(
INTERVAL
)
as
u32
;
let
reliability
=
if
max
<
64
{
(
reliability
as
u32
*
64
/
max
)
as
u8
}
else
{
reliability
};
let
duration
=
now
.duration_since
(
self
.local_time
);
if
duration
>
TIMEOUT
{
let
duration
=
now
.duration_since
(
self
.local_time
)
.div_duration_f32
(
INTERVAL
)
as
u32
;
if
duration
>
64
{
self
.receive
=
0
;
Default
::
default
()
}
else
{
PeerQuality
{
delay
:
self
.delay
.saturating_cast
(),
jitter
:
self
.jitter
.saturating_cast
(),
reliability
:
reliability
.saturating_sub
((
duration
.div_duration_f32
(
INTERVAL
)
as
u8
)
.saturating_sub
(
1
)),
reliability
:
reliability
.saturating_sub
((
duration
as
u8
)
.saturating_sub
(
1
)),
}
}
}
else
{
...
...
src/settings.rs
View file @
02909afa
use
hickory_resolver
::
Resolver
;
use
hickory_resolver
::
name_server
::
GenericConnector
;
use
hickory_resolver
::
proto
::
runtime
::
TokioRuntimeProvider
;
use
hickory_resolver
::
Resolver
;
use
netlink_packet_route
::
route
::
RouteProtocol
;
use
serde
::
Deserialize
;
use
std
::
net
::
SocketAddr
;
...
...
@@ -11,11 +11,6 @@ pub struct Settings {
pub
id
:
u8
,
pub
server
:
Endpoint
,
pub
bind
:
SocketAddr
,
// pub TIMEOUT: u32,
// pub history: usize,
// pub INTERVAL: u64,
// pub table: u16,
// pub proto: u16,
}
#[derive(Deserialize)]
...
...
@@ -34,9 +29,7 @@ impl TryFrom<String> for Endpoint {
return
Err
(
format!
(
"Invalid endpoint format: {}"
,
value
));
}
let
port
=
parts
[
0
]
.parse
::
<
u16
>
()
.map_err
(|
e
|
format!
(
"Invalid port: {}"
,
e
))
?
;
let
port
=
parts
[
0
]
.parse
::
<
u16
>
()
.map_err
(|
e
|
format!
(
"Invalid port: {}"
,
e
))
?
;
let
host
=
parts
[
1
]
.to_string
();
Ok
(
Endpoint
{
host
,
port
})
...
...
@@ -44,19 +37,13 @@ impl TryFrom<String> for Endpoint {
}
impl
Endpoint
{
pub
async
fn
to_socket_addrs
(
&
self
,
resolver
:
&
Resolver
<
GenericConnector
<
TokioRuntimeProvider
>>
,
)
->
anyhow
::
Result
<
SocketAddr
>
{
pub
async
fn
to_socket_addrs
(
&
self
,
resolver
:
&
Resolver
<
GenericConnector
<
TokioRuntimeProvider
>>
)
->
anyhow
::
Result
<
SocketAddr
>
{
let
lookup
=
resolver
.lookup_ip
(
&
self
.host
)
.await
?
;
let
ip
=
lookup
.into_iter
()
.next
()
.ok_or_else
(||
anyhow
::
anyhow!
(
"No IP address found for host"
))
?
;
let
ip
=
lookup
.into_iter
()
.next
()
.ok_or_else
(||
anyhow
::
anyhow!
(
"No IP address found for host"
))
?
;
Ok
(
SocketAddr
::
new
(
ip
,
self
.port
))
}
}
pub
const
INTERVAL
:
Duration
=
Duration
::
from_secs
(
1
);
pub
const
TIMEOUT
:
Duration
=
Duration
::
from_secs
(
6
0
);
pub
const
LEARN
:
Duration
=
Duration
::
from_secs
(
1
0
);
pub
const
ROUTE_PROTOCOL
:
RouteProtocol
=
RouteProtocol
::
Other
(
252
);
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