Skip to content

Commit

Permalink
zmq channel implementation, using the brand new Liberty Eiffel "ezmq"…
Browse files Browse the repository at this point in the history
… library
  • Loading branch information
cadrian committed Aug 21, 2015
1 parent 760a3d2 commit 30f24a6
Show file tree
Hide file tree
Showing 12 changed files with 604 additions and 78 deletions.
73 changes: 73 additions & 0 deletions conf/pwd-zmq.properties
@@ -0,0 +1,73 @@
#
# This example configuration file uses a local vault as backup.
#
# Copy it to either $HOME/.pwd/config.rc
# or /etc/pwd.rc
#

######################################################################
# Shared data
[shared]

# Logging level, default is info
log.level = info

# The default recipe for building strong passwords
default_recipe = an+s+14ansanansaan

# The communication method between server and clients (default: fifo)
channel.method = zmq

# Master input command
master.command = zenity

# Master input arguments
master.arguments = --entry --hide-text --title=Password "--text=\"#(1)\""

######################################################################
# Data used by the console
[console]

# The remote sections, separated by commas (NO SPACES)
# (each remote looks for a file with the same name and a .rc extension)
remote.sections = curl

# The size of the commands history (0 or not define for no limit)
history.size = 100

######################################################################
# Data used by the menu
[menu]

# command
command = dmenu

# dmenu arguments
arguments = -b -i -p 'Key: ' -fn fixed -nb '#3f3f3f' -nf ivory -sb '#ff4040' -sf black

######################################################################
# Data used by the vault (running inside the server)
[vault]

# The cipher method used to encrypt the vault; see openssl(1) for possible values
openssl.cipher = bf

######################################################################
# Data used by the zmq layer
[zmq]

# The server address (default: localhost)
address = localhost

# The server port (default: 4799)
port = 4799

######################################################################
# Data used by the web client
[webclient]

# path to the template files
template.path = web/templates

# path to the static files
static.path = web/static
4 changes: 4 additions & 0 deletions src/channel/channel_factory.e
Expand Up @@ -29,6 +29,8 @@ feature {CLIENT}
create {CLIENT_FIFO} Result.make(tmpdir)
when "socket" then
create {CLIENT_SOCKET} Result.make(tmpdir)
when "zmq" then
create {CLIENT_ZMQ} Result.make(tmpdir)
else
log.error.put_line(once "Unknown channel method: #(1)" # shared.channel_method)
die_with_code(1)
Expand All @@ -44,6 +46,8 @@ feature {SERVER}
create {SERVER_FIFO} Result.make
when "socket" then
create {SERVER_SOCKET} Result.make
when "zmq" then
create {SERVER_ZMQ} Result.make
else
log.error.put_line(once "Unknown channel method: #(1)" # shared.channel_method)
die_with_code(1)
Expand Down
11 changes: 3 additions & 8 deletions src/channel/client_channel.e
Expand Up @@ -16,20 +16,19 @@
deferred class CLIENT_CHANNEL

feature {CLIENT}
server_running: BOOLEAN
server_running (when_reply: PROCEDURE[TUPLE[BOOLEAN]])
-- True if the server is running, False otherwise
require
when_reply /= Void
deferred
end

server_start
require
not server_running
deferred
end

call (query: MESSAGE; when_reply: PROCEDURE[TUPLE[MESSAGE]])
require
server_is_ready
is_ready
query /= Void
when_reply /= Void
Expand All @@ -42,10 +41,6 @@ feature {CLIENT}
deferred
end

server_is_ready: BOOLEAN
deferred
end

cleanup
deferred
end
Expand Down
18 changes: 8 additions & 10 deletions src/channel/impl/fifo/client_fifo.e
Expand Up @@ -7,7 +7,7 @@
--
-- pwd is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
Expand All @@ -28,9 +28,10 @@ create {CHANNEL_FACTORY}
make

feature {CLIENT}
server_running: BOOLEAN
server_running (when_reply: PROCEDURE[TUPLE[BOOLEAN]])
local
tfr: TEXT_FILE_READ; pid: INTEGER; shared: SHARED
res: BOOLEAN
do
if extern.exists(server_fifo) then
check
Expand All @@ -43,22 +44,24 @@ feature {CLIENT}
if tfr.last_string.is_integer then
pid := tfr.last_string.to_integer
if extern.process_running(pid) then
Result := True
res := True
end
end

tfr.disconnect
end

if not Result then
if not res then
delete(shared.server_pidfile)
end
end

if not Result then
if not res then
delete(server_fifo)
end
end

when_reply.call([res])
end

server_start
Expand Down Expand Up @@ -135,11 +138,6 @@ feature {CLIENT}
Result := not extern.exists(client_fifo)
end

server_is_ready: BOOLEAN
do
Result := extern.exists(server_fifo)
end

cleanup
do
if extern.exists(client_fifo) then
Expand Down
22 changes: 11 additions & 11 deletions src/channel/impl/socket/client_socket.e
Expand Up @@ -26,13 +26,9 @@ create {CHANNEL_FACTORY}
make

feature {CLIENT}
server_running: BOOLEAN
server_running (when_reply: PROCEDURE[TUPLE[BOOLEAN]])
do
if channel = Void or else not channel.is_connected then
channel := access.stream
end
Result := channel /= Void and then channel.is_connected
log.info.put_line(once "Server is running: #(1)" # Result.out)
when_reply.call([is_server_running])
end

server_start
Expand Down Expand Up @@ -78,11 +74,6 @@ feature {CLIENT}
Result := not busy
end

server_is_ready: BOOLEAN
do
Result := server_running and then not busy
end

cleanup
do
if channel /= Void then
Expand All @@ -100,6 +91,15 @@ feature {}
log.info.put_line(once "Starting client on port #(1)" # socket.port.out)
end

is_server_running: BOOLEAN
do
if channel = Void or else not channel.is_connected then
channel := access.stream
end
Result := channel /= Void and then channel.is_connected
log.info.put_line(once "Server is running: #(1)" # Result.out)
end

access: TCP_ACCESS

channel: SOCKET_INPUT_OUTPUT_STREAM
Expand Down
3 changes: 2 additions & 1 deletion src/channel/impl/socket/server_socket.e
Expand Up @@ -85,7 +85,8 @@ feature {SERVER}
end

cleanup
do -- nothing to do
do
-- nothing to do
end

feature {}
Expand Down

0 comments on commit 30f24a6

Please sign in to comment.