Exemple #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()
Exemple #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()
Exemple #3
0
def main():
    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)
    queue = Queue()
    live = Value('b',True)
    ear = listener(settings.config['port'],settings.config['outbound'],queue,live,settings.config['server'])
    ear.daemon = True
    ear.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)
    live.value = False
Exemple #4
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()
Exemple #5
0
        requestBounties((get_lan_ip(),44566))
        sleep(4)
        requestBounties(("localhost",44566))
        sleep(4)
        safeprint(bounty.getBountyList())
    #TODO move test incoming_bounty here
    #TODO move test incoming_bounty here
    safeprint("Sending term signal")
    v.value = False
    try:
        requestPeerlist(("localhost",44566))
    except:
        safeprint("This was supposed to fail. Good job")

if __name__ == "__main__": #pragma: no cover
    settings.setup()
    settings.config['port'] = 44566
    testBounty(('8.8.8.8',8888),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Correctly formed bounty")
    testBounty(('8.8.8.8',-1),"1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9",1440,"Malformed bounty 1 (ip failure)")
    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")
Exemple #6
0
        sleep(4)
        requestBounties(("localhost", 44566))
        sleep(4)
        safeprint(bounty.getBountyList())
    #TODO move test incoming_bounty here
    #TODO move test incoming_bounty here
    safeprint("Sending term signal")
    v.value = False
    try:
        requestPeerlist(("localhost", 44566))
    except:
        safeprint("This was supposed to fail. Good job")


if __name__ == "__main__":  #pragma: no cover
    settings.setup()
    settings.config['port'] = 44566
    testBounty(('8.8.8.8', 8888), "1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9", 1440,
               "Correctly formed bounty")
    testBounty(('8.8.8.8', -1), "1JTGcHS3GMhBGLcFRuHLk6Gww4ZEDmP7u9", 1440,
               "Malformed bounty 1 (ip failure)")
    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)")