'Called by protocol at first connect. This adds a not-yet
authenticated session using an ever-increasing counter for
sessid.
Args:
session (PortalSession): The Session connecting.
Notes:
We implement a throttling mechanism here to limit the speed at
which new connections are accepted - this is both a stop
against DoS attacks as well as helps using the Dummyrunner
tester with a large number of connector dummies.'

def connect(self, session):

    global _CONNECTION_QUEUE
    if session:
        self.latest_sessid += 1
        session.sessid = self.latest_sessid
        session.server_connected = False
        _CONNECTION_QUEUE.appendleft(session)
        if (len(_CONNECTION_QUEUE) > 1):
            session.data_out(text=[[('%s    DoS    protection    is    active.    You    are    queued    to    connect    in    %g    seconds    ...' % (settings.SERVERNAME, (len(_CONNECTION_QUEUE) * _MIN_TIME_BETWEEN_CONNECTS)))], {}])
    now = time.time()
    if (((now - self.connection_last) < _MIN_TIME_BETWEEN_CONNECTS) or (not self.portal.amp_protocol)):
        if ((not session) or (not self.connection_task)):
            self.connection_task = reactor.callLater(_MIN_TIME_BETWEEN_CONNECTS, self.connect, None)
        self.connection_last = now
        return
    elif (not session):
        if _CONNECTION_QUEUE:
            self.connection_task = reactor.callLater(_MIN_TIME_BETWEEN_CONNECTS, self.connect, None)
        else:
            self.connection_task = None
    self.connection_last = now
    if _CONNECTION_QUEUE:
        session = _CONNECTION_QUEUE.pop()
        sessdata = session.get_sync_data()
        self[session.sessid] = session
        session.server_connected = True
        self.portal.amp_protocol.send_AdminPortal2Server(session, operation=PCONN, sessiondata=sessdata)
