Ejemplo n.º 1
0
        public InviteSession(LocalDrpPeer localDrpPeer)
        {
            _localDrpPeer = localDrpPeer;
            _localDrpPeer.CryptoLibrary.GenerateEcdh25519Keypair(out LocalInviteAckEcdhePrivateKey, out LocalInviteAckEcdhePublicKey);
            _localDrpPeer.CryptoLibrary.GenerateEcdh25519Keypair(out LocalDirectChannelEcdhePrivateKey, out LocalDirectChannelEcdhePublicKey);

            DirectChannelToken32 localDirectChannelToken32 = null;

            for (int i = 0; i < 100; i++)
            {
                localDirectChannelToken32 = new DirectChannelToken32 {
                    Token32 = (uint)localDrpPeer.Engine.InsecureRandom.Next()
                };
                var token16 = localDirectChannelToken32.Token16;
                if (localDrpPeer.Engine.InviteSessionsByToken16[token16] == null)
                {
                    localDrpPeer.Engine.InviteSessionsByToken16[token16] = this;
                    break;
                }
            }
            if (localDirectChannelToken32 == null)
            {
                throw new InsufficientResourcesException();
            }
            LocalDirectChannelToken32 = localDirectChannelToken32;
        }
Ejemplo n.º 2
0
        public DrpTester1(VisionChannel visionChannel, Action cb = null)
        {
            _visionChannel = visionChannel;
            _ep            = new DrpPeerEngine(new DrpPeerEngineConfiguration
            {
                InsecureRandomSeed                 = _insecureRandom.Next(),
                LocalPort                          = EpLocalPort,
                VisionChannel                      = visionChannel,
                VisionChannelSourceId              = "EP",
                ForcedPublicIpApiProviderResponse  = IPAddress.Loopback,
                SandboxModeOnly_NumberOfDimensions = NumberOfDimensions
            });
            var epLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(_ep.CryptoLibrary, NumberOfDimensions);

            _ep.BeginCreateLocalPeer(epLocalDrpPeerConfig, new DrpTesterPeerApp(_ep, epLocalDrpPeerConfig), (rpLocalPeer) =>
            {
                _a = new DrpPeerEngine(new DrpPeerEngineConfiguration
                {
                    InsecureRandomSeed = _insecureRandom.Next(),
                    VisionChannel      = visionChannel,
                    ForcedPublicIpApiProviderResponse  = IPAddress.Loopback,
                    VisionChannelSourceId              = "A",
                    SandboxModeOnly_NumberOfDimensions = NumberOfDimensions
                });
                var aLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(_a.CryptoLibrary, NumberOfDimensions);
                aLocalDrpPeerConfig.EntryPeerEndpoints = new[] { new IPEndPoint(IPAddress.Loopback, EpLocalPort) };

                _x = new DrpPeerEngine(new DrpPeerEngineConfiguration
                {
                    InsecureRandomSeed = _insecureRandom.Next(),
                    VisionChannel      = visionChannel,
                    ForcedPublicIpApiProviderResponse  = IPAddress.Loopback,
                    VisionChannelSourceId              = "X",
                    SandboxModeOnly_NumberOfDimensions = NumberOfDimensions
                });

                _retryx:
                var xLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(_x.CryptoLibrary, NumberOfDimensions);
                var distance_eptoa      = epLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_x.CryptoLibrary, aLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions);
                var distance_xtoa       = xLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_x.CryptoLibrary, aLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions);
                if (distance_xtoa.IsGreaterThan(distance_eptoa))
                {
                    goto _retryx;
                }
                xLocalDrpPeerConfig.EntryPeerEndpoints = new[] { new IPEndPoint(IPAddress.Loopback, EpLocalPort) };

                _n = new DrpPeerEngine(new DrpPeerEngineConfiguration
                {
                    InsecureRandomSeed = _insecureRandom.Next(),
                    VisionChannel      = visionChannel,
                    ForcedPublicIpApiProviderResponse  = IPAddress.Loopback,
                    VisionChannelSourceId              = "N",
                    SandboxModeOnly_NumberOfDimensions = NumberOfDimensions
                });


                _retryn:
                var nLocalDrpPeerConfig = LocalDrpPeerConfiguration.Create(_n.CryptoLibrary, NumberOfDimensions);
                var distance_ntoa       = nLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_n.CryptoLibrary, aLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions);
                if (distance_ntoa.IsGreaterThan(distance_xtoa))
                {
                    goto _retryn;
                }
                nLocalDrpPeerConfig.EntryPeerEndpoints = new[] { new IPEndPoint(IPAddress.Loopback, EpLocalPort) };

                var distance_xton  = xLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_n.CryptoLibrary, nLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions);
                var distance_epton = epLocalDrpPeerConfig.LocalPeerRegistrationId.GetDistanceTo(_n.CryptoLibrary, nLocalDrpPeerConfig.LocalPeerRegistrationId, NumberOfDimensions);
                if (distance_xton.IsGreaterThan(distance_epton))
                {
                    goto _retryn;
                }

                _xUser  = new DrpTesterPeerApp(_x, xLocalDrpPeerConfig);
                var swX = Stopwatch.StartNew();
                _x.BeginRegister(xLocalDrpPeerConfig, _xUser, (xLocalPeer) =>
                {
                    _visionChannel.Emit(_x.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName,
                                        AttentionLevel.guiActivity, $"registration complete in {(int)swX.Elapsed.TotalMilliseconds}ms");

                    _xLocalDrpPeer = xLocalPeer;
                    var swN        = Stopwatch.StartNew();
                    _n.BeginRegister(nLocalDrpPeerConfig, new DrpTesterPeerApp(_n, nLocalDrpPeerConfig), (nLocalPeer) =>
                    {
                        _visionChannel.Emit(_n.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName,
                                            AttentionLevel.guiActivity, $"registration complete in {(int)swN.Elapsed.TotalMilliseconds}ms");
                        _nLocalDrpPeer = nLocalPeer;
                        _aUser         = new DrpTesterPeerApp(_a, aLocalDrpPeerConfig);
                        var swA        = Stopwatch.StartNew();
                        _a.BeginRegister(aLocalDrpPeerConfig, _aUser, (aLocalPeer) =>
                        {
                            _visionChannel.Emit(_a.Configuration.VisionChannelSourceId, DrpTesterVisionChannelModuleName,
                                                AttentionLevel.guiActivity, $"registration complete in {(int)swA.Elapsed.TotalMilliseconds}ms");
                            _aLocalDrpPeer = aLocalPeer;
                            if (cb != null)
                            {
                                cb();
                            }
                        });
                    });
                });
            });
        }