Merge pull request #41 from onenameio/dht

tested DHT and small fixes
This commit is contained in:
Muneeb Ali
2015-02-02 18:50:12 -05:00
3 changed files with 23 additions and 5 deletions

View File

@@ -40,8 +40,23 @@ def printValue(value):
logger.info(pretty_dump(value))
def getFormat(result):
reply = {}
value = json.loads(json.dumps(result))
try:
value = ast.literal_eval(value)
except:
pass
reply['value'] = value
return reply
def printError(error):
reply = {}
reply['error'] = "Got an error"
@@ -218,8 +233,8 @@ def run_cli():
reply = {}
value = args.data
logger.debug('Storing %s', value)
key = coinkit.hex_hash160(value)
logger.debug('Storing %s', value)
client = proxy.callRemote('set', key, value)
@@ -227,6 +242,7 @@ def run_cli():
logger.debug('Get %s', args.hash)
client = proxy.callRemote('get', args.hash)
client.addCallback(getFormat)
client.addCallback(printValue).addErrback(printError).addBoth(shutDown)
reactor.run()

View File

@@ -14,6 +14,7 @@ import os
import sys
import subprocess
import signal
import json
from txjsonrpc.netstring import jsonrpc
from twisted.internet import reactor
@@ -84,8 +85,9 @@ class OpennamedRPC(jsonrpc.JSONRPC):
reply = {}
try:
test_value = json.loads(json.dumps(value))
except:
test_value = json.loads(value)
except Exception as e:
print e
reply['error'] = "value not JSON, not storing"
return reply

View File

@@ -28,7 +28,7 @@ from opennamed import OpennamedRPC
application = service.Application("opennamed")
factory_openname = jsonrpc.RPCFactory(OpennamedRPC())
factory_openname = jsonrpc.RPCFactory(OpennamedRPC(dht_server))
server_openname = internet.TCPServer(OPENNAMED_PORT, factory_openname)
server_openname.setServiceParent(application)