Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #136 from jjnicola/multiclient-listener
Browse files Browse the repository at this point in the history
Add support to handle multiple requests simultaneously.
  • Loading branch information
bjoernricks authored Sep 27, 2019
2 parents 65a6d30 + 0dad696 commit 47acd97
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 131 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add pid file creation to avoid having two daemons. [#126](https://github.com/greenbone/ospd/pull/126) [#128](https://github.com/greenbone/ospd/pull/128)
- Add OSP <get_performance> command. [#131](https://github.com/greenbone/ospd/pull/131) [#137](https://github.com/greenbone/ospd/pull/137)
- Add method to check if a target finished cleanly or crashed. [#133](https://github.com/greenbone/ospd/pull/133)
- Add the --stream-timeout option to configure the socket timeout. [#136](https://github.com/greenbone/ospd/pull/136)
- Add support to handle multiple requests simultaneously. [#136](https://github.com/greenbone/ospd/pull/136)

### Changed
- Improve documentation.
Expand Down
13 changes: 11 additions & 2 deletions ospd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,19 @@ def main(
)

if args.port == 0:
server = UnixSocketServer(args.unix_socket, args.socket_mode)
server = UnixSocketServer(
args.unix_socket,
args.socket_mode,
args.stream_timeout,
)
else:
server = TlsServer(
args.address, args.port, args.cert_file, args.key_file, args.ca_file
args.address,
args.port,
args.cert_file,
args.key_file,
args.ca_file,
args.stream_timeout,
)

daemon = daemon_class(**vars(args))
Expand Down
11 changes: 5 additions & 6 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from ospd.errors import OspdCommandError, OspdError
from ospd.misc import ScanCollection, ResultType, ScanStatus, valid_uuid
from ospd.network import resolve_hostname, target_str_to_list
from ospd.server import Server
from ospd.server import BaseServer
from ospd.vtfilter import VtsFilter
from ospd.xml import simple_response_str, get_result_xml

Expand Down Expand Up @@ -1645,21 +1645,20 @@ def check(self):
""" Asserts to False. Should be implemented by subclass. """
raise NotImplementedError

def run(self, server: Server):
def run(self, server: BaseServer):
""" Starts the Daemon, handling commands until interrupted.
"""

server.bind()
server.start(self.handle_client_stream)

try:
while True:
server.select(
self.handle_client_stream, timeout=SCHEDULER_CHECK_PERIOD
)
time.sleep(10)
self.scheduler()
except KeyboardInterrupt:
logger.info("Received Ctrl-C shutting-down ...")
finally:
logger.info("Shutting-down server ...")
server.close()

def scheduler(self):
Expand Down
8 changes: 8 additions & 0 deletions ospd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
DEFAULT_CONFIG_PATH = "~/.config/ospd.conf"
DEFAULT_UNIX_SOCKET_PATH = "/tmp/ospd.sock"
DEFAULT_PID_PATH = "/run/ospd/ospd.pid"
DEFAULT_STREAM_TIMEOUT = 10 # ten seconds

ParserType = argparse.ArgumentParser
Arguments = argparse.Namespace
Expand Down Expand Up @@ -122,6 +123,13 @@ def __init__(self, description):
action='store_true',
help='Run in foreground and logs all messages to console.',
)
parser.add_argument(
'-t',
'--stream-timeout',
default=DEFAULT_STREAM_TIMEOUT,
type=int,
help='Stream timeout. Default: %(default)s',
)
parser.add_argument(
'-l', '--log-file', help='Path to the logging file.'
)
Expand Down
Loading

0 comments on commit 47acd97

Please sign in to comment.