Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

matrix-org / synapse / 4532

23 Sep 2019 - 19:39 coverage decreased (-49.7%) to 17.596%
4532

Pull #6079

buildkite

Richard van der Hoff
update changelog
Pull Request #6079: Add submit_url response parameter to msisdn /requestToken

359 of 12986 branches covered (2.76%)

Branch coverage included in aggregate %.

0 of 7 new or added lines in 1 file covered. (0.0%)

18869 existing lines in 281 files now uncovered.

8809 of 39116 relevant lines covered (22.52%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.68
/synapse/config/ratelimiting.py
1
# Copyright 2014-2016 OpenMarket Ltd
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
from ._base import Config
1×
16

17

18
class RateLimitConfig(object):
1×
19
    def __init__(self, config, defaults={"per_second": 0.17, "burst_count": 3.0}):
1×
UNCOV
20
        self.per_second = config.get("per_second", defaults["per_second"])
!
UNCOV
21
        self.burst_count = config.get("burst_count", defaults["burst_count"])
!
22

23

24
class FederationRateLimitConfig(object):
1×
25
    _items_and_default = {
1×
26
        "window_size": 1000,
27
        "sleep_limit": 10,
28
        "sleep_delay": 500,
29
        "reject_limit": 50,
30
        "concurrent": 3,
31
    }
32

33
    def __init__(self, **kwargs):
1×
UNCOV
34
        for i in self._items_and_default.keys():
Branches [[0, 33], [0, 35]] missed. !
UNCOV
35
            setattr(self, i, kwargs.get(i) or self._items_and_default[i])
!
36

37

38
class RatelimitConfig(Config):
1×
39
    def read_config(self, config, **kwargs):
1×
40

41
        # Load the new-style messages config if it exists. Otherwise fall back
42
        # to the old method.
UNCOV
43
        if "rc_message" in config:
Branches [[0, 44], [0, 48]] missed. !
44
            self.rc_message = RateLimitConfig(
!
45
                config["rc_message"], defaults={"per_second": 0.2, "burst_count": 10.0}
46
            )
47
        else:
UNCOV
48
            self.rc_message = RateLimitConfig(
!
49
                {
50
                    "per_second": config.get("rc_messages_per_second", 0.2),
51
                    "burst_count": config.get("rc_message_burst_count", 10.0),
52
                }
53
            )
54

55
        # Load the new-style federation config, if it exists. Otherwise, fall
56
        # back to the old method.
UNCOV
57
        if "rc_federation" in config:
Branches [[0, 58], [0, 60]] missed. !
UNCOV
58
            self.rc_federation = FederationRateLimitConfig(**config["rc_federation"])
!
59
        else:
60
            self.rc_federation = FederationRateLimitConfig(
!
61
                **{
62
                    "window_size": config.get("federation_rc_window_size"),
63
                    "sleep_limit": config.get("federation_rc_sleep_limit"),
64
                    "sleep_delay": config.get("federation_rc_sleep_delay"),
65
                    "reject_limit": config.get("federation_rc_reject_limit"),
66
                    "concurrent": config.get("federation_rc_concurrent"),
67
                }
68
            )
69

UNCOV
70
        self.rc_registration = RateLimitConfig(config.get("rc_registration", {}))
!
71

UNCOV
72
        rc_login_config = config.get("rc_login", {})
!
UNCOV
73
        self.rc_login_address = RateLimitConfig(rc_login_config.get("address", {}))
!
UNCOV
74
        self.rc_login_account = RateLimitConfig(rc_login_config.get("account", {}))
!
UNCOV
75
        self.rc_login_failed_attempts = RateLimitConfig(
!
76
            rc_login_config.get("failed_attempts", {})
77
        )
78

UNCOV
79
        self.federation_rr_transactions_per_room_per_second = config.get(
!
80
            "federation_rr_transactions_per_room_per_second", 50
81
        )
82

UNCOV
83
        rc_admin_redaction = config.get("rc_admin_redaction")
!
UNCOV
84
        if rc_admin_redaction:
Branches [[0, 85], [0, 87]] missed. !
85
            self.rc_admin_redaction = RateLimitConfig(rc_admin_redaction)
!
86
        else:
UNCOV
87
            self.rc_admin_redaction = None
!
88

89
    def generate_config_section(self, **kwargs):
1×
90
        return """\
!
91
        ## Ratelimiting ##
92

93
        # Ratelimiting settings for client actions (registration, login, messaging).
94
        #
95
        # Each ratelimiting configuration is made of two parameters:
96
        #   - per_second: number of requests a client can send per second.
97
        #   - burst_count: number of requests a client can send before being throttled.
98
        #
99
        # Synapse currently uses the following configurations:
100
        #   - one for messages that ratelimits sending based on the account the client
101
        #     is using
102
        #   - one for registration that ratelimits registration requests based on the
103
        #     client's IP address.
104
        #   - one for login that ratelimits login requests based on the client's IP
105
        #     address.
106
        #   - one for login that ratelimits login requests based on the account the
107
        #     client is attempting to log into.
108
        #   - one for login that ratelimits login requests based on the account the
109
        #     client is attempting to log into, based on the amount of failed login
110
        #     attempts for this account.
111
        #   - one for ratelimiting redactions by room admins. If this is not explicitly
112
        #     set then it uses the same ratelimiting as per rc_message. This is useful
113
        #     to allow room admins to deal with abuse quickly.
114
        #
115
        # The defaults are as shown below.
116
        #
117
        #rc_message:
118
        #  per_second: 0.2
119
        #  burst_count: 10
120
        #
121
        #rc_registration:
122
        #  per_second: 0.17
123
        #  burst_count: 3
124
        #
125
        #rc_login:
126
        #  address:
127
        #    per_second: 0.17
128
        #    burst_count: 3
129
        #  account:
130
        #    per_second: 0.17
131
        #    burst_count: 3
132
        #  failed_attempts:
133
        #    per_second: 0.17
134
        #    burst_count: 3
135
        #
136
        #rc_admin_redaction:
137
        #  per_second: 1
138
        #  burst_count: 50
139

140

141
        # Ratelimiting settings for incoming federation
142
        #
143
        # The rc_federation configuration is made up of the following settings:
144
        #   - window_size: window size in milliseconds
145
        #   - sleep_limit: number of federation requests from a single server in
146
        #     a window before the server will delay processing the request.
147
        #   - sleep_delay: duration in milliseconds to delay processing events
148
        #     from remote servers by if they go over the sleep limit.
149
        #   - reject_limit: maximum number of concurrent federation requests
150
        #     allowed from a single server
151
        #   - concurrent: number of federation requests to concurrently process
152
        #     from a single server
153
        #
154
        # The defaults are as shown below.
155
        #
156
        #rc_federation:
157
        #  window_size: 1000
158
        #  sleep_limit: 10
159
        #  sleep_delay: 500
160
        #  reject_limit: 50
161
        #  concurrent: 3
162

163
        # Target outgoing federation transaction frequency for sending read-receipts,
164
        # per-room.
165
        #
166
        # If we end up trying to send out more read-receipts, they will get buffered up
167
        # into fewer transactions.
168
        #
169
        #federation_rr_transactions_per_room_per_second: 50
170
        """
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC