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

Create data manager and spawn new process to keep the vts dictionary. #191

Merged
merged 5 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changes
- Modify __init__() method and use new syntax for super(). [#186](https://github.com/greenbone/ospd/pull/186)
- Create data manager and spawn new process to keep the vts dictionary. [#191](https://github.com/greenbone/ospd/pull/191)

## [2.0.1] (unreleased)

Expand Down
19 changes: 17 additions & 2 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def __init__(
for name, param in BASE_SCANNER_PARAMS.items():
self.add_scanner_param(name, param)

self.vts = dict()
self.vts = None
self.vt_id_pattern = re.compile("[0-9a-zA-Z_\\-:.]{1,80}")
self.vts_version = None

Expand Down Expand Up @@ -262,7 +262,16 @@ def add_vt(
severities=None,
):
""" Add a vulnerability test information.

IMPORTANT: The VT's Data Manager will store the vts collection.
If the collection is considerably big and it will be consultated
intensible during a routine, consider to do a deepcopy(), since
accessing the shared memory in the data manager is very expensive.
At the end of the routine, the temporal copy must be set to None
and deleted.
"""
if self.vts is None:
self.vts = multiprocessing.Manager().dict()

if not vt_id:
raise OspdError('Invalid vt_id {}'.format(vt_id))
Expand Down Expand Up @@ -1589,6 +1598,9 @@ def get_vts_xml(self, vt_id=None, filtered_vts=None):

vts_xml = Element('vts')

if not self.vts:
return vts_xml

if filtered_vts is not None and len(filtered_vts) == 0:
return vts_xml

Expand All @@ -1598,7 +1610,10 @@ def get_vts_xml(self, vt_id=None, filtered_vts=None):
elif vt_id:
vts_xml.append(self.get_vt_xml(vt_id))
else:
for vt_id in self.vts:
# TODO: Because DictProxy for python3.5 doesn't support
# iterkeys(), itervalues(), or iteritems() either, the iteration
# must be done as follow.
for vt_id in iter(self.vts.keys()):
vts_xml.append(self.get_vt_xml(vt_id))

return vts_xml
Expand Down