Git Product home page Git Product logo

gevent-dht's Introduction

This is a basic implementation of a DHT using the gevent library.

There are two things you have to concern yourself with.
1] Bootstrapping the network
The following example creates a network of one node

import gevent_dht

// This tell the network it is the first node by default it listens on port 8339
table = gevent_dht.distributedHashTable( None )

// This sets a value in our hash table
table['key_1'] = [1,2,3]
for i in table['key_1']:
    // Prints 123
    print i
    
// Adds an item to a list in a hash table. 
// Note : If the key is not in the hash table. It will put a list in place and then append to it.
table.append('key_1', 4) 
                         
// Now we are adding another node :
// Another client has connected. It supplied the address of a node in the network to connect with the preexisting network
other_clients_table = gevent_dht.distributedHashTable( '127.0.0.1:8339' , local_port = 8449 )

for i in other_clients_table['key_1']:
    // Prints 1234
    print i

So in order to connect to an existing network you must have a way to get an address of another member. It doesn't have to be the first node but needs to be a node in the network.

2] Latency/ This may fail

Keys are not guarenteed to persist forever, nodes may crash, the network may eat messages etc... While we are working in tcp/ip mode there may still be bizarre glitches. Always check for a return value of None.

Additionally due to the time it takes for messages to travel the network sometimes a key will not be immedietly available after you set it or when you get the result back it may not be completely current.

gevent-dht's People

Contributors

akaisercxp avatar c00w avatar

Watchers

 avatar

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.