public LidgrenPunchThroughFacilitator(LidgrenNetworkTransporter transporter,
                                              ICoroutineScheduler coroutineScheduler, LidgrenNatPunchClient natPunchClient, float connectionAttemptTimeout,
                                              ConnectionIdPool connectionIdPool)
        {
            _connectionIdPool           = connectionIdPool;
            _connectionRegistrationPool = new ObjectPool <ConnectionRegistration>(() => new ConnectionRegistration());

            _punchAttempts      = new Dictionary <NatPunchId, IPooledObject <ConnectionRegistration> >();
            _connectionAttempts = new ArrayDictionary <ConnectionId, IPooledObject <ConnectionRegistration> >(
                connectionIdPool.MaxConnectionIds);
            _activeConnections = new ArrayDictionary <ConnectionId, IPooledObject <ConnectionRegistration> >(
                connectionIdPool.MaxConnectionIds);

            _cancelledAttempts = new ConnectionId[_connectionIdPool.MaxConnectionIds];
            for (int i = 0; i < _cancelledAttempts.Length; i++)
            {
                _cancelledAttempts[i] = ConnectionId.NoConnection;
            }

            _transporter = transporter;
            _connectionAttemptTimeout = connectionAttemptTimeout;
            _connectionIdPool         = connectionIdPool;
            _natPunchClient           = natPunchClient;

            _transporter.RequestApproval    += PassRequestApproval;
            _transporter.OnConnectionOpened += OnConnectionOpened;
            _transporter.OnConnectionClosed += OnConnectionClosed;

            _cleanupRoutine = coroutineScheduler.Run(PunchTimeoutCleanup());
        }
Example #2
0
        public DefaultConnectionManager(IConnectionTransporter transporter, ConnectionIdPool connectionIdPool)
        {
            _transporter      = transporter;
            _connectionIdPool = connectionIdPool;
            _connections      = new ArrayDictionary <ConnectionId, ConnectionRegistration>(connectionIdPool.MaxConnectionIds);

            _transporter.RequestApproval    += PassRequestApproval;
            _transporter.OnConnectionOpened += OnConnectionOpened;
            _transporter.OnConnectionClosed += OnConnectionClosed;
        }