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
5325b88b
You need to sign in or sign up before continuing.
Commit
5325b88b
authored
Jan 06, 2026
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time
parent
02909afa
Pipeline
#42436
passed with stages
in 58 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
7 deletions
+9
-7
src/main.rs
src/main.rs
+6
-3
src/router.rs
src/router.rs
+3
-4
No files found.
src/main.rs
View file @
5325b88b
...
...
@@ -18,6 +18,7 @@ mod protocol;
mod
router
;
mod
server
;
mod
settings
;
use
hickory_resolver
::
Resolver
;
use
tokio
::
time
::
Instant
;
...
...
@@ -44,6 +45,7 @@ async fn main() -> anyhow::Result<()> {
let
mut
timer
=
time
::
interval
(
INTERVAL
);
let
mut
buf
=
[
0
;
1500
];
let
start
=
Instant
::
now
();
let
start_timestamp
=
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
?
;
let
resolver
=
Resolver
::
builder_tokio
()
?
.build
();
...
...
@@ -55,12 +57,14 @@ async fn main() -> anyhow::Result<()> {
result
=
socket
.recv_from
(
&
mut
buf
)
=>
{
let
(
len
,
addr
)
=
result
?
;
let
now
=
Instant
::
now
();
let
now_timestamp
=
(
start_timestamp
+
now
.duration_since
(
start
))
.as_millis
()
as
u32
;
tracing
::
info!
(
"{:?} {:?}"
,
addr
,
server_addr
);
if
addr
.port
()
==
config
.bind
.port
()
&&
let
Some
(
peer
)
=
Router
::
get
(
&
mut
routers
,
addr
)
&&
let
Ok
((
hello
,
_
))
=
bincode
::
decode_from_slice
(
&
buf
[
..
len
],
bincode
::
config
::
standard
())
{
peer
.on_message
(
&
hello
);
peer
.on_message
(
&
hello
,
now
,
now_timestamp
);
}
else
if
addr
.port
()
==
config
.server.port
&&
let
Ok
((
downlink
,
_
))
=
bincode
::
decode_from_slice
(
&
buf
[
..
len
],
bincode
::
config
::
standard
())
&&
let
Some
(
uplink
)
=
server
.on_message
(
downlink
,
&
routers_data
,
&
connections
[
&
config
.id
],
&
config
)
.await
...
...
@@ -71,8 +75,7 @@ async fn main() -> anyhow::Result<()> {
}
now
=
timer
.tick
()
=>
{
// to clients
let
hello
=
Hello
{
time
:
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
?
.as_millis
()
as
u32
};
let
hello
=
Hello
{
time
:
(
start_timestamp
+
now
.duration_since
(
start
))
.as_millis
()
as
u32
};
let
len
=
bincode
::
encode_into_slice
(
&
hello
,
&
mut
buf
,
bincode
::
config
::
standard
())
?
;
for
id
in
connections
[
&
config
.id
]
.keys
()
{
...
...
src/router.rs
View file @
5325b88b
...
...
@@ -4,7 +4,6 @@ use crate::settings::{Settings, INTERVAL};
use
saturating_cast
::
SaturatingCast
;
use
std
::
collections
::
BTreeMap
;
use
std
::
net
::{
IpAddr
,
Ipv4Addr
,
SocketAddr
};
use
std
::
time
::
SystemTime
;
use
tokio
::
time
::
Instant
;
pub
struct
Router
{
...
...
@@ -42,7 +41,7 @@ impl Router {
}
}
pub
fn
on_message
(
&
mut
self
,
data
:
&
Hello
)
{
pub
fn
on_message
(
&
mut
self
,
data
:
&
Hello
,
now
:
Instant
,
now_timestamp
:
u32
)
{
let
delta
=
(
data
.time
.wrapping_sub
(
self
.remote_time
)
as
i32
as
f32
/
INTERVAL
.as_millis
()
as
f32
)
.round
()
as
i32
;
match
delta
{
-
63
..=-
1
=>
{
...
...
@@ -52,7 +51,7 @@ impl Router {
1
..=
63
=>
{
self
.receive
=
(
self
.receive
<<
delta
)
|
1
;
self
.remote_time
=
data
.time
;
self
.local_time
=
Instant
::
now
()
;
self
.local_time
=
now
;
}
_
=>
{
self
.remote_time
=
data
.time
;
...
...
@@ -60,7 +59,7 @@ impl Router {
}
}
let
delay
=
(
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
.unwrap
()
.as_millis
()
as
u32
)
.wrapping_sub
(
data
.time
)
as
i32
;
let
delay
=
now_timestamp
.wrapping_sub
(
data
.time
)
as
i32
;
self
.delay
=
delay
;
//+= (delay - self.delay) / 4;
...
...
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