parent
9b843905f3
commit
b3dbb89529
|
@ -1,4 +1,5 @@
|
|||
include ../syndicate-nim/depends.tup
|
||||
NIM_FLAGS += --path:$(TUP_CWD)/../syndicate-nim/src
|
||||
NIM_FLAGS += --path:$(TUP_CWD)/../libssh/src
|
||||
|
||||
NIM_FLAGS += --backend:cpp
|
||||
|
|
|
@ -112,16 +112,26 @@ type
|
|||
dataspace: Ref
|
||||
SocketArgs {.preservesDictionary.} = object
|
||||
`listen-socket`: string
|
||||
ServeSshArgs {.preservesDictionary.} = object
|
||||
`keyfile`: string
|
||||
`sshhost`: string
|
||||
`sshport`: int
|
||||
|
||||
proc bootNixActor(root: Ref; turn: var Turn) =
|
||||
connectStdio(root, turn)
|
||||
|
||||
during(turn, root, ?RefArgs) do (ds: Ref):
|
||||
discard bootNixFacet(ds, turn)
|
||||
|
||||
during(turn, root, ?SocketArgs) do (path: string):
|
||||
removeFile(path)
|
||||
asyncCheck(turn, emulateSocket(path))
|
||||
|
||||
during(turn, root, ?ServeSshArgs) do (keyFile: string, host: string, port: int):
|
||||
let srv = serveSsh(keyFile, host, port)
|
||||
do:
|
||||
removeFile(path)
|
||||
stderr.writeLine "stop SSH server"
|
||||
stop(srv)
|
||||
|
||||
initNix() # Nix lib isn't actually being used but it's nice to know that it links.
|
||||
runActor("main", bootNixActor)
|
||||
|
|
|
@ -457,8 +457,32 @@ proc emulateSocket*(path: string) {.async, gcsafe.} =
|
|||
except ProtocolError as err:
|
||||
stderr.writeLine "failed to service client, ", err.msg
|
||||
|
||||
when isMainModule:
|
||||
const path = "/tmp/worker.nix.socket"
|
||||
if fileExists(path): removeFile(path)
|
||||
try: waitFor emulateSocket(path)
|
||||
finally: removeFile(path)
|
||||
import libssh
|
||||
|
||||
type Server* = ref object
|
||||
bnd: Bind
|
||||
callbacks: BindCallbacks
|
||||
|
||||
proc stop*(srv: Server) =
|
||||
free(srv.bnd)
|
||||
|
||||
proc serveSsh*(keyFile: string, host: string, port: int): Server =
|
||||
stderr.writeLine "initialize libssh"
|
||||
libssh.init()
|
||||
|
||||
let srv = Server(bnd: newBind())
|
||||
try:
|
||||
stderr.writeLine "load key ", keyFile
|
||||
setOption(srv.bnd, SSH_BIND_OPTIONS_HOSTKEY, keyFile)
|
||||
setOption(srv.bnd, SSH_BIND_OPTIONS_BINDADDR, host)
|
||||
setOption(srv.bnd, SSH_BIND_OPTIONS_BINDPORT, uint port)
|
||||
|
||||
srv.callbacks.incoming_connection = proc (b: Bind; data: pointer) {.cdecl.} =
|
||||
let srv = cast[Server](data)
|
||||
stderr.writeLine "got an incoming connection"
|
||||
setCallbacks(srv.bnd, addr srv.callbacks, cast[pointer](srv))
|
||||
listen(srv.bnd)
|
||||
return srv
|
||||
except CatchableError as err:
|
||||
stop(srv)
|
||||
raise err
|
||||
|
|
Loading…
Reference in New Issue