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 mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/gnunet-developers

Reply via email to