[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-developers] gnunet-python library
From: |
Andrew Cann |
Subject: |
[GNUnet-developers] gnunet-python library |
Date: |
Fri, 18 Apr 2014 22:08:49 +0800 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
I've started writing a gnunet library for python. It uses thet gnunet-dbus
bindings available on subversion. You can clone it from:
git clone git://canndrew.org/gnunet-python.git
Currently it can do everything that the dbus wrapper can do, which is putting
and getting from the dht and doing gns lookups.
Here's some example code (available in the repo):
## example-dht.py
#!/usr/bin/python3
import gnunet.dht
import time
key =
gnunet.HashCode("RMKN0U1JNA3PVCL148D6JI0STVG94A8A65INOK849CF1RT6BGF26AMMT14GMDMNRDFSJRJME6IKJ3LDFBUL2R1TPQJE64I55I32QN5G")
gnunet.dht.put(key, 1, "test", b"hello")
def result_callback(block_type, key, data, expiry, get_path, put_path):
print("Got result from DHT")
print(" block_type == %s" % repr(block_type))
print(" key == %s" % repr(key))
print(" expiry == %s" % repr(expiry))
print(" get_path == %s" % repr(get_path))
print(" put_path == %s" % repr(put_path))
print(" data == %s" % repr(data))
gnunet.dht.get_start(result_callback, "test", key, 1, record_route=True)
time.sleep(1)
## example output
Got result from DHT
block_type == 'test'
key ==
gnunet.HashCode('RMKN0U1JNA3PVCL148D6JI0STVG94A8A65INOK849CF1RT6BGF26AMMT14GMDMNRDFSJRJME6IKJ3LDFBUL2R1TPQJE64I55I32QN5G')
expiry == None
get_path == []
put_path == []
data == bytearray(b'hello')
Got result from DHT
block_type == 'test'
key ==
gnunet.HashCode('RMKN0U1JNA3PVCL148D6JI0STVG94A8A65INOK849CF1RT6BGF26AMMT14GMDMNRDFSJRJME6IKJ3LDFBUL2R1TPQJE64I55I32QN5G')
expiry == None
get_path == []
put_path == []
data == bytearray(b'')
## example-gns.py
#!/usr/bin/python3
import gnunet.gns
results = gnunet.gns.lookup("www.gnu",
"JK55QA8JLAL64MBO8UM209KE93M9JBBO7M2UB8M3M03FKRFSUOMG", "A", True)
for r in results:
print("Got result from gns")
print(" record_type == %s" % repr(r.record_type))
print(" data == %s" % repr(r.data))
print(" expiration_time == %s" % repr(r.expiration_time))
print(" private == %s" % repr(r.private))
print(" pending == %s" % repr(r.pending))
print(" shadow == %s" % repr(r.shadow))
## example output
Got result from gns
record_type == 'A'
data == '1.2.3.4'
expiration_time == None
private == True
pending == False
shadow == False
- [GNUnet-developers] gnunet-python library,
Andrew Cann <=