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
1c797d7b
Commit
1c797d7b
authored
Jan 06, 2026
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time
parent
6874aaee
Pipeline
#42441
passed with stages
in 2 minutes and 54 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
8 deletions
+6
-8
src/main.rs
src/main.rs
+2
-5
src/router.rs
src/router.rs
+4
-3
No files found.
src/main.rs
View file @
1c797d7b
...
@@ -45,7 +45,6 @@ async fn main() -> anyhow::Result<()> {
...
@@ -45,7 +45,6 @@ async fn main() -> anyhow::Result<()> {
let
mut
timer
=
time
::
interval
(
INTERVAL
);
let
mut
timer
=
time
::
interval
(
INTERVAL
);
let
mut
buf
=
[
0
;
1500
];
let
mut
buf
=
[
0
;
1500
];
let
start
=
Instant
::
now
();
let
start
=
Instant
::
now
();
let
start_timestamp
=
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
?
;
let
resolver
=
Resolver
::
builder_tokio
()
?
.build
();
let
resolver
=
Resolver
::
builder_tokio
()
?
.build
();
...
@@ -62,9 +61,7 @@ async fn main() -> anyhow::Result<()> {
...
@@ -62,9 +61,7 @@ async fn main() -> anyhow::Result<()> {
&&
let
Some
(
peer
)
=
Router
::
get
(
&
mut
routers
,
addr
)
&&
let
Some
(
peer
)
=
Router
::
get
(
&
mut
routers
,
addr
)
&&
let
Ok
((
hello
,
_
))
=
bincode
::
decode_from_slice
(
&
buf
[
..
len
],
bincode
::
config
::
standard
())
&&
let
Ok
((
hello
,
_
))
=
bincode
::
decode_from_slice
(
&
buf
[
..
len
],
bincode
::
config
::
standard
())
{
{
let
now
=
Instant
::
now
();
peer
.on_message
(
&
hello
);
let
now_timestamp
=
(
start_timestamp
+
now
.duration_since
(
start
))
.as_millis
()
as
u32
;
peer
.on_message
(
&
hello
,
now
,
now_timestamp
);
}
else
if
addr
.port
()
==
config
.server.port
}
else
if
addr
.port
()
==
config
.server.port
&&
let
Ok
((
downlink
,
_
))
=
bincode
::
decode_from_slice
(
&
buf
[
..
len
],
bincode
::
config
::
standard
())
&&
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
&&
let
Some
(
uplink
)
=
server
.on_message
(
downlink
,
&
routers_data
,
&
connections
[
&
config
.id
],
&
config
)
.await
...
@@ -75,7 +72,7 @@ async fn main() -> anyhow::Result<()> {
...
@@ -75,7 +72,7 @@ async fn main() -> anyhow::Result<()> {
}
}
now
=
timer
.tick
()
=>
{
now
=
timer
.tick
()
=>
{
let
hello
=
Hello
{
time
:
(
start_timestamp
+
now
.duration_since
(
start
))
.as_millis
()
as
u32
};
let
hello
=
Hello
{
time
:
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
?
.as_millis
()
as
u32
};
let
len
=
bincode
::
encode_into_slice
(
&
hello
,
&
mut
buf
,
bincode
::
config
::
standard
())
?
;
let
len
=
bincode
::
encode_into_slice
(
&
hello
,
&
mut
buf
,
bincode
::
config
::
standard
())
?
;
for
id
in
connections
[
&
config
.id
]
.keys
()
{
for
id
in
connections
[
&
config
.id
]
.keys
()
{
...
...
src/router.rs
View file @
1c797d7b
...
@@ -4,6 +4,7 @@ use crate::settings::{Settings, INTERVAL};
...
@@ -4,6 +4,7 @@ use crate::settings::{Settings, INTERVAL};
use
saturating_cast
::
SaturatingCast
;
use
saturating_cast
::
SaturatingCast
;
use
std
::
collections
::
BTreeMap
;
use
std
::
collections
::
BTreeMap
;
use
std
::
net
::{
IpAddr
,
Ipv4Addr
,
SocketAddr
};
use
std
::
net
::{
IpAddr
,
Ipv4Addr
,
SocketAddr
};
use
std
::
time
::
SystemTime
;
use
tokio
::
time
::
Instant
;
use
tokio
::
time
::
Instant
;
pub
struct
Router
{
pub
struct
Router
{
...
@@ -41,7 +42,7 @@ impl Router {
...
@@ -41,7 +42,7 @@ impl Router {
}
}
}
}
pub
fn
on_message
(
&
mut
self
,
data
:
&
Hello
,
now
:
Instant
,
now_timestamp
:
u32
)
{
pub
fn
on_message
(
&
mut
self
,
data
:
&
Hello
)
{
let
delta
=
(
data
.time
.wrapping_sub
(
self
.remote_time
)
as
i32
as
f32
/
INTERVAL
.as_millis
()
as
f32
)
.round
()
as
i32
;
let
delta
=
(
data
.time
.wrapping_sub
(
self
.remote_time
)
as
i32
as
f32
/
INTERVAL
.as_millis
()
as
f32
)
.round
()
as
i32
;
match
delta
{
match
delta
{
-
63
..=-
1
=>
{
-
63
..=-
1
=>
{
...
@@ -51,7 +52,7 @@ impl Router {
...
@@ -51,7 +52,7 @@ impl Router {
1
..=
63
=>
{
1
..=
63
=>
{
self
.receive
=
(
self
.receive
<<
delta
)
|
1
;
self
.receive
=
(
self
.receive
<<
delta
)
|
1
;
self
.remote_time
=
data
.time
;
self
.remote_time
=
data
.time
;
self
.local_time
=
now
;
self
.local_time
=
Instant
::
now
()
;
}
}
_
=>
{
_
=>
{
self
.remote_time
=
data
.time
;
self
.remote_time
=
data
.time
;
...
@@ -59,7 +60,7 @@ impl Router {
...
@@ -59,7 +60,7 @@ impl Router {
}
}
}
}
let
delay
=
now_timestamp
.wrapping_sub
(
data
.time
)
as
i32
;
let
delay
=
(
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
.unwrap
()
.as_millis
()
as
u32
)
.wrapping_sub
(
data
.time
)
as
i32
;
self
.delay
=
delay
;
//+= (delay - self.delay) / 4;
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