Ejemplo n.º 1
0
async def test_store():
    node = kademlia.Node('localhost', 3000)
    await node.listen()

    first = protocol.Server(mynodeid=ID(0b1000))
    second = protocol.Server(mynodeid=ID(0b1001))
    third = protocol.Server(mynodeid=ID(0b1010))

    await first.listen('localhost', 3001)
    await second.listen('localhost', 3002)
    await third.listen('localhost', 3003)

    await node.bootstrap('localhost', 3001)

    first.table.node_seen(second.node)
    second.table.node_seen(third.node)

    await asyncio.wait_for(node.store_value(key=ID(0b1010), value=b'hello'),
                           timeout=0.1)

    storage = lambda server: server.storage

    assert 0b1010 in storage(third)
    assert 0b1010 in storage(second)
    assert 0b1010 not in storage(first)  # first is not in the first k peers
Ejemplo n.º 2
0
    def __init__(self, addr: str, port: int, constants: core.Constants = None):
        self.constants = constants if constants is not None else core.Constants(
        )
        self.addr = addr
        self.port = port
        self.nodeid = core.ID()

        self.node = core.Node(addr=addr, port=port, nodeid=self.nodeid)
        self.server = protocol.Server(self.nodeid, self.constants)
Ejemplo n.º 3
0
    def __init__(self, noshell=1):

        global flist, root
        root = Tk(className="Idle")
        fixwordbreaks(root)
        root.withdraw()
        flist = PyShellFileList(root)

        # the following causes lockups and silent failures when debugging
        # changes to EditorWindow.__init__  ; the console works fine for idle
        # debugging in any case, so disable this unnescesary stuff.
        #dbg=OnDemandOutputWindow(flist)
        #dbg.set_title('IDLE Debugging Messages')
        #sys.stdout = PseudoFile(dbg,['stdout'])
        #sys.stderr = PseudoFile(dbg,['stderr'])

        try:
            self.server = protocol.Server(connection_hook=self.address_ok)
            protocol.publish('IDLE', self.connect)
            self.main(sys.argv[1:], noshell)
            return
        except protocol.connectionLost:
            try:
                client = protocol.Client()
                IDLE = client.getobject('IDLE')
                if IDLE:
                    try:
                        IDLE.remote(sys.argv[1:])
                    except usageError, msg:
                        sys.stderr.write("Error: %s\n" % str(msg))
                        sys.stderr.write(usage_msg)
                    return
            except protocol.connectionLost:
                pass

        #maybe the following should be handled by a tkmessagebox for
        #users who don't start idle from a console??
        print """\
IDLE cannot run.

IDLE needs to use a specific TCP/IP port (7454) in order to execute and
debug programs. IDLE is unable to bind to this port, and so cannot
start. Here are some possible causes of this problem:

  1. TCP/IP networking is not installed or not working on this computer
  2. Another program is running that uses this port
  3. Another copy of IDLE stopped responding but is still bound to the port
  4. Personal firewall software is preventing IDLE from using this port

IDLE makes and accepts connections only with this computer, and does not
communicate over the internet in any way. It's use of port 7454 should not 
be a security risk on a single-user machine.
"""
        dbg.owin.gotoline(1)
        dbg.owin.remove_selection()
        root.mainloop()  # wait for user to read message
Ejemplo n.º 4
0
async def test_value_lookup():
    node = kademlia.Node('localhost', 3000)
    await node.listen()

    first = protocol.Server(mynodeid=ID(0b1000))
    second = protocol.Server(mynodeid=ID(0b1001))
    third = protocol.Server(mynodeid=ID(0b1010))

    await first.listen('localhost', 3001)
    await second.listen('localhost', 3002)
    await third.listen('localhost', 3003)

    await node.bootstrap('localhost', 3001)

    first.table.node_seen(second.node)
    second.table.node_seen(third.node)

    third.storage[0b100] = b'hello'

    result = await asyncio.wait_for(node.find_value(ID(0b100)), timeout=0.1)
    assert result == b'hello'
Ejemplo n.º 5
0
 def load(self):
     print "Loading Root"
     
     # hard coded root data
     self.masterPublicKey="xxx"
     self.masterServerAddress="http://127.0.0.1"
     
     # load subnode, the serverList
     masterServer=protocol.Server("master",self.masterServerAddress,8080,"http",self.masterPublicKey)
     
     self.serverList=nodes.ServerList(address=masterServer.httpAddress("ServerList"),
         key=masterServer.key,
         loadCallBacks=[self.loaded])
Ejemplo n.º 6
0
 def load(self):
     print "Loading Server List"
     clientNodes.HttpFile.load(self,skipLoaded=False)
     
     # if read failed, should report it here, and use version from local cache
     
     key=self.linkFields["key"]
     
     # TODO: Verify listText is properly signed here
    
     # parse listText
     lines=self.fileText.splitlines()
     self.servers={}
     for s in lines[1:]:
         t=s.split()
         self.servers[t[1]]=protocol.Server(*t[1:6])
     
     self.loaded()
     print "ServerList loaded"
Ejemplo n.º 7
0
import socket
import protocol

server = protocol.Server()

server.start()