diff options
author | Andrew Cann <shum@canndrew.org> | 2014-05-11 02:54:29 +0000 |
---|---|---|
committer | Andrew Cann <shum@canndrew.org> | 2014-05-11 02:54:29 +0000 |
commit | 6c2287eb042c560098f0cdcbfb1997b1a62c3cdf (patch) | |
tree | 0eefe406d1d1d577ab099a4cd42eb2b46a9e8d45 | |
parent | 7c05570f7a2c7baeecf9fa9c9e9f47acb39b56bd (diff) | |
download | gnunet-python-6c2287eb042c560098f0cdcbfb1997b1a62c3cdf.tar.gz gnunet-python-6c2287eb042c560098f0cdcbfb1997b1a62c3cdf.zip |
Added filter_known_results, stop functions to dht. Bug fixes.
-rw-r--r-- | .gitignore | 4 | ||||
-rwxr-xr-x | example-dht.py | 4 | ||||
-rw-r--r-- | gnunet/__init__.py | 2 | ||||
-rw-r--r-- | gnunet/dht.py | 13 |
4 files changed, 21 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e6f516 --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,4 @@ | |||
1 | *.swp | ||
2 | *.swo | ||
3 | /gnunet/__pycache__ | ||
4 | |||
diff --git a/example-dht.py b/example-dht.py index 726e0be..64dd1cb 100755 --- a/example-dht.py +++ b/example-dht.py | |||
@@ -16,7 +16,9 @@ def result_callback(block_type, key, data, expiry, get_path, put_path): | |||
16 | print(" put_path == %s" % repr(put_path)) | 16 | print(" put_path == %s" % repr(put_path)) |
17 | print(" data == %s" % repr(data)) | 17 | print(" data == %s" % repr(data)) |
18 | 18 | ||
19 | gnunet.dht.get_start(result_callback, "test", key, 1, record_route=True) | 19 | req = gnunet.dht.get_start(result_callback, "test", key, 1, record_route=True) |
20 | req.filter_known_results([]) | ||
21 | req.stop() | ||
20 | 22 | ||
21 | time.sleep(1) | 23 | time.sleep(1) |
22 | 24 | ||
diff --git a/gnunet/__init__.py b/gnunet/__init__.py index 425ab86..a517180 100644 --- a/gnunet/__init__.py +++ b/gnunet/__init__.py | |||
@@ -6,7 +6,7 @@ class GNUNetDaemonError(Exception): | |||
6 | class _Key: | 6 | class _Key: |
7 | def __init__(self, arg, subtype, bits): | 7 | def __init__(self, arg, subtype, bits): |
8 | if isinstance(arg, subtype): | 8 | if isinstance(arg, subtype): |
9 | self._data = arg.data | 9 | self._data = arg._data |
10 | elif isinstance(arg, str): | 10 | elif isinstance(arg, str): |
11 | self._data = strings.string_to_data(arg) | 11 | self._data = strings.string_to_data(arg) |
12 | else: | 12 | else: |
diff --git a/gnunet/dht.py b/gnunet/dht.py index d26b7f2..849f07a 100644 --- a/gnunet/dht.py +++ b/gnunet/dht.py | |||
@@ -51,6 +51,19 @@ class GetRequest: | |||
51 | self.callback = callback | 51 | self.callback = callback |
52 | self.record_route = record_route | 52 | self.record_route = record_route |
53 | 53 | ||
54 | def filter_known_results(self, keys): | ||
55 | keys = dbus.Array([dbusize(HashCode(key)) for key in list(keys)], signature="v") | ||
56 | try: | ||
57 | sysbus.get_object("gnu.gnunet.dht", self._path).filter_known_results(keys, dbus_interface="gnu.gnunet.dht.get") | ||
58 | except dbus.DBusException as e: | ||
59 | handle_exception(e, "dht", "gnu.gnunet.dht") | ||
60 | |||
61 | def stop(self): | ||
62 | try: | ||
63 | sysbus.get_object("gnu.gnunet.dht", self._path).stop(dbus_interface="gnu.gnunet.dht.get") | ||
64 | except dbus.DBusException as e: | ||
65 | handle_exception(e, "dht", "gnu.gnunet.dht") | ||
66 | |||
54 | def put(key, desired_replication_level, block_type, data, expiry=None, demultiplex_everywhere=False, record_route=False, bart=False): | 67 | def put(key, desired_replication_level, block_type, data, expiry=None, demultiplex_everywhere=False, record_route=False, bart=False): |
55 | key = dbusize(HashCode(key), True) | 68 | key = dbusize(HashCode(key), True) |
56 | desired_replication_level = dbus.UInt32(desired_replication_level) | 69 | desired_replication_level = dbus.UInt32(desired_replication_level) |