@@ -3,61 +3,63 @@ package main
33import (
44 "encoding/json"
55 "fmt"
6- zmq "github.com/gophergala2016/gophernotes/Godeps/_workspace/src/github.com/alecthomas/gozmq"
76 "io"
87 "io/ioutil"
98 "log"
109 "os"
10+
11+ zmq "github.com/gophergala2016/gophernotes/Godeps/_workspace/src/github.com/alecthomas/gozmq"
1112)
1213
1314var logger * log.Logger
1415
1516// ConnectionInfo stores the contents of the kernel connection file created by Jupyter.
1617type ConnectionInfo struct {
17- Signature_scheme string
18- Transport string
19- Stdin_port int
20- Control_port int
21- IOPub_port int
22- HB_port int
23- Shell_port int
24- Key string
25- IP string
18+ SignatureScheme string
19+ Transport string
20+ StdinPort int
21+ ControlPort int
22+ IOPubPort int
23+ HBPort int
24+ ShellPort int
25+ Key string
26+ IP string
2627}
2728
2829// SocketGroup holds the sockets needed to communicate with the kernel, and
2930// the key for message signing.
3031type SocketGroup struct {
31- Shell_socket * zmq.Socket
32- Control_socket * zmq.Socket
33- Stdin_socket * zmq.Socket
34- IOPub_socket * zmq.Socket
35- Key []byte
32+ ShellSocket * zmq.Socket
33+ ControlSocket * zmq.Socket
34+ StdinSocket * zmq.Socket
35+ IOPubSocket * zmq.Socket
36+ Key []byte
3637}
3738
3839// PrepareSockets sets up the ZMQ sockets through which the kernel will communicate.
39- func PrepareSockets (conn_info ConnectionInfo ) (sg SocketGroup ) {
40+ func PrepareSockets (connInfo ConnectionInfo ) (sg SocketGroup ) {
4041
42+ // TODO handle errors.
4143 context , _ := zmq .NewContext ()
42- sg .Shell_socket , _ = context .NewSocket (zmq .ROUTER )
43- sg .Control_socket , _ = context .NewSocket (zmq .ROUTER )
44- sg .Stdin_socket , _ = context .NewSocket (zmq .ROUTER )
45- sg .IOPub_socket , _ = context .NewSocket (zmq .PUB )
44+ sg .ShellSocket , _ = context .NewSocket (zmq .ROUTER )
45+ sg .ControlSocket , _ = context .NewSocket (zmq .ROUTER )
46+ sg .StdinSocket , _ = context .NewSocket (zmq .ROUTER )
47+ sg .IOPubSocket , _ = context .NewSocket (zmq .PUB )
4648
47- address := fmt .Sprintf ("%v://%v:%%v" , conn_info .Transport , conn_info .IP )
49+ address := fmt .Sprintf ("%v://%v:%%v" , connInfo .Transport , connInfo .IP )
4850
49- sg .Shell_socket .Bind (fmt .Sprintf (address , conn_info . Shell_port ))
50- sg .Control_socket .Bind (fmt .Sprintf (address , conn_info . Control_port ))
51- sg .Stdin_socket .Bind (fmt .Sprintf (address , conn_info . Stdin_port ))
52- sg .IOPub_socket .Bind (fmt .Sprintf (address , conn_info . IOPub_port ))
51+ sg .ShellSocket .Bind (fmt .Sprintf (address , connInfo . ShellPort ))
52+ sg .ControlSocket .Bind (fmt .Sprintf (address , connInfo . ControlPort ))
53+ sg .StdinSocket .Bind (fmt .Sprintf (address , connInfo . StdinPort ))
54+ sg .IOPubSocket .Bind (fmt .Sprintf (address , connInfo . IOPubPort ))
5355
5456 // Message signing key
55- sg .Key = []byte (conn_info .Key )
57+ sg .Key = []byte (connInfo .Key )
5658
5759 // Start the heartbeat device
58- HB_socket , _ := context .NewSocket (zmq .REP )
59- HB_socket .Bind (fmt .Sprintf (address , conn_info . HB_port ))
60- go zmq .Device (zmq .FORWARDER , HB_socket , HB_socket )
60+ HBSocket , _ := context .NewSocket (zmq .REP )
61+ HBSocket .Bind (fmt .Sprintf (address , connInfo . HBPort ))
62+ go zmq .Device (zmq .FORWARDER , HBSocket , HBSocket )
6163
6264 return
6365}
@@ -78,8 +80,8 @@ func HandleShellMsg(receipt MsgReceipt) {
7880
7981// KernelInfo holds information about the igo kernel, for kernel_info_reply messages.
8082type KernelInfo struct {
81- Protocol_version []int `json:"protocol_version"`
82- Language string `json:"language"`
83+ ProtocolVersion []int `json:"protocol_version"`
84+ Language string `json:"language"`
8385}
8486
8587// KernelStatus holds a kernel state, for status broadcast messages.
@@ -91,7 +93,7 @@ type KernelStatus struct {
9193func SendKernelInfo (receipt MsgReceipt ) {
9294 reply := NewMsg ("kernel_info_reply" , receipt .Msg )
9395 reply .Content = KernelInfo {[]int {4 , 0 }, "go" }
94- receipt .SendResponse (receipt .Sockets .Shell_socket , reply )
96+ receipt .SendResponse (receipt .Sockets .ShellSocket , reply )
9597}
9698
9799// ShutdownReply encodes a boolean indication of stutdown/restart
@@ -105,38 +107,38 @@ func HandleShutdownRequest(receipt MsgReceipt) {
105107 content := receipt .Msg .Content .(map [string ]interface {})
106108 restart := content ["restart" ].(bool )
107109 reply .Content = ShutdownReply {restart }
108- receipt .SendResponse (receipt .Sockets .Shell_socket , reply )
110+ receipt .SendResponse (receipt .Sockets .ShellSocket , reply )
109111 logger .Println ("Shutting down in response to shutdown_request" )
110112 os .Exit (0 )
111113}
112114
113115// RunKernel is the main entry point to start the kernel. This is what is called by the
114116// gophernotes executable.
115- func RunKernel (connection_file string , logwriter io.Writer ) {
117+ func RunKernel (connectionFile string , logwriter io.Writer ) {
116118
117119 logger = log .New (logwriter , "gophernotes " , log .LstdFlags )
118120
119121 // set up the "Session" with the replpkg
120122 SetupExecutionEnvironment ()
121123
122- var conn_info ConnectionInfo
123- bs , err := ioutil .ReadFile (connection_file )
124+ var connInfo ConnectionInfo
125+ bs , err := ioutil .ReadFile (connectionFile )
124126 if err != nil {
125127 log .Fatalln (err )
126128 }
127- err = json .Unmarshal (bs , & conn_info )
129+ err = json .Unmarshal (bs , & connInfo )
128130 if err != nil {
129131 log .Fatalln (err )
130132 }
131- logger .Printf ("%+v\n " , conn_info )
133+ logger .Printf ("%+v\n " , connInfo )
132134
133135 // Set up the ZMQ sockets through which the kernel will communicate
134- sockets := PrepareSockets (conn_info )
136+ sockets := PrepareSockets (connInfo )
135137
136138 pi := zmq.PollItems {
137- zmq.PollItem {Socket : sockets .Shell_socket , Events : zmq .POLLIN },
138- zmq.PollItem {Socket : sockets .Stdin_socket , Events : zmq .POLLIN },
139- zmq.PollItem {Socket : sockets .Control_socket , Events : zmq .POLLIN },
139+ zmq.PollItem {Socket : sockets .ShellSocket , Events : zmq .POLLIN },
140+ zmq.PollItem {Socket : sockets .StdinSocket , Events : zmq .POLLIN },
141+ zmq.PollItem {Socket : sockets .ControlSocket , Events : zmq .POLLIN },
140142 }
141143
142144 var msgparts [][]byte
0 commit comments