Esempio n. 1
0
def _locationConnect( localUserName, localRSAKey, localPublicIP,
        remotePublicKey, remoteLocation, reactor, callback=None ) :
    sslContext = makeSSLContext( localUserName, localRSAKey )
    directLocations = remoteLocation.directLocations
    routedLocations = remoteLocation.routedLocations
    remotePublicIP = remoteLocation.publicIP
    maybePublic = False
    for dloc in directLocations :
        if remotePublicIP == dloc.addr[0] :
            maybePublic = True
            break
    samePublic = (localPublicIP == remotePublicIP)
    connOps = {}
    def doCancel() :
        for connOp in connOps.keys() :
            connOp.cancel()
        connOps.clear()
    def onConnect( connOp, sslConn ) :
        del connOps[connOp]
        if sslConn is None :
            if not connOps :
                op.notify( None )
            return
        doCancel()
        op.notify( sslConn )
    def doDirectConnect( dloc ) :
        connOp = _directConnect( sslContext, remotePublicKey,
                dloc, reactor, lambda x : onConnect(connOp,x) )
        connOps[connOp] = 1
    def doRoutedConnect( rloc ) :
        connOp = _routedConnect( sslContext, remotePublicKey,
                rloc, reactor, lambda x : onConnect(connOp,x) )
        connOps[connOp] = 1
    def onTimer() :
        del connOps[timerOp]
        for rloc in routedLocations : doRoutedConnect( rloc )
        if not connOps :
            op.notify( None )
    for dloc in directLocations : doDirectConnect( dloc )
    routedDelay = 0
    if (maybePublic or samePublic) and (len(connOps) > 0) :
        routedDelay = 1
    timerOp = reactor.callLater( routedDelay, onTimer )
    connOps[timerOp] = 1
    op = AsyncOp( callback, doCancel )
    return op
Esempio n. 2
0
    def __init__(self, userName, rsaKey, updateLevelStore, dhtClient,
                 nodeTable, reactor):
        self.userName = userName
        self.rsaKey = rsaKey
        self.updateLevelStore = updateLevelStore
        self.dhtClient = dhtClient
        self.nodeTable = nodeTable
        self.reactor = reactor
        self.state = self.STOPPED
        self.closeCallback = None
        self.sslContext = makeSSLContext(userName, rsaKey)
        self.incomingCallback = None

        self.initOp = None
        self.tcpListener = None
        self.routerList = None
        self.publicIP = None
        self.localIP = None
        self.localPort = None
        self.publishOp = None
        self.otherOps = {}
Esempio n. 3
0
    def __init__( self, userName, rsaKey, updateLevelStore,
            dhtClient, nodeTable, reactor ) :
        self.userName = userName
        self.rsaKey = rsaKey
        self.updateLevelStore = updateLevelStore
        self.dhtClient = dhtClient
        self.nodeTable = nodeTable
        self.reactor = reactor
        self.state = self.STOPPED
        self.closeCallback = None
        self.sslContext = makeSSLContext( userName, rsaKey )
        self.incomingCallback = None

        self.initOp = None
        self.tcpListener = None
        self.routerList = None
        self.publicIP = None
        self.localIP = None
        self.localPort = None
        self.publishOp = None
        self.otherOps = {}