コード例 #1
0
ファイル: OutboundRuleManager.cs プロジェクト: tmutn/MantaMTA
        /// <summary>
        /// Gets the maximum amount of simultaneous connections to specified host.
        /// </summary>
        /// <param name="ipAddress">IP Address connecting from.</param>
        /// <param name="record">MXRecord of the destination.</param>
        /// <returns>Max number of connections.</returns>
        internal static int GetMaxConnectionsToDestination(VirtualMTA ipAddress, MXRecord record)
        {
            int mxPatternID = -1;
            OutboundRuleCollection rules = OutboundRuleManager.GetRules(record, ipAddress, out mxPatternID);

            for (int i = 0; i < rules.Count; i++)
            {
                if (rules[i].Type == OutboundRuleType.MaxConnections)
                {
                    int tmp = 0;
                    if (int.TryParse(rules[i].Value, out tmp))
                    {
                        return(tmp);
                    }
                    else
                    {
                        Logging.Error("Failed to get max connections for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " value wasn't valid [" + rules[i].Value + "], defaulting to 1");
                        return(1);
                    }
                }
            }

            Logging.Error("Failed to get max connections for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " defaulting to 1");
            return(1);
        }
コード例 #2
0
ファイル: OutboundRuleManager.cs プロジェクト: tmutn/MantaMTA
        /// <summary>
        /// Gets the MAX number of messages allowed to be sent through the connection.
        /// </summary>
        /// <param name="record">MX Record for the destination.</param>
        /// <param name="ipAddress">IPAddress that we are sending from.</param>
        /// <returns>Max number of messages per connection.</returns>
        public static int GetMaxMessagesPerConnection(MXRecord record, VirtualMTA ipAddress)
        {
            int mxPatternID = 0;
            OutboundRuleCollection rules = GetRules(record, ipAddress, out mxPatternID);

            for (int i = 0; i < rules.Count; i++)
            {
                if (rules[i].Type == OutboundRuleType.MaxMessagesConnection)
                {
                    int tmp = 0;
                    if (int.TryParse(rules[i].Value, out tmp))
                    {
                        return(tmp);
                    }
                    else
                    {
                        Logging.Error("Failed to get max messages per connection for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " value wasn't valid [" + rules[i].Value + "], defaulting to 1");
                        return(1);
                    }
                }
            }

            Logging.Error("Failed to get max messages per connection for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " defaulting to 1");
            return(1);
        }
コード例 #3
0
ファイル: OutboundRuleManager.cs プロジェクト: tmutn/MantaMTA
        /// <summary>
        /// Gets the maximum amount of messages to send per hour from each ip address to mx.
        /// </summary>
        /// <param name="ipAddress">Outbound IP address</param>
        /// <param name="record">MX Record of destination server.</param>
        /// <param name="mxPatternID">ID of the pattern used to identify the rule.</param>
        /// <returns>Maximum number of messages per hour or -1 for unlimited.</returns>
        public static int GetMaxMessagesDestinationHour(VirtualMTA ipAddress, MXRecord record, out int mxPatternID)
        {
            OutboundRuleCollection rules = OutboundRuleManager.GetRules(record, ipAddress, out mxPatternID);

            for (int i = 0; i < rules.Count; i++)
            {
                if (rules[i].Type == OutboundRuleType.MaxMessagesPerHour)
                {
                    int tmp = 0;
                    if (int.TryParse(rules[i].Value, out tmp))
                    {
                        return(tmp);
                    }
                    else
                    {
                        Logging.Error("Failed to get max messages per hour for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " value wasn't valid [" + rules[i].Value + "], defaulting to unlimited");
                        return(-1);
                    }
                }
            }

            Logging.Error("Failed to get max messages per hour for " + record.Host + " using " + ipAddress.IPAddress.ToString() + " defaulting to unlimited");
            return(-1);
        }