Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
96e7ba69
Commit
96e7ba69
authored
Apr 01, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite token bucket.
parent
2171df59
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
10 deletions
+14
-10
message.c
message.c
+10
-9
message.h
message.h
+3
-0
network.c
network.c
+1
-1
No files found.
message.c
View file @
96e7ba69
...
@@ -329,17 +329,18 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
...
@@ -329,17 +329,18 @@ handle_request(struct neighbour *neigh, const unsigned char *prefix,
static
int
static
int
check_bucket
(
struct
network
*
net
)
check_bucket
(
struct
network
*
net
)
{
{
if
(
net
->
bucket
>
0
&&
now
.
tv_sec
>
net
->
bucket_time
)
{
if
(
net
->
bucket
<=
0
)
{
net
->
bucket
=
int
seconds
=
now
.
tv_sec
-
net
->
bucket_time
;
MIN
(
MAX
((
int
)
net
->
bucket
-
40
*
(
now
.
tv_sec
-
net
->
bucket_time
),
if
(
seconds
>
0
)
{
0
),
net
->
bucket
=
MIN
(
BUCKET_TOKENS_MAX
,
400
);
seconds
*
BUCKET_TOKENS_PER_SEC
);
}
/* Reset bucket time unconditionally, in case clock is stepped. */
net
->
bucket_time
=
now
.
tv_sec
;
}
}
net
->
bucket_time
=
now
.
tv_sec
;
if
(
net
->
bucket
>
0
)
{
net
->
bucket
--
;
if
(
net
->
bucket
<
400
)
{
net
->
bucket
++
;
return
1
;
return
1
;
}
else
{
}
else
{
return
0
;
return
0
;
...
...
message.h
View file @
96e7ba69
...
@@ -22,6 +22,9 @@ THE SOFTWARE.
...
@@ -22,6 +22,9 @@ THE SOFTWARE.
#define MAX_BUFFERED_UPDATES 200
#define MAX_BUFFERED_UPDATES 200
#define BUCKET_TOKENS_MAX 200
#define BUCKET_TOKENS_PER_SEC 40
extern
unsigned
short
myseqno
;
extern
unsigned
short
myseqno
;
extern
struct
timeval
seqno_time
;
extern
struct
timeval
seqno_time
;
extern
int
seqno_interval
;
extern
int
seqno_interval
;
...
...
network.c
View file @
96e7ba69
...
@@ -59,7 +59,7 @@ add_network(char *ifname)
...
@@ -59,7 +59,7 @@ add_network(char *ifname)
nets
[
numnets
].
sendbuf
=
NULL
;
nets
[
numnets
].
sendbuf
=
NULL
;
nets
[
numnets
].
buffered
=
0
;
nets
[
numnets
].
buffered
=
0
;
nets
[
numnets
].
bucket_time
=
now
.
tv_sec
;
nets
[
numnets
].
bucket_time
=
now
.
tv_sec
;
nets
[
numnets
].
bucket
=
0
;
nets
[
numnets
].
bucket
=
BUCKET_TOKENS_MAX
;
nets
[
numnets
].
hello_seqno
=
(
random
()
&
0xFFFF
);
nets
[
numnets
].
hello_seqno
=
(
random
()
&
0xFFFF
);
numnets
++
;
numnets
++
;
return
&
nets
[
numnets
-
1
];
return
&
nets
[
numnets
-
1
];
...
...
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