Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Beyond Protocol
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Maintenance moved to Monday 17.3. at 13:00. ETA 60 - 90 minutes.
Show more breadcrumbs
Beyond AKA
Beyond Protocol
Commits
04bea32d
Commit
04bea32d
authored
2 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
#6
Add peer garbage collection
parent
b504373f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/ftl/protocol/self.hpp
+17
-0
17 additions, 0 deletions
include/ftl/protocol/self.hpp
src/self.cpp
+8
-0
8 additions, 0 deletions
src/self.cpp
src/universe.cpp
+21
-19
21 additions, 19 deletions
src/universe.cpp
src/universe.hpp
+3
-0
3 additions, 0 deletions
src/universe.hpp
with
49 additions
and
19 deletions
include/ftl/protocol/self.hpp
+
17
−
0
View file @
04bea32d
...
...
@@ -114,6 +114,23 @@ class Self {
*/
size_t
numberOfNodes
()
const
;
/**
* @brief Get the maximum allowed number of connections. Any attempt to connect more
* peers will result in them being rejected.
*
* @return size_t
*/
size_t
getMaxConnections
()
const
;
/**
* @brief Set the maximum allowed connections. This should only be changed before
* there are any active connections, resizing with active connections could cause
* errors. The default number is 10.
*
* @param m Number of allowed node connections
*/
void
setMaxConnections
(
size_t
m
);
/**
* @brief Will block until all currently registered connnections have completed.
* You should not use this, but rather use onConnect.
...
...
This diff is collapsed.
Click to expand it.
src/self.cpp
+
8
−
0
View file @
04bea32d
...
...
@@ -76,6 +76,14 @@ size_t Self::numberOfNodes() const {
return
universe_
->
numberOfPeers
();
}
size_t
Self
::
getMaxConnections
()
const
{
return
universe_
->
getMaxConnections
();
}
void
Self
::
setMaxConnections
(
size_t
m
)
{
universe_
->
setMaxConnections
(
m
);
}
int
Self
::
waitConnections
(
int
seconds
)
{
return
universe_
->
waitConnections
(
seconds
);
}
...
...
This diff is collapsed.
Click to expand it.
src/universe.cpp
+
21
−
19
View file @
04bea32d
...
...
@@ -47,6 +47,8 @@ using ftl::net::internal::SocketServer;
using
ftl
::
net
::
internal
::
Server_TCP
;
using
std
::
chrono
::
milliseconds
;
constexpr
int
kDefaultMaxConnections
=
10
;
namespace
ftl
{
namespace
net
{
...
...
@@ -81,30 +83,12 @@ Universe::Universe() :
active_
(
true
),
this_peer
(
ftl
::
protocol
::
id
),
impl_
(
new
ftl
::
net
::
NetImplDetail
()),
peers_
(
10
),
peers_
(
kDefaultMaxConnections
),
phase_
(
0
),
periodic_time_
(
1.0
),
reconnect_attempts_
(
5
),
thread_
(
Universe
::
__start
,
this
)
{
_installBindings
();
// Add an idle timer job to garbage collect peer objects
// Note: Important to be a timer job to ensure no other timer jobs are
// using the object.
// FIXME: Replace use of timer.
/*garbage_timer_ = ftl::timer::add(ftl::timer::kTimerIdle10, [this](int64_t ts) {
if (garbage_.size() > 0) {
UNIQUE_LOCK(net_mutex_,lk);
if (ftl::pool.n_idle() == ftl::pool.size()) {
if (garbage_.size() > 0) LOG(1) << "Garbage collection";
while (garbage_.size() > 0) {
delete garbage_.front();
garbage_.pop_front();
}
}
}
return true;
});*/
}
Universe
::~
Universe
()
{
...
...
@@ -112,6 +96,11 @@ Universe::~Universe() {
CHECK_EQ
(
peer_instances_
,
0
);
}
void
Universe
::
setMaxConnections
(
size_t
m
)
{
UNIQUE_LOCK
(
net_mutex_
,
lk
);
peers_
.
resize
(
m
);
}
size_t
Universe
::
getSendBufferSize
(
ftl
::
URI
::
scheme_t
s
)
{
// TODO(Nick): Allow these to be configured again.
switch
(
s
)
{
...
...
@@ -448,6 +437,19 @@ void Universe::_periodic() {
i = reconnects_.erase(i);
}*/
}
// Garbage peers may not be needed any more
if
(
garbage_
.
size
()
>
0
)
{
UNIQUE_LOCK
(
net_mutex_
,
lk
);
// Only do garbage if processing is idle.
if
(
ftl
::
pool
.
n_idle
()
==
ftl
::
pool
.
size
())
{
if
(
garbage_
.
size
()
>
0
)
DLOG
(
1
)
<<
"Garbage collection"
;
while
(
garbage_
.
size
()
>
0
)
{
garbage_
.
front
().
reset
();
garbage_
.
pop_front
();
}
}
}
}
void
Universe
::
__start
(
Universe
*
u
)
{
...
...
This diff is collapsed.
Click to expand it.
src/universe.hpp
+
3
−
0
View file @
04bea32d
...
...
@@ -172,6 +172,9 @@ class Universe {
static
inline
std
::
shared_ptr
<
Universe
>
getInstance
()
{
return
instance_
;
}
void
setMaxConnections
(
size_t
m
);
size_t
getMaxConnections
()
const
{
return
peers_
.
size
();
}
// --- Test support -------------------------------------------------------
PeerPtr
injectFakePeer
(
std
::
unique_ptr
<
ftl
::
net
::
internal
::
SocketConnection
>
s
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment