Skip to content

Commit

Permalink
Fix psalm errors / change return type of tunnel to void
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Mar 19, 2024
1 parent bf9cfb7 commit acc0a2f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Socks5SocketConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ public static function tunnel(
?string $username,
?string $password,
?Cancellation $cancellation
): Socket {
): void {
if (($username === null) !== ($password === null)) {
throw new \Error("Both or neither username and password must be provided!");
}

/** @psalm-suppress DeprecatedMethod */
$uri = Uri::createFromString($target);

$read = function (int $length) use ($socket, $cancellation): string {
Expand All @@ -85,7 +86,10 @@ public static function tunnel(
$buffer = '';

do {
$chunk = $socket->read($cancellation, $length - \strlen($buffer));
$limit = $length - \strlen($buffer);
\assert($limit > 0);

$chunk = $socket->read($cancellation, $limit);
if ($chunk === null) {
throw new SocketException("The socket was closed before the tunnel could be established");
}
Expand Down Expand Up @@ -153,8 +157,6 @@ public static function tunnel(
0x4 => 18,
0x3 => \ord($read(1)) + 2
});

return $socket;
}

public function __construct(
Expand All @@ -173,7 +175,8 @@ public function connect(SocketAddress|string $uri, ?ConnectContext $context = nu
$connector = $this->socketConnector ?? socketConnector();

$socket = $connector->connect($this->proxyAddress, $context, $cancellation);
self::tunnel($socket, (string) $uri, $this->username, $this->password, $cancellation);

return self::tunnel($socket, (string) $uri, $this->username, $this->password, $cancellation);
return $socket;
}
}

0 comments on commit acc0a2f

Please sign in to comment.