File tree Expand file tree Collapse file tree 8 files changed +50
-1
lines changed
Expand file tree Collapse file tree 8 files changed +50
-1
lines changed Original file line number Diff line number Diff line change 44
55namespace TorPHP \Exception ;
66
7+ /**
8+ * @author Edouard Courty
9+ */
710class SocketException extends \Exception
811{
912}
Original file line number Diff line number Diff line change 44
55namespace TorPHP \Helper ;
66
7+ /**
8+ * Helper class for private key management.
9+ *
10+ * @author Edouard Courty
11+ */
712class PrivateKeyHelper
813{
914 public const string NO_PRIVATE_KEY = 'NEW: ' . self ::PRIVATE_KEY_PREFIX ;
1015
1116 private const string PRIVATE_KEY_PREFIX = 'ED25519-V3 ' ;
1217
18+ /**
19+ * Parse the private key to ensure it has the correct prefix.
20+ */
1321 public static function parsePrivateKey (string $ privateKey ): string
1422 {
1523 if (str_starts_with ($ privateKey , self ::PRIVATE_KEY_PREFIX ) === true ) {
Original file line number Diff line number Diff line change 44
55namespace TorPHP \Model ;
66
7+ /**
8+ * Represents a Tor circuit.
9+ *
10+ * @author Edouard Courty
11+ */
712class Circuit
813{
914 /**
Original file line number Diff line number Diff line change 44
55namespace TorPHP \Model ;
66
7+ /**
8+ * Represents a Tor Onion service.
9+ *
10+ * @author Edouard Courty
11+ */
712class OnionService
813{
914 public function __construct (
Original file line number Diff line number Diff line change 44
55namespace TorPHP \Model ;
66
7+ /**
8+ * Represents a port mapping for a Tor hidden service.
9+ *
10+ * @author Edouard Courty
11+ */
712class PortMapping
813{
914 public function __construct (
Original file line number Diff line number Diff line change @@ -39,6 +39,10 @@ public function __construct(
3939 $ this ->authenticate ();
4040 }
4141
42+ /**
43+ * Helper method to assert the response from Tor ControlPort.
44+ * Returns the response string if successful.
45+ */
4246 private function assertSuccessResponse (): string
4347 {
4448 $ response = $ this ->socketClient ->readLine ();
@@ -55,7 +59,7 @@ private function assertSuccessResponse(): string
5559 }
5660
5761 /**
58- * Authenticates against the Tor ControlPort using password or cookie.
62+ * Helper method to authenticate against the Tor ControlPort using password or cookie.
5963 */
6064 private function authenticate (): void
6165 {
@@ -136,6 +140,8 @@ public function close(): void
136140 }
137141
138142 /**
143+ * Fetches the current Tor circuits the node has.
144+ *
139145 * @return Circuit[]
140146 */
141147 public function getCircuits (): array
Original file line number Diff line number Diff line change @@ -121,6 +121,9 @@ public function newIdentity(): void
121121 $ torControlClient ->close ();
122122 }
123123
124+ /**
125+ * Helper method to build the HTTP client with the current options.
126+ */
124127 private function buildHttpClient (): void
125128 {
126129 $ this ->httpClient = $ this ->baseHttpClient ->withOptions ($ this ->clientOptions );
Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ public function connect(): void
4747 $ this ->socket = $ socket ;
4848 }
4949
50+ /**
51+ * Helper method to write to the socket
52+ */
5053 public function write (string $ data ): void
5154 {
5255 $ this ->ensureConnected ();
@@ -57,6 +60,9 @@ public function write(string $data): void
5760 }
5861 }
5962
63+ /**
64+ * Reads one line from the socket
65+ */
6066 public function readLine (): ?string
6167 {
6268 $ this ->ensureConnected ();
@@ -70,6 +76,8 @@ public function readLine(): ?string
7076 }
7177
7278 /**
79+ * Reads a block of data from the socket until the specified string is found.
80+ *
7381 * @return string[]
7482 */
7583 public function readBlock (string $ until ): array
@@ -101,6 +109,9 @@ public function readBlock(string $until): array
101109 return $ buffer ;
102110 }
103111
112+ /**
113+ * Closes the socket connection.
114+ */
104115 public function close (): void
105116 {
106117 if (\is_resource ($ this ->socket ) === true ) {
@@ -110,6 +121,9 @@ public function close(): void
110121 $ this ->socket = false ;
111122 }
112123
124+ /**
125+ * Helper method to check if the socket is instantiated
126+ */
113127 private function ensureConnected (): void
114128 {
115129 if (\is_resource ($ this ->socket ) === false ) {
You can’t perform that action at this time.
0 commit comments