Exemplo n.º 1
0
def main():
    # Begin Init
    settings.setup()
    try:
        import miniupnpc
    except:
        safeprint("Miniupnpc is not installed. Running in outbound only mode")
        settings.config['outbound'] = True
    safeprint("settings are:")
    safeprint(settings.config)
    live = initParallels()
    global ext_ip, ext_port
    peers.initializePeerConnections(settings.config['port'], ext_ip, ext_port)
    # End Init

    # Begin main loop
    if settings.config.get('seed'):
        safeprint("Seed mode activated")
        try:
            while True and not settings.config.get('test'):
                sleep(0.1)
        except KeyboardInterrupt:
            safeprint("Keyboard Interrupt")
    elif settings.config.get('server'):
        safeprint("Server mode activated")
    else:
        safeprint("Client mode activated")
    # End main loop

    # Begin shutdown
    safeprint("Beginning exit process")
    live.value = False
    settings.saveSettings()
    peers.saveToFile()
    bounty.saveToFile()
Exemplo n.º 2
0
def main():
    #Begin Init
    settings.setup()
    from common.safeprint import safeprint
    try:
        import miniupnpc
    except:
        safeprint("Dependency miniupnpc is not installed. Running in outbound only mode")
        settings.config['outbound'] = True
    safeprint("settings are:")
    safeprint(settings.config)
    queue = Queue()
    live = Value('b',True)
    ear = listener(settings.config['port'],settings.config['outbound'],queue,live,settings.config['server'])
    ear.daemon = True
    ear.items = sync()
    ear.start()
    mouth = propagator(settings.config['port'] + 1, live)
    mouth.daemon = True
    mouth.items = ear.items
    mouth.start()
    feedback = []
    stamp = time()
    while queue.empty():
        if time() - 5 > stamp:
            break #pragma: no cover
    try:
        feedback = queue.get(False)
    except: #pragma: no cover
        safeprint("No feedback received from listener")
    ext_ip = ""     #Does this affect peers?
    ext_port = -1   #Does this affect peers?
    if feedback != []:
        settings.outbound = feedback[0]
        if settings.outbound is not True:
            ext_ip = feedback[1]
            ext_port = feedback[2]
    initializePeerConnections(settings.config['port'], ext_ip, ext_port)
    #End Init
    
    #Begin main loop
    if settings.config.get('seed'):
        safeprint("Seed mode activated")
        try:
            while True and not settings.config.get('test'):
                sleep(0.1)
        except KeyboardInterrupt:
            safeprint("Keyboard Interrupt")
    elif settings.config.get('server'):
        safeprint("Server mode activated")
    else:
        safeprint("Client mode activated")
    #End main loop
    
    #Begin shutdown
    safeprint("Beginning exit process")
    live.value = False
    settings.saveSettings()
    saveToFile()
    bounty.saveToFile()
Exemplo n.º 3
0
def main():
    #Begin Init
    settings.setup()
    try:
        import miniupnpc
    except:
        safeprint(
            "Dependency miniupnpc is not installed. Running in outbound only mode"
        )
        settings.config['outbound'] = True
    safeprint("settings are:")
    safeprint(settings.config)
    live = initParallels()
    peers.initializePeerConnections(settings.config['port'], ext_ip, ext_port)
    #End Init

    #Begin main loop
    if settings.config.get('seed'):
        safeprint("Seed mode activated")
        try:
            while True and not settings.config.get('test'):
                sleep(0.1)
        except KeyboardInterrupt:
            safeprint("Keyboard Interrupt")
    elif settings.config.get('server'):
        safeprint("Server mode activated")
    else:
        safeprint("Client mode activated")
    #End main loop

    #Begin shutdown
    safeprint("Beginning exit process")
    live.value = False
    settings.saveSettings()
    peers.saveToFile()
    bounty.saveToFile()
Exemplo n.º 4
0
 testBounty(('8.8.8',8888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 2 (ip failure)")
 testBounty(('8.8.8.8',888888888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 3 (ip failure)")
 testBounty(('8.8.12348.8',8888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 4 (ip failure)")
 testBounty(('8.8.8.8',8888),"1JTGcHS3GMhBGGww4ZEDmP7u9",1440,"Malformed bounty 5 (btc failure)")
 testBounty(('8.8.8.8',8888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",-1440,"Malformed bounty 6 (reward failure)")
 testBounty(('8.8.8.8',8888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",0,"Malformed bounty 7 (signature failure)")
 testBounty(('8.8.8.8',8888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Correctly formed bounty 2", data={'reqs':{("__builtin__","pow",2,2):4}})
 testBounty(('8.8.8.8',8888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 8 (requirements failure)", data={'reqs':{("sys","platform","index=2","end=3"):"win33"}})
 testBounty(('8.8.8.8',8888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 9 (requirements failure)", data={'reqs':{("__builtin__","pow",2,2):4,("sys","platform"):"win33"}})
 safeprint("Malformed bounty 11 (timeout error)")
 safeprint(addBounty(pickle.dumps(bounty.Bounty(('8.8.8.8',8888),"1LhPsd4ng3AXmVPzrLWprWFx351pW4HJm8",10900,timeout=1),0)))
 testBounty(('8.8.8.8',8888),"1LhPsd4ng3AXmVPzrLWprWFx351pW4HJm8",10900,"Correctly formed bounty 3")
 testBounty(('8.8.8.8',8888),"1MWSdYMKEpfWVxC6BGYARxsksaQuyEWzG5",1480,"Correctly formed bounty 4")
 testBounty(('8.8.8.8',8888),"1EgGfDetymjMzcQ1AEhHjHEyXHjnEavwgg",10290,"Correctly formed bounty 5")
 safeprint(bounty.getBountyList())
 bounty.saveToFile()
 bounty.loadFromFile()
 safeprint(bounty.getBountyList())
 safeprint("3 bounties should follow")
 safeprint(bounty.getBounty(settings.config.get('charity'),settings.config.get('propagate_factor')))
 safeprint(bounty.getBounty(False,2))
 safeprint(bounty.getBounty(True,2))
 settings.saveSettings()
 settings.loadSettings()
 saveToFile()
 getFromFile()
 if not (sys.version_info[0] < 3 and sys.platform == "win32"):
     safeprint("Test listener begin")
     v = Value('b',True)
     q = Queue()
     a = Process(target=waitForty,args=(v,q))
Exemplo n.º 5
0
 testBounty('8.8.8.8:8888',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Correctly formed bounty")
 testBounty('8.8.8.8',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 1 (ip failure)")
 testBounty('8.8.8:8888',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 2 (ip failure)")
 testBounty('8.8.8.8:88888888888888',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 3 (ip failure)")
 testBounty('8.8.12348.8',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 4 (ip failure)")
 testBounty('8.8.8.8:8888',"1JTGcHS3GMhBGGww4ZEDmP7u9",1440,"Malformed bounty 5 (btc failure)")
 testBounty('8.8.8.8:8888',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",-1440,"Malformed bounty 6 (reward failure)")
 testBounty('8.8.8.8:8888',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",0,"Malformed bounty 7 (signature failure)")
 testBounty('8.8.8.8:8888',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 8 (requirement failure)", data={'reqs':{("__builtins__","pow",2,2):4}})
 testBounty('8.8.8.8:8888',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Correctly formed bounty 2", data={'reqs':{("sys","platform","index=2","end=3"):"win33"}})
 testBounty('8.8.8.8:8888',"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 10 (requirements failure)", data={'reqs':{("__builtins__","pow",2,2):4,("sys","platform"):"win33"}})
 testBounty('8.8.8.8:8888',"1LhPsd4ng3AXmVPzrLWprWFx351pW4HJm8",10900,"Correctly formed bounty 3")
 testBounty('8.8.8.8:8888',"1MWSdYMKEpfWVxC6BGYARxsksaQuyEWzG5",1480,"Correctly formed bounty 4")
 testBounty('8.8.8.8:8888',"1EgGfDetymjMzcQ1AEhHjHEyXHjnEavwgg",10290,"Correctly formed bounty 5")
 safeprint(bounty.getBountyList())
 bounty.saveToFile(bounty.getBountyList())
 bounty.loadFromFile()
 safeprint(bounty.getBountyList())
 safeprint("3 bounties should follow")
 safeprint(bounty.getBounty(settings.config.get('charity'),settings.config.get('propagate_factor')))
 safeprint(bounty.getBounty(False,2))
 safeprint(bounty.getBounty(True,2))
 settings.saveSettings()
 settings.loadSettings()
 saveToFile()
 getFromFile()
 if not (sys.version_info[0] < 3 and sys.platform == "win32"):
     safeprint("Test listener begin")
     v = Value('b',True)
     q = Queue()
     a = Process(target=waitForty,args=(v,q))
Exemplo n.º 6
0
 safeprint("Malformed bounty 11 (timeout error)")
 safeprint(
     addBounty(
         pickle.dumps(
             bounty.Bounty(('8.8.8.8', 8888),
                           "1LhPsd4ng3AXmVPzrLWprWFx351pW4HJm8",
                           10900,
                           timeout=1), 0)))
 testBounty(('8.8.8.8', 8888), "1LhPsd4ng3AXmVPzrLWprWFx351pW4HJm8", 10900,
            "Correctly formed bounty 2")
 testBounty(('8.8.8.8', 8888), "1MWSdYMKEpfWVxC6BGYARxsksaQuyEWzG5", 1480,
            "Correctly formed bounty 3")
 testBounty(('8.8.8.8', 8888), "1EgGfDetymjMzcQ1AEhHjHEyXHjnEavwgg", 10290,
            "Correctly formed bounty 4")
 safeprint(bounty.getBountyList())
 bounty.saveToFile()
 bounty.loadFromFile()
 safeprint(bounty.getBountyList())
 safeprint("3 bounties should follow")
 safeprint(
     bounty.getBounty(settings.config.get('charity'),
                      settings.config.get('propagate_factor')))
 safeprint(bounty.getBounty(False, 2))
 safeprint(bounty.getBounty(True, 2))
 settings.saveSettings()
 settings.loadSettings()
 saveToFile()
 getFromFile()
 if not (sys.version_info[0] < 3 and sys.platform == "win32"):
     safeprint("Test listener begin")
     v = Value('b', True)