Ejemplo n.º 1
0
 public Traits(
     long?autonomousSystemNumber,
     string?autonomousSystemOrganization,
     string?connectionType,
     string?domain,
     string?ipAddress,
     bool isAnonymous,
     bool isAnonymousProxy,
     bool isAnonymousVpn,
     bool isHostingProvider,
     bool isLegitimateProxy,
     bool isPublicProxy,
     bool isSatelliteProvider,
     bool isTorExitNode,
     string?isp,
     string?organization,
     string?userType,
     Network?network,
     double?staticIPScore,
     int?userCount
     ) : this(autonomousSystemNumber, autonomousSystemOrganization, connectionType, domain,
              ipAddress, isAnonymous, isAnonymousProxy, isAnonymousVpn, isHostingProvider,
              isLegitimateProxy, isPublicProxy, false, isSatelliteProvider, isTorExitNode,
              isp, organization, userType, network, staticIPScore, userCount)
 {
 }
Ejemplo n.º 2
0
        private object DecodeMapToType(
            Type expectedType,
            long offset,
            int size,
            out long outOffset,
            InjectableValues?injectables,
            Network?network
            )
        {
            var constructor = _typeAcivatorCreator.GetActivator(expectedType);
            var parameters  = constructor.DefaultParameters();

            for (var i = 0; i < size; i++)
            {
                var key = DecodeKey(offset, out offset);
                if (constructor.DeserializationParameters.ContainsKey(key))
                {
                    var param     = constructor.DeserializationParameters[key];
                    var paramType = param.ParameterType;
                    var value     = Decode(paramType, offset, out offset, injectables, network);
                    parameters[param.Position] = value;
                }
                else
                {
                    offset = NextValueOffset(offset, 1);
                }
            }

            SetInjectables(constructor, parameters, injectables);
            SetNetwork(constructor, parameters, network);
            SetAlwaysCreatedParams(constructor, parameters, injectables, network);

            outOffset = offset;
            return(constructor.Activator(parameters));
        }
Ejemplo n.º 3
0
 internal ComputeInstanceContainer(string name, Autosave?autosave, string gpu, Network?network, ComputeInstanceEnvironmentInfo environment, IReadOnlyList <BinaryData> services)
 {
     Name        = name;
     Autosave    = autosave;
     Gpu         = gpu;
     Network     = network;
     Environment = environment;
     Services    = services;
 }
Ejemplo n.º 4
0
 public ConnectionTypeResponse(
     [Parameter("connection_type")] string?connectionType,
     [Inject("ip_address")] string?ipAddress,
     [Network] Network?network = null
     )
 {
     ConnectionType = connectionType;
     IPAddress      = ipAddress;
     Network        = network;
 }
Ejemplo n.º 5
0
 public DomainResponse(
     string?domain,
     [Inject("ip_address")] string?ipAddress,
     [Network] Network?network = null
     )
 {
     Domain    = domain;
     IPAddress = ipAddress;
     Network   = network;
 }
Ejemplo n.º 6
0
 public override int Compare(Network?x, Network?y)
 {
     if (x !.Height == y !.Height)
     {
         return(0);
     }
     if (x !.Height > y !.Height)
     {
         return(1);
     }
     return(-1);
 }
Ejemplo n.º 7
0
 public AsnResponse(
     [Parameter("autonomous_system_number")] long?autonomousSystemNumber,
     [Parameter("autonomous_system_organization")] string?autonomousSystemOrganization,
     [Inject("ip_address")] string?ipAddress,
     [Network] Network?network = null
     )
 {
     AutonomousSystemNumber       = autonomousSystemNumber;
     AutonomousSystemOrganization = autonomousSystemOrganization;
     IPAddress = ipAddress;
     Network   = network;
 }
Ejemplo n.º 8
0
 public static Gen <OutputDescriptor> OutputDescriptorGen(Network?n = null) =>
 Gen.OneOf(
     AddrOutputDescriptorGen(n),
     RawOutputDescriptorGen(),
     PKOutputDescriptorGen(n),
     PKHOutputDescriptorGen(n),
     WPKHOutputDescriptorGen(n),
     ComboOutputDescriptorGen(n),
     MultisigOutputDescriptorGen(3, n),                     // top level multisig can not have more than 3 pubkeys.
     SHOutputDescriptorGen(n),
     WSHOutputDescriptorGen(n)
     );
Ejemplo n.º 9
0
 public AnonymousIPResponse(
     bool isAnonymous,
     bool isAnonymousVpn,
     bool isHostingProvider,
     bool isPublicProxy,
     bool isTorExitNode,
     string?ipAddress,
     Network?network
     ) : this(isAnonymous, isAnonymousVpn, isHostingProvider, isPublicProxy, false,
              isTorExitNode, ipAddress, network)
 {
 }
Ejemplo n.º 10
0
        public Traits(
            [Parameter("autonomous_system_number")] long?autonomousSystemNumber = null,
            [Parameter("autonomous_system_organization")] string?autonomousSystemOrganization = null,
            [Parameter("connection_type")] string?connectionType = null,
            string?domain = null,
            [Inject("ip_address")] string?ipAddress                       = null,
            [Parameter("is_anonymous")] bool isAnonymous                  = false,
            [Parameter("is_anonymous_proxy")] bool isAnonymousProxy       = false,
            [Parameter("is_anonymous_vpn")] bool isAnonymousVpn           = false,
            [Parameter("is_hosting_provider")] bool isHostingProvider     = false,
            [Parameter("is_legitimate_proxy")] bool isLegitimateProxy     = false,
            [Parameter("is_public_proxy")] bool isPublicProxy             = false,
            [Parameter("is_residential_proxy")] bool isResidentialProxy   = false,
            [Parameter("is_satellite_provider")] bool isSatelliteProvider = false,
            [Parameter("is_tor_exit_node")] bool isTorExitNode            = false,
            string?isp = null,
            [Parameter("mobile_country_code")] string?mobileCountryCode = null,
            [Parameter("mobile_network_code")] string?mobileNetworkCode = null,
            string?organization = null,
            [Parameter("user_type")] string?userType = null,
            [Network] Network?network = null,
            [Parameter("static_ip_score")] double?staticIPScore = null,
            [Parameter("user_count")] int?userCount             = null
            )
        {
            AutonomousSystemNumber       = autonomousSystemNumber;
            AutonomousSystemOrganization = autonomousSystemOrganization;
            ConnectionType = connectionType;
            Domain         = domain;
            IPAddress      = ipAddress;
            IsAnonymous    = isAnonymous;
#pragma warning disable 618
            IsAnonymousProxy = isAnonymousProxy;
#pragma warning restore 618
            IsAnonymousVpn     = isAnonymousVpn;
            IsHostingProvider  = isHostingProvider;
            IsLegitimateProxy  = isLegitimateProxy;
            IsPublicProxy      = isPublicProxy;
            IsResidentialProxy = isResidentialProxy;
#pragma warning disable 618
            IsSatelliteProvider = isSatelliteProvider;
#pragma warning restore 618
            IsTorExitNode     = isTorExitNode;
            Isp               = isp;
            MobileCountryCode = mobileCountryCode;
            MobileNetworkCode = mobileNetworkCode;
            Network           = network;
            Organization      = organization;
            StaticIPScore     = staticIPScore;
            UserCount         = userCount;
            UserType          = userType;
        }
Ejemplo n.º 11
0
        private T ResolveDataPointer <T>(int pointer, InjectableValues?injectables, Network?network) where T : class
        {
            var resolved = pointer - Metadata.NodeCount + Metadata.SearchTreeSize;

            if (resolved >= _database.Length)
            {
                throw new InvalidDatabaseException(
                          "The MaxMind Db file's search tree is corrupt: "
                          + "contains pointer larger than the database.");
            }

            return(Decoder.Decode <T>(resolved, out _, injectables, network));
        }
Ejemplo n.º 12
0
 public int Compare(Network?x, Network?y)
 {
     if (ReferenceEquals(x, y))
     {
         return(0);
     }
     if (ReferenceEquals(null, y))
     {
         return(1);
     }
     if (ReferenceEquals(null, x))
     {
         return(-1);
     }
     return(x.Height.CompareTo(y.Height));
 }
Ejemplo n.º 13
0
    /// <inheritdoc />
    public override Network?ReadJson(JsonReader reader, Type objectType, Network?existingValue, bool hasExistingValue, JsonSerializer serializer)
    {
        // check additional strings that are not checked by GetNetwork
        var networkString = ((string?)reader.Value)?.Trim();

        if (networkString is null)
        {
            throw new ArgumentNullException(nameof(networkString));
        }

        if ("regression".Equals(networkString, StringComparison.OrdinalIgnoreCase))
        {
            return(Network.RegTest);
        }

        return(Network.GetNetwork(networkString));
    }
Ejemplo n.º 14
0
 public AnonymousIPResponse(
     [Parameter("is_anonymous")] bool isAnonymous,
     [Parameter("is_anonymous_vpn")] bool isAnonymousVpn,
     [Parameter("is_hosting_provider")] bool isHostingProvider,
     [Parameter("is_public_proxy")] bool isPublicProxy,
     [Parameter("is_tor_exit_node")] bool isTorExitNode,
     [Inject("ip_address")] string?ipAddress,
     [Network] Network?network = null
     )
 {
     IsAnonymous       = isAnonymous;
     IsAnonymousVpn    = isAnonymousVpn;
     IsHostingProvider = isHostingProvider;
     IsPublicProxy     = isPublicProxy;
     IsTorExitNode     = isTorExitNode;
     IPAddress         = ipAddress;
     Network           = network;
 }
Ejemplo n.º 15
0
        /// <summary>
        ///     Decodes the array.
        /// </summary>
        /// <param name="expectedType"></param>
        /// <param name="size">The size.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="outOffset">The out offset.</param>
        /// <param name="injectables"></param>
        /// <param name="network"></param>
        /// <returns></returns>
        private object DecodeArray(Type expectedType, int size, long offset, out long outOffset,
                                   InjectableValues?injectables, Network?network)
        {
            var genericArgs   = expectedType.GetGenericArguments();
            var argType       = genericArgs.Length == 0 ? typeof(object) : genericArgs[0];
            var interfaceType = typeof(ICollection <>).MakeGenericType(argType);

            var array = _listActivatorCreator.GetActivator(expectedType)(size);

            for (var i = 0; i < size; i++)
            {
                var r = Decode(argType, offset, out offset, injectables, network);
                interfaceType.GetMethod("Add").Invoke(array, new[] { r });
            }

            outOffset = offset;
            return(array);
        }
Ejemplo n.º 16
0
 public IspResponse(
     [Parameter("autonomous_system_number")] long?autonomousSystemNumber,
     [Parameter("autonomous_system_organization")] string?autonomousSystemOrganization,
     string?isp,
     [Parameter("mobile_country_code")] string?mobileCountryCode,
     [Parameter("mobile_network_code")] string?mobileNetworkCode,
     string?organization,
     [Inject("ip_address")] string?ipAddress,
     [Network] Network?network = null
     )
 {
     AutonomousSystemNumber       = autonomousSystemNumber;
     AutonomousSystemOrganization = autonomousSystemOrganization;
     Isp = isp;
     MobileCountryCode = mobileCountryCode;
     MobileNetworkCode = mobileNetworkCode;
     Organization      = organization;
     IPAddress         = ipAddress;
     Network           = network;
 }
Ejemplo n.º 17
0
        private void SetAlwaysCreatedParams(
            TypeActivator constructor,
            object[] parameters,
            InjectableValues?injectables,
            Network?network
            )
        {
            foreach (var param in constructor.AlwaysCreatedParameters)
            {
                if (parameters[param.Position] != null)
                {
                    continue;
                }

                var activator   = _typeAcivatorCreator.GetActivator(param.ParameterType);
                var cstorParams = activator.DefaultParameters();
                SetInjectables(activator, cstorParams, injectables);
                SetNetwork(activator, cstorParams, network);
                SetAlwaysCreatedParams(activator, cstorParams, injectables, network);
                parameters[param.Position] = activator.Activator(cstorParams);
            }
        }
Ejemplo n.º 18
0
        private object DecodeMapToDictionary(Type expectedType, long offset, int size, out long outOffset,
                                             InjectableValues?injectables, Network?network)
        {
            var genericArgs = expectedType.GetGenericArguments();

            if (genericArgs.Length != 2)
            {
                throw new DeserializationException(
                          $"Unexpected number of Dictionary generic arguments: {genericArgs.Length}");
            }

            var obj = (IDictionary)_dictionaryActivatorCreator.GetActivator(expectedType)(size);

            for (var i = 0; i < size; i++)
            {
                var key   = Decode(genericArgs[0], offset, out offset);
                var value = Decode(genericArgs[1], offset, out offset, injectables, network);
                obj.Add(key, value);
            }

            outOffset = offset;

            return(obj);
        }
Ejemplo n.º 19
0
        /// <summary>
        ///     Decodes the map.
        /// </summary>
        /// <param name="expectedType"></param>
        /// <param name="offset">The offset.</param>
        /// <param name="size">The size.</param>
        /// <param name="outOffset">The out offset.</param>
        /// <param name="injectables"></param>
        /// <param name="network"></param>
        /// <returns></returns>
        private object DecodeMap(
            Type expectedType,
            long offset,
            int size,
            out long outOffset,
            InjectableValues?injectables,
            Network?network
            )
        {
            var objDictType = typeof(Dictionary <string, object>);

            if (!expectedType.GetTypeInfo().IsGenericType&& expectedType.IsAssignableFrom(objDictType))
            {
                expectedType = objDictType;
            }

            // Currently we don't support non-dict generic types
            if (expectedType.GetTypeInfo().IsGenericType)
            {
                return(DecodeMapToDictionary(expectedType, offset, size, out outOffset, injectables, network));
            }

            return(DecodeMapToType(expectedType, offset, size, out outOffset, injectables, network));
        }
Ejemplo n.º 20
0
    /// <inheritdoc />
    public override void WriteJson(JsonWriter writer, Network?value, JsonSerializer serializer)
    {
        var network = value?.ToString() ?? throw new ArgumentNullException(nameof(value));

        writer.WriteValue(network);
    }
 public NotSupportedNetworkException(Network?network)
     : base(network is null ? $"{nameof(Network)} wasn't specified." : $"{nameof(Network)} not supported: {network}.")
 {
 }
Ejemplo n.º 22
0
 private static Gen <PubKeyProvider> OriginPubKeyProviderGen(Network?n = null) =>
 from keyOrigin in CryptoGenerator.RootedKeyPath()
 from inner in Gen.OneOf(ConstPubKeyProviderGen(), HDPubKeyProviderGen(n))
 select PubKeyProvider.NewOrigin(keyOrigin, inner);
        private object Decode(Type expectedType, long offset, out long outOffset, InjectableValues?injectables = null, Network?network = null)
        {
            var type = CtrlData(offset, out var size, out offset);

            return(DecodeByType(expectedType, type, offset, size, out outOffset, injectables, network));
        }
Ejemplo n.º 24
0
 private static Gen <OutputDescriptor> WSHOutputDescriptorGen(Network?n = null) =>
 from inner in WSHInnerGen(20, n)
 select OutputDescriptor.NewWSH(inner);
        /// <summary>
        ///     Decodes the type of the by.
        /// </summary>
        /// <param name="expectedType"></param>
        /// <param name="type">The type.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="size">The size.</param>
        /// <param name="outOffset">The out offset</param>
        /// <param name="injectables"></param>
        /// <param name="network"></param>
        /// <returns></returns>
        /// <exception cref="Exception">Unable to handle type!</exception>
        private object DecodeByType(
            Type expectedType,
            ObjectType type,
            long offset,
            int size,
            out long outOffset,
            InjectableValues?injectables,
            Network?network
            )
        {
            outOffset = offset + size;

            switch (type)
            {
            case ObjectType.Pointer:
                var pointer = DecodePointer(offset, size, out offset);
                outOffset = offset;
                if (!_followPointers)
                {
                    return(pointer);
                }

                var result = Decode(expectedType, Convert.ToInt32(pointer), out _, injectables, network);
                return(result);

            case ObjectType.Map:
                return(DecodeMap(expectedType, offset, size, out outOffset, injectables, network));

            case ObjectType.Array:
                return(DecodeArray(expectedType, size, offset, out outOffset, injectables, network));

            case ObjectType.Boolean:
                outOffset = offset;
                return(DecodeBoolean(expectedType, size));

            case ObjectType.Utf8String:
                return(DecodeString(expectedType, offset, size));

            case ObjectType.Double:
                return(DecodeDouble(expectedType, offset, size));

            case ObjectType.Float:
                return(DecodeFloat(expectedType, offset, size));

            case ObjectType.Bytes:
                return(DecodeBytes(expectedType, offset, size));

            case ObjectType.Uint16:
                return(DecodeInteger(expectedType, offset, size));

            case ObjectType.Uint32:
                return(DecodeLong(expectedType, offset, size));

            case ObjectType.Int32:
                return(DecodeInteger(expectedType, offset, size));

            case ObjectType.Uint64:
                return(DecodeUInt64(expectedType, offset, size));

            case ObjectType.Uint128:
                return(DecodeBigInteger(expectedType, offset, size));

            default:
                throw new InvalidDatabaseException("Unable to handle type:" + type);
            }
        }
Ejemplo n.º 26
0
 private static Gen <OutputDescriptor> SHOutputDescriptorGen(Network?n = null) =>
 from inner in Gen.OneOf(InnerOutputDescriptorGen(15, n), WSHOutputDescriptorGen(n))
 select OutputDescriptor.NewSH(inner);
 /// <summary>
 ///     Decodes the object at the specified offset.
 /// </summary>
 /// <param name="offset">The offset.</param>
 /// <param name="outOffset">The out offset</param>
 /// <param name="injectables"></param>
 /// <param name="network"></param>
 /// <returns>An object containing the data read from the stream</returns>
 internal T Decode <T>(long offset, out long outOffset, InjectableValues?injectables = null, Network?network = default) where T : class
 {
     if (!(Decode(typeof(T), offset, out outOffset, injectables, network) is T decoded))
     {
         throw new InvalidDatabaseException("The value cannot be decoded as " + typeof(T));
     }
     return(decoded);
 }
Ejemplo n.º 28
0
 private static Gen <OutputDescriptor> InnerOutputDescriptorGen(int maxMultisigN, Network?n = null) =>
 Gen.OneOf(
     WPKHOutputDescriptorGen(n),
     WSHInnerGen(maxMultisigN, n)
     );
Ejemplo n.º 29
0
 private static void SetNetwork(TypeActivator constructor, object?[] parameters, Network?network)
 {
     foreach (var item in constructor.NetworkParameters)
     {
         // We don't check that we have a non-null network as we want to
         // allow enumeration to use the same models as normal lookups. We
         // cannot support the network field for enumeration as the objects
         // are cached.
         parameters[item.Position] = network;
     }
 }
Ejemplo n.º 30
0
 private static Gen <PubKeyProvider> PubKeyProviderGen(Network?n = null) =>
 Gen.OneOf(OriginPubKeyProviderGen(n), ConstPubKeyProviderGen(), HDPubKeyProviderGen(n));