Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MERGE MASTER BACK : ADD IPV6 SUPPORT #23

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
50 changes: 21 additions & 29 deletions darwin/darwinapi.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ class DarwinApi:

DEFAULT_TIMEOUT = 10

_SOCKET_PROTOCOL = {
'unix': (socket.AF_UNIX, socket.SOCK_STREAM),
'tcp': (socket.AF_INET, socket.SOCK_STREAM),
'tcp6': (socket.AF_INET6, socket.SOCK_STREAM),
}

@classmethod
def get_filter_code(cls, filter_name):
"""
Expand Down Expand Up @@ -136,59 +142,45 @@ def __init__(self, **kwargs):

socket_type = kwargs.get("socket_type", None)

if not socket_type or (socket_type.lower() != "tcp" and socket_type.lower() != "unix"):
raise DarwinInvalidArgumentError("DarwinApi:: __init__:: You must give a socket type (tcp/unix)")

try:
darwin_timeout = kwargs["timeout"]

except KeyError:
darwin_timeout = self.DEFAULT_TIMEOUT

self.socket = None
connection_info = None

if socket_type == "unix":
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
darwin_socket_path = kwargs.get("socket_path", None)

if darwin_socket_path is None:
connection_info = kwargs.get("socket_path", None)
if connection_info is None:
raise DarwinInvalidArgumentError("DarwinApi:: __init__:: No socket path has been given")

self.socket.setblocking(False)
self.socket.settimeout(darwin_timeout)

if self.verbose:
print("DarwinApi:: __init__:: Connecting to " + str(darwin_socket_path) + "...")
print("DarwinApi:: __init__:: Connecting to " + str(connection_info) + "...")

try:
self.socket.connect(darwin_socket_path)
except socket.error as error:
raise DarwinConnectionError(str(error))

else:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
elif socket_type in self._SOCKET_PROTOCOL:
darwin_socket_host = kwargs.get("socket_host", None)
darwin_socket_port = kwargs.get("socket_port", None)

if darwin_socket_host is None:
raise DarwinInvalidArgumentError("DarwinApi:: __init__:: No socket host has been given")

if darwin_socket_port is None:
raise DarwinInvalidArgumentError("DarwinApi:: __init__:: No socket port has been given")

self.socket.setblocking(False)
self.socket.settimeout(darwin_timeout)

connection_info = (darwin_socket_host, darwin_socket_port)
if self.verbose:
print("DarwinApi:: __init__:: Connecting to {darwin_socket_host}: {darwin_socket_port}...".format(
darwin_socket_host=darwin_socket_host,
darwin_socket_port=darwin_socket_port,
))
else :
raise DarwinInvalidArgumentError("DarwinApi:: __init__:: Unknown socket_type provided")

try:
self.socket.connect((darwin_socket_host, darwin_socket_port))
except socket.error as error:
raise DarwinConnectionError(str(error))
try:
self.socket = socket.socket(*self._SOCKET_PROTOCOL[socket_type])
self.socket.setblocking(False)
self.socket.settimeout(darwin_timeout)
self.socket.connect(connection_info)
except socket.error as error:
raise DarwinConnectionError(str(error))

def low_level_call(self, **kwargs):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="darwin",
version="1.2.1",
version="1.2.2",
description="Call Darwin with your Python code!",
url="https://github.com/VultureProject/darwin-client-python",
author="Guillaume Catto",
Expand Down