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
1f6fcc19
Commit
1f6fcc19
authored
Aug 19, 2022
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
dbb5e3c2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
26 deletions
+16
-26
src/Peer.ts
src/Peer.ts
+9
-2
src/Server.ts
src/Server.ts
+7
-22
src/main.ts
src/main.ts
+0
-2
No files found.
src/Peer.ts
View file @
1f6fcc19
...
@@ -50,14 +50,21 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
...
@@ -50,14 +50,21 @@ export class Peer implements PeerMessage, PeerQuality, RouterConfig {
this
.
time
=
data
.
time
;
this
.
time
=
data
.
time
;
}
}
update
(
time
:
number
)
{
update
(
):
PeerQuality
{
if
(
this
.
reliability
===
0
)
{
if
(
this
.
reliability
===
0
)
{
return
;
return
;
}
}
// 有几个包没到
// 有几个包没到
const
step
=
Math
.
floor
((
time
-
this
.
time
+
this
.
delay
-
config
.
interval
)
/
config
.
interval
);
const
step
=
Math
.
floor
((
Date
.
now
()
-
this
.
time
+
this
.
delay
-
config
.
interval
)
/
config
.
interval
);
if
(
step
>
config
.
timeout
)
{
if
(
step
>
config
.
timeout
)
{
this
.
reset
();
this
.
reset
();
}
}
return
{
delay
:
Math
.
round
(
this
.
delay
),
jitter
:
0
,
reliability
:
this
.
reliability
};
}
}
}
}
src/Server.ts
View file @
1f6fcc19
...
@@ -4,7 +4,7 @@ import config from '../config/config.json';
...
@@ -4,7 +4,7 @@ import config from '../config/config.json';
import
{
RouteWriter
}
from
'
./RouteWriter
'
;
import
{
RouteWriter
}
from
'
./RouteWriter
'
;
import
{
Peer
}
from
'
./Peer
'
;
import
{
Peer
}
from
'
./Peer
'
;
import
{
DownloadMessage
,
PeerMessage
,
PeerQuality
,
UploadMessage
}
from
'
../protocol
'
;
import
{
DownloadMessage
,
PeerMessage
,
UploadMessage
}
from
'
../protocol
'
;
export
class
Server
{
export
class
Server
{
ack
=
0
;
ack
=
0
;
...
@@ -13,7 +13,7 @@ export class Server {
...
@@ -13,7 +13,7 @@ export class Server {
console
.
log
(
message
);
console
.
log
(
message
);
if
(
message
.
seq
&&
this
.
ack
!==
message
.
seq
)
{
if
(
message
.
seq
&&
this
.
ack
!==
message
.
seq
)
{
console
.
log
(
"
seq mismatch rejected
"
);
console
.
log
(
'
seq mismatch rejected
'
);
return
;
return
;
}
}
...
@@ -39,26 +39,11 @@ export class Server {
...
@@ -39,26 +39,11 @@ export class Server {
}
}
update
(
socket
:
Socket
,
self
:
PeerMessage
,
peers
:
Peer
[])
{
update
(
socket
:
Socket
,
self
:
PeerMessage
,
peers
:
Peer
[])
{
const
p
:
Record
<
number
,
PeerQuality
>
=
{};
const
message
:
UploadMessage
=
{
id
:
self
.
id
,
for
(
const
peer
of
peers
)
{
ack
:
this
.
ack
,
if
(
peer
.
reliability
===
0
)
{
peers
:
Object
.
fromEntries
(
peers
.
map
(
peer
=>
[
peer
.
id
,
peer
.
update
()]))
continue
;
};
}
// 有几个包没到
const
step
=
Math
.
max
(
0
,
Math
.
floor
((
self
.
time
-
peer
.
time
+
peer
.
delay
-
config
.
interval
/
2
)
/
config
.
interval
));
if
(
step
>=
config
.
timeout
)
{
peer
.
reset
();
continue
;
}
const
{
id
,
delay
}
=
peer
;
const
reliability
=
(
peer
.
reliability
*
(
config
.
timeout
-
step
))
/
config
.
timeout
;
// TODO: jitter 没算
p
[
id
]
=
{
delay
:
Math
.
round
(
delay
),
jitter
:
0
,
reliability
};
}
const
message
:
UploadMessage
=
{
id
:
self
.
id
,
ack
:
this
.
ack
,
peers
:
p
};
// console.log(message);
// console.log(message);
socket
.
send
(
JSON
.
stringify
(
message
),
config
.
server_port
,
config
.
server_address
);
socket
.
send
(
JSON
.
stringify
(
message
),
config
.
server_port
,
config
.
server_address
);
}
}
...
...
src/main.ts
View file @
1f6fcc19
...
@@ -38,10 +38,8 @@ const socket = dgram
...
@@ -38,10 +38,8 @@ const socket = dgram
socket
.
bind
(
config
.
port
);
socket
.
bind
(
config
.
port
);
setInterval
(()
=>
{
setInterval
(()
=>
{
self
.
time
=
Date
.
now
();
const
message
=
JSON
.
stringify
(
self
);
const
message
=
JSON
.
stringify
(
self
);
for
(
const
peer
of
peers
)
{
for
(
const
peer
of
peers
)
{
peer
.
update
(
self
.
time
);
socket
.
send
(
message
,
config
.
port
,
`10.200.
${
peer
.
id
}
.
${
self
.
id
}
`
);
socket
.
send
(
message
,
config
.
port
,
`10.200.
${
peer
.
id
}
.
${
self
.
id
}
`
);
}
}
server
.
update
(
socket
,
self
,
peers
);
server
.
update
(
socket
,
self
,
peers
);
...
...
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