ResolvePeer method now checks if the caller is a host and the request contains a IdentifyAs header

This commit is contained in:
netkas 2025-01-27 02:45:04 -05:00
parent c3f6f6096e
commit ec18199c08

View file

@ -6,6 +6,7 @@
use InvalidArgumentException; use InvalidArgumentException;
use Socialbox\Abstracts\Method; use Socialbox\Abstracts\Method;
use Socialbox\Classes\Configuration; use Socialbox\Classes\Configuration;
use Socialbox\Enums\ReservedUsernames;
use Socialbox\Enums\StandardError; use Socialbox\Enums\StandardError;
use Socialbox\Exceptions\DatabaseOperationException; use Socialbox\Exceptions\DatabaseOperationException;
use Socialbox\Exceptions\RpcException; use Socialbox\Exceptions\RpcException;
@ -41,10 +42,17 @@
throw new StandardException('Peer Address Error: ' . $e->getMessage(), StandardError::RPC_INVALID_ARGUMENTS, $e); throw new StandardException('Peer Address Error: ' . $e->getMessage(), StandardError::RPC_INVALID_ARGUMENTS, $e);
} }
// Check if host is making the request & the identifier is not empty
$identifyAs = null;
if($request->getPeer()->getUsername() == ReservedUsernames::HOST && $request->getIdentifyAs() != null)
{
$identifyAs = $request->getIdentifyAs();
}
// Resolve the peer using the server's peer resolver, this will resolve both internal peers and external peers // Resolve the peer using the server's peer resolver, this will resolve both internal peers and external peers
try try
{ {
return $rpcRequest->produceResponse(Socialbox::resolvePeer($peerAddress)); return $rpcRequest->produceResponse(Socialbox::resolvePeer($peerAddress, $identifyAs));
} }
catch(Exception $e) catch(Exception $e)
{ {