diff --git a/src/FederationLib/Classes/Configuration.php b/src/FederationLib/Classes/Configuration.php index 57df17c..2d77cd4 100644 --- a/src/FederationLib/Classes/Configuration.php +++ b/src/FederationLib/Classes/Configuration.php @@ -54,7 +54,7 @@ self::$configuration->setDefault('cache_system.cache.client_objects_ttl', 200); self::$configuration->setDefault('cache_system.cache.client_objects_server_preference', 'redis_master'); self::$configuration->setDefault('cache_system.cache.client_objects_server_fallback', 'redis_slave'); - // Peer Objects + // PeerRecord Objects self::$configuration->setDefault('cache_system.cache.peer_objects_enabled', true); self::$configuration->setDefault('cache_system.cache.peer_objects_ttl', 200); self::$configuration->setDefault('cache_system.cache.peer_objects_server_preference', 'redis_master'); diff --git a/src/FederationLib/FederationLib.php b/src/FederationLib/FederationLib.php index ffe5eba..bff7dd0 100755 --- a/src/FederationLib/FederationLib.php +++ b/src/FederationLib/FederationLib.php @@ -13,7 +13,7 @@ use FederationLib\Exceptions\Standard\InvalidClientDescriptionException; use FederationLib\Exceptions\Standard\InvalidClientNameException; use FederationLib\Managers\ClientManager; - use FederationLib\Objects\Client; + use FederationLib\Objects\ClientRecord; use FederationLib\Objects\ResolvedIdentity; use FederationLib\Objects\Standard\ClientIdentity; use TamerLib\Enums\TamerMode; @@ -197,14 +197,14 @@ * Returns an existing client from the database * * @param ClientIdentity|null $identity - * @param string|Client $client_uuid - * @throws AccessDeniedException - * @throws ClientNotFoundException + * @param string|ClientRecord $client_uuid + * @return Objects\Standard\Client + *@throws ClientNotFoundException * @throws DatabaseException * @throws InternalServerException - * @return Objects\Standard\Client + * @throws AccessDeniedException */ - public function getClient(?ClientIdentity $identity, string|Client $client_uuid): Objects\Standard\Client + public function getClient(?ClientIdentity $identity, string|ClientRecord $client_uuid): Objects\Standard\Client { if(!$this->checkPermission(Methods::GET_CLIENT, $this->resolveIdentity($identity))) { diff --git a/src/FederationLib/Interfaces/PeerMetadataManagerInterface.php b/src/FederationLib/Interfaces/PeerMetadataManagerInterface.php index 72696d0..70625dd 100644 --- a/src/FederationLib/Interfaces/PeerMetadataManagerInterface.php +++ b/src/FederationLib/Interfaces/PeerMetadataManagerInterface.php @@ -2,8 +2,8 @@ namespace FederationLib\Interfaces; - use FederationLib\Objects\Client; - use FederationLib\Objects\Peer; + use FederationLib\Objects\ClientRecord; + use FederationLib\Objects\PeerRecord; use FederationLib\Objects\Standard\PeerMetadata\TelegramUserMetadata; interface PeerMetadataManagerInterface @@ -12,27 +12,27 @@ * Intelligently syncs the metadata of the given federated address, this will ignore raw metadata & use * data from the given $client_uuid * - * @param Client|string $client_uuid + * @param ClientRecord|string $client_uuid * @param TelegramUserMetadata $telegram_user_metadata * @return string */ - public function syncMetadata(Client|string $client_uuid, TelegramUserMetadata $telegram_user_metadata): string; + public function syncMetadata(ClientRecord|string $client_uuid, TelegramUserMetadata $telegram_user_metadata): string; /** * Registers the metadata of the given federated address, this will ignore raw metadata & use data from the * given $client_uuid * - * @param Client|string $client_uuid + * @param ClientRecord|string $client_uuid * @param TelegramUserMetadata $telegram_user_metadata * @return string */ - public function registerMetadata(Client|string $client_uuid, TelegramUserMetadata $telegram_user_metadata): string; + public function registerMetadata(ClientRecord|string $client_uuid, TelegramUserMetadata $telegram_user_metadata): string; /** * Returns the metadata of the given federated address, this returns the full raw metadata * - * @param Peer|string $federated_address + * @param PeerRecord|string $federated_address * @return TelegramUserMetadata */ - public function getMetadata(Peer|string $federated_address): TelegramUserMetadata; + public function getMetadata(PeerRecord|string $federated_address): TelegramUserMetadata; } \ No newline at end of file diff --git a/src/FederationLib/Managers/ClientManager.php b/src/FederationLib/Managers/ClientManager.php index e5d8505..d36820e 100644 --- a/src/FederationLib/Managers/ClientManager.php +++ b/src/FederationLib/Managers/ClientManager.php @@ -19,7 +19,7 @@ use FederationLib\Exceptions\Standard\InvalidClientNameException; use FederationLib\Exceptions\Standard\InvalidPermissionRoleException; use FederationLib\FederationLib; - use FederationLib\Objects\Client; + use FederationLib\Objects\ClientRecord; use LogLib\Log; use Symfony\Component\Uid\Uuid; use TamerLib\Enums\TamerMode; @@ -119,14 +119,14 @@ /** * Returns an existing client from the database. * - * @param string|Client $client_uuid - * @return Client + * @param string|ClientRecord $client_uuid + * @return ClientRecord * @throws ClientNotFoundException * @throws DatabaseException */ - public function getClient(string|Client $client_uuid): Client + public function getClient(string|ClientRecord $client_uuid): ClientRecord { - if($client_uuid instanceof Client) + if($client_uuid instanceof ClientRecord) { $client_uuid = $client_uuid->getUuid(); } @@ -143,7 +143,7 @@ if($redis->exists($client_uuid)) { - $client = Client::fromArray($redis->hGetAll($client_uuid)); + $client = ClientRecord::fromArray($redis->hGetAll($client_uuid)); Log::debug(Misc::FEDERATIONLIB, sprintf('Loaded client object %s from cache', $client_uuid)); return $client; } @@ -170,7 +170,7 @@ throw new ClientNotFoundException($client_uuid); } - $client = Client::fromArray($result->fetchAssociative()); + $client = ClientRecord::fromArray($result->fetchAssociative()); } catch(ClientNotFoundException $e) { @@ -211,16 +211,16 @@ /** * Changes the name of a client. * - * @param string|Client $client_uuid + * @param string|ClientRecord $client_uuid * @param string|null $name * @return void * @throws ClientNotFoundException * @throws DatabaseException * @throws InvalidClientNameException */ - public function changeClientName(string|Client $client_uuid, ?string $name=null): void + public function changeClientName(string|ClientRecord $client_uuid, ?string $name=null): void { - if($client_uuid instanceof Client) + if($client_uuid instanceof ClientRecord) { $client_uuid = $client_uuid->getUuid(); } @@ -297,16 +297,16 @@ /** * Changes the description of a client * - * @param string|Client $client_uuid + * @param string|ClientRecord $client_uuid * @param string|null $description * @return void * @throws ClientNotFoundException * @throws DatabaseException * @throws InvalidClientDescriptionException */ - public function changeClientDescription(string|Client $client_uuid, ?string $description=null): void + public function changeClientDescription(string|ClientRecord $client_uuid, ?string $description=null): void { - if($client_uuid instanceof Client) + if($client_uuid instanceof ClientRecord) { $client_uuid = $client_uuid->getUuid(); } @@ -377,16 +377,16 @@ /** * Updates the permission role of a client. * - * @param string|Client $client_uuid + * @param string|ClientRecord $client_uuid * @param int $permission_role * @return void * @throws ClientNotFoundException * @throws DatabaseException * @throws InvalidPermissionRoleException */ - public function changeClientPermissionRole(string|Client $client_uuid, int $permission_role): void + public function changeClientPermissionRole(string|ClientRecord $client_uuid, int $permission_role): void { - if($client_uuid instanceof Client) + if($client_uuid instanceof ClientRecord) { $client_uuid = $client_uuid->getUuid(); } @@ -457,14 +457,14 @@ /** * Updates a client's last seen timestamp. * - * @param string|Client $uuid + * @param string|ClientRecord $uuid * @return void * @throws DatabaseException * @noinspection PhpUnused */ - public function updateLastSeen(string|Client $uuid): void + public function updateLastSeen(string|ClientRecord $uuid): void { - if($uuid instanceof Client) + if($uuid instanceof ClientRecord) { $uuid = $uuid->getUuid(); } @@ -593,7 +593,7 @@ while($row = $result->fetchAssociative()) { - $client_object = Client::fromArray($row); + $client_object = ClientRecord::fromArray($row); if($redis_client !== null) { @@ -657,13 +657,13 @@ /** * Deletes an existing client from the database. * - * @param string|Client $uuid + * @param string|ClientRecord $uuid * @return void * @throws DatabaseException */ - public function deleteClient(string|Client $uuid): void + public function deleteClient(string|ClientRecord $uuid): void { - if($uuid instanceof Client) + if($uuid instanceof ClientRecord) { $uuid = $uuid->getUuid(); } diff --git a/src/FederationLib/Managers/MetadataManagers/TelegramUserManager.php b/src/FederationLib/Managers/MetadataManagers/TelegramUserManager.php index 9cc65f0..3cf891f 100644 --- a/src/FederationLib/Managers/MetadataManagers/TelegramUserManager.php +++ b/src/FederationLib/Managers/MetadataManagers/TelegramUserManager.php @@ -14,23 +14,23 @@ use FederationLib\Exceptions\Standard\PeerMetadataNotFoundException; use FederationLib\Interfaces\PeerMetadataManagerInterface; use FederationLib\Managers\RedisConnectionManager; - use FederationLib\Objects\Client; - use FederationLib\Objects\Peer; + use FederationLib\Objects\ClientRecord; + use FederationLib\Objects\PeerRecord; use FederationLib\Objects\Standard\PeerMetadata\TelegramUserMetadata; use LogLib\Log; class TelegramUserManager implements PeerMetadataManagerInterface { /** - * @param Client|string $client_uuid + * @param ClientRecord|string $client_uuid * @param TelegramUserMetadata $telegram_user_metadata * @return string * @throws DatabaseException * @throws InvalidPeerMetadataException */ - public function syncMetadata(Client|string $client_uuid, TelegramUserMetadata $telegram_user_metadata): string + public function syncMetadata(ClientRecord|string $client_uuid, TelegramUserMetadata $telegram_user_metadata): string { - if($client_uuid instanceof Client) + if($client_uuid instanceof ClientRecord) { $client_uuid = $client_uuid->getUuid(); } @@ -126,14 +126,14 @@ /** * Registers the client's metadata with the database * - * @param Client|string $client_uuid + * @param ClientRecord|string $client_uuid * @param TelegramUserMetadata $telegram_user_metadata * @return string * @throws DatabaseException */ - public function registerMetadata(Client|string $client_uuid, TelegramUserMetadata $telegram_user_metadata): string + public function registerMetadata(ClientRecord|string $client_uuid, TelegramUserMetadata $telegram_user_metadata): string { - if($client_uuid instanceof Client) + if($client_uuid instanceof ClientRecord) { $client_uuid = $client_uuid->getUuid(); } @@ -182,14 +182,14 @@ } /** - * @param Peer|string $federated_address - * @throws PeerMetadataNotFoundException - * @throws DatabaseException + * @param PeerRecord|string $federated_address * @return TelegramUserMetadata + *@throws DatabaseException + * @throws PeerMetadataNotFoundException */ - public function getMetadata(Peer|string $federated_address): TelegramUserMetadata + public function getMetadata(PeerRecord|string $federated_address): TelegramUserMetadata { - if($federated_address instanceof Peer) + if($federated_address instanceof PeerRecord) { $federated_address = $federated_address->getFederatedAddress(); } @@ -243,7 +243,7 @@ if($result->rowCount() === 0) { - throw new PeerMetadataNotFoundException(sprintf('Peer metadata not found for federated address %s', $federated_address)); + throw new PeerMetadataNotFoundException(sprintf('PeerRecord metadata not found for federated address %s', $federated_address)); } $telegram_user_metadata = TelegramUserMetadata::fromArray($result->fetchAssociative(), true); diff --git a/src/FederationLib/Managers/PeerManager.php b/src/FederationLib/Managers/PeerManager.php index 5860236..dd1c3da 100644 --- a/src/FederationLib/Managers/PeerManager.php +++ b/src/FederationLib/Managers/PeerManager.php @@ -4,6 +4,7 @@ use FederationLib\Enums\Standard\UserPeerType; use FederationLib\FederationLib; + use FederationLib\Interfaces\PeerMetadataInterface; use FederationLib\Interfaces\PeerMetadataManagerInterface; use FederationLib\Objects\Standard\PeerMetadata\TelegramUserMetadata; @@ -29,4 +30,9 @@ $this->federationLib = $federationLib; $this->metadata_managers[UserPeerType::TELEGRAM_USER] = new TelegramUserMetadata(); } + + public function registerPeer(string $federated_address, PeerMetadataInterface $peer_metadata): void + { + + } } \ No newline at end of file diff --git a/src/FederationLib/Objects/Client.php b/src/FederationLib/Objects/ClientRecord.php similarity index 97% rename from src/FederationLib/Objects/Client.php rename to src/FederationLib/Objects/ClientRecord.php index 01e5bb7..30ce7e4 100755 --- a/src/FederationLib/Objects/Client.php +++ b/src/FederationLib/Objects/ClientRecord.php @@ -9,7 +9,7 @@ use FederationLib\Enums\Standard\PermissionRole; use FederationLib\Interfaces\SerializableObjectInterface; - class Client implements SerializableObjectInterface + class ClientRecord implements SerializableObjectInterface { /** * @var string @@ -238,9 +238,9 @@ * Constructs object from an array representation. * * @param array $array - * @return Client + * @return ClientRecord */ - public static function fromArray(array $array): Client + public static function fromArray(array $array): ClientRecord { $client = new self(); diff --git a/src/FederationLib/Objects/InvokeResults.php b/src/FederationLib/Objects/InvokeResults.php deleted file mode 100644 index 441ff45..0000000 --- a/src/FederationLib/Objects/InvokeResults.php +++ /dev/null @@ -1,50 +0,0 @@ -exit_code = $exit_code; - $this->output = $output; - } - - /** - * Returns the exit code of the command. - * - * @return int - */ - public function getExitCode(): int - { - return $this->exit_code; - } - - /** - * Returns the output of the command. - * - * @return string - */ - public function getOutput(): string - { - return $this->output; - } - } \ No newline at end of file diff --git a/src/FederationLib/Objects/Peer.php b/src/FederationLib/Objects/PeerRecord.php similarity index 95% rename from src/FederationLib/Objects/Peer.php rename to src/FederationLib/Objects/PeerRecord.php index 4bfdb44..3a99978 100644 --- a/src/FederationLib/Objects/Peer.php +++ b/src/FederationLib/Objects/PeerRecord.php @@ -6,7 +6,7 @@ use FederationLib\Interfaces\SerializableObjectInterface; - class Peer implements SerializableObjectInterface + class PeerRecord implements SerializableObjectInterface { /** * @var string @@ -120,9 +120,9 @@ * Constructs object from an array representation * * @param array $array - * @return Peer + * @return PeerRecord */ - public static function fromArray(array $array): Peer + public static function fromArray(array $array): PeerRecord { $object = new self(); diff --git a/src/FederationLib/Objects/QueryDocument.php b/src/FederationLib/Objects/QueryDocument.php deleted file mode 100644 index a0e3092..0000000 --- a/src/FederationLib/Objects/QueryDocument.php +++ /dev/null @@ -1,17 +0,0 @@ -client = $client; $this->peer = $peer; @@ -73,17 +73,17 @@ } /** - * @return Client|null + * @return ClientRecord|null */ - public function getClient(): ?Client + public function getClient(): ?ClientRecord { return $this->client; } /** - * @return Peer|null + * @return PeerRecord|null */ - public function getPeer(): ?Peer + public function getPeer(): ?PeerRecord { return $this->peer; } diff --git a/src/FederationLib/Objects/Standard/Client.php b/src/FederationLib/Objects/Standard/Client.php index e05e445..602e552 100644 --- a/src/FederationLib/Objects/Standard/Client.php +++ b/src/FederationLib/Objects/Standard/Client.php @@ -5,6 +5,7 @@ namespace FederationLib\Objects\Standard; use FederationLib\Interfaces\SerializableObjectInterface; + use FederationLib\Objects\ClientRecord; class Client implements SerializableObjectInterface { @@ -51,9 +52,9 @@ /** * Client constructor. * - * @param \FederationLib\Objects\Client|null $client + * @param ClientRecord|null $client */ - public function __construct(?\FederationLib\Objects\Client $client=null) + public function __construct(?ClientRecord $client=null) { if($client === null) { diff --git a/src/FederationLib/Objects/Standard/Peer.php b/src/FederationLib/Objects/Standard/Peer.php deleted file mode 100644 index 5c86283..0000000 --- a/src/FederationLib/Objects/Standard/Peer.php +++ /dev/null @@ -1,176 +0,0 @@ -federated_address = $peer->getFederatedAddress(); - $this->client_first_seen = $peer->getClientFirstSeen(); - $this->client_last_seen = $peer->getClientLastSeen(); - $this->active_restriction = $peer->getActiveRestriction(); - $this->permission_role = $peer->getPermissionRole(); - $this->discovered_timestamp = $peer->getDiscoveredTimestamp(); - $this->seen_timestamp = $peer->getSeenTimestamp(); - } - - /** - * Returns the federated address of the peer - * - * @return string - */ - public function getFederatedAddress(): string - { - return $this->federated_address; - } - - /** - * Returns the Client UUID that first saw the peer - * - * @return string - */ - public function getClientFirstSeen(): string - { - return $this->client_first_seen; - } - - /** - * Returns the Client UUID that last saw the peer - * - * @return string - */ - public function getClientLastSeen(): string - { - return $this->client_last_seen; - } - - /** - * Optional. Returns the ID of the active restriction applied to the peer - * if null, no restriction is applied - * - * @return string|null - */ - public function getActiveRestriction(): ?string - { - return $this->active_restriction; - } - - /** - * Returns the permission role of the peer - * - * @return int - */ - public function getPermissionRole(): int - { - return $this->permission_role; - } - - /** - * Returns the timestamp of when the peer was discovered by the client - * - * @return int - */ - public function getDiscoveredTimestamp(): int - { - return $this->discovered_timestamp; - } - - /** - * Returns the timestamp of when the peer was last seen by the client - * - * @return int - */ - public function getSeenTimestamp(): int - { - return $this->seen_timestamp; - } - - /** - * Returns an array representation of the object - * - * @return array - */ - public function toArray(): array - { - return [ - 'federated_address' => $this->federated_address, - 'client_first_seen' => $this->client_first_seen, - 'client_last_seen' => $this->client_last_seen, - 'active_restriction' => $this->active_restriction, - 'permission_role' => $this->permission_role, - 'discovered_timestamp' => $this->discovered_timestamp, - 'seen_timestamp' => $this->seen_timestamp - ]; - } - - /** - * Constructs object from an array representation - * - * @param array $array - * @return Peer - */ - public static function fromArray(array $array): Peer - { - $object = new self(); - - $object->federated_address = $array['federated_address']; - $object->client_first_seen = $array['client_first_seen']; - $object->client_last_seen = $array['client_last_seen']; - $object->active_restriction = $array['active_restriction']; - $object->permission_role = $array['permission_role']; - $object->discovered_timestamp = $array['discovered_timestamp']; - $object->seen_timestamp = $array['seen_timestamp']; - - return $object; - } - } \ No newline at end of file diff --git a/tests/client_manager/cache_update_test.php b/tests/client_manager/cache_update_test.php index 2a7f2cc..7c5c245 100644 --- a/tests/client_manager/cache_update_test.php +++ b/tests/client_manager/cache_update_test.php @@ -5,7 +5,7 @@ import('net.nosial.federationlib'); $federationlib = new \FederationLib\FederationLib(); - $client = new \FederationLib\Objects\Client(); + $client = new \FederationLib\Objects\ClientRecord(); $client->setDescription('This is a test client generated by a test script.'); $uuid = $federationlib->getClientManager()->registerClient($client); diff --git a/tests/client_manager/create_client.php b/tests/client_manager/create_client.php index e92e19a..88a41da 100644 --- a/tests/client_manager/create_client.php +++ b/tests/client_manager/create_client.php @@ -5,7 +5,7 @@ import('net.nosial.federationlib'); $federationlib = new \FederationLib\FederationLib(); - $client = new \FederationLib\Objects\Client(); + $client = new \FederationLib\Objects\ClientRecord(); $client->setDescription('This is a test client generated by a test script.'); $uuid = $federationlib->getClientManager()->registerClient($client); diff --git a/tests/client_manager/create_secured_client.php b/tests/client_manager/create_secured_client.php index effc672..a366ac6 100644 --- a/tests/client_manager/create_secured_client.php +++ b/tests/client_manager/create_secured_client.php @@ -8,7 +8,7 @@ // loop 50 times to create 50 clients for($i = 0; $i < 50; $i++) { - $client = new \FederationLib\Objects\Client(); + $client = new \FederationLib\Objects\ClientRecord(); $client->setDescription('This is a test client generated by a test script.'); $client->enableAuthentication();