From 0fbb824f1050a47dfd631aa1df0e3ae8519b1025 Mon Sep 17 00:00:00 2001 From: netkas Date: Sat, 11 Jan 2025 19:49:20 -0500 Subject: [PATCH] Add error handling and refactor peer synchronization logic --- src/Socialbox/Socialbox.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Socialbox/Socialbox.php b/src/Socialbox/Socialbox.php index 59cbaae..c00e18f 100644 --- a/src/Socialbox/Socialbox.php +++ b/src/Socialbox/Socialbox.php @@ -39,6 +39,9 @@ * missing or invalid request types. * * @return void + * @throws CryptographyException + * @throws DatabaseOperationException + * @throws ResolutionException */ public static function handleRequest(): void { @@ -279,6 +282,7 @@ * required to perform the DHE exchange. * * @return void + * @throws CryptographyException */ private static function handleDheExchange(ClientRequest $clientRequest): void { @@ -412,6 +416,9 @@ * @param ClientRequest $clientRequest The RPC client request containing headers, body, and session information. * * @return void + * @throws CryptographyException + * @throws DatabaseOperationException + * @throws ResolutionException */ private static function handleRpc(ClientRequest $clientRequest): void { @@ -484,8 +491,7 @@ // Synchronize the peer try { - $client = self::getExternalSession($clientRequest->getIdentifyAs()->getDomain()); - RegisteredPeerManager::synchronizeExternalPeer($client->resolvePeer($clientRequest->getIdentifyAs())); + self::synchronizeExternalPeer($clientRequest->getIdentifyAs()); } catch (DatabaseOperationException $e) { @@ -701,6 +707,27 @@ } } + /** + * Synchronizes an external peer by resolving and integrating its information into the system. + * + * @param PeerAddress|string $externalPeer The external peer to synchronize, provided as a PeerAddress instance or a string. + * @return void + * @throws CryptographyException If there is an error in the cryptography + * @throws DatabaseOperationException If there is an error while processing the peer against the database + * @throws ResolutionException If the synchronization process fails due to unresolved peer information or other errors. + * @throws RpcException If there is an RPC exception while connecting to the remote server + */ + public static function synchronizeExternalPeer(PeerAddress|string $externalPeer): void + { + if($externalPeer instanceof PeerAddress) + { + $externalPeer = $externalPeer->getAddress(); + } + + $client = self::getExternalSession($externalPeer->getDomain()); + RegisteredPeerManager::synchronizeExternalPeer($client->resolvePeer($externalPeer)); + } + /** * Retrieves the server information by assembling data from the configuration settings. *