Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@
namespace Throttr\SDK;

use Co;
use http\Env\Request;
use Swoole\Coroutine\Client;
use Swoole\Coroutine\Channel;
use Throttr\SDK\Enum\RequestType;
use Throttr\SDK\Enum\ValueSize;
use Throttr\SDK\Responses\ChannelResponse;
use Throttr\SDK\Responses\ChannelsResponse;
use Throttr\SDK\Responses\ConnectionResponse;
use Throttr\SDK\Responses\ConnectionsResponse;
use Throttr\SDK\Responses\GetResponse;
use Throttr\SDK\Responses\InfoResponse;
use Throttr\SDK\Responses\ListResponse;
use Throttr\SDK\Responses\QueryResponse;
use Throttr\SDK\Responses\StatResponse;
use Throttr\SDK\Responses\StatsResponse;
use Throttr\SDK\Responses\StatusResponse;
use Throttr\SDK\Responses\WhoamiResponse;

/**
* Connection
Expand Down Expand Up @@ -182,6 +188,11 @@ private function processResponses(): void
RequestType::INFO => InfoResponse::fromBytes($buffer, $this->size),
RequestType::STAT => StatResponse::fromBytes($buffer, $this->size),
RequestType::STATS => StatsResponse::fromBytes($buffer, $this->size),
RequestType::CONNECTIONS => ConnectionsResponse::fromBytes($buffer, $this->size),
RequestType::CONNECTION => ConnectionResponse::fromBytes($buffer, $this->size),
RequestType::CHANNELS => ChannelsResponse::fromBytes($buffer, $this->size),
RequestType::CHANNEL => ChannelResponse::fromBytes($buffer, $this->size),
RequestType::WHOAMI => WhoamiResponse::fromBytes($buffer, $this->size),
};

if ($response === null) {
Expand Down
34 changes: 34 additions & 0 deletions src/Enum/ConnectionKind.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Enum;

/**
* Connection kind
*/
enum ConnectionKind: int
{
/**
* TCP socket
*/
case TCP = 0x00;

/**
* Unix socket
*/
case UNIX = 0x01;
}
34 changes: 34 additions & 0 deletions src/Enum/ConnectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Enum;

/**
* Connection type
*/
enum ConnectionType: int
{
/**
* Client
*/
case CLIENT = 0x00;

/**
* Agent
*/
case AGENT = 0x01;
}
34 changes: 34 additions & 0 deletions src/Enum/IpVersion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Enum;

/**
* IpVersion
*/
enum IpVersion: int
{
/**
* V4
*/
case V4 = 0x04;

/**
* V6
*/
case V6 = 0x06;
}
58 changes: 58 additions & 0 deletions src/Requests/ChannelRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
use Throttr\SDK\Enum\ValueSize;

/**
* Connection request
*/
class ChannelRequest extends BaseRequest
{
/**
* Type
*
* @var RequestType
*/
public RequestType $type = RequestType::CHANNEL;

/**
* Constructor
*
* @param string $name
*/
public function __construct(
public string $name
)
{
}

/**
* To bytes
*
* @param ValueSize $size
* @return string
*/
public function toBytes(ValueSize $size): string
{
return pack(static::pack(ValueSize::UINT8), $this->type->value) .
pack(static::pack(ValueSize::UINT8), strlen($this->name)) .
$this->name;
}
}
52 changes: 52 additions & 0 deletions src/Requests/ChannelsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
use Throttr\SDK\Enum\ValueSize;

/**
* Channels request
*/
class ChannelsRequest extends BaseRequest
{
/**
* Type
*
* @var RequestType
*/
public RequestType $type = RequestType::CHANNELS;

/**
* Constructor
*/
public function __construct()
{
}

/**
* To bytes
*
* @param ValueSize $size
* @return string
*/
public function toBytes(ValueSize $size): string
{
return pack(static::pack(ValueSize::UINT8), $this->type->value);
}
}
57 changes: 57 additions & 0 deletions src/Requests/ConnectionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
use Throttr\SDK\Enum\ValueSize;

/**
* Connection request
*/
class ConnectionRequest extends BaseRequest
{
/**
* Type
*
* @var RequestType
*/
public RequestType $type = RequestType::CONNECTION;

/**
* Constructor
*
* @param string $id
*/
public function __construct(
public string $id
)
{
}

/**
* To bytes
*
* @param ValueSize $size
* @return string
*/
public function toBytes(ValueSize $size): string
{
return pack(static::pack(ValueSize::UINT8), $this->type->value) .
hex2bin($this->id);
}
}
52 changes: 52 additions & 0 deletions src/Requests/ConnectionsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

// Copyright (C) 2025 Ian Torres
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

namespace Throttr\SDK\Requests;

use Throttr\SDK\Enum\RequestType;
use Throttr\SDK\Enum\ValueSize;

/**
* Connections request
*/
class ConnectionsRequest extends BaseRequest
{
/**
* Type
*
* @var RequestType
*/
public RequestType $type = RequestType::CONNECTIONS;

/**
* Constructor
*/
public function __construct()
{
}

/**
* To bytes
*
* @param ValueSize $size
* @return string
*/
public function toBytes(ValueSize $size): string
{
return pack(static::pack(ValueSize::UINT8), $this->type->value);
}
}
Loading