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
a6800c1e
Commit
a6800c1e
authored
Dec 21, 2025
by
nanamicat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
32 bit time
parent
94e98c1e
Pipeline
#42083
passed with stages
in 4 minutes and 29 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
20 deletions
+20
-20
src/main.rs
src/main.rs
+6
-6
src/protocol.rs
src/protocol.rs
+1
-1
src/router.rs
src/router.rs
+13
-13
No files found.
src/main.rs
View file @
a6800c1e
...
...
@@ -33,7 +33,7 @@ async fn main() -> anyhow::Result<()> {
// groups
// .iter()
// .map(|g| (g.id, g.routers(&groups, &routers_data)))
// .collect::<BTreeMap<u
16
, HashSet<u8>>>(),
// .collect::<BTreeMap<u
32
, HashSet<u8>>>(),
);
let
mut
hello
=
Hello
{
time
:
0
};
...
...
@@ -73,11 +73,11 @@ async fn main() -> anyhow::Result<()> {
_
=
timer
.tick
()
=>
{
// to clients
hello
.time
=
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
?
.as_millis
()
as
u
16
;
let
message
=
bincode
::
encode_to_vec
(
&
hello
,
bincode
::
config
::
standard
())
?
;
hello
.time
=
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
?
.as_millis
()
as
u
32
;
let
len
=
bincode
::
encode_into_slice
(
&
hello
,
&
mut
buf
,
bincode
::
config
::
standard
())
?
;
for
id
in
connections
[
&
config
.id
]
.keys
()
{
let
router
=
&
routers
[
id
];
let
_
=
socket
.send_to
(
message
.as_slice
()
,
router
.link_address
)
.await
;
let
_
=
socket
.send_to
(
&
buf
[
..
len
]
,
router
.link_address
)
.await
;
}
// to server
...
...
@@ -91,8 +91,8 @@ async fn main() -> anyhow::Result<()> {
.map
(|(
from
,
_
)|
routers
.get_mut
(
from
)
.unwrap
()
.update
(
hello
.time
))
.collect
(),
};
let
message
=
bincode
::
encode_to_vec
(
&
report
,
bincode
::
config
::
standard
())
?
;
let
_
=
socket
.send_to
(
message
.as_slice
()
,
config
.server
)
.await
;
let
len
=
bincode
::
encode_into_slice
(
&
report
,
&
mut
buf
,
bincode
::
config
::
standard
())
?
;
let
_
=
socket
.send_to
(
&
buf
[
..
len
]
,
config
.server
)
.await
;
}
}
}
...
...
src/protocol.rs
View file @
a6800c1e
...
...
@@ -3,7 +3,7 @@ use bincode::{Decode, Encode};
#[derive(Encode,
Decode)]
pub
struct
Hello
{
pub
time
:
u
16
,
pub
time
:
u
32
,
}
#[derive(Encode,
Decode)]
...
...
src/router.rs
View file @
a6800c1e
...
...
@@ -9,9 +9,9 @@ use std::time::SystemTime;
pub
struct
Router
{
pub
link_address
:
SocketAddr
,
quality
:
PeerQuality
,
remote_time
:
u
16
,
local_time
:
u
16
,
history
:
Vec
<
Option
<
i
16
>>
,
remote_time
:
u
32
,
local_time
:
u
32
,
history
:
Vec
<
Option
<
i
32
>>
,
}
impl
Router
{
...
...
@@ -49,13 +49,13 @@ impl Router {
pub
fn
on_message
(
&
mut
self
,
data
:
&
Hello
)
{
// 这个包发出距离上一个包
let
diff
=
data
.time
.wrapping_sub
(
self
.remote_time
)
as
i
16
;
let
diff
=
data
.time
.wrapping_sub
(
self
.remote_time
)
as
i
32
;
// 收到时间略小于或相等的,可能是网络乱序或重包,忽略
if
-
(
TIMEOUT
.as_millis
()
as
i
16
)
<
diff
&&
diff
<=
0
{
if
-
(
TIMEOUT
.as_millis
()
as
i
32
)
<
diff
&&
diff
<=
0
{
return
;
}
if
0
<
diff
&&
diff
<=
(
TIMEOUT
.as_millis
()
as
i
16
)
{
if
0
<
diff
&&
diff
<=
(
TIMEOUT
.as_millis
()
as
i
32
)
{
// 差距较小,补上中间丢的包
let
step
=
(
diff
as
f64
/
INTERVAL
.as_millis
()
as
f64
)
.round
()
as
u8
;
for
_
in
0
..
step
-
1
{
...
...
@@ -67,9 +67,9 @@ impl Router {
}
self
.remote_time
=
data
.time
;
self
.local_time
=
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
.unwrap
()
.as_millis
()
as
u
16
;
self
.local_time
=
SystemTime
::
now
()
.duration_since
(
SystemTime
::
UNIX_EPOCH
)
.unwrap
()
.as_millis
()
as
u
32
;
let
delay
=
self
.local_time
.wrapping_sub
(
self
.remote_time
)
as
i
16
;
let
delay
=
self
.local_time
.wrapping_sub
(
self
.remote_time
)
as
i
32
;
self
.history
.push
(
Some
(
delay
));
...
...
@@ -77,7 +77,7 @@ impl Router {
self
.history
.drain
(
0
..
self
.history
.len
()
-
HISTORY
as
usize
);
}
let
received
:
Vec
<
i
16
>
=
self
.history
.iter
()
.filter_map
(|
&
s
|
s
)
.collect
();
let
received
:
Vec
<
i
32
>
=
self
.history
.iter
()
.filter_map
(|
&
s
|
s
)
.collect
();
assert
!
(
!
received
.is_empty
());
// 因为走到这里一定刚放过一个进去
self
.quality.reliability
=
(
received
.len
()
*
255
/
HISTORY
as
usize
)
as
u8
;
...
...
@@ -85,14 +85,14 @@ impl Router {
self
.quality.jitter
=
(
1
..
received
.len
())
.map
(|
i
|
f64
::
from
(
received
[
i
]
.abs_diff
(
received
[
i
-
1
])))
.collect
::
<
Mean
>
()
.mean
()
as
u8
;
}
pub
(
crate
)
fn
update
(
&
mut
self
,
local_time
:
u
16
)
->
PeerQuality
{
pub
(
crate
)
fn
update
(
&
mut
self
,
local_time
:
u
32
)
->
PeerQuality
{
if
self
.quality.reliability
>
0
{
let
diff
=
(
local_time
.wrapping_sub
(
self
.local_time
)
as
i
16
as
f64
/
INTERVAL
.as_millis
()
as
f64
)
.round
()
as
i16
;
let
diff
=
(
local_time
.wrapping_sub
(
self
.local_time
)
as
i
32
as
f64
/
INTERVAL
.as_millis
()
as
f64
)
.round
()
as
i32
;
// 有几个包没到
if
diff
>
TIMEOUT
.as_millis
()
as
i
16
{
if
diff
>
TIMEOUT
.as_millis
()
as
i
32
{
self
.reset
();
}
else
if
diff
>=
(
INTERVAL
.as_millis
()
*
2
)
as
i
16
{
}
else
if
diff
>=
(
INTERVAL
.as_millis
()
*
2
)
as
i
32
{
self
.quality.reliability
=
self
.quality.reliability
.saturating_sub
(
255
/
HISTORY
);
}
}
...
...
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