Code Monkey home page Code Monkey logo

iota-swarm-node's Introduction

IOTA Swarm Node

Summary

iota-swarm-node is a proof-of-concept implementation of IOTA Swarm node, that is a device with software/hardware implementing an algorithm aiming for allowing several swarm nodes behave as a full node.

Most use cases for micropayments involve a single user or device interacting repeatedly with a few vendors.

Prerequisites

Install dependent packages:

$ sudo apt-get install python-pip python-setuptools python-dev python3-dev \
                       build-essential libssl-dev libffi-dev

Install Python package dependencies:

$ pip install -r requirements.txt

(Alternative) Install dependencies and activate virtualenv with Pipenv:

$ pipenv install
$ pipenv shell

Build from scratch

Ensure gcc or clang available in build environment and then execute:

$ make

(Optional) run test suite:

$ make check

Launch the service

  • Launch swarm node as server:
$ python server.py
Listening on localhost:8000
  • Generate an unused address:
$ python tests/generate_address.py
Generating an unused address ...
{u'addresses': [Address('OMAEMGRMASNBLYVFCRG9UARBBCWDIC9RGCOFTVAVJZDWISOHVMFLSW9ZL9FIJIHVVRYQLIMYBWEYP9WSX')]}
Duration: 73.5027749538 seconds
  • Get tips from full node
$ python tests/get_tips.py
Getting tips ...
{u'duration': 484, u'branchTransaction': TransactionHash('QCPNKOXJXFERNNLTZZG9LBWDJQRLFIWDYNYQBHZJANJGXAADKNFTPWBWVDGHROVVVQWBKP9ROKRMZ9999'), u'trunkTransaction': TransactionHash('GEPJNFUNQGPDSFECJZGEWYYWYMGVWDCOELBKZQWILEUGGVHPNWFRLHNQHYKHCHPQWSQAXGYG9AIBA9999')}
Duration: 0.960033893585 seconds
  • Send data (0 value transaction)
$ python tests/send_transfer.py
Send send transfer command ...
WIAEHXJUVO9IDZXROJEDBQLFHVFLZCIQKPLLXCGWLNZFIUJZLBZACVLZPWAKUBYLDYRZKFIDKLSAHJHEY
Duration: 1.91658091545 seconds

Build the docker image

Before building the docker image, you need to build the iota-swarm-node.

  $ make

Build the docker image and tag with iota-swarm-node.

  $ docker build -t iota-swarm-node .

Publish docker image to Docker Hub

  1. Login to the Docker Hub.
  $ docker login
  1. Tag docker image.
  $ docker tag iota-swarm-node DOCKER_ID_USER/iota-swarm-node
  1. Push image to Docker Hub.
  $ docker push DOCKER_ID_USER/iota-swarm-node

Licensing

iota-swarm-node is freely redistributable under the two-clause BSD License. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

iota-swarm-node's People

Contributors

ender503 avatar furuame avatar hexrabbit avatar jserv avatar yillkid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

iota-swarm-node's Issues

Bundle inconsistency if it has multiple transactions

There is no problem preparing 0 value transfer which bundle only has one transaction. However, if we send a value transfer, the bundle would be inconsistent since all transactions' trunk/branch transactions are point to same tips.

Expected behavior:

Actual behavior:

Exception happened during processing specific request

Reproduction:

171.34.168.69 - - [22/Jun/2018 12:28:14] "GET http://www.minghui.org/ HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('171.34.168.69', 58976)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 290, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 318, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 654, in __init__
    self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 713, in finish
    self.wfile.close()
  File "/usr/lib/python2.7/socket.py", line 283, in close
    self.flush()
  File "/usr/lib/python2.7/socket.py", line 307, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------

Failed to send_transfer

When sending the new claim request to swarm node, it will get the empty reply from server.

To reproduce this error, launch the server and use the following command.

curl http://localhost:8000 \
          -X POST \
          -H 'Content-Type: application/json' \
          -d '{"command":"new_claim","uuid": "SD9BCRDGJYWDHPTDNOPRULFWWG","part_a":"9JVXCXMFAMKLUQQCDACSWJVDLH","part_b":"9JVXCXMFAMKLUQQCDACSWJVDLH","exp_date":"20190101","claim_pic":"https://www.chill.ie/images/Customer-Care/ncb-example.png", "msg":"testing message"}'
curl: (52) Empty reply from server

The server-side will print the following error message.

Exception happened during processing of request from ('1.34.47.14', 54055)
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/socketserver.py", line 313, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/local/lib/python3.5/socketserver.py", line 341, in process_request
    self.finish_request(request, client_address)
  File "/usr/local/lib/python3.5/socketserver.py", line 354, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/lib/python3.5/socketserver.py", line 681, in __init__
    self.handle()
  File "/usr/local/lib/python3.5/http/server.py", line 422, in handle
    self.handle_one_request()
  File "/usr/local/lib/python3.5/http/server.py", line 410, in handle_one_request
    method()
  File "server.py", line 63, in do_POST
    result = extension_tangleid.load(request_data)
  File "/home/ender503/iota-swarm-node/extensions/tangleid/main.py", line 13, in load
    bundle_hash = new_claim(data)
  File "/home/ender503/iota-swarm-node/extensions/tangleid/main.py", line 52, in new_claim
    response = send_transfer(tag, json.dumps(data), address, 0, dict_tips, debug=0)
  File "/home/ender503/iota-swarm-node/swarm_node.py", line 172, in send_transfer
    return str(obj_txn['hashes'][0])
IndexError: list index out of range

Masked Authenticated Messaging (MAM) support

According to IOTA R&D roadmap, IOTA Foundation is planning to rewrite the Masked Authenticated Message (MAM) implementation. Once iota.lib.py completes the transition, dev-team will work on adding that functionality to PyOTA. Therefore the MAM temporarily workaround of python is implement it with iota.lib.js and running as an independent daemon that can access via REST API by swarm-node.

The claim transaction message is not JSON format

I create a new claim by new_claim command, but the transaction message is not JSON format on the
Tangle Explorer

Expected Format

{
  "uuid": "SD9BCRDGJYWDHPTDNOPRULFWWG",
  "part_a": "9JVXCXMFAMKLUQQCDACSWJVDLH",
  "part_b": "9JVXCXMFAMKLUQQCDACSWJVDLH",
  "command": "new_claim",
  "msg": "testing message",
  "exp_date": "20190101",
  "claim_pic": "https://www.chill.ie/images/Customer-Care/ncb-example.png"
}

Current Format

{u'uuid': u'SD9BCRDGJYWDHPTDNOPRULFWWG', u'part_a': u'9JVXCXMFAMKLUQQCDACSWJVDLH', u'part_b': u'9JVXCXMFAMKLUQQCDACSWJVDLH', u'command': u'new_claim', u'msg': u'testing message', u'exp_date': u'20190101', u'claim_pic': u'https://www.chill.ie/images/Customer-Care/ncb-example.png'}

Introduce load balancer

The possible steps to implement load balancing with swarm nodes can be enumerated as follows:

loading-balance

  1. Both public and private IP swarm node support because the swarm node may deploy on IoT devices that have private IP only.
  2. First available process in the queue list has the highest priority because of swarm node deploy on a wide variety of devices, we should set the higher level device on the top.
  3. No head-of-line blocking problem.

Reference:

Switch to Python 3

Since dcurl prefers Python 3 for packaging, it would be more consistent if we can switch iota-swarm-node to Python 3+ (version 3.7 in particular).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.