示例#1
0
def init(auto_start=True):
    global _State
    if _State != '':
        dhnio.Dprint(4, 'transport_q2q.init WARNING already called and current _State is '+_State)
        return succeed(_State)

    _State = 'init'
        
    dhnio.Dprint(4, 'transport_q2q.init')

    resultDefer = Deferred()

    if settings.getQ2Qusername().strip() == '' or settings.getQ2Qhost().strip() == '':
        dhnio.Dprint(6, 'transport_q2q.init  want to erase local data base in ' + settings.Q2QDir())
        clear_local_db(settings.Q2QDir())

    dhnvertex.init(q2qdir = settings.Q2QDir(),
                   logFunc = dhnio.Dprint,
                   receiveNotifyFunc = receive_status_func,
                   sentNotifyFunc = sent_status_func,
                   tempFileFunc = tmpfile.make,)

    if auto_start:
        _State = 'auto'
        auto(resultDefer)
    else:
        resultDefer.callback(_State)
       
    return resultDefer
示例#2
0
def auto(resultDefer):
    dhnio.Dprint(4, 'transport_q2q.auto')
    
    def receive_started(resultDefer):
        global _State
        _State = 'ready'
        resultDefer.callback(x)
    
    def do_receive(resultDefer):
        global _State
        _State = 'receive'
        d = dhnvertex.receive()
        d.addCallback(lambda x: receive_started(resultDefer))
        d.addErrback(resultDefer.errback)
        
    def do_register(resultDefer):
        global _State
        _State = 'register'
        
        d = install()
        d.addCallback(lambda x: do_receive(resultDefer))
        d.addErrback(resultDefer.errback)
        
    if settings.getQ2Qusername().strip() == '' or settings.getQ2Qhost().strip() == '':
        do_register(resultDefer)
    else:
        do_receive(resultDefer)
        
    return resultDefer