Esempio n. 1
0
        private async Task <StunResult5389> BindingTestBaseAsync(IPEndPoint remote, bool notifyChanged, CancellationToken token)
        {
            BindingTestResult res;
            var test = new StunMessage5389 {
                StunMessageType = StunMessageType.BindingRequest
            };

            var(response1, _, local1) = await TestAsync(test, remote, remote, token);

            var mappedAddress1 = AttributeExtensions.GetXorMappedAddressAttribute(response1);
            var otherAddress   = AttributeExtensions.GetOtherAddressAttribute(response1);
            var local          = local1 == null ? null : new IPEndPoint(local1, LocalEndPoint.Port);

            if (response1 == null)
            {
                res = BindingTestResult.Fail;
            }
            else if (mappedAddress1 == null)
            {
                res = BindingTestResult.UnsupportedServer;
            }
            else
            {
                res = BindingTestResult.Success;
            }

            if (notifyChanged)
            {
                _bindingSubj.OnNext(res);
                PubSubj.OnNext(mappedAddress1);
            }
            LocalSubj.OnNext(LocalEndPoint);

            return(new StunResult5389
            {
                BindingTestResult = res,
                LocalEndPoint = local,
                PublicEndPoint = mappedAddress1,
                OtherEndPoint = otherAddress
            });
        }