Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 5e2efa4

Browse files
committed
Added zmq identifier to action calls
1 parent 99c24c7 commit 5e2efa4

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
lines changed

src/Actions/Action.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
interface Action
88
{
9-
public function call(array $header, array $content);
9+
public function call(array $header, array $content, $zmqId = null);
1010
}

src/Actions/ExecuteAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(
5252
$this->shellSoul = $shellSoul;
5353
}
5454

55-
public function call(array $header, array $content)
55+
public function call(array $header, array $content, $zmqId = null)
5656
{
5757
$this->broker->send(
5858
$this->iopubSocket, 'status', ['execution_state' => 'busy'], $header

src/Actions/HistoryAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function __construct(JupyterBroker $broker, SocketWrapper $shellSocket)
2828
$this->shellSocket = $shellSocket;
2929
}
3030

31-
public function call(array $header, array $content)
31+
public function call(array $header, array $content, $zmqId = null)
3232
{
33-
$this->broker->send($this->shellSocket, 'history_reply', ['history' => []], $header);
33+
$this->broker->send($this->shellSocket, 'history_reply', ['history' => []], $header, [], $zmqId);
3434
}
3535
}

src/Actions/KernelInfoAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(JupyterBroker $broker, SocketWrapper $shellSocket, S
3232
$this->iopubSocket = $iopubSocket;
3333
}
3434

35-
public function call(array $header, array $content)
35+
public function call(array $header, array $content, $zmqId = null)
3636
{
3737
// TODO: Implement call() method.
3838

src/Actions/ShutdownAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
final class ShutdownAction implements Action
88
{
9-
public function call(array $header, array $content)
9+
public function call(array $header, array $content, $zmqId = null)
1010
{
1111
// TODO: Implement call() method.
1212
}

src/Handlers/ShellMessagesHandler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __invoke(array $msg)
7575

7676
$this->logger->debug('Received message', [
7777
'processId' => getmypid(),
78-
'zmqId' => $zmqId,
78+
'zmqId' => htmlentities($zmqId, ENT_COMPAT, "UTF-8"),
7979
'delim' => $delim,
8080
'hmac' => $hmac,
8181
'header' => $header,
@@ -85,13 +85,13 @@ public function __invoke(array $msg)
8585
]);
8686

8787
if ('kernel_info_request' === $header['msg_type']) {
88-
$this->kernelInfoAction->call($header, $content);
88+
$this->kernelInfoAction->call($header, $content, $zmqId);
8989
} elseif ('execute_request' === $header['msg_type']) {
90-
$this->executeAction->call($header, $content);
90+
$this->executeAction->call($header, $content, $zmqId);
9191
} elseif ('history_request' === $header['msg_type']) {
92-
$this->historyAction->call($header, $content);
92+
$this->historyAction->call($header, $content, $zmqId);
9393
} elseif ('shutdown_request' === $header['msg_type']) {
94-
$this->shutdownAction->call($header, $content);
94+
$this->shutdownAction->call($header, $content, $zmqId);
9595
} elseif ('comm_open' === $header['msg_type']) {
9696
// TODO: Research about what should be done.
9797
} else {

src/JupyterBroker.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@ public function __construct($key, $signatureScheme, UuidInterface $sessionId, Lo
5757
* @param array $content
5858
* @param array $parentHeader
5959
* @param array $metadata
60+
* @param string $zmqId
6061
*/
6162
public function send(
62-
SocketWrapper $stream, $msgType, array $content = [], array $parentHeader = [], array $metadata = []
63-
)
64-
{
63+
SocketWrapper $stream,
64+
$msgType,
65+
array $content = [],
66+
array $parentHeader = [],
67+
array $metadata = [],
68+
$zmqId = null
69+
) {
6570
$header = $this->createHeader($msgType);
6671

6772
$msgDef = [
@@ -71,10 +76,16 @@ public function send(
7176
json_encode(empty($content) ? new \stdClass : $content),
7277
];
7378

79+
if ($zmqId !== null) {
80+
$finalMsg = [$zmqId];
81+
} else {
82+
$finalMsg = [];
83+
}
84+
7485
$finalMsg = array_merge(
86+
$finalMsg,
7587
['<IDS|MSG>', $this->sign($msgDef)],
76-
$msgDef
77-
);
88+
$msgDef);
7889

7990
if (null !== $this->logger) {
8091
$this->logger->debug('Sent message', ['processId' => getmypid(), 'message' => $finalMsg]);
@@ -90,15 +101,17 @@ public function send(
90101
private function createHeader($msgType)
91102
{
92103
return [
93-
'date' => (new \DateTime('NOW'))->format('c'),
94-
'msg_id' => Uuid::uuid4()->toString(),
104+
'date' => (new \DateTime('NOW'))->format('c'),
105+
'msg_id' => Uuid::uuid4()->toString(),
95106
'username' => "kernel",
96-
'session' => $this->sesssionId->toString(),
107+
'session' => $this->sesssionId->toString(),
97108
'msg_type' => $msgType,
109+
'version' => '5.0',
98110
];
99111
}
100112

101-
private function sign(array $message_list) {
113+
private function sign(array $message_list)
114+
{
102115
$hm = hash_init(
103116
$this->hashAlgorithm,
104117
HASH_HMAC,

0 commit comments

Comments
 (0)