Esempio n. 1
0
    def __acceptIncomingConnection(self, svcName=False):
        """
        This method just gets the incoming connection, checks IP address
        and generates job. SSL/TLS handshake and execution of the remote call
        are made by Service._processInThread() (in another thread) so
        the service can accept other clients while another thread handling remote call

        :param str svcName=False: Name of a service if you use multiple
                                  services at the same time
        """
        sel = self.__getListeningSelector(svcName)
        while self.__alive:
            try:
                events = sel.select(timeout=10)
                if len(events) == 0:
                    return
                for key, event in events:
                    if event & selectors.EVENT_READ:
                        svcName = key.data
                        retVal = self.__listeningConnections[svcName][
                            "transport"].acceptConnection()
                        if not retVal["OK"]:
                            gLogger.warn(
                                "Error while accepting a connection: ",
                                retVal["Message"])
                            return
                        clientTransport = retVal["Value"]
            except socket.error:
                return
            self.__maxFD = max(self.__maxFD, clientTransport.oSocket.fileno())
            # Is it banned?
            clientIP = clientTransport.getRemoteAddress()[0]
            if clientIP in Registry.getBannedIPs():
                gLogger.warn("Client connected from banned ip %s" % clientIP)
                clientTransport.close()
                continue
            # Handle connection
            self.__stats.connectionStablished()
            self.__services[svcName].handleConnection(clientTransport)
            while self.__services[svcName].wantsThrottle:
                gLogger.warn("Sleeping as service requested throttling",
                             svcName)
                time.sleep(THROTTLE_SERVICE_SLEEP_SECONDS)
            # Renew context?
            now = time.time()
            renewed = False
            for svcName in self.__listeningConnections:
                tr = self.__listeningConnections[svcName]["transport"]
                if now - tr.latestServerRenewTime(
                ) > self.__services[svcName].getConfig().getContextLifeTime():
                    result = tr.renewServerContext()
                    if result["OK"]:
                        renewed = True
            if renewed:
                sel = self.__getListeningSelector()
Esempio n. 2
0
    def __acceptIncomingConnection(self, svcName=False):
        """
      This method just gets the incoming connection, checks IP address
      and generates job. SSL/TLS handshake and execution of the remote call
      are made by Service._processInThread() (in another thread) so
      the service can accept other clients while another thread handling remote call

      :param str svcName=False: Name of a service if you use multiple
                                services at the same time
    """
        sockets = self.__getListeningSocketsList(svcName)
        while self.__alive:
            try:
                inList, _outList, _exList = select.select(sockets, [], [], 10)
                if len(inList) == 0:
                    return
                for inSocket in inList:
                    for svcName in self.__listeningConnections:
                        if inSocket == self.__listeningConnections[svcName][
                                'socket']:
                            retVal = self.__listeningConnections[svcName][
                                'transport'].acceptConnection()
                            if not retVal['OK']:
                                gLogger.warn(
                                    "Error while accepting a connection: ",
                                    retVal['Message'])
                                return
                            clientTransport = retVal['Value']
            except socket.error:
                return
            self.__maxFD = max(self.__maxFD, clientTransport.oSocket.fileno())
            # Is it banned?
            clientIP = clientTransport.getRemoteAddress()[0]
            if clientIP in Registry.getBannedIPs():
                gLogger.warn("Client connected from banned ip %s" % clientIP)
                clientTransport.close()
                continue
            # Handle connection
            self.__stats.connectionStablished()
            self.__services[svcName].handleConnection(clientTransport)
            # Renew context?
            now = time.time()
            renewed = False
            for svcName in self.__listeningConnections:
                tr = self.__listeningConnections[svcName]['transport']
                if now - tr.latestServerRenewTime(
                ) > self.__services[svcName].getConfig().getContextLifeTime():
                    result = tr.renewServerContext()
                    if result['OK']:
                        renewed = True
            if renewed:
                sockets = self.__getListeningSocketsList()
Esempio n. 3
0
  def __acceptIncomingConnection(self, svcName=False):
    """
      This method just gets the incoming connection, checks IP address
      and generates job. SSL/TLS handshake and execution of the remote call
      are made by Service._processInThread() (in another thread) so
      the service can accept other clients while another thread handling remote call

      :param str svcName=False: Name of a service if you use multiple
                                services at the same time
    """
    sockets = self.__getListeningSocketsList(svcName)
    while self.__alive:
      try:
        inList, _outList, _exList = select.select(sockets, [], [], 10)
        if len(inList) == 0:
          return
        for inSocket in inList:
          for svcName in self.__listeningConnections:
            if inSocket == self.__listeningConnections[svcName]['socket']:
              retVal = self.__listeningConnections[svcName]['transport'].acceptConnection()
              if not retVal['OK']:
                gLogger.warn("Error while accepting a connection: ", retVal['Message'])
                return
              clientTransport = retVal['Value']
      except socket.error:
        return
      self.__maxFD = max(self.__maxFD, clientTransport.oSocket.fileno())
      # Is it banned?
      clientIP = clientTransport.getRemoteAddress()[0]
      if clientIP in Registry.getBannedIPs():
        gLogger.warn("Client connected from banned ip %s" % clientIP)
        clientTransport.close()
        continue
      # Handle connection
      self.__stats.connectionStablished()
      self.__services[svcName].handleConnection(clientTransport)
      # Renew context?
      now = time.time()
      renewed = False
      for svcName in self.__listeningConnections:
        tr = self.__listeningConnections[svcName]['transport']
        if now - tr.latestServerRenewTime() > self.__services[svcName].getConfig().getContextLifeTime():
          result = tr.renewServerContext()
          if result['OK']:
            renewed = True
      if renewed:
        sockets = self.__getListeningSocketsList()
Esempio n. 4
0
 def __acceptIncomingConnection(self, svcName=False):
     sockets = self.__getListeningSocketsList(svcName)
     while self.__alive:
         try:
             inList, outList, exList = select.select(sockets, [], [], 10)
             if len(inList) == 0:
                 return
             for inSocket in inList:
                 for svcName in self.__listeningConnections:
                     if inSocket == self.__listeningConnections[svcName][
                             'socket']:
                         retVal = self.__listeningConnections[svcName][
                             'transport'].acceptConnection()
                         if not retVal['OK']:
                             gLogger.warn(
                                 "Error while accepting a connection: ",
                                 retVal['Message'])
                             return
                         clientTransport = retVal['Value']
         except socket.error:
             return
         self.__maxFD = max(self.__maxFD, clientTransport.oSocket.fileno())
         #Is it banned?
         clientIP = clientTransport.getRemoteAddress()[0]
         if clientIP in Registry.getBannedIPs():
             gLogger.warn("Client connected from banned ip %s" % clientIP)
             clientTransport.close()
             continue
         #Handle connection
         self.__stats.connectionStablished()
         self.__services[svcName].handleConnection(clientTransport)
         #Renew context?
         now = time.time()
         renewed = False
         for svcName in self.__listeningConnections:
             tr = self.__listeningConnections[svcName]['transport']
             if now - tr.latestServerRenewTime(
             ) > self.__services[svcName].getConfig().getContextLifeTime():
                 result = tr.renewServerContext()
                 if result['OK']:
                     renewed = True
         if renewed:
             sockets = self.__getListeningSocketsList()
Esempio n. 5
0
 def __acceptIncomingConnection( self, svcName = False ):
   sockets = self.__getListeningSocketsList( svcName )
   while self.__alive:
     try:
       inList, _outList, _exList = select.select( sockets, [], [], 10 )
       if len( inList ) == 0:
         return
       for inSocket in inList:
         for svcName in self.__listeningConnections:
           if inSocket == self.__listeningConnections[ svcName ][ 'socket' ]:
             retVal = self.__listeningConnections[ svcName ][ 'transport' ].acceptConnection()
             if not retVal[ 'OK' ]:
               gLogger.warn( "Error while accepting a connection: ", retVal[ 'Message' ] )
               return
             clientTransport = retVal[ 'Value' ]
     except socket.error:
       return
     self.__maxFD = max( self.__maxFD, clientTransport.oSocket.fileno() )
     #Is it banned?
     clientIP = clientTransport.getRemoteAddress()[0]
     if clientIP in Registry.getBannedIPs():
       gLogger.warn( "Client connected from banned ip %s" % clientIP )
       clientTransport.close()
       continue
     #Handle connection
     self.__stats.connectionStablished()
     self.__services[ svcName ].handleConnection( clientTransport )
     #Renew context?
     now = time.time()
     renewed = False
     for svcName in self.__listeningConnections:
       tr = self.__listeningConnections[ svcName ][ 'transport' ]
       if now - tr.latestServerRenewTime() > self.__services[ svcName ].getConfig().getContextLifeTime():
         result = tr.renewServerContext()
         if result[ 'OK' ]:
           renewed = True
     if renewed:
       sockets = self.__getListeningSocketsList()