diff options
| -rw-r--r-- | pica-client/nodes.cpp | 31 | ||||
| -rw-r--r-- | pica-client/skynet.cpp | 4 |
2 files changed, 33 insertions, 2 deletions
diff --git a/pica-client/nodes.cpp b/pica-client/nodes.cpp index 9ffbd67..983bb56 100644 --- a/pica-client/nodes.cpp +++ b/pica-client/nodes.cpp @@ -68,7 +68,38 @@ QList<Nodes::NodeRecord> Nodes::GetNodes() void Nodes::MakeClean() { + QSqlQuery query; + quint32 count = 0; + + query.exec("select count(*) from nodes"); + + if (lasterr.isValid()) + return; + + if (query.next()) + { + count = query.value(0).toUInt(); + } + + if (count > 32) + { + quint32 delcnt; + + query.prepare("select inactive_count from nodes order by inactive_count asc limit 1 offset :halfcount"); + query.bindValue(":halfcount", count / 2); + query.exec(); + if (lasterr.isValid()) + return; + + if (query.next()) + { + delcnt = query.value(0).toUInt(); + query.prepare("delete from nodes where inactive_count >= :delcnt"); + query.bindValue(":delcnt", delcnt); + query.exec(); + } + } } void Nodes::UpdateStatus(NodeRecord &n, bool alive) diff --git a/pica-client/skynet.cpp b/pica-client/skynet.cpp index 9f41f4e..bf02e11 100644 --- a/pica-client/skynet.cpp +++ b/pica-client/skynet.cpp @@ -129,6 +129,8 @@ void SkyNet::nodelink_activated(PICA_c2n *c2n) self_aware = true; active_nodelink = c2n; + nodes.MakeClean(); + emit BecameSelfAware(); // //restore old peer connections, if any @@ -165,8 +167,6 @@ void SkyNet::nodelink_activated(PICA_c2n *c2n) retry_timer_id = startTimer(10000); // } - - } void SkyNet::nodelink_closed(PICA_c2n *c2n, int error) |
