mirror of
https://github.com/YGGverse/YGGstate.git
synced 2025-01-09 22:37:54 +00:00
fix coordinate port update, improve insert/total counter conditions
This commit is contained in:
parent
42f939ca8e
commit
10a52b50fc
@ -88,10 +88,11 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$dbPeerId = $db->addPeer($connectedPeerAddress, $connectedPeerInfo->key, time());
|
if ($dbPeerId = $db->addPeer($connectedPeerAddress, $connectedPeerInfo->key, time())) {
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['total']['insert']++;
|
$debug['yggdrasil']['peer']['total']['insert']++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init peer remote
|
// Init peer remote
|
||||||
if ($connectedPeerRemoteUrl = Yggverse\Parser\Url::parse($connectedPeerInfo->remote)) {
|
if ($connectedPeerRemoteUrl = Yggverse\Parser\Url::parse($connectedPeerInfo->remote)) {
|
||||||
@ -122,38 +123,49 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$peerRemoteId = $db->addPeerRemote($dbPeerId,
|
if ($peerRemoteId = $db->addPeerRemote($dbPeerId,
|
||||||
$connectedPeerRemoteUrl->host->scheme,
|
$connectedPeerRemoteUrl->host->scheme,
|
||||||
$connectedPeerRemoteUrl->host->name,
|
$connectedPeerRemoteUrl->host->name,
|
||||||
$connectedPeerRemoteUrl->host->port,
|
$connectedPeerRemoteUrl->host->port,
|
||||||
$connectedPeerInfo->bytes_recvd,
|
$connectedPeerInfo->bytes_recvd,
|
||||||
$connectedPeerInfo->bytes_sent,
|
$connectedPeerInfo->bytes_sent,
|
||||||
$connectedPeerInfo->uptime,
|
$connectedPeerInfo->uptime,
|
||||||
time());
|
time())) {
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['remote']['total']['insert']++;
|
$debug['yggdrasil']['peer']['remote']['total']['insert']++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init peer coordinate
|
// Init peer coordinate
|
||||||
if ($dbPeerCoordinate = $db->getLastCoordinate($dbPeerId)) {
|
if ($dbPeerCoordinate = $db->getLastCoordinate($dbPeerId)) {
|
||||||
|
|
||||||
$peerCoordinateId = $dbPeerCoordinate->peerCoordinateId;
|
$peerCoordinateId = $dbPeerCoordinate->peerCoordinateId;
|
||||||
|
|
||||||
} else {
|
// Create new peer coordinate on port change
|
||||||
|
if ($dbPeerCoordinate->port !== $connectedPeerInfo->port) {
|
||||||
|
|
||||||
|
if ($peerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time())) {
|
||||||
|
|
||||||
$peerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time());
|
|
||||||
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Init peer coordinate route
|
} else {
|
||||||
|
|
||||||
|
if ($peerCoordinateId = $db->addPeerCoordinate($dbPeerId, $connectedPeerInfo->port, time())) {
|
||||||
|
|
||||||
|
$debug['yggdrasil']['peer']['coordinate']['total']['insert']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init peer coordinate routing
|
||||||
$localPeerCoordinateRoute = [];
|
$localPeerCoordinateRoute = [];
|
||||||
foreach ($db->getPeerCoordinateRoute($peerCoordinateId) as $dbPeerCoordinateRoute) {
|
foreach ($db->getPeerCoordinateRoute($peerCoordinateId) as $dbPeerCoordinateRoute) {
|
||||||
|
|
||||||
$localPeerCoordinateRoute[$dbPeerCoordinateRoute->level] = $dbPeerCoordinateRoute->port;
|
$localPeerCoordinateRoute[$dbPeerCoordinateRoute->level] = $dbPeerCoordinateRoute->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare remote and local routes to prevent write operations
|
// Compare remote and local routes to prevent extra writing operations
|
||||||
if ($localPeerCoordinateRoute !== $connectedPeerInfo->coords) {
|
if ($localPeerCoordinateRoute !== $connectedPeerInfo->coords) {
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['coordinate']['route']['total']['delete'] +=
|
$debug['yggdrasil']['peer']['coordinate']['route']['total']['delete'] +=
|
||||||
@ -161,8 +173,10 @@ if ($connectedPeers = Yggverse\Yggdrasilctl\Yggdrasil::getPeers()) {
|
|||||||
|
|
||||||
foreach ($connectedPeerInfo->coords as $level => $port) {
|
foreach ($connectedPeerInfo->coords as $level => $port) {
|
||||||
|
|
||||||
$debug['yggdrasil']['peer']['coordinate']['route']['total']['insert'] +=
|
if ($db->addPeerCoordinateRoute($peerCoordinateId, $level, $port)) {
|
||||||
$db->addPeerCoordinateRoute($peerCoordinateId, $level, $port);
|
|
||||||
|
$debug['yggdrasil']['peer']['coordinate']['route']['total']['insert']++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user